| 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/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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { |
| 94 if (url == identity.url()) |
| 95 base::MessageLoop::current()->QuitWhenIdle(); |
| 96 } |
| 97 |
| 93 } // namespace | 98 } // namespace |
| 94 | 99 |
| 95 Context::Context() | 100 Context::Context() |
| 96 : io_thread_(CreateIOThread("io_thread")), | 101 : io_thread_(CreateIOThread("io_thread")), |
| 97 main_entry_time_(base::Time::Now()) {} | 102 main_entry_time_(base::Time::Now()) {} |
| 98 | 103 |
| 99 Context::~Context() { | 104 Context::~Context() { |
| 100 DCHECK(!base::MessageLoop::current()); | 105 DCHECK(!base::MessageLoop::current()); |
| 101 blocking_pool_->Shutdown(); | 106 blocking_pool_->Shutdown(); |
| 102 } | 107 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 << "supported because statics in apps interact. Use static build" | 141 << "supported because statics in apps interact. Use static build" |
| 137 << " or don't pass --single-process."; | 142 << " or don't pass --single-process."; |
| 138 #endif | 143 #endif |
| 139 runner_factory.reset( | 144 runner_factory.reset( |
| 140 new InProcessNativeRunnerFactory(blocking_pool_.get())); | 145 new InProcessNativeRunnerFactory(blocking_pool_.get())); |
| 141 } else { | 146 } else { |
| 142 runner_factory.reset(new OutOfProcessNativeRunnerFactory( | 147 runner_factory.reset(new OutOfProcessNativeRunnerFactory( |
| 143 blocking_pool_.get(), command_line_switches_)); | 148 blocking_pool_.get(), command_line_switches_)); |
| 144 } | 149 } |
| 145 application_manager_.reset(new ApplicationManager( | 150 application_manager_.reset(new ApplicationManager( |
| 146 std::move(runner_factory), blocking_pool_.get(), true)); | 151 std::move(runner_factory), blocking_pool_.get(), true)); |
| 147 | 152 |
| 148 shell::mojom::InterfaceProviderPtr tracing_remote_interfaces; | 153 shell::mojom::InterfaceProviderPtr tracing_remote_interfaces; |
| 149 shell::mojom::InterfaceProviderPtr tracing_local_interfaces; | 154 shell::mojom::InterfaceProviderPtr tracing_local_interfaces; |
| 150 new TracingInterfaceProvider(&tracer_, GetProxy(&tracing_local_interfaces)); | 155 new TracingInterfaceProvider(&tracer_, GetProxy(&tracing_local_interfaces)); |
| 151 | 156 |
| 152 scoped_ptr<ConnectParams> params(new ConnectParams); | 157 scoped_ptr<ConnectParams> params(new ConnectParams); |
| 153 params->set_source(Identity(GURL("mojo:shell"), std::string(), | 158 params->set_source(Identity(GURL("mojo:shell"), std::string(), |
| 154 GetPermissiveCapabilityFilter())); | 159 GetPermissiveCapabilityFilter())); |
| 155 params->set_target(Identity(GURL("mojo:tracing"), std::string(), | 160 params->set_target(Identity(GURL("mojo:tracing"), std::string(), |
| 156 GetPermissiveCapabilityFilter())); | 161 GetPermissiveCapabilityFilter())); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 base::Bind(edk::ShutdownIPCSupport)); | 200 base::Bind(edk::ShutdownIPCSupport)); |
| 196 // We'll quit when we get OnShutdownComplete(). | 201 // We'll quit when we get OnShutdownComplete(). |
| 197 base::MessageLoop::current()->Run(); | 202 base::MessageLoop::current()->Run(); |
| 198 } | 203 } |
| 199 | 204 |
| 200 void Context::OnShutdownComplete() { | 205 void Context::OnShutdownComplete() { |
| 201 DCHECK_EQ(base::MessageLoop::current()->task_runner(), shell_runner_); | 206 DCHECK_EQ(base::MessageLoop::current()->task_runner(), shell_runner_); |
| 202 base::MessageLoop::current()->QuitWhenIdle(); | 207 base::MessageLoop::current()->QuitWhenIdle(); |
| 203 } | 208 } |
| 204 | 209 |
| 210 void Context::RunCommandLineApplication() { |
| 211 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 212 base::CommandLine::StringVector args = command_line->GetArgs(); |
| 213 for (size_t i = 0; i < args.size(); ++i) { |
| 214 GURL possible_app(args[i]); |
| 215 if (possible_app.SchemeIs("mojo")) { |
| 216 Run(possible_app); |
| 217 break; |
| 218 } |
| 219 } |
| 220 } |
| 221 |
| 205 void Context::Run(const GURL& url) { | 222 void Context::Run(const GURL& url) { |
| 206 DCHECK(app_complete_callback_.is_null()); | 223 application_manager_->SetInstanceQuitCallback( |
| 224 base::Bind(&OnInstanceQuit, url)); |
| 225 |
| 207 shell::mojom::InterfaceProviderPtr remote_interfaces; | 226 shell::mojom::InterfaceProviderPtr remote_interfaces; |
| 208 shell::mojom::InterfaceProviderPtr local_interfaces; | 227 shell::mojom::InterfaceProviderPtr local_interfaces; |
| 209 | 228 |
| 210 app_urls_.insert(url); | |
| 211 | |
| 212 scoped_ptr<ConnectParams> params(new ConnectParams); | 229 scoped_ptr<ConnectParams> params(new ConnectParams); |
| 213 params->set_target( | 230 params->set_target( |
| 214 Identity(url, std::string(), GetPermissiveCapabilityFilter())); | 231 Identity(url, std::string(), GetPermissiveCapabilityFilter())); |
| 215 params->set_remote_interfaces(GetProxy(&remote_interfaces)); | 232 params->set_remote_interfaces(GetProxy(&remote_interfaces)); |
| 216 params->set_local_interfaces(std::move(local_interfaces)); | 233 params->set_local_interfaces(std::move(local_interfaces)); |
| 217 params->set_on_application_end( | |
| 218 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url)); | |
| 219 application_manager_->Connect(std::move(params)); | 234 application_manager_->Connect(std::move(params)); |
| 220 } | 235 } |
| 221 | 236 |
| 222 void Context::RunCommandLineApplication(const base::Closure& callback) { | |
| 223 DCHECK(app_urls_.empty()); | |
| 224 DCHECK(app_complete_callback_.is_null()); | |
| 225 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 226 base::CommandLine::StringVector args = command_line->GetArgs(); | |
| 227 for (size_t i = 0; i < args.size(); ++i) { | |
| 228 GURL possible_app(args[i]); | |
| 229 if (possible_app.SchemeIs("mojo")) { | |
| 230 Run(possible_app); | |
| 231 app_complete_callback_ = callback; | |
| 232 break; | |
| 233 } | |
| 234 } | |
| 235 } | |
| 236 | |
| 237 void Context::OnApplicationEnd(const GURL& url) { | |
| 238 if (app_urls_.find(url) != app_urls_.end()) { | |
| 239 app_urls_.erase(url); | |
| 240 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { | |
| 241 DCHECK_EQ(base::MessageLoop::current()->task_runner(), shell_runner_); | |
| 242 if (app_complete_callback_.is_null()) { | |
| 243 base::MessageLoop::current()->QuitWhenIdle(); | |
| 244 } else { | |
| 245 app_complete_callback_.Run(); | |
| 246 } | |
| 247 } | |
| 248 } | |
| 249 } | |
| 250 | |
| 251 } // namespace shell | 237 } // namespace shell |
| 252 } // namespace mojo | 238 } // namespace mojo |
| OLD | NEW |