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 "content/browser/tracing/background_tracing_manager_impl.h" | 5 #include "content/browser/tracing/background_tracing_manager_impl.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/time/time.h" | |
8 #include "content/public/browser/background_tracing_preemptive_config.h" | 9 #include "content/public/browser/background_tracing_preemptive_config.h" |
9 #include "content/public/browser/background_tracing_reactive_config.h" | 10 #include "content/public/browser/background_tracing_reactive_config.h" |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller = | 17 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller = |
17 LAZY_INSTANCE_INITIALIZER; | 18 LAZY_INSTANCE_INITIALIZER; |
(...skipping 13 matching lines...) Expand all Loading... | |
31 void BackgroundTracingManagerImpl::TraceDataEndpointWrapper:: | 32 void BackgroundTracingManagerImpl::TraceDataEndpointWrapper:: |
32 ReceiveTraceFinalContents(const std::string& file_contents) { | 33 ReceiveTraceFinalContents(const std::string& file_contents) { |
33 std::string tmp = file_contents; | 34 std::string tmp = file_contents; |
34 scoped_refptr<base::RefCountedString> contents_ptr = | 35 scoped_refptr<base::RefCountedString> contents_ptr = |
35 base::RefCountedString::TakeString(&tmp); | 36 base::RefCountedString::TakeString(&tmp); |
36 | 37 |
37 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 38 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
38 base::Bind(done_callback_, contents_ptr)); | 39 base::Bind(done_callback_, contents_ptr)); |
39 } | 40 } |
40 | 41 |
42 BackgroundTracingManagerImpl::TracingTimer:: | |
43 TracingTimer(StartedFinalizingCallback callback) : callback_(callback) { | |
44 } | |
45 | |
46 BackgroundTracingManagerImpl::TracingTimer::~TracingTimer() { | |
47 } | |
48 | |
49 void BackgroundTracingManagerImpl::TracingTimer::StartTimer() { | |
50 | |
shatch
2015/06/01 15:33:33
nit: Remove blank line.
fmeawad
2015/06/01 18:15:26
Done.
| |
51 tracing_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(10), this, | |
52 &BackgroundTracingManagerImpl::TracingTimer::TracingTimerFired); | |
53 } | |
54 | |
55 void BackgroundTracingManagerImpl::TracingTimer::CancelTimer() { | |
56 tracing_timer_.Stop(); | |
57 } | |
58 | |
59 void BackgroundTracingManagerImpl::TracingTimer::TracingTimerFired() { | |
60 BackgroundTracingManagerImpl::GetInstance()->BeginFinalizing(callback_); | |
61 } | |
62 | |
41 BackgroundTracingManager* BackgroundTracingManager::GetInstance() { | 63 BackgroundTracingManager* BackgroundTracingManager::GetInstance() { |
42 return BackgroundTracingManagerImpl::GetInstance(); | 64 return BackgroundTracingManagerImpl::GetInstance(); |
43 } | 65 } |
44 | 66 |
45 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() { | 67 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() { |
46 return g_controller.Pointer(); | 68 return g_controller.Pointer(); |
47 } | 69 } |
48 | 70 |
49 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl() | 71 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl() |
50 : is_gathering_(false), | 72 : is_gathering_(false), |
(...skipping 14 matching lines...) Expand all Loading... | |
65 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 87 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
66 idle_callback_ = idle_callback; | 88 idle_callback_ = idle_callback; |
67 } | 89 } |
68 | 90 |
69 bool BackgroundTracingManagerImpl::IsSupportedConfig( | 91 bool BackgroundTracingManagerImpl::IsSupportedConfig( |
70 BackgroundTracingConfig* config) { | 92 BackgroundTracingConfig* config) { |
71 // No config is just fine, we just don't do anything. | 93 // No config is just fine, we just don't do anything. |
72 if (!config) | 94 if (!config) |
73 return true; | 95 return true; |
74 | 96 |
75 // TODO(simonhatch): Implement reactive tracing path. | 97 if (config->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { |
76 if (config->mode != BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) | 98 BackgroundTracingPreemptiveConfig* preemptive_config = |
77 return false; | 99 static_cast<BackgroundTracingPreemptiveConfig*>(config); |
100 const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>& | |
101 configs = preemptive_config->configs; | |
102 for (size_t i = 0; i < configs.size(); ++i) { | |
103 if (configs[i].type != | |
104 BackgroundTracingPreemptiveConfig:: | |
105 MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) | |
106 return false; | |
107 } | |
108 } | |
78 | 109 |
79 // TODO(fmeawad): Implement uma triggers. | 110 if (config->mode == BackgroundTracingConfig::REACTIVE_TRACING_MODE) { |
80 BackgroundTracingPreemptiveConfig* preemptive_config = | 111 BackgroundTracingReactiveConfig* reactive_config = |
81 static_cast<BackgroundTracingPreemptiveConfig*>(config); | 112 static_cast<BackgroundTracingReactiveConfig*>(config); |
82 const std::vector<BackgroundTracingPreemptiveConfig::MonitoringRule>& | 113 const std::vector<BackgroundTracingReactiveConfig::TracingRule>& |
83 configs = preemptive_config->configs; | 114 configs = reactive_config->configs; |
84 for (size_t i = 0; i < configs.size(); ++i) { | 115 for (size_t i = 0; i < configs.size(); ++i) { |
85 if (configs[i].type != | 116 if (configs[i].type != |
86 BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) | 117 BackgroundTracingReactiveConfig:: |
87 return false; | 118 TRACE_UNTIL_10S_OR_TRIGGER_OR_FULL) |
119 return false; | |
120 } | |
88 } | 121 } |
89 | 122 |
90 return true; | 123 return true; |
91 } | 124 } |
92 | 125 |
93 bool BackgroundTracingManagerImpl::SetActiveScenario( | 126 bool BackgroundTracingManagerImpl::SetActiveScenario( |
94 scoped_ptr<BackgroundTracingConfig> config, | 127 scoped_ptr<BackgroundTracingConfig> config, |
95 const BackgroundTracingManager::ReceiveCallback& receive_callback, | 128 const BackgroundTracingManager::ReceiveCallback& receive_callback, |
96 bool requires_anonymized_data) { | 129 bool requires_anonymized_data) { |
97 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 130 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
(...skipping 18 matching lines...) Expand all Loading... | |
116 | 149 |
117 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { | 150 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { |
118 if (!config_) | 151 if (!config_) |
119 return; | 152 return; |
120 | 153 |
121 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { | 154 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { |
122 EnableRecording(GetCategoryFilterForCategoryPreset( | 155 EnableRecording(GetCategoryFilterForCategoryPreset( |
123 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get()) | 156 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get()) |
124 ->category_preset)); | 157 ->category_preset)); |
125 } else { | 158 } else { |
126 // TODO(simonhatch): Implement reactive tracing path. | 159 // There is nothing to do in case of reactive tracing. |
127 NOTREACHED(); | |
128 } | 160 } |
129 } | 161 } |
130 | 162 |
131 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( | 163 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( |
132 TriggerHandle handle) const { | 164 TriggerHandle handle) const { |
133 if (!config_) | 165 if (!config_) |
134 return false; | 166 return false; |
135 | 167 |
136 // If the last trace is still uploading, we don't allow a new one to trigger. | 168 // If the last trace is still uploading, we don't allow a new one to trigger. |
137 if (is_gathering_) | 169 if (is_gathering_) |
(...skipping 15 matching lines...) Expand all Loading... | |
153 for (size_t i = 0; i < configs.size(); ++i) { | 185 for (size_t i = 0; i < configs.size(); ++i) { |
154 if (configs[i].type != BackgroundTracingPreemptiveConfig:: | 186 if (configs[i].type != BackgroundTracingPreemptiveConfig:: |
155 MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) | 187 MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) |
156 continue; | 188 continue; |
157 | 189 |
158 if (trigger_name == configs[i].named_trigger_info.trigger_name) { | 190 if (trigger_name == configs[i].named_trigger_info.trigger_name) { |
159 return true; | 191 return true; |
160 } | 192 } |
161 } | 193 } |
162 } else { | 194 } else { |
163 // TODO(simonhatch): Implement reactive path. | 195 BackgroundTracingReactiveConfig* reactive_config = |
164 NOTREACHED(); | 196 static_cast<BackgroundTracingReactiveConfig*>(config_.get()); |
197 | |
198 const std::vector<BackgroundTracingReactiveConfig::TracingRule>& | |
199 configs = reactive_config->configs; | |
200 | |
201 for (size_t i = 0; i < configs.size(); ++i) { | |
202 if (configs[i].type != | |
203 BackgroundTracingReactiveConfig:: | |
204 TRACE_UNTIL_10S_OR_TRIGGER_OR_FULL) | |
205 continue; | |
206 if (trigger_name == configs[i].trigger_name) { | |
207 return true; | |
208 } | |
209 } | |
165 } | 210 } |
166 | |
167 return false; | 211 return false; |
168 } | 212 } |
169 | 213 |
170 void BackgroundTracingManagerImpl::TriggerNamedEvent( | 214 void BackgroundTracingManagerImpl::TriggerNamedEvent( |
171 BackgroundTracingManagerImpl::TriggerHandle handle, | 215 BackgroundTracingManagerImpl::TriggerHandle handle, |
172 StartedFinalizingCallback callback) { | 216 StartedFinalizingCallback callback) { |
173 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 217 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
174 content::BrowserThread::PostTask( | 218 content::BrowserThread::PostTask( |
175 content::BrowserThread::UI, FROM_HERE, | 219 content::BrowserThread::UI, FROM_HERE, |
176 base::Bind(&BackgroundTracingManagerImpl::TriggerNamedEvent, | 220 base::Bind(&BackgroundTracingManagerImpl::TriggerNamedEvent, |
177 base::Unretained(this), handle, callback)); | 221 base::Unretained(this), handle, callback)); |
178 return; | 222 return; |
179 } | 223 } |
180 | 224 |
181 if (!IsAbleToTriggerTracing(handle)) { | 225 if (!IsAbleToTriggerTracing(handle)) { |
182 if (!callback.is_null()) | 226 if (!callback.is_null()) |
183 callback.Run(false); | 227 callback.Run(false); |
184 return; | 228 return; |
185 } | 229 } |
186 | 230 |
187 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { | 231 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { |
188 BeginFinalizing(callback); | 232 BeginFinalizing(callback); |
189 } else { | 233 } else { |
190 // TODO(simonhatch): Implement reactive tracing path. | 234 if (is_tracing_) { |
191 NOTREACHED(); | 235 tracing_timer_->CancelTimer(); |
236 BeginFinalizing(callback); | |
237 return; | |
238 } else { | |
239 BackgroundTracingReactiveConfig* reactive_config = | |
240 static_cast<BackgroundTracingReactiveConfig*>(config_.get()); | |
241 const std::vector<BackgroundTracingReactiveConfig::TracingRule>& | |
242 configs = reactive_config->configs; | |
243 std::string trigger_name = GetTriggerNameFromHandle(handle); | |
244 for (size_t i = 0; i < configs.size(); ++i) { | |
245 if (configs[i].trigger_name == trigger_name) { | |
246 EnableRecording( | |
247 GetCategoryFilterForCategoryPreset(configs[i].category_preset)); | |
248 tracing_timer_.reset(new TracingTimer(callback)); | |
249 tracing_timer_->StartTimer(); | |
250 break; | |
251 } | |
252 } | |
253 } | |
192 } | 254 } |
193 } | 255 } |
194 | 256 |
195 BackgroundTracingManagerImpl::TriggerHandle | 257 BackgroundTracingManagerImpl::TriggerHandle |
196 BackgroundTracingManagerImpl::RegisterTriggerType(const char* trigger_name) { | 258 BackgroundTracingManagerImpl::RegisterTriggerType(const char* trigger_name) { |
197 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 259 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
198 | 260 |
199 trigger_handle_ids_ += 1; | 261 trigger_handle_ids_ += 1; |
200 | 262 |
201 trigger_handles_.insert( | 263 trigger_handles_.insert( |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 return NULL; | 365 return NULL; |
304 } | 366 } |
305 | 367 |
306 void BackgroundTracingConfig::IntoDict(const BackgroundTracingConfig* config, | 368 void BackgroundTracingConfig::IntoDict(const BackgroundTracingConfig* config, |
307 base::DictionaryValue* dict) { | 369 base::DictionaryValue* dict) { |
308 // TODO(simonhatch): Implement this. | 370 // TODO(simonhatch): Implement this. |
309 CHECK(false); | 371 CHECK(false); |
310 } | 372 } |
311 | 373 |
312 } // namspace content | 374 } // namspace content |
OLD | NEW |