| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "mojo/application/application_runner_chromium.h" | |
| 12 #include "mojo/common/tracing_impl.h" | 11 #include "mojo/common/tracing_impl.h" |
| 12 #include "mojo/environment/scoped_chromium_init.h" |
| 13 #include "mojo/public/c/system/main.h" | 13 #include "mojo/public/c/system/main.h" |
| 14 #include "mojo/public/cpp/application/application_delegate.h" | 14 #include "mojo/public/cpp/application/application_impl_base.h" |
| 15 #include "mojo/public/cpp/application/application_impl.h" | 15 #include "mojo/public/cpp/application/run_application.h" |
| 16 #include "mojo/public/cpp/application/service_provider_impl.h" | 16 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 17 | 17 |
| 18 // This is an example app that uses implementation of tracing from mojo/common | 18 // This is an example app that uses implementation of tracing from mojo/common |
| 19 // to participate in the tracing ecosystem. | 19 // to participate in the tracing ecosystem. |
| 20 // | 20 // |
| 21 // To collect a startup trace, run: | 21 // To collect a startup trace, run: |
| 22 // `mojo_run mojo:trace_me --trace-startup [--android] | 22 // `mojo_run mojo:trace_me --trace-startup [--android] |
| 23 // | 23 // |
| 24 // You can also use `mojo_debug` to start and stop tracing interactively. | 24 // You can also use `mojo_debug` to start and stop tracing interactively. |
| 25 | 25 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 void DoWork() { | 38 void DoWork() { |
| 39 TRACE_EVENT0("trace_me", "DoWork"); | 39 TRACE_EVENT0("trace_me", "DoWork"); |
| 40 base::PlatformThread::Sleep(kSleepTime); | 40 base::PlatformThread::Sleep(kSleepTime); |
| 41 NestedFunction(); | 41 NestedFunction(); |
| 42 base::PlatformThread::Sleep(kSleepTime); | 42 base::PlatformThread::Sleep(kSleepTime); |
| 43 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, base::Bind(&DoWork), | 43 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, base::Bind(&DoWork), |
| 44 kDoWorkDelay); | 44 kDoWorkDelay); |
| 45 } | 45 } |
| 46 | 46 |
| 47 class TraceMeApp : public mojo::ApplicationDelegate { | 47 class TraceMeApp : public mojo::ApplicationImplBase { |
| 48 public: | 48 public: |
| 49 TraceMeApp() {} | 49 TraceMeApp() {} |
| 50 ~TraceMeApp() override {} | 50 ~TraceMeApp() override {} |
| 51 | 51 |
| 52 // mojo:ApplicationDelegate: | 52 // mojo:ApplicationImplBase: |
| 53 void Initialize(mojo::ApplicationImpl* app) override { | 53 void OnInitialize() override { |
| 54 // Allow TracingImpl to connect to the central tracing service, advertising | 54 // Allow TracingImpl to connect to the central tracing service, advertising |
| 55 // its ability to provide trace events. | 55 // its ability to provide trace events. |
| 56 tracing_.Initialize(app->shell(), &app->args()); | 56 tracing_.Initialize(shell(), &args()); |
| 57 | 57 |
| 58 TRACE_EVENT0("trace_me", "initialized"); | 58 TRACE_EVENT0("trace_me", "initialized"); |
| 59 | 59 |
| 60 base::MessageLoop::current()->PostDelayedTask( | 60 base::MessageLoop::current()->PostDelayedTask( |
| 61 FROM_HERE, base::Bind(&DoWork), kDoWorkDelay); | 61 FROM_HERE, base::Bind(&DoWork), kDoWorkDelay); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // mojo:ApplicationDelegate: | 64 // mojo:ApplicationImplBase: |
| 65 bool ConfigureIncomingConnection( | 65 bool OnAcceptConnection( |
| 66 mojo::ServiceProviderImpl* service_provider_impl) override { | 66 mojo::ServiceProviderImpl* service_provider_impl) override { |
| 67 TRACE_EVENT0("trace_me", "connected"); | 67 TRACE_EVENT0("trace_me", "connected"); |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 mojo::TracingImpl tracing_; | 72 mojo::TracingImpl tracing_; |
| 73 DISALLOW_COPY_AND_ASSIGN(TraceMeApp); | 73 DISALLOW_COPY_AND_ASSIGN(TraceMeApp); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 } // namespace examples | 76 } // namespace examples |
| 77 | 77 |
| 78 MojoResult MojoMain(MojoHandle application_request) { | 78 MojoResult MojoMain(MojoHandle application_request) { |
| 79 mojo::ApplicationRunnerChromium runner(new examples::TraceMeApp); | 79 mojo::ScopedChromiumInit init; |
| 80 return runner.Run(application_request); | 80 examples::TraceMeApp trace_me_app; |
| 81 return mojo::RunApplication(application_request, &trace_me_app); |
| 81 } | 82 } |
| OLD | NEW |