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/services/gles2/BUILD.gn b/services/gles2/BUILD.gn
index 2caa74e..43e8cc0 100644
--- a/services/gles2/BUILD.gn
+++ b/services/gles2/BUILD.gn
@@ -6,7 +6,7 @@
source_set("gles2") {
visibility = [
- "//shell:lib", # For android
+ "//shell:parent_lib", # For android
"//services/native_viewport:*",
]
@@ -15,10 +15,10 @@
"command_buffer_driver.h",
"command_buffer_impl.cc",
"command_buffer_impl.h",
- "gpu_state.cc",
- "gpu_state.h",
"gpu_impl.cc",
"gpu_impl.h",
+ "gpu_state.cc",
+ "gpu_state.h",
]
public_deps = [
diff --git a/shell/BUILD.gn b/shell/BUILD.gn
index 5827d86..20788fb 100644
--- a/shell/BUILD.gn
+++ b/shell/BUILD.gn
@@ -44,7 +44,7 @@
if (!mojo_use_prebuilt_mojo_shell) {
shell_common_deps = [
- ":lib",
+ ":parent_lib",
"//base",
"//base/allocator",
"//build/config/sanitizers:deps",
@@ -90,7 +90,6 @@
]
deps = [
- # TODO(vtl): Reduce these dependencies (probably mostly in :lib).
":child_controller_bindings",
":common_lib",
"//base",
@@ -106,6 +105,8 @@
# Files used both by mojo_shell and mojo_shell_child (and tests).
source_set("common_lib") {
sources = [
+ "child_switches.cc",
+ "child_switches.h",
"init.cc",
"init.h",
]
@@ -116,12 +117,10 @@
public_deps = [
":native_application_support",
- ":switches",
]
}
-# TODO(vtl): Split this target into parent/child/common libs.
-source_set("lib") {
+source_set("parent_lib") {
sources = [
"background_application_loader.cc",
"background_application_loader.h",
@@ -137,6 +136,8 @@
"in_process_native_runner.h",
"out_of_process_native_runner.cc",
"out_of_process_native_runner.h",
+ "switches.cc",
+ "switches.h",
"task_runners.cc",
"task_runners.h",
"tracer.cc",
@@ -228,19 +229,6 @@
check_includes = false
}
-# TODO(vtl): This should just be a part of :common_lib, but stuff in
-# application_manager uses it. We should fix that.
-source_set("switches") {
- sources = [
- "switches.cc",
- "switches.h",
- ]
-
- deps = [
- "//base",
- ]
-}
-
if (is_android) {
generate_jni("jni_headers") {
sources = [
@@ -395,7 +383,7 @@
]
deps = [
- ":lib",
+ ":parent_lib",
"//base",
"//base:i18n",
"//base/test:test_support",
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_;
diff --git a/shell/child_main.cc b/shell/child_main.cc
index 1e3834e..33b35e4 100644
--- a/shell/child_main.cc
+++ b/shell/child_main.cc
@@ -27,9 +27,9 @@
#include "mojo/edk/embedder/simple_platform_support.h"
#include "mojo/public/cpp/system/core.h"
#include "shell/child_controller.mojom.h"
+#include "shell/child_switches.h"
#include "shell/init.h"
#include "shell/native_application_support.h"
-#include "shell/switches.h"
namespace shell {
namespace {
diff --git a/shell/child_process_host.cc b/shell/child_process_host.cc
index 8660162..0a027ae 100644
--- a/shell/child_process_host.cc
+++ b/shell/child_process_host.cc
@@ -18,8 +18,8 @@
#include "base/task_runner_util.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/public/cpp/system/message_pipe.h"
+#include "shell/child_switches.h"
#include "shell/context.h"
-#include "shell/switches.h"
#include "shell/task_runners.h"
namespace shell {
diff --git a/shell/child_switches.cc b/shell/child_switches.cc
new file mode 100644
index 0000000..5dc85ae
--- /dev/null
+++ b/shell/child_switches.cc
@@ -0,0 +1,12 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "shell/child_switches.h"
+
+namespace switches {
+
+// Used only by the child process. Not for user use.
+const char kChildProcess[] = "child-process";
+
+} // namespace switches
diff --git a/shell/child_switches.h b/shell/child_switches.h
new file mode 100644
index 0000000..6f65fdc
--- /dev/null
+++ b/shell/child_switches.h
@@ -0,0 +1,18 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Switches recognized by the child process (not really for user use).
+
+#ifndef SHELL_CHILD_SWITCHES_H_
+#define SHELL_CHILD_SWITCHES_H_
+
+namespace switches {
+
+// All switches in alphabetical order. The switches should be documented
+// alongside the definition of their values in the .cc file.
+extern const char kChildProcess[];
+
+} // namespace switches
+
+#endif // SHELL_CHILD_SWITCHES_H_
diff --git a/shell/context.cc b/shell/context.cc
index 331efa1..b50916f 100644
--- a/shell/context.cc
+++ b/shell/context.cc
@@ -61,6 +61,16 @@
DISALLOW_COPY_AND_ASSIGN(Setup);
};
+ApplicationManager::Options MakeApplicationManagerOptions() {
+ ApplicationManager::Options options;
+ options.disable_cache = base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableCache);
+ options.predictable_app_filenames =
+ base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kPredictableAppFilenames);
+ return options;
+}
+
bool ConfigureURLMappings(const base::CommandLine& command_line,
Context* context) {
URLResolver* resolver = context->url_resolver();
@@ -201,7 +211,9 @@
} // namespace
-Context::Context(Tracer* tracer) : tracer_(tracer), application_manager_(this) {
+Context::Context(Tracer* tracer)
+ : tracer_(tracer),
+ application_manager_(MakeApplicationManagerOptions(), this) {
DCHECK(!base::MessageLoop::current());
// By default assume that the local apps reside alongside the shell.
@@ -289,9 +301,6 @@
runner_factory.reset(new InProcessNativeRunnerFactory(this));
application_manager_.set_blocking_pool(task_runners_->blocking_pool());
application_manager_.set_native_runner_factory(runner_factory.Pass());
- application_manager_.set_disable_cache(
- base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableCache));
InitContentHandlers(&application_manager_, command_line);
InitNativeOptions(&application_manager_, command_line);
diff --git a/shell/native_runner_unittest.cc b/shell/native_runner_unittest.cc
index fe792c9..a04d4c8 100644
--- a/shell/native_runner_unittest.cc
+++ b/shell/native_runner_unittest.cc
@@ -56,7 +56,8 @@
class NativeApplicationLoaderTest : public testing::Test,
public ApplicationManager::Delegate {
public:
- NativeApplicationLoaderTest() : application_manager_(this) {}
+ NativeApplicationLoaderTest()
+ : application_manager_(ApplicationManager::Options(), this) {}
~NativeApplicationLoaderTest() override {}
void SetUp() override {
context_.Init();
diff --git a/shell/shell_test_main.cc b/shell/shell_test_main.cc
index 6df2215..cad352b 100644
--- a/shell/shell_test_main.cc
+++ b/shell/shell_test_main.cc
@@ -8,7 +8,7 @@
#include "base/logging.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"
-#include "shell/switches.h"
+#include "shell/child_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
int main(int argc, char** argv) {
diff --git a/shell/switches.cc b/shell/switches.cc
index 1b1e291..6aee104 100644
--- a/shell/switches.cc
+++ b/shell/switches.cc
@@ -21,9 +21,6 @@
// --args-for='mojo:wget http://www.google.com'
const char kArgsFor[] = "args-for";
-// Used only by the child process. Not for user use.
-const char kChildProcess[] = "child-process";
-
// Comma separated list like:
// text/html,mojo:html_viewer,application/bravo,https://abarth.com/bravo
const char kContentHandlers[] = "content-handlers";
@@ -84,7 +81,6 @@
// Switches valid for the main process (i.e., that the user may pass in).
const char* kSwitchArray[] = {kV,
kArgsFor,
- // |kChildProcess| not for user use.
kContentHandlers,
kCPUProfile,
kDisableCache,
diff --git a/shell/switches.h b/shell/switches.h
index a1ff4c4..1e5508a 100644
--- a/shell/switches.h
+++ b/shell/switches.h
@@ -11,10 +11,9 @@
namespace switches {
// All switches in alphabetical order. The switches should be documented
-// alongside the definition of their values in the .cc file and, as needed,
-// in mojo_main's Usage() function.
+// alongside the definition of their values in the .cc file and, as needed, in
+// desktop/main.cc's Usage() function.
extern const char kArgsFor[];
-extern const char kChildProcess[];
extern const char kContentHandlers[];
extern const char kCPUProfile[];
extern const char kDisableCache[];