| 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 "services/tracing/public/cpp/provider.h" | 5 #include "services/tracing/public/cpp/provider.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 } | 36 } |
| 37 | 37 |
| 38 Provider::Provider() | 38 Provider::Provider() |
| 39 : binding_(this), tracing_forced_(false), weak_factory_(this) {} | 39 : binding_(this), tracing_forced_(false), weak_factory_(this) {} |
| 40 | 40 |
| 41 Provider::~Provider() { | 41 Provider::~Provider() { |
| 42 StopTracing(); | 42 StopTracing(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void Provider::InitializeWithFactoryInternal(mojom::FactoryPtr* factory) { |
| 46 mojom::ProviderPtr provider; |
| 47 Bind(GetProxy(&provider)); |
| 48 (*factory)->CreateRecorder(std::move(provider)); |
| 49 #ifdef NDEBUG |
| 50 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 51 tracing::kEarlyTracing)) { |
| 52 ForceEnableTracing(); |
| 53 } |
| 54 #else |
| 55 ForceEnableTracing(); |
| 56 #endif |
| 57 } |
| 58 |
| 59 void Provider::InitializeWithFactory(mojom::FactoryPtr* factory) { |
| 60 { |
| 61 base::AutoLock lock(g_singleton_lock.Get()); |
| 62 if (g_tracing_singleton_created) |
| 63 return; |
| 64 g_tracing_singleton_created = true; |
| 65 } |
| 66 InitializeWithFactoryInternal(factory); |
| 67 } |
| 68 |
| 45 void Provider::Initialize(service_manager::Connector* connector, | 69 void Provider::Initialize(service_manager::Connector* connector, |
| 46 const std::string& url) { | 70 const std::string& url) { |
| 47 { | 71 { |
| 48 base::AutoLock lock(g_singleton_lock.Get()); | 72 base::AutoLock lock(g_singleton_lock.Get()); |
| 49 if (g_tracing_singleton_created) | 73 if (g_tracing_singleton_created) |
| 50 return; | 74 return; |
| 51 g_tracing_singleton_created = true; | 75 g_tracing_singleton_created = true; |
| 52 } | 76 } |
| 53 | 77 mojom::FactoryPtr factory; |
| 78 connector->ConnectToInterface("service:tracing", &factory); |
| 79 InitializeWithFactoryInternal(&factory); |
| 54 // This will only set the name for the first app in a loaded mojo file. It's | 80 // This will only set the name for the first app in a loaded mojo file. It's |
| 55 // up to something like CoreServices to name its own child threads. | 81 // up to something like CoreServices to name its own child threads. |
| 56 base::PlatformThread::SetName(url); | 82 base::PlatformThread::SetName(url); |
| 57 | |
| 58 mojom::FactoryPtr factory; | |
| 59 connector->ConnectToInterface("service:tracing", &factory); | |
| 60 mojom::ProviderPtr provider; | |
| 61 Bind(GetProxy(&provider)); | |
| 62 factory->CreateRecorder(std::move(provider)); | |
| 63 #ifdef NDEBUG | |
| 64 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 65 tracing::kEarlyTracing)) { | |
| 66 ForceEnableTracing(); | |
| 67 } | |
| 68 #else | |
| 69 ForceEnableTracing(); | |
| 70 #endif | |
| 71 } | 83 } |
| 72 | 84 |
| 73 void Provider::Bind(mojom::ProviderRequest request) { | 85 void Provider::Bind(mojom::ProviderRequest request) { |
| 74 if (!binding_.is_bound()) { | 86 if (!binding_.is_bound()) { |
| 75 binding_.Bind(std::move(request)); | 87 binding_.Bind(std::move(request)); |
| 76 } else { | 88 } else { |
| 77 LOG(ERROR) << "Cannot accept two connections to TraceProvider."; | 89 LOG(ERROR) << "Cannot accept two connections to TraceProvider."; |
| 78 } | 90 } |
| 79 } | 91 } |
| 80 | 92 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // events. Empty string is not a valid chunk to record so skip in this case. | 150 // events. Empty string is not a valid chunk to record so skip in this case. |
| 139 if (!events_str->data().empty()) { | 151 if (!events_str->data().empty()) { |
| 140 recorder_->Record(mojo::String(events_str->data())); | 152 recorder_->Record(mojo::String(events_str->data())); |
| 141 } | 153 } |
| 142 if (!has_more_events) { | 154 if (!has_more_events) { |
| 143 recorder_.reset(); | 155 recorder_.reset(); |
| 144 } | 156 } |
| 145 } | 157 } |
| 146 | 158 |
| 147 } // namespace tracing | 159 } // namespace tracing |
| OLD | NEW |