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

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, 9 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/desktop/launcher_process.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>
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/utf_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"
39 #include "mojo/shell/public/cpp/names.h"
38 #include "mojo/shell/runner/host/in_process_native_runner.h" 40 #include "mojo/shell/runner/host/in_process_native_runner.h"
39 #include "mojo/shell/runner/host/out_of_process_native_runner.h" 41 #include "mojo/shell/runner/host/out_of_process_native_runner.h"
40 #include "mojo/shell/standalone/tracer.h" 42 #include "mojo/shell/standalone/tracer.h"
41 #include "mojo/shell/switches.h" 43 #include "mojo/shell/switches.h"
42 #include "mojo/util/filename_util.h" 44 #include "mojo/util/filename_util.h"
43 #include "url/gurl.h"
44 45
45 namespace mojo { 46 namespace mojo {
46 namespace shell { 47 namespace shell {
47 namespace { 48 namespace {
48 49
49 // Used to ensure we only init once. 50 // Used to ensure we only init once.
50 class Setup { 51 class Setup {
51 public: 52 public:
52 Setup() { edk::Init(); } 53 Setup() { edk::Init(); }
53 54
(...skipping 29 matching lines...) Expand all
83 const size_t kMaxBlockingPoolThreads = 3; 84 const size_t kMaxBlockingPoolThreads = 3;
84 85
85 scoped_ptr<base::Thread> CreateIOThread(const char* name) { 86 scoped_ptr<base::Thread> CreateIOThread(const char* name) {
86 scoped_ptr<base::Thread> thread(new base::Thread(name)); 87 scoped_ptr<base::Thread> thread(new base::Thread(name));
87 base::Thread::Options options; 88 base::Thread::Options options;
88 options.message_loop_type = base::MessageLoop::TYPE_IO; 89 options.message_loop_type = base::MessageLoop::TYPE_IO;
89 thread->StartWithOptions(options); 90 thread->StartWithOptions(options);
90 return thread; 91 return thread;
91 } 92 }
92 93
93 void OnInstanceQuit(const GURL& url, const Identity& identity) { 94 void OnInstanceQuit(const std::string& name, const Identity& identity) {
94 if (url == identity.url()) 95 if (name == identity.name())
95 base::MessageLoop::current()->QuitWhenIdle(); 96 base::MessageLoop::current()->QuitWhenIdle();
96 } 97 }
97 98
98 } // namespace 99 } // namespace
99 100
100 Context::InitParams::InitParams() {} 101 Context::InitParams::InitParams() {}
101 Context::InitParams::~InitParams() {} 102 Context::InitParams::~InitParams() {}
102 103
103 Context::Context() 104 Context::Context()
104 : io_thread_(CreateIOThread("io_thread")), 105 : io_thread_(CreateIOThread("io_thread")),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } else { 150 } else {
150 NativeRunnerDelegate* native_runner_delegate = init_params ? 151 NativeRunnerDelegate* native_runner_delegate = init_params ?
151 init_params->native_runner_delegate : nullptr; 152 init_params->native_runner_delegate : nullptr;
152 runner_factory.reset(new OutOfProcessNativeRunnerFactory( 153 runner_factory.reset(new OutOfProcessNativeRunnerFactory(
153 blocking_pool_.get(), native_runner_delegate)); 154 blocking_pool_.get(), native_runner_delegate));
154 } 155 }
155 scoped_ptr<package_manager::ApplicationCatalogStore> app_catalog; 156 scoped_ptr<package_manager::ApplicationCatalogStore> app_catalog;
156 if (init_params) 157 if (init_params)
157 app_catalog = std::move(init_params->app_catalog); 158 app_catalog = std::move(init_params->app_catalog);
158 application_manager_.reset(new ApplicationManager(std::move(runner_factory), 159 application_manager_.reset(new ApplicationManager(std::move(runner_factory),
159 blocking_pool_.get(), true, 160 blocking_pool_.get(),
160 std::move(app_catalog))); 161 std::move(app_catalog)));
161 162
162 shell::mojom::InterfaceProviderPtr tracing_remote_interfaces; 163 shell::mojom::InterfaceProviderPtr tracing_remote_interfaces;
163 shell::mojom::InterfaceProviderPtr tracing_local_interfaces; 164 shell::mojom::InterfaceProviderPtr tracing_local_interfaces;
164 new TracingInterfaceProvider(&tracer_, GetProxy(&tracing_local_interfaces)); 165 new TracingInterfaceProvider(&tracer_, GetProxy(&tracing_local_interfaces));
165 166
166 scoped_ptr<ConnectParams> params(new ConnectParams); 167 scoped_ptr<ConnectParams> params(new ConnectParams);
167 params->set_source(CreateShellIdentity()); 168 params->set_source(CreateShellIdentity());
168 params->set_target(Identity(GURL("mojo:tracing"), std::string(), 169 params->set_target(Identity("mojo:tracing", std::string(),
169 mojom::Connector::kUserInherit)); 170 mojom::Connector::kUserInherit));
170 params->set_remote_interfaces(GetProxy(&tracing_remote_interfaces)); 171 params->set_remote_interfaces(GetProxy(&tracing_remote_interfaces));
171 params->set_local_interfaces(std::move(tracing_local_interfaces)); 172 params->set_local_interfaces(std::move(tracing_local_interfaces));
172 application_manager_->Connect(std::move(params)); 173 application_manager_->Connect(std::move(params));
173 174
174 if (command_line.HasSwitch(tracing::kTraceStartup)) { 175 if (command_line.HasSwitch(tracing::kTraceStartup)) {
175 tracing::TraceCollectorPtr coordinator; 176 tracing::TraceCollectorPtr coordinator;
176 auto coordinator_request = GetProxy(&coordinator); 177 auto coordinator_request = GetProxy(&coordinator);
177 tracing_remote_interfaces->GetInterface( 178 tracing_remote_interfaces->GetInterface(
178 tracing::TraceCollector::Name_, coordinator_request.PassMessagePipe()); 179 tracing::TraceCollector::Name_, coordinator_request.PassMessagePipe());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 213
213 void Context::OnShutdownComplete() { 214 void Context::OnShutdownComplete() {
214 DCHECK_EQ(base::MessageLoop::current()->task_runner(), shell_runner_); 215 DCHECK_EQ(base::MessageLoop::current()->task_runner(), shell_runner_);
215 base::MessageLoop::current()->QuitWhenIdle(); 216 base::MessageLoop::current()->QuitWhenIdle();
216 } 217 }
217 218
218 void Context::RunCommandLineApplication() { 219 void Context::RunCommandLineApplication() {
219 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 220 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
220 base::CommandLine::StringVector args = command_line->GetArgs(); 221 base::CommandLine::StringVector args = command_line->GetArgs();
221 for (size_t i = 0; i < args.size(); ++i) { 222 for (size_t i = 0; i < args.size(); ++i) {
222 GURL possible_app(args[i]); 223 #if defined(OS_WIN)
223 if (possible_app.SchemeIs("mojo")) { 224 std::string possible_app = base::WideToUTF8(args[i]);
225 #else
226 std::string possible_app = args[i];
227 #endif
228 if (GetNameType(possible_app) == "mojo") {
224 Run(possible_app); 229 Run(possible_app);
225 break; 230 break;
226 } 231 }
227 } 232 }
228 } 233 }
229 234
230 void Context::Run(const GURL& url) { 235 void Context::Run(const std::string& name) {
231 application_manager_->SetInstanceQuitCallback( 236 application_manager_->SetInstanceQuitCallback(
232 base::Bind(&OnInstanceQuit, url)); 237 base::Bind(&OnInstanceQuit, name));
233 238
234 shell::mojom::InterfaceProviderPtr remote_interfaces; 239 shell::mojom::InterfaceProviderPtr remote_interfaces;
235 shell::mojom::InterfaceProviderPtr local_interfaces; 240 shell::mojom::InterfaceProviderPtr local_interfaces;
236 241
237 scoped_ptr<ConnectParams> params(new ConnectParams); 242 scoped_ptr<ConnectParams> params(new ConnectParams);
238 params->set_source(CreateShellIdentity()); 243 params->set_source(CreateShellIdentity());
239 params->set_target(Identity(url, std::string(), mojom::Connector::kUserRoot)); 244 params->set_target(Identity(name, std::string(),
245 mojom::Connector::kUserRoot));
240 params->set_remote_interfaces(GetProxy(&remote_interfaces)); 246 params->set_remote_interfaces(GetProxy(&remote_interfaces));
241 params->set_local_interfaces(std::move(local_interfaces)); 247 params->set_local_interfaces(std::move(local_interfaces));
242 application_manager_->Connect(std::move(params)); 248 application_manager_->Connect(std::move(params));
243 } 249 }
244 250
245 } // namespace shell 251 } // namespace shell
246 } // namespace mojo 252 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/standalone/context.h ('k') | mojo/shell/standalone/desktop/launcher_process.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698