| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/profiler.h" | 8 #include "base/debug/profiler.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "mojo/application/application_runner_chromium.h" | 11 #include "mojo/application/application_runner_chromium.h" |
| 12 #include "mojo/data_pipe_utils/data_pipe_utils.h" | 12 #include "mojo/data_pipe_utils/data_pipe_utils.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_delegate.h" |
| 15 #include "mojo/public/cpp/application/application_impl.h" | 15 #include "mojo/public/cpp/application/application_impl.h" |
| 16 #include "mojo/public/cpp/application/connect.h" |
| 16 #include "mojo/public/cpp/bindings/binding.h" | 17 #include "mojo/public/cpp/bindings/binding.h" |
| 17 #include "mojo/services/http_server/cpp/http_server_util.h" | 18 #include "mojo/services/http_server/cpp/http_server_util.h" |
| 18 #include "mojo/services/http_server/interfaces/http_server.mojom.h" | 19 #include "mojo/services/http_server/interfaces/http_server.mojom.h" |
| 19 #include "mojo/services/http_server/interfaces/http_server_factory.mojom.h" | 20 #include "mojo/services/http_server/interfaces/http_server_factory.mojom.h" |
| 20 #include "mojo/services/network/interfaces/net_address.mojom.h" | 21 #include "mojo/services/network/interfaces/net_address.mojom.h" |
| 21 #include "mojo/services/tracing/interfaces/tracing.mojom.h" | 22 #include "mojo/services/tracing/interfaces/tracing.mojom.h" |
| 22 #include "services/debugger/trace_collector.h" | 23 #include "services/debugger/trace_collector.h" |
| 23 | 24 |
| 24 // Debugger is a Mojo application that exposes an http server and talks to other | 25 // Debugger is a Mojo application that exposes an http server and talks to other |
| 25 // mojo apps in response to url requests received by the server. Supported | 26 // mojo apps in response to url requests received by the server. Supported |
| (...skipping 14 matching lines...) Expand all Loading... |
| 40 app_ = app; | 41 app_ = app; |
| 41 | 42 |
| 42 // Format: --args-for="app_url command_port" | 43 // Format: --args-for="app_url command_port" |
| 43 if (app->args().size() < 2) { | 44 if (app->args().size() < 2) { |
| 44 LOG(ERROR) << "--args-for required to specify command_port"; | 45 LOG(ERROR) << "--args-for required to specify command_port"; |
| 45 mojo::ApplicationImpl::Terminate(); | 46 mojo::ApplicationImpl::Terminate(); |
| 46 return; | 47 return; |
| 47 } | 48 } |
| 48 base::StringToUint(app->args()[1], &command_port_); | 49 base::StringToUint(app->args()[1], &command_port_); |
| 49 http_server::HttpServerFactoryPtr http_server_factory; | 50 http_server::HttpServerFactoryPtr http_server_factory; |
| 50 app->ConnectToServiceDeprecated("mojo:http_server", &http_server_factory); | 51 mojo::ConnectToService(app->shell(), "mojo:http_server", |
| 52 GetProxy(&http_server_factory)); |
| 51 | 53 |
| 52 mojo::NetAddressPtr local_address(mojo::NetAddress::New()); | 54 mojo::NetAddressPtr local_address(mojo::NetAddress::New()); |
| 53 local_address->family = mojo::NetAddressFamily::IPV4; | 55 local_address->family = mojo::NetAddressFamily::IPV4; |
| 54 local_address->ipv4 = mojo::NetAddressIPv4::New(); | 56 local_address->ipv4 = mojo::NetAddressIPv4::New(); |
| 55 local_address->ipv4->addr.resize(4); | 57 local_address->ipv4->addr.resize(4); |
| 56 local_address->ipv4->addr[0] = 127; | 58 local_address->ipv4->addr[0] = 127; |
| 57 local_address->ipv4->addr[1] = 0; | 59 local_address->ipv4->addr[1] = 0; |
| 58 local_address->ipv4->addr[2] = 0; | 60 local_address->ipv4->addr[2] = 0; |
| 59 local_address->ipv4->addr[3] = 1; | 61 local_address->ipv4->addr[3] = 1; |
| 60 local_address->ipv4->port = command_port_; | 62 local_address->ipv4->port = command_port_; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // TODO(eseidel): We should orderly shutdown once mojo can. | 115 // TODO(eseidel): We should orderly shutdown once mojo can. |
| 114 exit(0); | 116 exit(0); |
| 115 } | 117 } |
| 116 | 118 |
| 117 void StartTracing(const HandleRequestCallback& callback) { | 119 void StartTracing(const HandleRequestCallback& callback) { |
| 118 if (is_tracing_) { | 120 if (is_tracing_) { |
| 119 Error(callback, "Already tracing. Use stop_tracing to stop.\n"); | 121 Error(callback, "Already tracing. Use stop_tracing to stop.\n"); |
| 120 return; | 122 return; |
| 121 } | 123 } |
| 122 | 124 |
| 123 if (!tracing_) | 125 if (!tracing_) { |
| 124 app_->ConnectToServiceDeprecated("mojo:tracing", &tracing_); | 126 mojo::ConnectToService(app_->shell(), "mojo:tracing", |
| 127 GetProxy(&tracing_)); |
| 128 } |
| 125 is_tracing_ = true; | 129 is_tracing_ = true; |
| 126 mojo::DataPipe pipe; | 130 mojo::DataPipe pipe; |
| 127 tracing_->Start(pipe.producer_handle.Pass(), mojo::String("*")); | 131 tracing_->Start(pipe.producer_handle.Pass(), mojo::String("*")); |
| 128 trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass())); | 132 trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass())); |
| 129 Respond(callback, "Starting trace (type 'stop_tracing' to stop)\n"); | 133 Respond(callback, "Starting trace (type 'stop_tracing' to stop)\n"); |
| 130 } | 134 } |
| 131 | 135 |
| 132 void StopTracing(const HandleRequestCallback& callback) { | 136 void StopTracing(const HandleRequestCallback& callback) { |
| 133 if (!is_tracing_) { | 137 if (!is_tracing_) { |
| 134 Error(callback, "Not tracing yet. Use start_tracing to start.\n"); | 138 Error(callback, "Not tracing yet. Use start_tracing to start.\n"); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 159 DISALLOW_COPY_AND_ASSIGN(Debugger); | 163 DISALLOW_COPY_AND_ASSIGN(Debugger); |
| 160 }; | 164 }; |
| 161 | 165 |
| 162 } // namespace debugger | 166 } // namespace debugger |
| 163 | 167 |
| 164 MojoResult MojoMain(MojoHandle application_request) { | 168 MojoResult MojoMain(MojoHandle application_request) { |
| 165 mojo::ApplicationRunnerChromium runner(new debugger::Debugger); | 169 mojo::ApplicationRunnerChromium runner(new debugger::Debugger); |
| 166 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); | 170 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); |
| 167 return runner.Run(application_request); | 171 return runner.Run(application_request); |
| 168 } | 172 } |
| OLD | NEW |