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

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

Issue 1743473002: Change Mojo URLs to structured names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@18collapse
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
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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/process/process_info.h" 20 #include "base/process/process_info.h"
21 #include "base/run_loop.h" 21 #include "base/run_loop.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_split.h" 23 #include "base/strings/string_split.h"
24 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
25 #include "base/strings/sys_string_conversions.h"
25 #include "base/threading/sequenced_worker_pool.h" 26 #include "base/threading/sequenced_worker_pool.h"
26 #include "base/trace_event/trace_event.h" 27 #include "base/trace_event/trace_event.h"
27 #include "build/build_config.h" 28 #include "build/build_config.h"
28 #include "components/tracing/tracing_switches.h" 29 #include "components/tracing/tracing_switches.h"
29 #include "mojo/edk/embedder/embedder.h" 30 #include "mojo/edk/embedder/embedder.h"
30 #include "mojo/public/cpp/bindings/strong_binding.h" 31 #include "mojo/public/cpp/bindings/strong_binding.h"
31 #include "mojo/services/package_manager/package_manager.h" 32 #include "mojo/services/package_manager/package_manager.h"
32 #include "mojo/services/tracing/public/cpp/switches.h" 33 #include "mojo/services/tracing/public/cpp/switches.h"
33 #include "mojo/services/tracing/public/cpp/trace_provider_impl.h" 34 #include "mojo/services/tracing/public/cpp/trace_provider_impl.h"
34 #include "mojo/services/tracing/public/cpp/tracing_impl.h" 35 #include "mojo/services/tracing/public/cpp/tracing_impl.h"
35 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" 36 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h"
36 #include "mojo/shell/application_loader.h" 37 #include "mojo/shell/application_loader.h"
37 #include "mojo/shell/connect_params.h" 38 #include "mojo/shell/connect_params.h"
38 #include "mojo/shell/runner/host/in_process_native_runner.h" 39 #include "mojo/shell/runner/host/in_process_native_runner.h"
39 #include "mojo/shell/runner/host/out_of_process_native_runner.h" 40 #include "mojo/shell/runner/host/out_of_process_native_runner.h"
40 #include "mojo/shell/standalone/tracer.h" 41 #include "mojo/shell/standalone/tracer.h"
41 #include "mojo/shell/switches.h" 42 #include "mojo/shell/switches.h"
42 #include "mojo/util/filename_util.h" 43 #include "mojo/util/filename_util.h"
43 #include "url/gurl.h"
44 44
45 namespace mojo { 45 namespace mojo {
46 namespace shell { 46 namespace shell {
47 namespace { 47 namespace {
48 48
49 // Used to ensure we only init once. 49 // Used to ensure we only init once.
50 class Setup { 50 class Setup {
51 public: 51 public:
52 Setup() { edk::Init(); } 52 Setup() { edk::Init(); }
53 53
(...skipping 29 matching lines...) Expand all
83 const size_t kMaxBlockingPoolThreads = 3; 83 const size_t kMaxBlockingPoolThreads = 3;
84 84
85 scoped_ptr<base::Thread> CreateIOThread(const char* name) { 85 scoped_ptr<base::Thread> CreateIOThread(const char* name) {
86 scoped_ptr<base::Thread> thread(new base::Thread(name)); 86 scoped_ptr<base::Thread> thread(new base::Thread(name));
87 base::Thread::Options options; 87 base::Thread::Options options;
88 options.message_loop_type = base::MessageLoop::TYPE_IO; 88 options.message_loop_type = base::MessageLoop::TYPE_IO;
89 thread->StartWithOptions(options); 89 thread->StartWithOptions(options);
90 return thread; 90 return thread;
91 } 91 }
92 92
93 void OnInstanceQuit(const GURL& url, const Identity& identity) { 93 void OnInstanceQuit(const std::string& name, const Identity& identity) {
94 if (url == identity.url()) 94 if (name == identity.name())
95 base::MessageLoop::current()->QuitWhenIdle(); 95 base::MessageLoop::current()->QuitWhenIdle();
96 } 96 }
97 97
98 } // namespace 98 } // namespace
99 99
100 Context::InitParams::InitParams() {} 100 Context::InitParams::InitParams() {}
101 Context::InitParams::~InitParams() {} 101 Context::InitParams::~InitParams() {}
102 102
103 Context::Context() 103 Context::Context()
104 : io_thread_(CreateIOThread("io_thread")), 104 : io_thread_(CreateIOThread("io_thread")),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } else { 149 } else {
150 NativeRunnerDelegate* native_runner_delegate = init_params ? 150 NativeRunnerDelegate* native_runner_delegate = init_params ?
151 init_params->native_runner_delegate : nullptr; 151 init_params->native_runner_delegate : nullptr;
152 runner_factory.reset(new OutOfProcessNativeRunnerFactory( 152 runner_factory.reset(new OutOfProcessNativeRunnerFactory(
153 blocking_pool_.get(), native_runner_delegate)); 153 blocking_pool_.get(), native_runner_delegate));
154 } 154 }
155 scoped_ptr<package_manager::ApplicationCatalogStore> app_catalog; 155 scoped_ptr<package_manager::ApplicationCatalogStore> app_catalog;
156 if (init_params) 156 if (init_params)
157 app_catalog = std::move(init_params->app_catalog); 157 app_catalog = std::move(init_params->app_catalog);
158 application_manager_.reset(new ApplicationManager(std::move(runner_factory), 158 application_manager_.reset(new ApplicationManager(std::move(runner_factory),
159 blocking_pool_.get(), true, 159 blocking_pool_.get(),
160 std::move(app_catalog))); 160 std::move(app_catalog)));
161 161
162 shell::mojom::InterfaceProviderPtr tracing_remote_interfaces; 162 shell::mojom::InterfaceProviderPtr tracing_remote_interfaces;
163 shell::mojom::InterfaceProviderPtr tracing_local_interfaces; 163 shell::mojom::InterfaceProviderPtr tracing_local_interfaces;
164 new TracingInterfaceProvider(&tracer_, GetProxy(&tracing_local_interfaces)); 164 new TracingInterfaceProvider(&tracer_, GetProxy(&tracing_local_interfaces));
165 165
166 scoped_ptr<ConnectParams> params(new ConnectParams); 166 scoped_ptr<ConnectParams> params(new ConnectParams);
167 params->set_source(CreateShellIdentity()); 167 params->set_source(CreateShellIdentity());
168 params->set_target(Identity(GURL("mojo:tracing"), std::string(), 168 params->set_target(Identity("mojo:tracing", std::string(),
169 mojom::Connector::kUserInherit)); 169 mojom::Connector::kUserInherit));
170 params->set_remote_interfaces(GetProxy(&tracing_remote_interfaces)); 170 params->set_remote_interfaces(GetProxy(&tracing_remote_interfaces));
171 params->set_local_interfaces(std::move(tracing_local_interfaces)); 171 params->set_local_interfaces(std::move(tracing_local_interfaces));
172 application_manager_->Connect(std::move(params)); 172 application_manager_->Connect(std::move(params));
173 173
174 if (command_line.HasSwitch(tracing::kTraceStartup)) { 174 if (command_line.HasSwitch(tracing::kTraceStartup)) {
175 tracing::TraceCollectorPtr coordinator; 175 tracing::TraceCollectorPtr coordinator;
176 auto coordinator_request = GetProxy(&coordinator); 176 auto coordinator_request = GetProxy(&coordinator);
177 tracing_remote_interfaces->GetInterface( 177 tracing_remote_interfaces->GetInterface(
178 tracing::TraceCollector::Name_, coordinator_request.PassMessagePipe()); 178 tracing::TraceCollector::Name_, coordinator_request.PassMessagePipe());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 212
213 void Context::OnShutdownComplete() { 213 void Context::OnShutdownComplete() {
214 DCHECK_EQ(base::MessageLoop::current()->task_runner(), shell_runner_); 214 DCHECK_EQ(base::MessageLoop::current()->task_runner(), shell_runner_);
215 base::MessageLoop::current()->QuitWhenIdle(); 215 base::MessageLoop::current()->QuitWhenIdle();
216 } 216 }
217 217
218 void Context::RunCommandLineApplication() { 218 void Context::RunCommandLineApplication() {
219 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 219 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
220 base::CommandLine::StringVector args = command_line->GetArgs(); 220 base::CommandLine::StringVector args = command_line->GetArgs();
221 for (size_t i = 0; i < args.size(); ++i) { 221 for (size_t i = 0; i < args.size(); ++i) {
222 GURL possible_app(args[i]); 222 std::string possible_app = base::SysWideToUTF8(args[i]);
223 if (possible_app.SchemeIs("mojo")) { 223 if (GetNameType(possible_app) == "mojo") {
224 Run(possible_app); 224 Run(possible_app);
225 break; 225 break;
226 } 226 }
227 } 227 }
228 } 228 }
229 229
230 void Context::Run(const GURL& url) { 230 void Context::Run(const std::string& name) {
231 application_manager_->SetInstanceQuitCallback( 231 application_manager_->SetInstanceQuitCallback(
232 base::Bind(&OnInstanceQuit, url)); 232 base::Bind(&OnInstanceQuit, name));
233 233
234 shell::mojom::InterfaceProviderPtr remote_interfaces; 234 shell::mojom::InterfaceProviderPtr remote_interfaces;
235 shell::mojom::InterfaceProviderPtr local_interfaces; 235 shell::mojom::InterfaceProviderPtr local_interfaces;
236 236
237 scoped_ptr<ConnectParams> params(new ConnectParams); 237 scoped_ptr<ConnectParams> params(new ConnectParams);
238 params->set_source(CreateShellIdentity()); 238 params->set_source(CreateShellIdentity());
239 params->set_target(Identity(url, std::string(), mojom::Connector::kUserRoot)); 239 params->set_target(Identity(name, std::string(),
240 mojom::Connector::kUserRoot));
240 params->set_remote_interfaces(GetProxy(&remote_interfaces)); 241 params->set_remote_interfaces(GetProxy(&remote_interfaces));
241 params->set_local_interfaces(std::move(local_interfaces)); 242 params->set_local_interfaces(std::move(local_interfaces));
242 application_manager_->Connect(std::move(params)); 243 application_manager_->Connect(std::move(params));
243 } 244 }
244 245
245 } // namespace shell 246 } // namespace shell
246 } // namespace mojo 247 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698