Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3851)

Unified Diff: chrome/browser/metrics/plugin_metrics_provider.cc

Issue 441013002: Eliminate MetricsProvider::RecordCurrentState() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: last changes Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f34ee3fcebbab40bb698fc61c8f1d3fd620f17ca 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) {
+ RecordCurrentStateIfPending();
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++;
+ RecordCurrentStateWithDelay(kRecordStateDelayMs);
}
void PluginMetricsProvider::SetPluginsForTesting(
@@ -339,14 +345,38 @@ PluginMetricsProvider::GetChildProcessStats(
void PluginMetricsProvider::BrowserChildProcessHostConnected(
const content::ChildProcessData& data) {
GetChildProcessStats(data).process_launches++;
+ RecordCurrentStateWithDelay(kRecordStateDelayMs);
}
void PluginMetricsProvider::BrowserChildProcessCrashed(
const content::ChildProcessData& data) {
GetChildProcessStats(data).process_crashes++;
+ RecordCurrentStateWithDelay(kRecordStateDelayMs);
}
void PluginMetricsProvider::BrowserChildProcessInstanceCreated(
const content::ChildProcessData& data) {
GetChildProcessStats(data).instances++;
+ RecordCurrentStateWithDelay(kRecordStateDelayMs);
+}
+
+bool PluginMetricsProvider::RecordCurrentStateWithDelay(int delay_sec) {
+ if (weak_ptr_factory_.HasWeakPtrs())
+ return false;
+
+ base::MessageLoopProxy::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&PluginMetricsProvider::RecordCurrentState,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::TimeDelta::FromMilliseconds(delay_sec));
+ return true;
+}
+
+bool PluginMetricsProvider::RecordCurrentStateIfPending() {
+ if (!weak_ptr_factory_.HasWeakPtrs())
+ return false;
+
+ weak_ptr_factory_.InvalidateWeakPtrs();
+ RecordCurrentState();
+ return true;
}
« no previous file with comments | « chrome/browser/metrics/plugin_metrics_provider.h ('k') | chrome/browser/metrics/plugin_metrics_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698