OLD | NEW |
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/runner/context.h" | 5 #include "mojo/runner/context.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if (!base::StringToUint(port_str, &port) || port > 65535) { | 186 if (!base::StringToUint(port_str, &port) || port > 65535) { |
187 LOG(ERROR) << "Invalid value for switch " | 187 LOG(ERROR) << "Invalid value for switch " |
188 << devtools_service::kRemoteDebuggingPort << ": '" << port_str | 188 << devtools_service::kRemoteDebuggingPort << ": '" << port_str |
189 << "' is not a valid port number."; | 189 << "' is not a valid port number."; |
190 return; | 190 return; |
191 } | 191 } |
192 | 192 |
193 ServiceProviderPtr devtools_service_provider; | 193 ServiceProviderPtr devtools_service_provider; |
194 URLRequestPtr request(URLRequest::New()); | 194 URLRequestPtr request(URLRequest::New()); |
195 request->url = "mojo:devtools_service"; | 195 request->url = "mojo:devtools_service"; |
196 manager->ConnectToApplication(request.Pass(), GURL("mojo:shell"), | 196 manager->ConnectToApplication( |
197 GetProxy(&devtools_service_provider), nullptr, | 197 request.Pass(), std::string(), GURL("mojo:shell"), |
198 base::Closure()); | 198 GetProxy(&devtools_service_provider), nullptr, base::Closure()); |
199 | 199 |
200 devtools_service::DevToolsCoordinatorPtr devtools_coordinator; | 200 devtools_service::DevToolsCoordinatorPtr devtools_coordinator; |
201 devtools_service_provider->ConnectToService( | 201 devtools_service_provider->ConnectToService( |
202 devtools_service::DevToolsCoordinator::Name_, | 202 devtools_service::DevToolsCoordinator::Name_, |
203 GetProxy(&devtools_coordinator).PassMessagePipe()); | 203 GetProxy(&devtools_coordinator).PassMessagePipe()); |
204 devtools_coordinator->Initialize(static_cast<uint16_t>(port)); | 204 devtools_coordinator->Initialize(static_cast<uint16_t>(port)); |
205 } | 205 } |
206 | 206 |
207 class TracingServiceProvider : public ServiceProvider { | 207 class TracingServiceProvider : public ServiceProvider { |
208 public: | 208 public: |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 base::CommandLine::ForCurrentProcess()->HasSwitch( | 301 base::CommandLine::ForCurrentProcess()->HasSwitch( |
302 switches::kDisableCache)); | 302 switches::kDisableCache)); |
303 | 303 |
304 InitContentHandlers(&application_manager_, command_line); | 304 InitContentHandlers(&application_manager_, command_line); |
305 InitNativeOptions(&application_manager_, command_line); | 305 InitNativeOptions(&application_manager_, command_line); |
306 | 306 |
307 ServiceProviderPtr tracing_service_provider_ptr; | 307 ServiceProviderPtr tracing_service_provider_ptr; |
308 new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr)); | 308 new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr)); |
309 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 309 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
310 request->url = mojo::String::From("mojo:tracing"); | 310 request->url = mojo::String::From("mojo:tracing"); |
311 application_manager_.ConnectToApplication(request.Pass(), GURL(""), nullptr, | 311 application_manager_.ConnectToApplication( |
312 tracing_service_provider_ptr.Pass(), | 312 request.Pass(), std::string(), GURL(""), nullptr, |
313 base::Closure()); | 313 tracing_service_provider_ptr.Pass(), base::Closure()); |
314 | 314 |
315 InitDevToolsServiceIfNeeded(&application_manager_, command_line); | 315 InitDevToolsServiceIfNeeded(&application_manager_, command_line); |
316 | 316 |
317 return true; | 317 return true; |
318 } | 318 } |
319 | 319 |
320 void Context::Shutdown() { | 320 void Context::Shutdown() { |
321 TRACE_EVENT0("mojo_shell", "Context::Shutdown"); | 321 TRACE_EVENT0("mojo_shell", "Context::Shutdown"); |
322 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 322 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
323 task_runners_->shell_runner()); | 323 task_runners_->shell_runner()); |
(...skipping 23 matching lines...) Expand all Loading... |
347 } | 347 } |
348 | 348 |
349 void Context::Run(const GURL& url) { | 349 void Context::Run(const GURL& url) { |
350 ServiceProviderPtr services; | 350 ServiceProviderPtr services; |
351 ServiceProviderPtr exposed_services; | 351 ServiceProviderPtr exposed_services; |
352 | 352 |
353 app_urls_.insert(url); | 353 app_urls_.insert(url); |
354 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 354 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
355 request->url = mojo::String::From(url.spec()); | 355 request->url = mojo::String::From(url.spec()); |
356 application_manager_.ConnectToApplication( | 356 application_manager_.ConnectToApplication( |
357 request.Pass(), GURL(), GetProxy(&services), exposed_services.Pass(), | 357 request.Pass(), std::string(), GURL(), GetProxy(&services), |
| 358 exposed_services.Pass(), |
358 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url)); | 359 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url)); |
359 } | 360 } |
360 | 361 |
361 void Context::RunCommandLineApplication() { | 362 void Context::RunCommandLineApplication() { |
362 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 363 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
363 base::CommandLine::StringVector args = command_line->GetArgs(); | 364 base::CommandLine::StringVector args = command_line->GetArgs(); |
364 for (size_t i = 0; i < args.size(); ++i) { | 365 for (size_t i = 0; i < args.size(); ++i) { |
365 GURL possible_app(args[i]); | 366 GURL possible_app(args[i]); |
366 if (possible_app.SchemeIs("mojo")) { | 367 if (possible_app.SchemeIs("mojo")) { |
367 Run(possible_app); | 368 Run(possible_app); |
368 break; | 369 break; |
369 } | 370 } |
370 } | 371 } |
371 } | 372 } |
372 | 373 |
373 void Context::OnApplicationEnd(const GURL& url) { | 374 void Context::OnApplicationEnd(const GURL& url) { |
374 if (app_urls_.find(url) != app_urls_.end()) { | 375 if (app_urls_.find(url) != app_urls_.end()) { |
375 app_urls_.erase(url); | 376 app_urls_.erase(url); |
376 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { | 377 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { |
377 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 378 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
378 task_runners_->shell_runner()); | 379 task_runners_->shell_runner()); |
379 base::MessageLoop::current()->Quit(); | 380 base::MessageLoop::current()->Quit(); |
380 } | 381 } |
381 } | 382 } |
382 } | 383 } |
383 | 384 |
384 } // namespace runner | 385 } // namespace runner |
385 } // namespace mojo | 386 } // namespace mojo |
OLD | NEW |