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