| 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/command_line.h" | |
| 8 #include "base/cpu.h" | 7 #include "base/cpu.h" |
| 9 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 10 #include "base/macros.h" | 9 #include "base/macros.h" |
| 11 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
| 13 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 14 #include "content/browser/tracing/background_tracing_rule.h" | 13 #include "content/browser/tracing/background_tracing_rule.h" |
| 15 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
| 17 #include "content/public/browser/gpu_data_manager.h" | 16 #include "content/public/browser/gpu_data_manager.h" |
| 18 #include "content/public/browser/tracing_delegate.h" | 17 #include "content/public/browser/tracing_delegate.h" |
| 19 #include "content/public/common/content_client.h" | 18 #include "content/public/common/content_client.h" |
| 20 #include "content/public/common/content_switches.h" | |
| 21 #include "gpu/config/gpu_info.h" | 19 #include "gpu/config/gpu_info.h" |
| 22 #include "net/base/network_change_notifier.h" | 20 #include "net/base/network_change_notifier.h" |
| 23 | 21 |
| 24 namespace content { | 22 namespace content { |
| 25 | 23 |
| 26 namespace { | 24 namespace { |
| 27 | 25 |
| 28 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller = | 26 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller = |
| 29 LAZY_INSTANCE_INITIALIZER; | 27 LAZY_INSTANCE_INITIALIZER; |
| 30 | 28 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 *config.get(), requires_anonymized_data)) { | 144 *config.get(), requires_anonymized_data)) { |
| 147 return false; | 145 return false; |
| 148 } | 146 } |
| 149 } else { | 147 } else { |
| 150 base::MessageLoop::current()->PostTask( | 148 base::MessageLoop::current()->PostTask( |
| 151 FROM_HERE, | 149 FROM_HERE, |
| 152 base::Bind(&BackgroundTracingManagerImpl::ValidateStartupScenario, | 150 base::Bind(&BackgroundTracingManagerImpl::ValidateStartupScenario, |
| 153 base::Unretained(this))); | 151 base::Unretained(this))); |
| 154 } | 152 } |
| 155 | 153 |
| 156 scoped_ptr<const content::BackgroundTracingConfigImpl> config_impl( | 154 // No point in tracing if there's nowhere to send it. |
| 157 static_cast<BackgroundTracingConfigImpl*>(config.release())); | 155 if (config && receive_callback.is_null()) |
| 156 return false; |
| 158 | 157 |
| 159 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 158 config_.reset(static_cast<BackgroundTracingConfigImpl*>(config.release())); |
| 160 | |
| 161 if (config_impl) { | |
| 162 // No point in tracing if there's nowhere to send it. | |
| 163 if (receive_callback.is_null()) | |
| 164 return false; | |
| 165 | |
| 166 // If the scenario requires us to toggle Blink features, we want | |
| 167 // to neither override anything else nor to do we want to activate | |
| 168 // the scenario without doing the toggle, so if something else has | |
| 169 // configured these switches we just abort. | |
| 170 if (!config_impl->enable_blink_features().empty() && | |
| 171 command_line->HasSwitch(switches::kEnableBlinkFeatures)) { | |
| 172 return false; | |
| 173 } | |
| 174 | |
| 175 if (!config_impl->disable_blink_features().empty() && | |
| 176 command_line->HasSwitch(switches::kDisableBlinkFeatures)) { | |
| 177 return false; | |
| 178 } | |
| 179 } | |
| 180 | |
| 181 config_ = config_impl.Pass(); | |
| 182 receive_callback_ = receive_callback; | 159 receive_callback_ = receive_callback; |
| 183 requires_anonymized_data_ = requires_anonymized_data; | 160 requires_anonymized_data_ = requires_anonymized_data; |
| 184 | 161 |
| 185 if (config_) { | 162 if (config_) { |
| 186 DCHECK(!config_.get()->rules().empty()); | 163 DCHECK(!config_.get()->rules().empty()); |
| 187 for (auto& rule : config_.get()->rules()) | 164 for (auto& rule : config_.get()->rules()) |
| 188 static_cast<BackgroundTracingRule*>(rule)->Install(); | 165 static_cast<BackgroundTracingRule*>(rule)->Install(); |
| 189 | |
| 190 if (!config_->enable_blink_features().empty()) { | |
| 191 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, | |
| 192 config_->enable_blink_features()); | |
| 193 } | |
| 194 | |
| 195 if (!config_->disable_blink_features().empty()) { | |
| 196 command_line->AppendSwitchASCII(switches::kDisableBlinkFeatures, | |
| 197 config_->disable_blink_features()); | |
| 198 } | |
| 199 } | 166 } |
| 200 | 167 |
| 201 EnableRecordingIfConfigNeedsIt(); | 168 EnableRecordingIfConfigNeedsIt(); |
| 202 | 169 |
| 203 RecordBackgroundTracingMetric(SCENARIO_ACTIVATED_SUCCESSFULLY); | 170 RecordBackgroundTracingMetric(SCENARIO_ACTIVATED_SUCCESSFULLY); |
| 204 return true; | 171 return true; |
| 205 } | 172 } |
| 206 | 173 |
| 207 bool BackgroundTracingManagerImpl::HasActiveScenarioForTesting() { | 174 bool BackgroundTracingManagerImpl::HasActiveScenarioForTesting() { |
| 208 return config_; | 175 return config_; |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_STARTUP: | 549 case BackgroundTracingConfigImpl::CategoryPreset::BENCHMARK_STARTUP: |
| 583 return "benchmark,toplevel,startup,disabled-by-default-file," | 550 return "benchmark,toplevel,startup,disabled-by-default-file," |
| 584 "disabled-by-default-toplevel.flow," | 551 "disabled-by-default-toplevel.flow," |
| 585 "disabled-by-default-ipc.flow"; | 552 "disabled-by-default-ipc.flow"; |
| 586 } | 553 } |
| 587 NOTREACHED(); | 554 NOTREACHED(); |
| 588 return ""; | 555 return ""; |
| 589 } | 556 } |
| 590 | 557 |
| 591 } // namspace content | 558 } // namspace content |
| OLD | NEW |