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

Side by Side Diff: services/service_manager/standalone/context.cc

Issue 2427013002: Make tracing work in service manager (Closed)
Patch Set: Rename InitializeWithFactoryLocked to InitializeWithFactoryInternal Created 4 years, 2 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 "services/service_manager/standalone/context.h" 5 #include "services/service_manager/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 18 matching lines...) Expand all
29 #include "base/threading/sequenced_worker_pool.h" 29 #include "base/threading/sequenced_worker_pool.h"
30 #include "base/threading/thread_task_runner_handle.h" 30 #include "base/threading/thread_task_runner_handle.h"
31 #include "base/trace_event/trace_event.h" 31 #include "base/trace_event/trace_event.h"
32 #include "build/build_config.h" 32 #include "build/build_config.h"
33 #include "components/tracing/common/tracing_switches.h" 33 #include "components/tracing/common/tracing_switches.h"
34 #include "mojo/edk/embedder/embedder.h" 34 #include "mojo/edk/embedder/embedder.h"
35 #include "mojo/public/cpp/bindings/strong_binding.h" 35 #include "mojo/public/cpp/bindings/strong_binding.h"
36 #include "services/catalog/catalog.h" 36 #include "services/catalog/catalog.h"
37 #include "services/catalog/store.h" 37 #include "services/catalog/store.h"
38 #include "services/service_manager/connect_params.h" 38 #include "services/service_manager/connect_params.h"
39 #include "services/service_manager/connect_util.h"
39 #include "services/service_manager/public/cpp/names.h" 40 #include "services/service_manager/public/cpp/names.h"
40 #include "services/service_manager/runner/common/switches.h" 41 #include "services/service_manager/runner/common/switches.h"
41 #include "services/service_manager/runner/host/in_process_native_runner.h" 42 #include "services/service_manager/runner/host/in_process_native_runner.h"
42 #include "services/service_manager/runner/host/out_of_process_native_runner.h" 43 #include "services/service_manager/runner/host/out_of_process_native_runner.h"
43 #include "services/service_manager/standalone/tracer.h" 44 #include "services/service_manager/standalone/tracer.h"
44 #include "services/service_manager/switches.h" 45 #include "services/service_manager/switches.h"
45 #include "services/tracing/public/cpp/provider.h" 46 #include "services/tracing/public/cpp/provider.h"
46 #include "services/tracing/public/cpp/switches.h" 47 #include "services/tracing/public/cpp/switches.h"
47 #include "services/tracing/public/interfaces/tracing.mojom.h" 48 #include "services/tracing/public/interfaces/tracing.mojom.h"
48 49
(...skipping 17 matching lines...) Expand all
66 class Setup { 67 class Setup {
67 public: 68 public:
68 Setup() { mojo::edk::Init(); } 69 Setup() { mojo::edk::Init(); }
69 70
70 ~Setup() {} 71 ~Setup() {}
71 72
72 private: 73 private:
73 DISALLOW_COPY_AND_ASSIGN(Setup); 74 DISALLOW_COPY_AND_ASSIGN(Setup);
74 }; 75 };
75 76
76 class TracingInterfaceProvider : public mojom::InterfaceProvider {
77 public:
78 explicit TracingInterfaceProvider(Tracer* tracer) : tracer_(tracer) {}
79 ~TracingInterfaceProvider() override {}
80
81 // mojom::InterfaceProvider:
82 void GetInterface(const std::string& interface_name,
83 mojo::ScopedMessagePipeHandle client_handle) override {
84 if (tracer_ && interface_name == tracing::mojom::Provider::Name_) {
85 tracer_->ConnectToProvider(
86 mojo::MakeRequest<tracing::mojom::Provider>(
87 std::move(client_handle)));
88 }
89 }
90
91 private:
92 Tracer* tracer_;
93
94 DISALLOW_COPY_AND_ASSIGN(TracingInterfaceProvider);
95 };
96
97 const size_t kMaxBlockingPoolThreads = 3; 77 const size_t kMaxBlockingPoolThreads = 3;
98 78
99 std::unique_ptr<base::Thread> CreateIOThread(const char* name) { 79 std::unique_ptr<base::Thread> CreateIOThread(const char* name) {
100 std::unique_ptr<base::Thread> thread(new base::Thread(name)); 80 std::unique_ptr<base::Thread> thread(new base::Thread(name));
101 base::Thread::Options options; 81 base::Thread::Options options;
102 options.message_loop_type = base::MessageLoop::TYPE_IO; 82 options.message_loop_type = base::MessageLoop::TYPE_IO;
103 thread->StartWithOptions(options); 83 thread->StartWithOptions(options);
104 return thread; 84 return thread;
105 } 85 }
106 86
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 std::unique_ptr<ServiceOverrides> service_overrides = 175 std::unique_ptr<ServiceOverrides> service_overrides =
196 base::MakeUnique<ServiceOverrides>(std::move(contents)); 176 base::MakeUnique<ServiceOverrides>(std::move(contents));
197 for (const auto& iter : service_overrides->entries()) { 177 for (const auto& iter : service_overrides->entries()) {
198 if (!iter.second.package_name.empty()) 178 if (!iter.second.package_name.empty())
199 catalog_->OverridePackageName(iter.first, iter.second.package_name); 179 catalog_->OverridePackageName(iter.first, iter.second.package_name);
200 } 180 }
201 service_manager_->SetServiceOverrides(std::move(service_overrides)); 181 service_manager_->SetServiceOverrides(std::move(service_overrides));
202 } 182 }
203 } 183 }
204 184
205 mojom::InterfaceProviderPtr tracing_remote_interfaces;
206 mojom::InterfaceProviderPtr tracing_local_interfaces;
207 mojo::MakeStrongBinding(base::MakeUnique<TracingInterfaceProvider>(&tracer_),
208 mojo::GetProxy(&tracing_local_interfaces));
209 185
210 std::unique_ptr<ConnectParams> params(new ConnectParams); 186 Identity source_identity = CreateServiceManagerIdentity();
211 params->set_source(CreateServiceManagerIdentity()); 187 Identity tracing_identity("service:tracing", mojom::kRootUserID);
212 params->set_target(Identity("service:tracing", mojom::kRootUserID)); 188 tracing::mojom::FactoryPtr factory;
213 params->set_remote_interfaces(mojo::GetProxy(&tracing_remote_interfaces)); 189 ConnectToInterface(service_manager(), source_identity, tracing_identity,
214 service_manager_->Connect(std::move(params)); 190 &factory);
191 provider_.InitializeWithFactory(&factory);
215 192
216 if (command_line.HasSwitch(tracing::kTraceStartup)) { 193 if (command_line.HasSwitch(tracing::kTraceStartup)) {
217 tracing::mojom::CollectorPtr coordinator; 194 tracing::mojom::CollectorPtr coordinator;
218 auto coordinator_request = GetProxy(&coordinator); 195 ConnectToInterface(service_manager(), source_identity, tracing_identity,
219 tracing_remote_interfaces->GetInterface( 196 &coordinator);
220 tracing::mojom::Collector::Name_,
221 coordinator_request.PassMessagePipe());
222 tracer_.StartCollectingFromTracingService(std::move(coordinator)); 197 tracer_.StartCollectingFromTracingService(std::move(coordinator));
223 } 198 }
224 199
225 // Record the service manager startup metrics used for performance testing. 200 // Record the service manager startup metrics used for performance testing.
226 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 201 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
227 tracing::kEnableStatsCollectionBindings)) { 202 tracing::kEnableStatsCollectionBindings)) {
228 tracing::mojom::StartupPerformanceDataCollectorPtr collector; 203 tracing::mojom::StartupPerformanceDataCollectorPtr collector;
229 tracing_remote_interfaces->GetInterface( 204 ConnectToInterface(service_manager(), source_identity, tracing_identity,
230 tracing::mojom::StartupPerformanceDataCollector::Name_, 205 &collector);
231 mojo::GetProxy(&collector).PassMessagePipe());
232 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) 206 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
233 // CurrentProcessInfo::CreationTime is only defined on some platforms. 207 // CurrentProcessInfo::CreationTime is only defined on some platforms.
234 const base::Time creation_time = base::CurrentProcessInfo::CreationTime(); 208 const base::Time creation_time = base::CurrentProcessInfo::CreationTime();
235 collector->SetServiceManagerProcessCreationTime( 209 collector->SetServiceManagerProcessCreationTime(
236 creation_time.ToInternalValue()); 210 creation_time.ToInternalValue());
237 #endif 211 #endif
238 collector->SetServiceManagerMainEntryPointTime( 212 collector->SetServiceManagerMainEntryPointTime(
239 main_entry_time_.ToInternalValue()); 213 main_entry_time_.ToInternalValue());
240 } 214 }
241 } 215 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 mojom::InterfaceProviderPtr local_interfaces; 263 mojom::InterfaceProviderPtr local_interfaces;
290 264
291 std::unique_ptr<ConnectParams> params(new ConnectParams); 265 std::unique_ptr<ConnectParams> params(new ConnectParams);
292 params->set_source(CreateServiceManagerIdentity()); 266 params->set_source(CreateServiceManagerIdentity());
293 params->set_target(Identity(name, mojom::kRootUserID)); 267 params->set_target(Identity(name, mojom::kRootUserID));
294 params->set_remote_interfaces(mojo::GetProxy(&remote_interfaces)); 268 params->set_remote_interfaces(mojo::GetProxy(&remote_interfaces));
295 service_manager_->Connect(std::move(params)); 269 service_manager_->Connect(std::move(params));
296 } 270 }
297 271
298 } // namespace service_manager 272 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/standalone/context.h ('k') | services/service_manager/standalone/tracer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698