Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: mojo/shell/standalone/context.cc

Issue 1701933004: Remove the old package manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@am2
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/shell/standalone/context.h ('k') | mojo/shell/standalone/register_local_aliases.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/shell/standalone/context.h" 5 #include "mojo/shell/standalone/context.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 15 matching lines...) Expand all
26 #include "build/build_config.h" 26 #include "build/build_config.h"
27 #include "components/tracing/tracing_switches.h" 27 #include "components/tracing/tracing_switches.h"
28 #include "mojo/edk/embedder/embedder.h" 28 #include "mojo/edk/embedder/embedder.h"
29 #include "mojo/public/cpp/bindings/strong_binding.h" 29 #include "mojo/public/cpp/bindings/strong_binding.h"
30 #include "mojo/services/tracing/public/cpp/switches.h" 30 #include "mojo/services/tracing/public/cpp/switches.h"
31 #include "mojo/services/tracing/public/cpp/trace_provider_impl.h" 31 #include "mojo/services/tracing/public/cpp/trace_provider_impl.h"
32 #include "mojo/services/tracing/public/cpp/tracing_impl.h" 32 #include "mojo/services/tracing/public/cpp/tracing_impl.h"
33 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" 33 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h"
34 #include "mojo/shell/application_loader.h" 34 #include "mojo/shell/application_loader.h"
35 #include "mojo/shell/connect_to_application_params.h" 35 #include "mojo/shell/connect_to_application_params.h"
36 #include "mojo/shell/package_manager/package_manager_impl.h"
37 #include "mojo/shell/query_util.h"
38 #include "mojo/shell/runner/host/in_process_native_runner.h" 36 #include "mojo/shell/runner/host/in_process_native_runner.h"
39 #include "mojo/shell/runner/host/out_of_process_native_runner.h" 37 #include "mojo/shell/runner/host/out_of_process_native_runner.h"
40 #include "mojo/shell/standalone/register_local_aliases.h"
41 #include "mojo/shell/standalone/switches.h" 38 #include "mojo/shell/standalone/switches.h"
42 #include "mojo/shell/standalone/tracer.h" 39 #include "mojo/shell/standalone/tracer.h"
43 #include "mojo/shell/switches.h" 40 #include "mojo/shell/switches.h"
44 #include "mojo/util/filename_util.h" 41 #include "mojo/util/filename_util.h"
45 #include "url/gurl.h" 42 #include "url/gurl.h"
46 43
47 namespace mojo { 44 namespace mojo {
48 namespace shell { 45 namespace shell {
49 namespace { 46 namespace {
50 47
51 // Used to ensure we only init once. 48 // Used to ensure we only init once.
52 class Setup { 49 class Setup {
53 public: 50 public:
54 Setup() { edk::Init(); } 51 Setup() { edk::Init(); }
55 52
56 ~Setup() {} 53 ~Setup() {}
57 54
58 private: 55 private:
59 DISALLOW_COPY_AND_ASSIGN(Setup); 56 DISALLOW_COPY_AND_ASSIGN(Setup);
60 }; 57 };
61 58
62 void InitContentHandlers(PackageManagerImpl* manager,
63 const base::CommandLine& command_line) {
64 // Default content handlers.
65 manager->RegisterContentHandler("application/javascript",
66 GURL("mojo:html_viewer"));
67 manager->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer"));
68 manager->RegisterContentHandler("image/gif", GURL("mojo:html_viewer"));
69 manager->RegisterContentHandler("image/jpeg", GURL("mojo:html_viewer"));
70 manager->RegisterContentHandler("image/png", GURL("mojo:html_viewer"));
71 manager->RegisterContentHandler("text/css", GURL("mojo:html_viewer"));
72 manager->RegisterContentHandler("text/html", GURL("mojo:html_viewer"));
73 manager->RegisterContentHandler("text/plain", GURL("mojo:html_viewer"));
74
75 // Command-line-specified content handlers.
76 std::string handlers_spec =
77 command_line.GetSwitchValueASCII(switches::kContentHandlers);
78 if (handlers_spec.empty())
79 return;
80
81 #if defined(OS_ANDROID)
82 // TODO(eseidel): On Android we pass command line arguments is via the
83 // 'parameters' key on the intent, which we specify during 'am shell start'
84 // via --esa, however that expects comma-separated values and says:
85 // am shell --help:
86 // [--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
87 // (to embed a comma into a string escape it using "\,")
88 // Whatever takes 'parameters' and constructs a CommandLine is failing to
89 // un-escape the commas, we need to move this fix to that file.
90 base::ReplaceSubstringsAfterOffset(&handlers_spec, 0, "\\,", ",");
91 #endif
92
93 std::vector<std::string> parts = base::SplitString(
94 handlers_spec, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
95 if (parts.size() % 2 != 0) {
96 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers
97 << ": must be a comma-separated list of mimetype/url pairs."
98 << handlers_spec;
99 return;
100 }
101
102 for (size_t i = 0; i < parts.size(); i += 2) {
103 GURL url(parts[i + 1]);
104 if (!url.is_valid()) {
105 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers
106 << ": '" << parts[i + 1] << "' is not a valid URL.";
107 return;
108 }
109 // TODO(eseidel): We should also validate that the mimetype is valid
110 // net/base/mime_util.h could do this, but we don't want to depend on net.
111 manager->RegisterContentHandler(parts[i], url);
112 }
113 }
114
115 class TracingInterfaceProvider : public shell::mojom::InterfaceProvider { 59 class TracingInterfaceProvider : public shell::mojom::InterfaceProvider {
116 public: 60 public:
117 TracingInterfaceProvider(Tracer* tracer, 61 TracingInterfaceProvider(Tracer* tracer,
118 shell::mojom::InterfaceProviderRequest request) 62 shell::mojom::InterfaceProviderRequest request)
119 : tracer_(tracer), binding_(this, std::move(request)) {} 63 : tracer_(tracer), binding_(this, std::move(request)) {}
120 ~TracingInterfaceProvider() override {} 64 ~TracingInterfaceProvider() override {}
121 65
122 // shell::mojom::InterfaceProvider: 66 // shell::mojom::InterfaceProvider:
123 void GetInterface(const mojo::String& interface_name, 67 void GetInterface(const mojo::String& interface_name,
124 ScopedMessagePipeHandle client_handle) override { 68 ScopedMessagePipeHandle client_handle) override {
125 if (tracer_ && interface_name == tracing::TraceProvider::Name_) { 69 if (tracer_ && interface_name == tracing::TraceProvider::Name_) {
126 tracer_->ConnectToProvider( 70 tracer_->ConnectToProvider(
127 MakeRequest<tracing::TraceProvider>(std::move(client_handle))); 71 MakeRequest<tracing::TraceProvider>(std::move(client_handle)));
128 } 72 }
129 } 73 }
130 74
131 private: 75 private:
132 Tracer* tracer_; 76 Tracer* tracer_;
133 StrongBinding<shell::mojom::InterfaceProvider> binding_; 77 StrongBinding<shell::mojom::InterfaceProvider> binding_;
134 78
135 DISALLOW_COPY_AND_ASSIGN(TracingInterfaceProvider); 79 DISALLOW_COPY_AND_ASSIGN(TracingInterfaceProvider);
136 }; 80 };
137 81
138 } // namespace 82 } // namespace
139 83
140 Context::Context() 84 Context::Context() : main_entry_time_(base::Time::Now()) {}
141 : package_manager_(nullptr), main_entry_time_(base::Time::Now()) {}
142 85
143 Context::~Context() { 86 Context::~Context() {
144 DCHECK(!base::MessageLoop::current()); 87 DCHECK(!base::MessageLoop::current());
145 } 88 }
146 89
147 // static 90 // static
148 void Context::EnsureEmbedderIsInitialized() { 91 void Context::EnsureEmbedderIsInitialized() {
149 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; 92 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER;
150 setup.Get(); 93 setup.Get();
151 } 94 }
(...skipping 11 matching lines...) Expand all
163 "mojo_runner.trace"); 106 "mojo_runner.trace");
164 } 107 }
165 108
166 EnsureEmbedderIsInitialized(); 109 EnsureEmbedderIsInitialized();
167 task_runners_.reset( 110 task_runners_.reset(
168 new TaskRunners(base::MessageLoop::current()->task_runner())); 111 new TaskRunners(base::MessageLoop::current()->task_runner()));
169 112
170 // TODO(vtl): This should be MASTER, not NONE. 113 // TODO(vtl): This should be MASTER, not NONE.
171 edk::InitIPCSupport(this, task_runners_->io_runner()); 114 edk::InitIPCSupport(this, task_runners_->io_runner());
172 115
173 package_manager_ = new PackageManagerImpl(
174 shell_file_root, task_runners_->blocking_pool(), nullptr);
175 InitContentHandlers(package_manager_, command_line);
176
177 RegisterLocalAliases(package_manager_);
178
179 scoped_ptr<NativeRunnerFactory> runner_factory; 116 scoped_ptr<NativeRunnerFactory> runner_factory;
180 if (command_line.HasSwitch(switches::kSingleProcess)) { 117 if (command_line.HasSwitch(switches::kSingleProcess)) {
181 #if defined(COMPONENT_BUILD) 118 #if defined(COMPONENT_BUILD)
182 LOG(ERROR) << "Running Mojo in single process component build, which isn't " 119 LOG(ERROR) << "Running Mojo in single process component build, which isn't "
183 << "supported because statics in apps interact. Use static build" 120 << "supported because statics in apps interact. Use static build"
184 << " or don't pass --single-process."; 121 << " or don't pass --single-process.";
185 #endif 122 #endif
186 runner_factory.reset( 123 runner_factory.reset(
187 new InProcessNativeRunnerFactory(task_runners_->blocking_pool())); 124 new InProcessNativeRunnerFactory(task_runners_->blocking_pool()));
188 } else { 125 } else {
189 runner_factory.reset( 126 runner_factory.reset(
190 new OutOfProcessNativeRunnerFactory(task_runners_->blocking_pool())); 127 new OutOfProcessNativeRunnerFactory(task_runners_->blocking_pool()));
191 } 128 }
192 application_manager_.reset(new ApplicationManager( 129 application_manager_.reset(new ApplicationManager(
193 make_scoped_ptr(package_manager_), std::move(runner_factory), 130 std::move(runner_factory), task_runners_->blocking_pool(), true));
194 task_runners_->blocking_pool(), true));
195 131
196 shell::mojom::InterfaceProviderPtr tracing_remote_interfaces; 132 shell::mojom::InterfaceProviderPtr tracing_remote_interfaces;
197 shell::mojom::InterfaceProviderPtr tracing_local_interfaces; 133 shell::mojom::InterfaceProviderPtr tracing_local_interfaces;
198 new TracingInterfaceProvider(&tracer_, GetProxy(&tracing_local_interfaces)); 134 new TracingInterfaceProvider(&tracer_, GetProxy(&tracing_local_interfaces));
199 135
200 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); 136 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
201 params->set_source(Identity(GURL("mojo:shell"), std::string(), 137 params->set_source(Identity(GURL("mojo:shell"), std::string(),
202 GetPermissiveCapabilityFilter())); 138 GetPermissiveCapabilityFilter()));
203 params->SetTarget(Identity(GURL("mojo:tracing"), std::string(), 139 params->SetTarget(Identity(GURL("mojo:tracing"), std::string(),
204 GetPermissiveCapabilityFilter())); 140 GetPermissiveCapabilityFilter()));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 base::MessageLoop::current()->QuitWhenIdle(); 230 base::MessageLoop::current()->QuitWhenIdle();
295 } else { 231 } else {
296 app_complete_callback_.Run(); 232 app_complete_callback_.Run();
297 } 233 }
298 } 234 }
299 } 235 }
300 } 236 }
301 237
302 } // namespace shell 238 } // namespace shell
303 } // namespace mojo 239 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/standalone/context.h ('k') | mojo/shell/standalone/register_local_aliases.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698