Shell: switches cleanup.

* Make //shell/application_manager stop depending on //shell:switches.
* Add child_switches.{cc,h}. That goes in :common_lib (since obviously
  both the parent and child need them.
* switches.{cc,h} can go in :parent_lib (formerly known as :lib),
  instead of being in a target of its own.

R=yzshen@chromium.org

Review URL: https://codereview.chromium.org/1131953006
diff --git a/shell/application_manager/BUILD.gn b/shell/application_manager/BUILD.gn
index e5ebb5d..9a510b7 100644
--- a/shell/application_manager/BUILD.gn
+++ b/shell/application_manager/BUILD.gn
@@ -44,7 +44,6 @@
     "//mojo/environment:chromium",
     "//mojo/services/content_handler/public/interfaces",
     "//shell:native_application_support",
-    "//shell:switches",
   ]
 }
 
diff --git a/shell/application_manager/application_manager.cc b/shell/application_manager/application_manager.cc
index 3b11289..680c501 100644
--- a/shell/application_manager/application_manager.cc
+++ b/shell/application_manager/application_manager.cc
@@ -94,10 +94,11 @@
          manager_->identity_to_shell_impl_.end();
 }
 
-ApplicationManager::ApplicationManager(Delegate* delegate)
-    : delegate_(delegate),
+ApplicationManager::ApplicationManager(const Options& options,
+                                       Delegate* delegate)
+    : options_(options),
+      delegate_(delegate),
       blocking_pool_(nullptr),
-      disable_cache_(false),
       weak_ptr_factory_(this) {
 }
 
@@ -186,7 +187,8 @@
                      &url_response_disk_cache_);
   }
 
-  new NetworkFetcher(disable_cache_, resolved_url, network_service_.get(),
+  new NetworkFetcher(options_.disable_cache, options_.predictable_app_filenames,
+                     resolved_url, network_service_.get(),
                      url_response_disk_cache_.get(), callback);
 }
 
diff --git a/shell/application_manager/application_manager.h b/shell/application_manager/application_manager.h
index 69bffd1..662e9b9 100644
--- a/shell/application_manager/application_manager.h
+++ b/shell/application_manager/application_manager.h
@@ -34,6 +34,13 @@
 
 class ApplicationManager {
  public:
+  struct Options {
+    Options() : disable_cache(false), predictable_app_filenames(false) {}
+
+    bool disable_cache;
+    bool predictable_app_filenames;
+  };
+
   class Delegate {
    public:
     // Gives the delegate a chance to apply any mappings for the specified url.
@@ -65,7 +72,7 @@
     DISALLOW_COPY_AND_ASSIGN(TestAPI);
   };
 
-  explicit ApplicationManager(Delegate* delegate);
+  ApplicationManager(const Options& options, Delegate* delegate);
   ~ApplicationManager();
 
   // Loads a service if necessary and establishes a new client connection.
@@ -103,7 +110,6 @@
   void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) {
     blocking_pool_ = blocking_pool;
   }
-  void set_disable_cache(bool disable_cache) { disable_cache_ = disable_cache; }
   // Sets a Loader to be used for a specific url.
   void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url);
   // Sets a Loader to be used for a specific url scheme.
@@ -217,6 +223,7 @@
 
   void CleanupRunner(NativeRunner* runner);
 
+  const Options options_;
   Delegate* const delegate_;
   // Loader management.
   // Loaders are chosen in the order they are listed here.
@@ -236,7 +243,6 @@
   mojo::URLResponseDiskCachePtr url_response_disk_cache_;
   MimeTypeToURLMap mime_type_to_url_;
   ScopedVector<NativeRunner> native_runners_;
-  bool disable_cache_;
   base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_;
 
   DISALLOW_COPY_AND_ASSIGN(ApplicationManager);
