Commit 29de18fc authored by blundell@chromium.org's avatar blundell@chromium.org

Introduce ChromeStabilityMetricsProvider

This class provides Chrome-specific stability metrics, enabling moving code
related to these metrics out of MetricsLog and MetricsService. It also
eliminates all notification listening from MetricsService. As part of the
latter change, ThreadWatcherObserver now registers explicitly for the
notifications it is concerned with rather than going through MetricsService for
this purpose.

BUG=375237

Review URL: https://codereview.chromium.org/289283011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272426 0039d316-1c4b-4281-b951-d872f2087c98
parent 7d00032d
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/chrome_stability_metrics_provider.h"
#include <vector>
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/proto/system_profile.pb.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/process_map.h"
#if defined(OS_WIN)
#include <windows.h> // Needed for STATUS_* codes
#endif
namespace {
void IncrementPrefValue(const char* path) {
PrefService* pref = g_browser_process->local_state();
DCHECK(pref);
int value = pref->GetInteger(path);
pref->SetInteger(path, value + 1);
}
void IncrementLongPrefsValue(const char* path) {
PrefService* pref = g_browser_process->local_state();
DCHECK(pref);
int64 value = pref->GetInt64(path);
pref->SetInt64(path, value + 1);
}
// Converts an exit code into something that can be inserted into our
// histograms (which expect non-negative numbers less than MAX_INT).
int MapCrashExitCodeForHistogram(int exit_code) {
#if defined(OS_WIN)
// Since |abs(STATUS_GUARD_PAGE_VIOLATION) == MAX_INT| it causes problems in
// histograms.cc. Solve this by remapping it to a smaller value, which
// hopefully doesn't conflict with other codes.
if (exit_code == STATUS_GUARD_PAGE_VIOLATION)
return 0x1FCF7EC3; // Randomly picked number.
#endif
return std::abs(exit_code);
}
} // namespace
ChromeStabilityMetricsProvider::ChromeStabilityMetricsProvider() {
}
ChromeStabilityMetricsProvider::~ChromeStabilityMetricsProvider() {
}
void ChromeStabilityMetricsProvider::OnRecordingEnabled() {
registrar_.Add(this,
content::NOTIFICATION_LOAD_START,
content::NotificationService::AllSources());
registrar_.Add(this,
content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
content::NotificationService::AllSources());
registrar_.Add(this,
content::NOTIFICATION_RENDER_WIDGET_HOST_HANG,
content::NotificationService::AllSources());
}
void ChromeStabilityMetricsProvider::OnRecordingDisabled() {
registrar_.RemoveAll();
}
void ChromeStabilityMetricsProvider::ProvideStabilityMetrics(
metrics::SystemProfileProto_Stability* stability_proto) {
PrefService* pref = g_browser_process->local_state();
int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
if (count) {
stability_proto->set_page_load_count(count);
pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
}
count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
if (count) {
stability_proto->set_renderer_crash_count(count);
pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
}
count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
if (count) {
stability_proto->set_extension_renderer_crash_count(count);
pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
}
count = pref->GetInteger(prefs::kStabilityRendererHangCount);
if (count) {
stability_proto->set_renderer_hang_count(count);
pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
}
}
void ChromeStabilityMetricsProvider::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case content::NOTIFICATION_LOAD_START: {
content::NavigationController* controller =
content::Source<content::NavigationController>(source).ptr();
content::WebContents* web_contents = controller->GetWebContents();
LogLoadStarted(web_contents);
break;
}
case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
content::RenderProcessHost::RendererClosedDetails* process_details =
content::Details<content::RenderProcessHost::RendererClosedDetails>(
details).ptr();
content::RenderProcessHost* host =
content::Source<content::RenderProcessHost>(source).ptr();
LogRendererCrash(
host, process_details->status, process_details->exit_code);
break;
}
case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG:
LogRendererHang();
break;
default:
NOTREACHED();
break;
}
}
void ChromeStabilityMetricsProvider::LogLoadStarted(
content::WebContents* web_contents) {
content::RecordAction(base::UserMetricsAction("PageLoad"));
HISTOGRAM_ENUMERATION("Chrome.UmaPageloadCounter", 1, 2);
IncrementPrefValue(prefs::kStabilityPageLoadCount);
IncrementLongPrefsValue(prefs::kUninstallMetricsPageLoadCount);
// We need to save the prefs, as page load count is a critical stat, and it
// might be lost due to a crash :-(.
}
void ChromeStabilityMetricsProvider::LogRendererCrash(
content::RenderProcessHost* host,
base::TerminationStatus status,
int exit_code) {
bool was_extension_process =
extensions::ProcessMap::Get(host->GetBrowserContext())
->Contains(host->GetID());
if (status == base::TERMINATION_STATUS_PROCESS_CRASHED ||
status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION) {
if (was_extension_process) {
IncrementPrefValue(prefs::kStabilityExtensionRendererCrashCount);
UMA_HISTOGRAM_SPARSE_SLOWLY("CrashExitCodes.Extension",
MapCrashExitCodeForHistogram(exit_code));
} else {
IncrementPrefValue(prefs::kStabilityRendererCrashCount);
UMA_HISTOGRAM_SPARSE_SLOWLY("CrashExitCodes.Renderer",
MapCrashExitCodeForHistogram(exit_code));
}
UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildCrashes",
was_extension_process ? 2 : 1);
} else if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) {
UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildKills",
was_extension_process ? 2 : 1);
} else if (status == base::TERMINATION_STATUS_STILL_RUNNING) {
UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.DisconnectedAlive",
was_extension_process ? 2 : 1);
}
}
void ChromeStabilityMetricsProvider::LogRendererHang() {
IncrementPrefValue(prefs::kStabilityRendererHangCount);
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_METRICS_CHROME_STABILITY_METRICS_PROVIDER_H_
#define CHROME_BROWSER_METRICS_CHROME_STABILITY_METRICS_PROVIDER_H_
#include "base/basictypes.h"
#include "base/metrics/user_metrics.h"
#include "base/process/kill.h"
#include "components/metrics/metrics_provider.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
namespace content {
class RenderProcessHost;
class WebContents;
}
// ChromeStabilityMetricsProvider gathers and logs Chrome-specific stability-
// related metrics.
class ChromeStabilityMetricsProvider : public metrics::MetricsProvider,
public content::NotificationObserver {
public:
ChromeStabilityMetricsProvider();
virtual ~ChromeStabilityMetricsProvider();
// metrics::MetricsDataProvider:
virtual void OnRecordingEnabled() OVERRIDE;
virtual void OnRecordingDisabled() OVERRIDE;
virtual void ProvideStabilityMetrics(
metrics::SystemProfileProto_Stability* stability_proto) OVERRIDE;
private:
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Logs the initiation of a page load and uses |web_contents| to do
// additional logging of the type of page loaded.
void LogLoadStarted(content::WebContents* web_contents);
// Records a renderer process crash.
void LogRendererCrash(content::RenderProcessHost* host,
base::TerminationStatus status,
int exit_code);
// Records a renderer process hang.
void LogRendererHang();
// Registrar for receiving stability-related notifications.
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(ChromeStabilityMetricsProvider);
};
#endif // CHROME_BROWSER_METRICS_CHROME_STABILITY_METRICS_PROVIDER_H_
...@@ -478,31 +478,8 @@ void MetricsLog::WriteRealtimeStabilityAttributes( ...@@ -478,31 +478,8 @@ void MetricsLog::WriteRealtimeStabilityAttributes(
SystemProfileProto::Stability* stability = SystemProfileProto::Stability* stability =
uma_proto()->mutable_system_profile()->mutable_stability(); uma_proto()->mutable_system_profile()->mutable_stability();
int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
if (count) {
stability->set_page_load_count(count);
pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
}
count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
if (count) {
stability->set_renderer_crash_count(count);
pref->SetInteger(prefs::kStabilityRendererCrashCount, 0);
}
count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount);
if (count) {
stability->set_extension_renderer_crash_count(count);
pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0);
}
count = pref->GetInteger(prefs::kStabilityRendererHangCount);
if (count) {
stability->set_renderer_hang_count(count);
pref->SetInteger(prefs::kStabilityRendererHangCount, 0);
}
count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); int count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount);
if (count) { if (count) {
stability->set_child_process_crash_count(count); stability->set_child_process_crash_count(count);
pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0);
......
...@@ -185,6 +185,7 @@ ...@@ -185,6 +185,7 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/io_thread.h" #include "chrome/browser/io_thread.h"
#include "chrome/browser/metrics/chrome_stability_metrics_provider.h"
#include "chrome/browser/metrics/compression_utils.h" #include "chrome/browser/metrics/compression_utils.h"
#include "chrome/browser/metrics/metrics_log.h" #include "chrome/browser/metrics/metrics_log.h"
#include "chrome/browser/metrics/metrics_state_manager.h" #include "chrome/browser/metrics/metrics_state_manager.h"
...@@ -202,15 +203,11 @@ ...@@ -202,15 +203,11 @@
#include "components/variations/entropy_provider.h" #include "components/variations/entropy_provider.h"
#include "components/variations/metrics_util.h" #include "components/variations/metrics_util.h"
#include "content/public/browser/child_process_data.h" #include "content/public/browser/child_process_data.h"
#include "content/public/browser/load_notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/plugin_service.h" #include "content/public/browser/plugin_service.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/user_metrics.h" #include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/process_type.h" #include "content/public/common/process_type.h"
#include "content/public/common/webplugininfo.h" #include "content/public/common/webplugininfo.h"
#include "extensions/browser/process_map.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
...@@ -233,7 +230,6 @@ ...@@ -233,7 +230,6 @@
using base::Time; using base::Time;
using content::BrowserThread; using content::BrowserThread;
using content::ChildProcessData; using content::ChildProcessData;
using content::LoadNotificationDetails;
using content::PluginService; using content::PluginService;
using metrics::MetricsLogManager; using metrics::MetricsLogManager;
...@@ -298,20 +294,6 @@ ResponseStatus ResponseCodeToStatus(int response_code) { ...@@ -298,20 +294,6 @@ ResponseStatus ResponseCodeToStatus(int response_code) {
} }
} }
// Converts an exit code into something that can be inserted into our
// histograms (which expect non-negative numbers less than MAX_INT).
int MapCrashExitCodeForHistogram(int exit_code) {
#if defined(OS_WIN)
// Since |abs(STATUS_GUARD_PAGE_VIOLATION) == MAX_INT| it causes problems in
// histograms.cc. Solve this by remapping it to a smaller value, which
// hopefully doesn't conflict with other codes.
if (exit_code == STATUS_GUARD_PAGE_VIOLATION)
return 0x1FCF7EC3; // Randomly picked number.
#endif
return std::abs(exit_code);
}
void MarkAppCleanShutdownAndCommit() { void MarkAppCleanShutdownAndCommit() {
PrefService* pref = g_browser_process->local_state(); PrefService* pref = g_browser_process->local_state();
pref->SetBoolean(prefs::kStabilityExitedCleanly, true); pref->SetBoolean(prefs::kStabilityExitedCleanly, true);
...@@ -468,6 +450,8 @@ MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, ...@@ -468,6 +450,8 @@ MetricsService::MetricsService(metrics::MetricsStateManager* state_manager,
scoped_ptr<metrics::MetricsProvider>(new NetworkMetricsProvider)); scoped_ptr<metrics::MetricsProvider>(new NetworkMetricsProvider));
RegisterMetricsProvider( RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider)); scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider));
RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(new ChromeStabilityMetricsProvider));
#if defined(OS_WIN) #if defined(OS_WIN)
google_update_metrics_provider_ = new GoogleUpdateMetricsProviderWin; google_update_metrics_provider_ = new GoogleUpdateMetricsProviderWin;
...@@ -553,7 +537,6 @@ void MetricsService::EnableRecording() { ...@@ -553,7 +537,6 @@ void MetricsService::EnableRecording() {
for (size_t i = 0; i < metrics_providers_.size(); ++i) for (size_t i = 0; i < metrics_providers_.size(); ++i)
metrics_providers_[i]->OnRecordingEnabled(); metrics_providers_[i]->OnRecordingEnabled();
SetUpNotifications(&registrar_, this);
base::RemoveActionCallback(action_callback_); base::RemoveActionCallback(action_callback_);
action_callback_ = base::Bind(&MetricsService::OnUserAction, action_callback_ = base::Bind(&MetricsService::OnUserAction,
base::Unretained(this)); base::Unretained(this));
...@@ -568,7 +551,6 @@ void MetricsService::DisableRecording() { ...@@ -568,7 +551,6 @@ void MetricsService::DisableRecording() {
recording_active_ = false; recording_active_ = false;
base::RemoveActionCallback(action_callback_); base::RemoveActionCallback(action_callback_);
registrar_.RemoveAll();
for (size_t i = 0; i < metrics_providers_.size(); ++i) for (size_t i = 0; i < metrics_providers_.size(); ++i)
metrics_providers_[i]->OnRecordingDisabled(); metrics_providers_[i]->OnRecordingDisabled();
...@@ -587,18 +569,6 @@ bool MetricsService::reporting_active() const { ...@@ -587,18 +569,6 @@ bool MetricsService::reporting_active() const {
return reporting_active_; return reporting_active_;
} }
// static
void MetricsService::SetUpNotifications(
content::NotificationRegistrar* registrar,
content::NotificationObserver* observer) {
registrar->Add(observer, content::NOTIFICATION_LOAD_START,
content::NotificationService::AllSources());
registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
content::NotificationService::AllSources());
registrar->Add(observer, content::NOTIFICATION_RENDER_WIDGET_HOST_HANG,
content::NotificationService::AllSources());
}
void MetricsService::RecordDelta(const base::HistogramBase& histogram, void MetricsService::RecordDelta(const base::HistogramBase& histogram,
const base::HistogramSamples& snapshot) { const base::HistogramSamples& snapshot) {
log_manager_.current_log()->RecordHistogramDelta(histogram.histogram_name(), log_manager_.current_log()->RecordHistogramDelta(histogram.histogram_name(),
...@@ -641,42 +611,6 @@ void MetricsService::BrowserChildProcessInstanceCreated( ...@@ -641,42 +611,6 @@ void MetricsService::BrowserChildProcessInstanceCreated(
GetChildProcessStats(data).instances++; GetChildProcessStats(data).instances++;
} }
void MetricsService::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK(log_manager_.current_log());
DCHECK(IsSingleThreaded());
switch (type) {
case content::NOTIFICATION_LOAD_START: {
content::NavigationController* controller =
content::Source<content::NavigationController>(source).ptr();
content::WebContents* web_contents = controller->GetWebContents();
LogLoadStarted(web_contents);
break;
}
case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
content::RenderProcessHost::RendererClosedDetails* process_details =
content::Details<
content::RenderProcessHost::RendererClosedDetails>(
details).ptr();
content::RenderProcessHost* host =
content::Source<content::RenderProcessHost>(source).ptr();
LogRendererCrash(
host, process_details->status, process_details->exit_code);
break;
}
case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG:
LogRendererHang();
break;
default:
NOTREACHED();
}
}
void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) { void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) {
// If there wasn't a lot of action, maybe the computer was asleep, in which // If there wasn't a lot of action, maybe the computer was asleep, in which
// case, the log transmissions should have stopped. Here we start them up // case, the log transmissions should have stopped. Here we start them up
...@@ -1504,50 +1438,6 @@ void MetricsService::IncrementLongPrefsValue(const char* path) { ...@@ -1504,50 +1438,6 @@ void MetricsService::IncrementLongPrefsValue(const char* path) {
pref->SetInt64(path, value + 1); pref->SetInt64(path, value + 1);
} }
void MetricsService::LogLoadStarted(content::WebContents* web_contents) {
content::RecordAction(base::UserMetricsAction("PageLoad"));
HISTOGRAM_ENUMERATION("Chrome.UmaPageloadCounter", 1, 2);
IncrementPrefValue(prefs::kStabilityPageLoadCount);
IncrementLongPrefsValue(prefs::kUninstallMetricsPageLoadCount);
// We need to save the prefs, as page load count is a critical stat, and it
// might be lost due to a crash :-(.
}
void MetricsService::LogRendererCrash(content::RenderProcessHost* host,
base::TerminationStatus status,
int exit_code) {
bool was_extension_process =
extensions::ProcessMap::Get(host->GetBrowserContext())
->Contains(host->GetID());
if (status == base::TERMINATION_STATUS_PROCESS_CRASHED ||
status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION) {
if (was_extension_process) {
IncrementPrefValue(prefs::kStabilityExtensionRendererCrashCount);
UMA_HISTOGRAM_SPARSE_SLOWLY("CrashExitCodes.Extension",
MapCrashExitCodeForHistogram(exit_code));
} else {
IncrementPrefValue(prefs::kStabilityRendererCrashCount);
UMA_HISTOGRAM_SPARSE_SLOWLY("CrashExitCodes.Renderer",
MapCrashExitCodeForHistogram(exit_code));
}
UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildCrashes",
was_extension_process ? 2 : 1);
} else if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) {
UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildKills",
was_extension_process ? 2 : 1);
} else if (status == base::TERMINATION_STATUS_STILL_RUNNING) {
UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.DisconnectedAlive",
was_extension_process ? 2 : 1);
}
}
void MetricsService::LogRendererHang() {
IncrementPrefValue(prefs::kStabilityRendererHangCount);
}
bool MetricsService::UmaMetricsProperlyShutdown() { bool MetricsService::UmaMetricsProperlyShutdown() {
CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN || CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN ||
clean_shutdown_status_ == NEED_TO_SHUTDOWN); clean_shutdown_status_ == NEED_TO_SHUTDOWN);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <vector> #include <vector>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
...@@ -22,7 +23,6 @@ ...@@ -22,7 +23,6 @@
#include "base/metrics/histogram_snapshot_manager.h" #include "base/metrics/histogram_snapshot_manager.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/process/kill.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/metrics/metrics_log.h" #include "chrome/browser/metrics/metrics_log.h"
...@@ -32,8 +32,6 @@ ...@@ -32,8 +32,6 @@
#include "components/metrics/metrics_service_observer.h" #include "components/metrics/metrics_service_observer.h"
#include "components/variations/active_field_trials.h" #include "components/variations/active_field_trials.h"
#include "content/public/browser/browser_child_process_observer.h" #include "content/public/browser/browser_child_process_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/user_metrics.h" #include "content/public/browser/user_metrics.h"
#include "net/url_request/url_fetcher_delegate.h" #include "net/url_request/url_fetcher_delegate.h"
...@@ -53,8 +51,6 @@ struct ActiveGroupId; ...@@ -53,8 +51,6 @@ struct ActiveGroupId;
} }
namespace content { namespace content {
class RenderProcessHost;
class WebContents;
struct WebPluginInfo; struct WebPluginInfo;
} }
...@@ -95,7 +91,6 @@ class MetricsService ...@@ -95,7 +91,6 @@ class MetricsService
: public base::HistogramFlattener, : public base::HistogramFlattener,
public chrome_browser_metrics::TrackingSynchronizerObserver, public chrome_browser_metrics::TrackingSynchronizerObserver,
public content::BrowserChildProcessObserver, public content::BrowserChildProcessObserver,
public content::NotificationObserver,
public net::URLFetcherDelegate { public net::URLFetcherDelegate {
public: public:
// The execution phase of the browser. // The execution phase of the browser.
...@@ -166,12 +161,6 @@ class MetricsService ...@@ -166,12 +161,6 @@ class MetricsService
// types we'll be using. // types we'll be using.
static void RegisterPrefs(PrefRegistrySimple* registry); static void RegisterPrefs(PrefRegistrySimple* registry);
// Set up notifications which indicate that a user is performing work. This is
// useful to allow some features to sleep, until the machine becomes active,
// such as precluding UMA uploads unless there was recent activity.
static void SetUpNotifications(content::NotificationRegistrar* registrar,
content::NotificationObserver* observer);
// HistogramFlattener: // HistogramFlattener:
virtual void RecordDelta(const base::HistogramBase& histogram, virtual void RecordDelta(const base::HistogramBase& histogram,
const base::HistogramSamples& snapshot) OVERRIDE; const base::HistogramSamples& snapshot) OVERRIDE;
...@@ -189,11 +178,6 @@ class MetricsService ...@@ -189,11 +178,6 @@ class MetricsService
virtual void BrowserChildProcessInstanceCreated( virtual void BrowserChildProcessInstanceCreated(
const content::ChildProcessData& data) OVERRIDE; const content::ChildProcessData& data) OVERRIDE;
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// This should be called when the application is not idle, i.e. the user seems // This should be called when the application is not idle, i.e. the user seems
// to be interacting with the application. // to be interacting with the application.
void OnApplicationNotIdle(); void OnApplicationNotIdle();
...@@ -413,14 +397,6 @@ class MetricsService ...@@ -413,14 +397,6 @@ class MetricsService
// stored as a string. // stored as a string.
void IncrementLongPrefsValue(const char* path); void IncrementLongPrefsValue(const char* path);
// Records a renderer process crash.
void LogRendererCrash(content::RenderProcessHost* host,
base::TerminationStatus status,
int exit_code);
// Records a renderer process hang.
void LogRendererHang();
// Records that the browser was shut down cleanly. // Records that the browser was shut down cleanly.
void LogCleanShutdown(); void LogCleanShutdown();
...@@ -436,10 +412,6 @@ class MetricsService ...@@ -436,10 +412,6 @@ class MetricsService
// buffered plugin stability statistics. // buffered plugin stability statistics.
void RecordCurrentState(PrefService* pref); void RecordCurrentState(PrefService* pref);
// Logs the initiation of a page load and uses |web_contents| to do
// additional logging of the type of page loaded.
void LogLoadStarted(content::WebContents* web_contents);
// Checks whether events should currently be logged. // Checks whether events should currently be logged.
bool ShouldLogEvents(); bool ShouldLogEvents();
...@@ -485,8 +457,6 @@ class MetricsService ...@@ -485,8 +457,6 @@ class MetricsService
base::ActionCallback action_callback_; base::ActionCallback action_callback_;
content::NotificationRegistrar registrar_;
// Indicate whether recording and reporting are currently happening. // Indicate whether recording and reporting are currently happening.
// These should not be set directly, but by calling SetRecording and // These should not be set directly, but by calling SetRecording and
// SetReporting. // SetReporting.
......
...@@ -11,16 +11,18 @@ ...@@ -11,16 +11,18 @@
#include "base/debug/alias.h" #include "base/debug/alias.h"
#include "base/debug/dump_without_crashing.h" #include "base/debug/dump_without_crashing.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/metrics/field_trial.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/string_tokenizer.h" #include "base/strings/string_tokenizer.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h" #include "chrome/common/chrome_version_info.h"
#include "chrome/common/logging_chrome.h" #include "chrome/common/logging_chrome.h"
#include "content/public/browser/notification_service.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
...@@ -783,7 +785,34 @@ void ThreadWatcherObserver::SetupNotifications( ...@@ -783,7 +785,34 @@ void ThreadWatcherObserver::SetupNotifications(
const base::TimeDelta& wakeup_interval) { const base::TimeDelta& wakeup_interval) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
ThreadWatcherObserver* observer = new ThreadWatcherObserver(wakeup_interval); ThreadWatcherObserver* observer = new ThreadWatcherObserver(wakeup_interval);
MetricsService::SetUpNotifications(&observer->registrar_, observer); observer->registrar_.Add(
observer,
chrome::NOTIFICATION_BROWSER_OPENED,
content::NotificationService::AllBrowserContextsAndSources());
observer->registrar_.Add(observer,
chrome::NOTIFICATION_BROWSER_CLOSED,
content::NotificationService::AllSources());
observer->registrar_.Add(observer,
chrome::NOTIFICATION_TAB_PARENTED,
content::NotificationService::AllSources());
observer->registrar_.Add(observer,
chrome::NOTIFICATION_TAB_CLOSING,
content::NotificationService::AllSources());
observer->registrar_.Add(observer,
content::NOTIFICATION_LOAD_START,
content::NotificationService::AllSources());
observer->registrar_.Add(observer,
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
observer->registrar_.Add(observer,
content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
content::NotificationService::AllSources());
observer->registrar_.Add(observer,
content::NOTIFICATION_RENDER_WIDGET_HOST_HANG,
content::NotificationService::AllSources());
observer->registrar_.Add(observer,
chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
content::NotificationService::AllSources());
} }
// static // static
......
...@@ -1189,6 +1189,8 @@ ...@@ -1189,6 +1189,8 @@
'browser/metrics/chrome_metrics_service_accessor.h', 'browser/metrics/chrome_metrics_service_accessor.h',
'browser/metrics/chrome_metrics_service_client.cc', 'browser/metrics/chrome_metrics_service_client.cc',
'browser/metrics/chrome_metrics_service_client.h', 'browser/metrics/chrome_metrics_service_client.h',
'browser/metrics/chrome_stability_metrics_provider.cc',
'browser/metrics/chrome_stability_metrics_provider.h',
'browser/metrics/compression_utils.cc', 'browser/metrics/compression_utils.cc',
'browser/metrics/compression_utils.h', 'browser/metrics/compression_utils.h',
'browser/metrics/extension_metrics.cc', 'browser/metrics/extension_metrics.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment