Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/metrics/plugin_metrics_provider.h" | 5 #include "chrome/browser/metrics/plugin_metrics_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | |
| 14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/plugins/plugin_prefs.h" | 16 #include "chrome/browser/plugins/plugin_prefs.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "components/metrics/proto/system_profile.pb.h" | 19 #include "components/metrics/proto/system_profile.pb.h" |
| 19 #include "content/public/browser/child_process_data.h" | 20 #include "content/public/browser/child_process_data.h" |
| 20 #include "content/public/browser/plugin_service.h" | 21 #include "content/public/browser/plugin_service.h" |
| 21 #include "content/public/common/process_type.h" | 22 #include "content/public/common/process_type.h" |
| 22 #include "content/public/common/webplugininfo.h" | 23 #include "content/public/common/webplugininfo.h" |
| 23 | 24 |
| 25 // Delay for RecordCurrentState execution 10 minutes in seconds. | |
| 26 const int kRecordStateDelaySec = 10 * 60; | |
|
Alexei Svitkine (slow)
2014/08/05 20:13:11
I think we can make the delay much shorter - e.g.
gayane -on leave until 09-2017
2014/08/05 21:24:55
Done.
| |
| 27 | |
| 24 namespace { | 28 namespace { |
| 25 | 29 |
| 26 // Returns the plugin preferences corresponding for this user, if available. | 30 // Returns the plugin preferences corresponding for this user, if available. |
| 27 // If multiple user profiles are loaded, returns the preferences corresponding | 31 // If multiple user profiles are loaded, returns the preferences corresponding |
| 28 // to an arbitrary one of the profiles. | 32 // to an arbitrary one of the profiles. |
| 29 PluginPrefs* GetPluginPrefs() { | 33 PluginPrefs* GetPluginPrefs() { |
| 30 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 34 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 31 | 35 |
| 32 if (!profile_manager) { | 36 if (!profile_manager) { |
| 33 // The profile manager can be NULL when testing. | 37 // The profile manager can be NULL when testing. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 void PluginMetricsProvider::ProvideSystemProfileMetrics( | 122 void PluginMetricsProvider::ProvideSystemProfileMetrics( |
| 119 metrics::SystemProfileProto* system_profile_proto) { | 123 metrics::SystemProfileProto* system_profile_proto) { |
| 120 PluginPrefs* plugin_prefs = GetPluginPrefs(); | 124 PluginPrefs* plugin_prefs = GetPluginPrefs(); |
| 121 for (size_t i = 0; i < plugins_.size(); ++i) { | 125 for (size_t i = 0; i < plugins_.size(); ++i) { |
| 122 SetPluginInfo(plugins_[i], plugin_prefs, | 126 SetPluginInfo(plugins_[i], plugin_prefs, |
| 123 system_profile_proto->add_plugin()); | 127 system_profile_proto->add_plugin()); |
| 124 } | 128 } |
| 125 } | 129 } |
| 126 | 130 |
| 127 void PluginMetricsProvider::ProvideStabilityMetrics( | 131 void PluginMetricsProvider::ProvideStabilityMetrics( |
| 128 metrics::SystemProfileProto* system_profile_proto) { | 132 metrics::SystemProfileProto* system_profile_proto) { |
|
Alexei Svitkine (slow)
2014/08/05 20:13:12
So this function actually reads the info from pref
gayane -on leave until 09-2017
2014/08/05 21:24:55
Added a ForcedRecordCurrentState function and call
| |
| 129 const base::ListValue* plugin_stats_list = local_state_->GetList( | 133 const base::ListValue* plugin_stats_list = local_state_->GetList( |
| 130 prefs::kStabilityPluginStats); | 134 prefs::kStabilityPluginStats); |
| 131 if (!plugin_stats_list) | 135 if (!plugin_stats_list) |
| 132 return; | 136 return; |
| 133 | 137 |
| 134 metrics::SystemProfileProto::Stability* stability = | 138 metrics::SystemProfileProto::Stability* stability = |
| 135 system_profile_proto->mutable_stability(); | 139 system_profile_proto->mutable_stability(); |
| 136 for (base::ListValue::const_iterator iter = plugin_stats_list->begin(); | 140 for (base::ListValue::const_iterator iter = plugin_stats_list->begin(); |
| 137 iter != plugin_stats_list->end(); ++iter) { | 141 iter != plugin_stats_list->end(); ++iter) { |
| 138 if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) { | 142 if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 ChildProcessStats& stats = child_process_stats_buffer_[plugin.name]; | 296 ChildProcessStats& stats = child_process_stats_buffer_[plugin.name]; |
| 293 // Initialize the type if this entry is new. | 297 // Initialize the type if this entry is new. |
| 294 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) { | 298 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) { |
| 295 // The plug-in process might not actually be of type PLUGIN (which means | 299 // The plug-in process might not actually be of type PLUGIN (which means |
| 296 // NPAPI), but we only care that it is *a* plug-in process. | 300 // NPAPI), but we only care that it is *a* plug-in process. |
| 297 stats.process_type = content::PROCESS_TYPE_PLUGIN; | 301 stats.process_type = content::PROCESS_TYPE_PLUGIN; |
| 298 } else { | 302 } else { |
| 299 DCHECK(IsPluginProcess(stats.process_type)); | 303 DCHECK(IsPluginProcess(stats.process_type)); |
| 300 } | 304 } |
| 301 stats.loading_errors++; | 305 stats.loading_errors++; |
| 306 DelayedRecordCurrentState(kRecordStateDelaySec); | |
| 302 } | 307 } |
| 303 | 308 |
| 304 void PluginMetricsProvider::SetPluginsForTesting( | 309 void PluginMetricsProvider::SetPluginsForTesting( |
| 305 const std::vector<content::WebPluginInfo>& plugins) { | 310 const std::vector<content::WebPluginInfo>& plugins) { |
| 306 plugins_ = plugins; | 311 plugins_ = plugins; |
| 307 } | 312 } |
| 308 | 313 |
| 309 // static | 314 // static |
| 310 bool PluginMetricsProvider::IsPluginProcess(int process_type) { | 315 bool PluginMetricsProvider::IsPluginProcess(int process_type) { |
| 311 return (process_type == content::PROCESS_TYPE_PLUGIN || | 316 return (process_type == content::PROCESS_TYPE_PLUGIN || |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 332 if (!ContainsKey(child_process_stats_buffer_, child_name)) { | 337 if (!ContainsKey(child_process_stats_buffer_, child_name)) { |
| 333 child_process_stats_buffer_[child_name] = | 338 child_process_stats_buffer_[child_name] = |
| 334 ChildProcessStats(data.process_type); | 339 ChildProcessStats(data.process_type); |
| 335 } | 340 } |
| 336 return child_process_stats_buffer_[child_name]; | 341 return child_process_stats_buffer_[child_name]; |
| 337 } | 342 } |
| 338 | 343 |
| 339 void PluginMetricsProvider::BrowserChildProcessHostConnected( | 344 void PluginMetricsProvider::BrowserChildProcessHostConnected( |
| 340 const content::ChildProcessData& data) { | 345 const content::ChildProcessData& data) { |
| 341 GetChildProcessStats(data).process_launches++; | 346 GetChildProcessStats(data).process_launches++; |
| 347 DelayedRecordCurrentState(kRecordStateDelaySec); | |
| 342 } | 348 } |
| 343 | 349 |
| 344 void PluginMetricsProvider::BrowserChildProcessCrashed( | 350 void PluginMetricsProvider::BrowserChildProcessCrashed( |
| 345 const content::ChildProcessData& data) { | 351 const content::ChildProcessData& data) { |
| 346 GetChildProcessStats(data).process_crashes++; | 352 GetChildProcessStats(data).process_crashes++; |
| 353 DelayedRecordCurrentState(kRecordStateDelaySec); | |
| 347 } | 354 } |
| 348 | 355 |
| 349 void PluginMetricsProvider::BrowserChildProcessInstanceCreated( | 356 void PluginMetricsProvider::BrowserChildProcessInstanceCreated( |
| 350 const content::ChildProcessData& data) { | 357 const content::ChildProcessData& data) { |
| 351 GetChildProcessStats(data).instances++; | 358 GetChildProcessStats(data).instances++; |
| 359 DelayedRecordCurrentState(kRecordStateDelaySec); | |
| 352 } | 360 } |
| 361 | |
| 362 bool PluginMetricsProvider::DelayedRecordCurrentState(int delay_sec) { | |
| 363 if (!weak_ptr_factory_.HasWeakPtrs()) { | |
|
Alexei Svitkine (slow)
2014/08/05 20:13:11
Nit: Chromium style prefers early returns rather t
gayane -on leave until 09-2017
2014/08/05 21:24:55
Done.
| |
| 364 base::MessageLoopProxy::current()->PostDelayedTask( | |
| 365 FROM_HERE, | |
| 366 base::Bind(&PluginMetricsProvider::RecordCurrentState, | |
| 367 weak_ptr_factory_.GetWeakPtr()), | |
| 368 base::TimeDelta::FromSeconds(delay_sec)); | |
| 369 return true; | |
| 370 } | |
| 371 | |
| 372 return false; | |
| 373 } | |
| OLD | NEW |