diff --git a/shell/application_manager/application_manager_unittest.cc b/shell/application_manager/application_manager_unittest.cc
index 9b14fcb..b346681 100644
--- a/shell/application_manager/application_manager_unittest.cc
+++ b/shell/application_manager/application_manager_unittest.cc
@@ -460,7 +460,8 @@
   ~ApplicationManagerTest() override {}
 
   void SetUp() override {
-    application_manager_.reset(new ApplicationManager(&test_delegate_));
+    application_manager_.reset(
+        new ApplicationManager(ApplicationManager::Options(), &test_delegate_));
     test_loader_ = new TestApplicationLoader;
     test_loader_->set_context(&context_);
     application_manager_->set_default_loader(
@@ -507,7 +508,7 @@
 
 // Confirm that no arguments are sent to an application by default.
 TEST_F(ApplicationManagerTest, NoArgs) {
-  ApplicationManager am(&test_delegate_);
+  ApplicationManager am(ApplicationManager::Options(), &test_delegate_);
   GURL test_url("test:test");
   TestApplicationLoader* loader = new TestApplicationLoader;
   loader->set_context(&context_);
@@ -523,7 +524,7 @@
 
 // Confirm that arguments are sent to an application.
 TEST_F(ApplicationManagerTest, Args) {
-  ApplicationManager am(&test_delegate_);
+  ApplicationManager am(ApplicationManager::Options(), &test_delegate_);
   GURL test_url("test:test");
   std::vector<std::string> args;
   args.push_back("test_arg1");
@@ -545,7 +546,7 @@
 
 // Confirm that arguments are aggregated through mappings.
 TEST_F(ApplicationManagerTest, ArgsAndMapping) {
-  ApplicationManager am(&test_delegate_);
+  ApplicationManager am(ApplicationManager::Options(), &test_delegate_);
   GURL test_url("test:test");
   GURL test_url2("test:test2");
   test_delegate_.AddMapping(test_url, test_url2);
@@ -603,7 +604,7 @@
 
 TEST_F(ApplicationManagerTest, Deletes) {
   {
-    ApplicationManager am(&test_delegate_);
+    ApplicationManager am(ApplicationManager::Options(), &test_delegate_);
     TestApplicationLoader* default_loader = new TestApplicationLoader;
     default_loader->set_context(&context_);
     TestApplicationLoader* url_loader1 = new TestApplicationLoader;
diff --git a/shell/application_manager/network_fetcher.cc b/shell/application_manager/network_fetcher.cc
index ca5fdd8..683e576 100644
--- a/shell/application_manager/network_fetcher.cc
+++ b/shell/application_manager/network_fetcher.cc
@@ -22,18 +22,19 @@
 #include "mojo/common/data_pipe_utils.h"
 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
 #include "shell/application_manager/data_pipe_peek.h"
-#include "shell/switches.h"
 
 namespace shell {
 
 NetworkFetcher::NetworkFetcher(
     bool disable_cache,
+    bool predictable_app_filenames,
     const GURL& url,
     mojo::NetworkService* network_service,
     mojo::URLResponseDiskCache* url_response_disk_cache,
     const FetchCallback& loader_callback)
     : Fetcher(loader_callback),
-      disable_cache_(false),
+      disable_cache_(disable_cache),
+      predictable_app_filenames_(predictable_app_filenames),
       url_(url),
       url_response_disk_cache_(url_response_disk_cache),
       weak_ptr_factory_(this) {
@@ -159,8 +160,7 @@
   if (success) {
     path_ = base::FilePath(std::string(
         reinterpret_cast<char*>(&path_as_array.front()), path_as_array.size()));
-    if (base::CommandLine::ForCurrentProcess()->HasSwitch(
-            switches::kPredictableAppFilenames)) {
+    if (predictable_app_filenames_) {
       // The copy completed, now move to $TMP/$APP_ID.mojo before the dlopen.
       base::FilePath new_path;
       if (RenameToAppId(url_, path_, &new_path)) {
diff --git a/shell/application_manager/network_fetcher.h b/shell/application_manager/network_fetcher.h
index c512b70..ca7428a 100644
--- a/shell/application_manager/network_fetcher.h
+++ b/shell/application_manager/network_fetcher.h
@@ -23,6 +23,7 @@
 class NetworkFetcher : public Fetcher {
  public:
   NetworkFetcher(bool disable_cache,
+                 bool predictable_app_filenames,
                  const GURL& url,
                  mojo::NetworkService* network_service,
                  mojo::URLResponseDiskCache* url_response_disk_cache,
@@ -72,7 +73,8 @@
 
   void OnLoadComplete(mojo::URLResponsePtr response);
 
-  bool disable_cache_;
+  const bool disable_cache_;
+  const bool predictable_app_filenames_;
   const GURL url_;
   mojo::URLResponseDiskCache* url_response_disk_cache_;
   mojo::URLLoaderPtr url_loader_;