Chromium Code Reviews| Index: chrome/browser/metrics/plugin_metrics_provider.cc |
| diff --git a/chrome/browser/metrics/plugin_metrics_provider.cc b/chrome/browser/metrics/plugin_metrics_provider.cc |
| index f7f5c1b509afea41e2a867dce718899a38b934de..e9cfe538dd2331e33ca9c6a5521a8a02183a2259 100644 |
| --- a/chrome/browser/metrics/plugin_metrics_provider.cc |
| +++ b/chrome/browser/metrics/plugin_metrics_provider.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/prefs/scoped_user_pref_update.h" |
| #include "base/stl_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/time/time.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/plugins/plugin_prefs.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| @@ -23,6 +24,9 @@ |
| namespace { |
| +// Delay for RecordCurrentState execution. |
| +const int kRecordStateDelayMs = 15 * base::Time::kMillisecondsPerSecond; |
| + |
| // Returns the plugin preferences corresponding for this user, if available. |
| // If multiple user profiles are loaded, returns the preferences corresponding |
| // to an arbitrary one of the profiles. |
| @@ -126,6 +130,7 @@ void PluginMetricsProvider::ProvideSystemProfileMetrics( |
| void PluginMetricsProvider::ProvideStabilityMetrics( |
| metrics::SystemProfileProto* system_profile_proto) { |
| + ForcedRecordCurrentState(); |
| const base::ListValue* plugin_stats_list = local_state_->GetList( |
| prefs::kStabilityPluginStats); |
| if (!plugin_stats_list) |
| @@ -299,6 +304,7 @@ void PluginMetricsProvider::LogPluginLoadingError( |
| DCHECK(IsPluginProcess(stats.process_type)); |
| } |
| stats.loading_errors++; |
| + DelayedRecordCurrentState(kRecordStateDelayMs); |
| } |
| void PluginMetricsProvider::SetPluginsForTesting( |
| @@ -339,14 +345,41 @@ PluginMetricsProvider::GetChildProcessStats( |
| void PluginMetricsProvider::BrowserChildProcessHostConnected( |
| const content::ChildProcessData& data) { |
| GetChildProcessStats(data).process_launches++; |
| + DelayedRecordCurrentState(kRecordStateDelayMs); |
| } |
| void PluginMetricsProvider::BrowserChildProcessCrashed( |
| const content::ChildProcessData& data) { |
| GetChildProcessStats(data).process_crashes++; |
| + DelayedRecordCurrentState(kRecordStateDelayMs); |
| } |
| void PluginMetricsProvider::BrowserChildProcessInstanceCreated( |
| const content::ChildProcessData& data) { |
| GetChildProcessStats(data).instances++; |
| + DelayedRecordCurrentState(kRecordStateDelayMs); |
| +} |
| + |
| +bool PluginMetricsProvider::DelayedRecordCurrentState(int delay_sec) { |
| + if (weak_ptr_factory_.HasWeakPtrs()) { |
| + return false; |
| + } else { |
|
Alexei Svitkine (slow)
2014/08/05 21:35:21
Nit: No else after early return. Here and in the f
gayane -on leave until 09-2017
2014/08/06 14:51:35
Done.
|
| + base::MessageLoopProxy::current()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&PluginMetricsProvider::RecordCurrentState, |
| + weak_ptr_factory_.GetWeakPtr()), |
| + base::TimeDelta::FromMilliseconds(delay_sec)); |
| + return true; |
| + } |
| +} |
| + |
| +bool PluginMetricsProvider::ForcedRecordCurrentState() { |
| + if (!weak_ptr_factory_.HasWeakPtrs()) { |
| + return false; |
| + } else { |
| + weak_ptr_factory_.InvalidateWeakPtrs(); |
| + RecordCurrentState(); |
| + return true; |
| + } |
| + |
| } |