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

Side by Side Diff: shell/context.cc

Issue 1105773002: Teach the mojo_shell --trace-startup flag to gather data from services (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 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 "shell/context.h" 5 #include "shell/context.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 18 matching lines...) Expand all
29 #include "mojo/public/cpp/application/application_delegate.h" 29 #include "mojo/public/cpp/application/application_delegate.h"
30 #include "mojo/public/cpp/application/application_impl.h" 30 #include "mojo/public/cpp/application/application_impl.h"
31 #include "services/tracing/tracing.mojom.h" 31 #include "services/tracing/tracing.mojom.h"
32 #include "shell/application_manager/application_loader.h" 32 #include "shell/application_manager/application_loader.h"
33 #include "shell/application_manager/application_manager.h" 33 #include "shell/application_manager/application_manager.h"
34 #include "shell/command_line_util.h" 34 #include "shell/command_line_util.h"
35 #include "shell/filename_util.h" 35 #include "shell/filename_util.h"
36 #include "shell/in_process_native_runner.h" 36 #include "shell/in_process_native_runner.h"
37 #include "shell/out_of_process_native_runner.h" 37 #include "shell/out_of_process_native_runner.h"
38 #include "shell/switches.h" 38 #include "shell/switches.h"
39 #include "shell/tracer.h"
39 #include "url/gurl.h" 40 #include "url/gurl.h"
40 41
41 using mojo::ServiceProvider; 42 using mojo::ServiceProvider;
42 using mojo::ServiceProviderPtr; 43 using mojo::ServiceProviderPtr;
43 44
44 namespace shell { 45 namespace shell {
45 namespace { 46 namespace {
46 47
47 // Used to ensure we only init once. 48 // Used to ensure we only init once.
48 class Setup { 49 class Setup {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 170 }
170 171
171 NativeRunnerFactory::Options options; 172 NativeRunnerFactory::Options options;
172 options.force_in_process = true; 173 options.force_in_process = true;
173 manager->SetNativeOptionsForURL(options, gurl); 174 manager->SetNativeOptionsForURL(options, gurl);
174 } 175 }
175 } 176 }
176 177
177 class TracingServiceProvider : public ServiceProvider { 178 class TracingServiceProvider : public ServiceProvider {
178 public: 179 public:
179 explicit TracingServiceProvider( 180 TracingServiceProvider(Tracer* tracer,
180 mojo::InterfaceRequest<ServiceProvider> request) 181 mojo::InterfaceRequest<ServiceProvider> request)
181 : binding_(this, request.Pass()) {} 182 : tracer_(tracer), binding_(this, request.Pass()) {}
182 ~TracingServiceProvider() override {} 183 ~TracingServiceProvider() override {}
183 184
184 void ConnectToService(const mojo::String& service_name, 185 void ConnectToService(const mojo::String& service_name,
185 mojo::ScopedMessagePipeHandle client_handle) override { 186 mojo::ScopedMessagePipeHandle client_handle) override {
186 if (service_name == tracing::TraceController::Name_) { 187 if (tracer_ && service_name == tracing::TraceController::Name_) {
187 new mojo::TraceControllerImpl( 188 tracer_->ConnectToController(
188 mojo::MakeRequest<tracing::TraceController>(client_handle.Pass())); 189 mojo::MakeRequest<tracing::TraceController>(client_handle.Pass()));
189 } 190 }
190 } 191 }
191 192
192 private: 193 private:
194 Tracer* tracer_;
193 mojo::StrongBinding<mojo::ServiceProvider> binding_; 195 mojo::StrongBinding<mojo::ServiceProvider> binding_;
194 196
195 DISALLOW_COPY_AND_ASSIGN(TracingServiceProvider); 197 DISALLOW_COPY_AND_ASSIGN(TracingServiceProvider);
196 }; 198 };
197 199
198 } // namespace 200 } // namespace
199 201
200 Context::Context() : application_manager_(this) { 202 Context::Context(Tracer* tracer) : tracer_(tracer), application_manager_(this) {
201 DCHECK(!base::MessageLoop::current()); 203 DCHECK(!base::MessageLoop::current());
202 204
203 // By default assume that the local apps reside alongside the shell. 205 // By default assume that the local apps reside alongside the shell.
204 // TODO(ncbray): really, this should be passed in rather than defaulting. 206 // TODO(ncbray): really, this should be passed in rather than defaulting.
205 // This default makes sense for desktop but not Android. 207 // This default makes sense for desktop but not Android.
206 base::FilePath shell_dir; 208 base::FilePath shell_dir;
207 PathService::Get(base::DIR_MODULE, &shell_dir); 209 PathService::Get(base::DIR_MODULE, &shell_dir);
208 SetShellFileRoot(shell_dir); 210 SetShellFileRoot(shell_dir);
209 211
210 base::FilePath cwd; 212 base::FilePath cwd;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 runner_factory.reset(new InProcessNativeRunnerFactory(this)); 281 runner_factory.reset(new InProcessNativeRunnerFactory(this));
280 application_manager_.set_blocking_pool(task_runners_->blocking_pool()); 282 application_manager_.set_blocking_pool(task_runners_->blocking_pool());
281 application_manager_.set_native_runner_factory(runner_factory.Pass()); 283 application_manager_.set_native_runner_factory(runner_factory.Pass());
282 application_manager_.set_disable_cache( 284 application_manager_.set_disable_cache(
283 base::CommandLine::ForCurrentProcess()->HasSwitch( 285 base::CommandLine::ForCurrentProcess()->HasSwitch(
284 switches::kDisableCache)); 286 switches::kDisableCache));
285 287
286 InitContentHandlers(&application_manager_, command_line); 288 InitContentHandlers(&application_manager_, command_line);
287 InitNativeOptions(&application_manager_, command_line); 289 InitNativeOptions(&application_manager_, command_line);
288 290
289 ServiceProviderPtr tracing_service_provider_ptr; 291 ServiceProviderPtr tracing_services;
290 new TracingServiceProvider(mojo::GetProxy(&tracing_service_provider_ptr)); 292 ServiceProviderPtr tracing_exposed_services;
293 new TracingServiceProvider(tracer_, GetProxy(&tracing_exposed_services));
291 application_manager_.ConnectToApplication( 294 application_manager_.ConnectToApplication(
292 GURL("mojo:tracing"), GURL(""), nullptr, 295 GURL("mojo:tracing"), GURL(""), GetProxy(&tracing_services),
293 tracing_service_provider_ptr.Pass(), base::Closure()); 296 tracing_exposed_services.Pass(), base::Closure());
297
298 if (command_line.HasSwitch(switches::kTraceStartup)) {
299 DCHECK(tracer_);
300 tracing::TraceCoordinatorPtr coordinator;
301 auto coordinator_request = GetProxy(&coordinator);
302 tracing_services->ConnectToService(tracing::TraceCoordinator::Name_,
303 coordinator_request.PassMessagePipe());
304 tracer_->StartCollectingFromTracingService(coordinator.Pass());
305 }
294 306
295 return true; 307 return true;
296 } 308 }
297 309
298 void Context::Shutdown() { 310 void Context::Shutdown() {
299 TRACE_EVENT0("mojo_shell", "Context::Shutdown"); 311 TRACE_EVENT0("mojo_shell", "Context::Shutdown");
300 DCHECK_EQ(base::MessageLoop::current()->task_runner(), 312 DCHECK_EQ(base::MessageLoop::current()->task_runner(),
301 task_runners_->shell_runner()); 313 task_runners_->shell_runner());
302 mojo::embedder::ShutdownIPCSupport(); 314 mojo::embedder::ShutdownIPCSupport();
303 // We'll quit when we get OnShutdownComplete(). 315 // We'll quit when we get OnShutdownComplete().
(...skipping 29 matching lines...) Expand all
333 app_urls_.erase(url); 345 app_urls_.erase(url);
334 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { 346 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) {
335 DCHECK_EQ(base::MessageLoop::current()->task_runner(), 347 DCHECK_EQ(base::MessageLoop::current()->task_runner(),
336 task_runners_->shell_runner()); 348 task_runners_->shell_runner());
337 base::MessageLoop::current()->Quit(); 349 base::MessageLoop::current()->Quit();
338 } 350 }
339 } 351 }
340 } 352 }
341 353
342 } // namespace shell 354 } // namespace shell
OLDNEW
« no previous file with comments | « shell/context.h ('k') | shell/desktop/main.cc » ('j') | shell/tracer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698