Commit cbd42073 authored by asvitkine's avatar asvitkine Committed by Commit bot

Move more metrics classes to metrics namespace.

BUG=374763
TBR=jam@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#291994}
parent 758c95cc
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
class AcceleratedPresenter; class AcceleratedPresenter;
class BrowserProcessImpl; class BrowserProcessImpl;
class HistogramSynchronizer; class HistogramSynchronizer;
class MetricsService;
class NativeBackendKWallet; class NativeBackendKWallet;
class ScopedAllowWaitForLegacyWebViewApi; class ScopedAllowWaitForLegacyWebViewApi;
class TestingAutomationProvider; class TestingAutomationProvider;
...@@ -61,6 +60,9 @@ class InFlightIO; ...@@ -61,6 +60,9 @@ class InFlightIO;
namespace media { namespace media {
class AudioOutputController; class AudioOutputController;
} }
namespace metrics {
class MetricsService;
}
namespace mojo { namespace mojo {
namespace common { namespace common {
class WatcherThreadManager; class WatcherThreadManager;
...@@ -223,7 +225,7 @@ class BASE_EXPORT ThreadRestrictions { ...@@ -223,7 +225,7 @@ class BASE_EXPORT ThreadRestrictions {
friend class net::internal::AddressTrackerLinux; // http://crbug.com/125097 friend class net::internal::AddressTrackerLinux; // http://crbug.com/125097
friend class ::AcceleratedPresenter; // http://crbug.com/125391 friend class ::AcceleratedPresenter; // http://crbug.com/125391
friend class ::BrowserProcessImpl; // http://crbug.com/125207 friend class ::BrowserProcessImpl; // http://crbug.com/125207
friend class ::MetricsService; // http://crbug.com/124954 friend class metrics::MetricsService; // http://crbug.com/124954
friend class ::NativeBackendKWallet; // http://crbug.com/125331 friend class ::NativeBackendKWallet; // http://crbug.com/125331
// END USAGE THAT NEEDS TO BE FIXED. // END USAGE THAT NEEDS TO BE FIXED.
......
...@@ -28,7 +28,6 @@ class IconManager; ...@@ -28,7 +28,6 @@ class IconManager;
class IntranetRedirectDetector; class IntranetRedirectDetector;
class IOThread; class IOThread;
class MediaFileSystemRegistry; class MediaFileSystemRegistry;
class MetricsService;
class MetricsServicesManager; class MetricsServicesManager;
class NotificationUIManager; class NotificationUIManager;
class PrefRegistrySimple; class PrefRegistrySimple;
...@@ -63,6 +62,10 @@ namespace message_center { ...@@ -63,6 +62,10 @@ namespace message_center {
class MessageCenter; class MessageCenter;
} }
namespace metrics {
class MetricsService;
}
namespace net { namespace net {
class URLRequestContextGetter; class URLRequestContextGetter;
} }
...@@ -115,7 +118,7 @@ class BrowserProcess { ...@@ -115,7 +118,7 @@ class BrowserProcess {
virtual MetricsServicesManager* GetMetricsServicesManager() = 0; virtual MetricsServicesManager* GetMetricsServicesManager() = 0;
// Services: any of these getters may return NULL // Services: any of these getters may return NULL
virtual MetricsService* metrics_service() = 0; virtual metrics::MetricsService* metrics_service() = 0;
virtual rappor::RapporService* rappor_service() = 0; virtual rappor::RapporService* rappor_service() = 0;
virtual ProfileManager* profile_manager() = 0; virtual ProfileManager* profile_manager() = 0;
virtual PrefService* local_state() = 0; virtual PrefService* local_state() = 0;
......
...@@ -479,7 +479,7 @@ void BrowserProcessImpl::EndSession() { ...@@ -479,7 +479,7 @@ void BrowserProcessImpl::EndSession() {
} }
// Tell the metrics service it was cleanly shutdown. // Tell the metrics service it was cleanly shutdown.
MetricsService* metrics = g_browser_process->metrics_service(); metrics::MetricsService* metrics = g_browser_process->metrics_service();
if (metrics && local_state()) { if (metrics && local_state()) {
metrics->RecordStartOfSessionEnd(); metrics->RecordStartOfSessionEnd();
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
...@@ -535,7 +535,7 @@ MetricsServicesManager* BrowserProcessImpl::GetMetricsServicesManager() { ...@@ -535,7 +535,7 @@ MetricsServicesManager* BrowserProcessImpl::GetMetricsServicesManager() {
return metrics_services_manager_.get(); return metrics_services_manager_.get();
} }
MetricsService* BrowserProcessImpl::metrics_service() { metrics::MetricsService* BrowserProcessImpl::metrics_service() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
return GetMetricsServicesManager()->GetMetricsService(); return GetMetricsServicesManager()->GetMetricsService();
} }
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
class ChromeNetLog; class ChromeNetLog;
class ChromeResourceDispatcherHostDelegate; class ChromeResourceDispatcherHostDelegate;
class MetricsServicesManager;
class RemoteDebuggingServer; class RemoteDebuggingServer;
class PrefRegistrySimple; class PrefRegistrySimple;
class PromoResourceService; class PromoResourceService;
...@@ -78,7 +77,7 @@ class BrowserProcessImpl : public BrowserProcess, ...@@ -78,7 +77,7 @@ class BrowserProcessImpl : public BrowserProcess,
virtual void ResourceDispatcherHostCreated() OVERRIDE; virtual void ResourceDispatcherHostCreated() OVERRIDE;
virtual void EndSession() OVERRIDE; virtual void EndSession() OVERRIDE;
virtual MetricsServicesManager* GetMetricsServicesManager() OVERRIDE; virtual MetricsServicesManager* GetMetricsServicesManager() OVERRIDE;
virtual MetricsService* metrics_service() OVERRIDE; virtual metrics::MetricsService* metrics_service() OVERRIDE;
virtual rappor::RapporService* rappor_service() OVERRIDE; virtual rappor::RapporService* rappor_service() OVERRIDE;
virtual IOThread* io_thread() OVERRIDE; virtual IOThread* io_thread() OVERRIDE;
virtual WatchDogThread* watchdog_thread() OVERRIDE; virtual WatchDogThread* watchdog_thread() OVERRIDE;
......
...@@ -149,7 +149,7 @@ bool ShutdownPreThreadsStop() { ...@@ -149,7 +149,7 @@ bool ShutdownPreThreadsStop() {
// consider putting it in BrowserProcessImpl::EndSession. // consider putting it in BrowserProcessImpl::EndSession.
PrefService* prefs = g_browser_process->local_state(); PrefService* prefs = g_browser_process->local_state();
MetricsService* metrics = g_browser_process->metrics_service(); metrics::MetricsService* metrics = g_browser_process->metrics_service();
if (metrics) if (metrics)
metrics->RecordCompletedSessionEnd(); metrics->RecordCompletedSessionEnd();
......
...@@ -574,7 +574,7 @@ void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() { ...@@ -574,7 +574,7 @@ void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
// Initialize FieldTrialList to support FieldTrials that use one-time // Initialize FieldTrialList to support FieldTrials that use one-time
// randomization. // randomization.
MetricsService* metrics = browser_process_->metrics_service(); metrics::MetricsService* metrics = browser_process_->metrics_service();
field_trial_list_.reset( field_trial_list_.reset(
new base::FieldTrialList(metrics->CreateEntropyProvider().release())); new base::FieldTrialList(metrics->CreateEntropyProvider().release()));
...@@ -631,7 +631,7 @@ void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() { ...@@ -631,7 +631,7 @@ void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
void ChromeBrowserMainParts::StartMetricsRecording() { void ChromeBrowserMainParts::StartMetricsRecording() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording"); TRACE_EVENT0("startup", "ChromeBrowserMainParts::StartMetricsRecording");
MetricsService* metrics = g_browser_process->metrics_service(); metrics::MetricsService* metrics = g_browser_process->metrics_service();
const bool only_do_metrics_recording = const bool only_do_metrics_recording =
parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) || parsed_command_line_.HasSwitch(switches::kMetricsRecordingOnly) ||
...@@ -1236,8 +1236,9 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { ...@@ -1236,8 +1236,9 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
// Profile creation ---------------------------------------------------------- // Profile creation ----------------------------------------------------------
MetricsService::SetExecutionPhase(MetricsService::CREATE_PROFILE, metrics::MetricsService::SetExecutionPhase(
g_browser_process->local_state()); metrics::MetricsService::CREATE_PROFILE,
g_browser_process->local_state());
profile_ = CreatePrimaryProfile(parameters(), profile_ = CreatePrimaryProfile(parameters(),
user_data_dir_, user_data_dir_,
parsed_command_line()); parsed_command_line());
...@@ -1408,8 +1409,9 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { ...@@ -1408,8 +1409,9 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
// Start watching for hangs during startup. We disarm this hang detector when // Start watching for hangs during startup. We disarm this hang detector when
// ThreadWatcher takes over or when browser is shutdown or when // ThreadWatcher takes over or when browser is shutdown or when
// startup_watcher_ is deleted. // startup_watcher_ is deleted.
MetricsService::SetExecutionPhase(MetricsService::STARTUP_TIMEBOMB_ARM, metrics::MetricsService::SetExecutionPhase(
g_browser_process->local_state()); metrics::MetricsService::STARTUP_TIMEBOMB_ARM,
g_browser_process->local_state());
startup_watcher_->Arm(base::TimeDelta::FromSeconds(300)); startup_watcher_->Arm(base::TimeDelta::FromSeconds(300));
// On mobile, need for clean shutdown arises only when the application comes // On mobile, need for clean shutdown arises only when the application comes
...@@ -1417,7 +1419,8 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { ...@@ -1417,7 +1419,8 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
// http://crbug.com/179143 // http://crbug.com/179143
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
// Start watching for a hang. // Start watching for a hang.
MetricsService::LogNeedForCleanShutdown(g_browser_process->local_state()); metrics::MetricsService::LogNeedForCleanShutdown(
g_browser_process->local_state());
#endif #endif
#if defined(ENABLE_FULL_PRINTING) #if defined(ENABLE_FULL_PRINTING)
...@@ -1431,8 +1434,9 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { ...@@ -1431,8 +1434,9 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
#endif #endif
// Start watching all browser threads for responsiveness. // Start watching all browser threads for responsiveness.
MetricsService::SetExecutionPhase(MetricsService::THREAD_WATCHER_START, metrics::MetricsService::SetExecutionPhase(
g_browser_process->local_state()); metrics::MetricsService::THREAD_WATCHER_START,
g_browser_process->local_state());
ThreadWatcherList::StartWatchingAll(parsed_command_line()); ThreadWatcherList::StartWatchingAll(parsed_command_line());
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -1594,8 +1598,9 @@ bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { ...@@ -1594,8 +1598,9 @@ bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) {
performance_monitor::PerformanceMonitor::GetInstance()->StartGatherCycle(); performance_monitor::PerformanceMonitor::GetInstance()->StartGatherCycle();
MetricsService::SetExecutionPhase(MetricsService::MAIN_MESSAGE_LOOP_RUN, metrics::MetricsService::SetExecutionPhase(
g_browser_process->local_state()); metrics::MetricsService::MAIN_MESSAGE_LOOP_RUN,
g_browser_process->local_state());
run_loop.Run(); run_loop.Run();
return true; return true;
...@@ -1612,8 +1617,9 @@ void ChromeBrowserMainParts::PostMainMessageLoopRun() { ...@@ -1612,8 +1617,9 @@ void ChromeBrowserMainParts::PostMainMessageLoopRun() {
// Start watching for jank during shutdown. It gets disarmed when // Start watching for jank during shutdown. It gets disarmed when
// |shutdown_watcher_| object is destructed. // |shutdown_watcher_| object is destructed.
MetricsService::SetExecutionPhase(MetricsService::SHUTDOWN_TIMEBOMB_ARM, metrics::MetricsService::SetExecutionPhase(
g_browser_process->local_state()); metrics::MetricsService::SHUTDOWN_TIMEBOMB_ARM,
g_browser_process->local_state());
shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(300)); shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(300));
// Disarm the startup hang detector time bomb if it is still Arm'ed. // Disarm the startup hang detector time bomb if it is still Arm'ed.
...@@ -1659,7 +1665,7 @@ void ChromeBrowserMainParts::PostDestroyThreads() { ...@@ -1659,7 +1665,7 @@ void ChromeBrowserMainParts::PostDestroyThreads() {
// a higher level on the stack, so that it is impossible for an early return // a higher level on the stack, so that it is impossible for an early return
// to bypass this code. Perhaps we need a *final* hook that is called on all // to bypass this code. Perhaps we need a *final* hook that is called on all
// paths from content/browser/browser_main. // paths from content/browser/browser_main.
CHECK(MetricsService::UmaMetricsProperlyShutdown()); CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown());
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::CrosSettings::Shutdown(); chromeos::CrosSettings::Shutdown();
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
// ChromeBrowserMetricsServiceObserver receives notifications when the metrics // ChromeBrowserMetricsServiceObserver receives notifications when the metrics
// service creates a new metrics log. // service creates a new metrics log.
class ChromeBrowserMetricsServiceObserver : public MetricsServiceObserver { class ChromeBrowserMetricsServiceObserver
: public metrics::MetricsServiceObserver {
public: public:
ChromeBrowserMetricsServiceObserver(); ChromeBrowserMetricsServiceObserver();
virtual ~ChromeBrowserMetricsServiceObserver(); virtual ~ChromeBrowserMetricsServiceObserver();
......
...@@ -156,7 +156,7 @@ void ChromeMetricsServiceClient::RegisterPrefs(PrefRegistrySimple* registry) { ...@@ -156,7 +156,7 @@ void ChromeMetricsServiceClient::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0);
registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0);
MetricsService::RegisterPrefs(registry); metrics::MetricsService::RegisterPrefs(registry);
ChromeStabilityMetricsProvider::RegisterPrefs(registry); ChromeStabilityMetricsProvider::RegisterPrefs(registry);
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -280,7 +280,7 @@ void ChromeMetricsServiceClient::LogPluginLoadingError( ...@@ -280,7 +280,7 @@ void ChromeMetricsServiceClient::LogPluginLoadingError(
} }
void ChromeMetricsServiceClient::Initialize() { void ChromeMetricsServiceClient::Initialize() {
metrics_service_.reset(new MetricsService( metrics_service_.reset(new metrics::MetricsService(
metrics_state_manager_, this, g_browser_process->local_state())); metrics_state_manager_, this, g_browser_process->local_state()));
// Register metrics providers. // Register metrics providers.
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
class ChromeOSMetricsProvider; class ChromeOSMetricsProvider;
class GoogleUpdateMetricsProviderWin; class GoogleUpdateMetricsProviderWin;
class MetricsService;
class PluginMetricsProvider; class PluginMetricsProvider;
class PrefRegistrySimple; class PrefRegistrySimple;
class ProfilerMetricsProvider; class ProfilerMetricsProvider;
...@@ -35,6 +34,7 @@ class FilePath; ...@@ -35,6 +34,7 @@ class FilePath;
} }
namespace metrics { namespace metrics {
class MetricsService;
class MetricsStateManager; class MetricsStateManager;
} }
...@@ -72,7 +72,7 @@ class ChromeMetricsServiceClient ...@@ -72,7 +72,7 @@ class ChromeMetricsServiceClient
const std::string& mime_type, const std::string& mime_type,
const base::Callback<void(int)>& on_upload_complete) OVERRIDE; const base::Callback<void(int)>& on_upload_complete) OVERRIDE;
MetricsService* metrics_service() { return metrics_service_.get(); } metrics::MetricsService* metrics_service() { return metrics_service_.get(); }
void LogPluginLoadingError(const base::FilePath& plugin_path); void LogPluginLoadingError(const base::FilePath& plugin_path);
...@@ -131,7 +131,7 @@ class ChromeMetricsServiceClient ...@@ -131,7 +131,7 @@ class ChromeMetricsServiceClient
metrics::MetricsStateManager* metrics_state_manager_; metrics::MetricsStateManager* metrics_state_manager_;
// The MetricsService that |this| is a client of. // The MetricsService that |this| is a client of.
scoped_ptr<MetricsService> metrics_service_; scoped_ptr<metrics::MetricsService> metrics_service_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#include "chrome/browser/metrics/extensions_metrics_provider.h" #include "chrome/browser/metrics/extensions_metrics_provider.h"
#include <algorithm>
#include <set> #include <set>
#include <vector>
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
...@@ -167,7 +169,7 @@ uint64 ExtensionsMetricsProvider::GetClientID() { ...@@ -167,7 +169,7 @@ uint64 ExtensionsMetricsProvider::GetClientID() {
// TODO(blundell): Create a MetricsLog::ClientIDAsInt() API and call it // TODO(blundell): Create a MetricsLog::ClientIDAsInt() API and call it
// here as well as in MetricsLog's population of the client_id field of // here as well as in MetricsLog's population of the client_id field of
// the uma_proto. // the uma_proto.
return MetricsLog::Hash(metrics_state_manager_->client_id()); return metrics::MetricsLog::Hash(metrics_state_manager_->client_id());
} }
void ExtensionsMetricsProvider::ProvideSystemProfileMetrics( void ExtensionsMetricsProvider::ProvideSystemProfileMetrics(
......
...@@ -103,7 +103,7 @@ TEST(ExtensionsMetricsProvider, HashExtension) { ...@@ -103,7 +103,7 @@ TEST(ExtensionsMetricsProvider, HashExtension) {
TEST(ExtensionsMetricsProvider, SystemProtoEncoding) { TEST(ExtensionsMetricsProvider, SystemProtoEncoding) {
metrics::SystemProfileProto system_profile; metrics::SystemProfileProto system_profile;
TestingPrefServiceSimple local_state; TestingPrefServiceSimple local_state;
MetricsService::RegisterPrefs(local_state.registry()); metrics::MetricsService::RegisterPrefs(local_state.registry());
scoped_ptr<metrics::MetricsStateManager> metrics_state_manager( scoped_ptr<metrics::MetricsStateManager> metrics_state_manager(
metrics::MetricsStateManager::Create( metrics::MetricsStateManager::Create(
&local_state, &local_state,
......
...@@ -24,7 +24,7 @@ bool ResolveMetricsReportingEnabled(bool enabled) { ...@@ -24,7 +24,7 @@ bool ResolveMetricsReportingEnabled(bool enabled) {
// succeeds. // succeeds.
enabled = update_pref; enabled = update_pref;
MetricsService* metrics = g_browser_process->metrics_service(); metrics::MetricsService* metrics = g_browser_process->metrics_service();
if (metrics) { if (metrics) {
if (enabled) if (enabled)
metrics->Start(); metrics->Start();
......
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
#include "components/metrics/metrics_service.h" #include "components/metrics/metrics_service.h"
#include "components/metrics/metrics_service_observer.h" #include "components/metrics/metrics_service_observer.h"
// TODO(asvitkine): Remove when this class is moved to metrics namespace.
using metrics::MetricsService;
using metrics::MetricsServiceObserver;
using metrics::SyntheticTrialGroup;
// static // static
void MetricsServiceAccessor::AddMetricsServiceObserver( void MetricsServiceAccessor::AddMetricsServiceObserver(
MetricsServiceObserver* observer) { MetricsServiceObserver* observer) {
......
...@@ -10,30 +10,35 @@ ...@@ -10,30 +10,35 @@
#include "base/macros.h" #include "base/macros.h"
namespace metrics {
class MetricsService; class MetricsService;
class MetricsServiceObserver; class MetricsServiceObserver;
}
// This class limits and documents access to metrics service helper methods. // This class limits and documents access to metrics service helper methods.
// These methods are protected so each user has to inherit own program-specific // These methods are protected so each user has to inherit own program-specific
// specialization and enable access there by declaring friends. // specialization and enable access there by declaring friends.
class MetricsServiceAccessor { class MetricsServiceAccessor {
protected: protected:
// Constructor declared as protected to enable inheritance. Decendants should // Constructor declared as protected to enable inheritance. Descendants should
// disallow instantiation. // disallow instantiation.
MetricsServiceAccessor() {} MetricsServiceAccessor() {}
// Registers/unregisters |observer| to receive MetricsLog notifications // Registers/unregisters |observer| to receive MetricsLog notifications
// from metrics service. // from metrics service.
static void AddMetricsServiceObserver(MetricsServiceObserver* observer); static void AddMetricsServiceObserver(
static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer); metrics::MetricsServiceObserver* observer);
static void RemoveMetricsServiceObserver(
metrics::MetricsServiceObserver* observer);
// Registers the specified synthetic field trial (identified by a hash of the // Registers the specified synthetic field trial (identified by a hash of the
// trial name and group name) with |metrics_service|, if the service is not // trial name and group name) with |metrics_service|, if the service is not
// NULL, returning true on success. // NULL, returning true on success.
// See the comment on MetricsService::RegisterSyntheticFieldTrial for details. // See the comment on MetricsService::RegisterSyntheticFieldTrial for details.
static bool RegisterSyntheticFieldTrial(MetricsService* metrics_service, static bool RegisterSyntheticFieldTrial(
uint32_t trial_name_hash, metrics::MetricsService* metrics_service,
uint32_t group_name_hash); uint32_t trial_name_hash,
uint32_t group_name_hash);
private: private:
DISALLOW_COPY_AND_ASSIGN(MetricsServiceAccessor); DISALLOW_COPY_AND_ASSIGN(MetricsServiceAccessor);
......
...@@ -30,7 +30,7 @@ MetricsServicesManager::MetricsServicesManager(PrefService* local_state) ...@@ -30,7 +30,7 @@ MetricsServicesManager::MetricsServicesManager(PrefService* local_state)
MetricsServicesManager::~MetricsServicesManager() { MetricsServicesManager::~MetricsServicesManager() {
} }
MetricsService* MetricsServicesManager::GetMetricsService() { metrics::MetricsService* MetricsServicesManager::GetMetricsService() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
return GetChromeMetricsServiceClient()->metrics_service(); return GetChromeMetricsServiceClient()->metrics_service();
} }
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
class ChromeMetricsServiceClient; class ChromeMetricsServiceClient;
class MetricsService;
class PrefService; class PrefService;
namespace base { namespace base {
...@@ -18,6 +17,7 @@ class FilePath; ...@@ -18,6 +17,7 @@ class FilePath;
} }
namespace metrics { namespace metrics {
class MetricsService;
class MetricsStateManager; class MetricsStateManager;
} }
...@@ -40,7 +40,7 @@ class MetricsServicesManager { ...@@ -40,7 +40,7 @@ class MetricsServicesManager {
// Returns the MetricsService, creating it if it hasn't been created yet (and // Returns the MetricsService, creating it if it hasn't been created yet (and
// additionally creating the ChromeMetricsServiceClient in that case). // additionally creating the ChromeMetricsServiceClient in that case).
MetricsService* GetMetricsService(); metrics::MetricsService* GetMetricsService();
// Returns the GetRapporService, creating it if it hasn't been created yet. // Returns the GetRapporService, creating it if it hasn't been created yet.
rappor::RapporService* GetRapporService(); rappor::RapporService* GetRapporService();
......
...@@ -113,7 +113,7 @@ void OmniboxMetricsProvider::RecordOmniboxOpenedURL(const OmniboxLog& log) { ...@@ -113,7 +113,7 @@ void OmniboxMetricsProvider::RecordOmniboxOpenedURL(const OmniboxLog& log) {
static_cast<int>(Tokenize(log.text, base::kWhitespaceUTF16, &terms)); static_cast<int>(Tokenize(log.text, base::kWhitespaceUTF16, &terms));
OmniboxEventProto* omnibox_event = omnibox_events_cache.add_omnibox_event(); OmniboxEventProto* omnibox_event = omnibox_events_cache.add_omnibox_event();
omnibox_event->set_time(MetricsLog::GetCurrentTime()); omnibox_event->set_time(metrics::MetricsLog::GetCurrentTime());
if (log.tab_id != -1) { if (log.tab_id != -1) {
// If we know what tab the autocomplete URL was opened in, log it. // If we know what tab the autocomplete URL was opened in, log it.
omnibox_event->set_tab_id(log.tab_id); omnibox_event->set_tab_id(log.tab_id);
......
...@@ -86,13 +86,14 @@ void WriteProfilerData(const ProcessDataSnapshot& profiler_data, ...@@ -86,13 +86,14 @@ void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
ProfilerEventProto::TrackedObject* tracked_object = ProfilerEventProto::TrackedObject* tracked_object =
performance_profile->add_tracked_object(); performance_profile->add_tracked_object();
tracked_object->set_birth_thread_name_hash( tracked_object->set_birth_thread_name_hash(
MetricsLog::Hash(MapThreadName(it->birth.thread_name))); metrics::MetricsLog::Hash(MapThreadName(it->birth.thread_name)));
tracked_object->set_exec_thread_name_hash( tracked_object->set_exec_thread_name_hash(
MetricsLog::Hash(MapThreadName(it->death_thread_name))); metrics::MetricsLog::Hash(MapThreadName(it->death_thread_name)));
tracked_object->set_source_file_name_hash( tracked_object->set_source_file_name_hash(
MetricsLog::Hash(NormalizeFileName(it->birth.location.file_name))); metrics::MetricsLog::Hash(NormalizeFileName(
it->birth.location.file_name)));
tracked_object->set_source_function_name_hash( tracked_object->set_source_function_name_hash(
MetricsLog::Hash(it->birth.location.function_name)); metrics::MetricsLog::Hash(it->birth.location.function_name));
tracked_object->set_source_line_number(it->birth.location.line_number); tracked_object->set_source_line_number(it->birth.location.line_number);
tracked_object->set_exec_count(death_data.count); tracked_object->set_exec_count(death_data.count);
tracked_object->set_exec_time_total(death_data.run_duration_sum); tracked_object->set_exec_time_total(death_data.run_duration_sum);
......
...@@ -69,7 +69,7 @@ void SafeBrowsingUIManager::LogPauseDelay(base::TimeDelta time) { ...@@ -69,7 +69,7 @@ void SafeBrowsingUIManager::LogPauseDelay(base::TimeDelta time) {
// Only report SafeBrowsing related stats when UMA is enabled. User must also // Only report SafeBrowsing related stats when UMA is enabled. User must also
// ensure that safe browsing is enabled from the calling profile. // ensure that safe browsing is enabled from the calling profile.
bool SafeBrowsingUIManager::CanReportStats() const { bool SafeBrowsingUIManager::CanReportStats() const {
const MetricsService* metrics = g_browser_process->metrics_service(); const metrics::MetricsService* metrics = g_browser_process->metrics_service();
return metrics && metrics->reporting_active(); return metrics && metrics->reporting_active();
} }
......
...@@ -104,7 +104,7 @@ MetricsServicesManager* TestingBrowserProcess::GetMetricsServicesManager() { ...@@ -104,7 +104,7 @@ MetricsServicesManager* TestingBrowserProcess::GetMetricsServicesManager() {
return NULL; return NULL;
} }
MetricsService* TestingBrowserProcess::metrics_service() { metrics::MetricsService* TestingBrowserProcess::metrics_service() {
return NULL; return NULL;
} }
......
...@@ -61,7 +61,7 @@ class TestingBrowserProcess : public BrowserProcess { ...@@ -61,7 +61,7 @@ class TestingBrowserProcess : public BrowserProcess {
virtual void ResourceDispatcherHostCreated() OVERRIDE; virtual void ResourceDispatcherHostCreated() OVERRIDE;
virtual void EndSession() OVERRIDE; virtual void EndSession() OVERRIDE;
virtual MetricsServicesManager* GetMetricsServicesManager() OVERRIDE; virtual MetricsServicesManager* GetMetricsServicesManager() OVERRIDE;
virtual MetricsService* metrics_service() OVERRIDE; virtual metrics::MetricsService* metrics_service() OVERRIDE;
virtual rappor::RapporService* rappor_service() OVERRIDE; virtual rappor::RapporService* rappor_service() OVERRIDE;
virtual IOThread* io_thread() OVERRIDE; virtual IOThread* io_thread() OVERRIDE;
virtual WatchDogThread* watchdog_thread() OVERRIDE; virtual WatchDogThread* watchdog_thread() OVERRIDE;
......
...@@ -43,12 +43,10 @@ extern "C" IMAGE_DOS_HEADER __ImageBase; ...@@ -43,12 +43,10 @@ extern "C" IMAGE_DOS_HEADER __ImageBase;
#endif #endif
using base::SampleCountIterator; using base::SampleCountIterator;
using metrics::HistogramEventProto;
using metrics::ProfilerEventProto;
using metrics::SystemProfileProto;
using metrics::UserActionEventProto;
typedef variations::ActiveGroupId ActiveGroupId; typedef variations::ActiveGroupId ActiveGroupId;
namespace metrics {
namespace { namespace {
// Any id less than 16 bytes is considered to be a testing id. // Any id less than 16 bytes is considered to be a testing id.
...@@ -435,3 +433,5 @@ void MetricsLog::GetEncodedLog(std::string* encoded_log) { ...@@ -435,3 +433,5 @@ void MetricsLog::GetEncodedLog(std::string* encoded_log) {
DCHECK(closed_); DCHECK(closed_);
uma_proto_.SerializeToString(encoded_log); uma_proto_.SerializeToString(encoded_log);
} }
} // namespace metrics
...@@ -27,11 +27,6 @@ namespace content { ...@@ -27,11 +27,6 @@ namespace content {
struct WebPluginInfo; struct WebPluginInfo;
} }
namespace metrics {
class MetricsProvider;
class MetricsServiceClient;
}
namespace tracked_objects { namespace tracked_objects {
struct ProcessDataSnapshot; struct ProcessDataSnapshot;
} }
...@@ -40,6 +35,11 @@ namespace variations { ...@@ -40,6 +35,11 @@ namespace variations {
struct ActiveGroupId; struct ActiveGroupId;
} }
namespace metrics {
class MetricsProvider;
class MetricsServiceClient;
class MetricsLog { class MetricsLog {
public: public:
enum LogType { enum LogType {
...@@ -58,7 +58,7 @@ class MetricsLog { ...@@ -58,7 +58,7 @@ class MetricsLog {
MetricsLog(const std::string& client_id, MetricsLog(const std::string& client_id,
int session_id, int session_id,
LogType log_type, LogType log_type,
metrics::MetricsServiceClient* client, MetricsServiceClient* client,
PrefService* local_state); PrefService* local_state);
virtual ~MetricsLog(); virtual ~MetricsLog();
...@@ -95,7 +95,7 @@ class MetricsLog { ...@@ -95,7 +95,7 @@ class MetricsLog {
// example, a pref may be mapped to a synthetic trial such that the group // example, a pref may be mapped to a synthetic trial such that the group
// is determined by the pref value. // is determined by the pref value.
void RecordEnvironment( void RecordEnvironment(
const std::vector<metrics::MetricsProvider*>& metrics_providers, const std::vector<MetricsProvider*>& metrics_providers,
const std::vector<variations::ActiveGroupId>& synthetic_trials, const std::vector<variations::ActiveGroupId>& synthetic_trials,
int64 install_date); int64 install_date);
...@@ -114,13 +114,13 @@ class MetricsLog { ...@@ -114,13 +114,13 @@ class MetricsLog {
// as number of incomplete shutdowns as well as extra breakpad and debugger // as number of incomplete shutdowns as well as extra breakpad and debugger
// stats. // stats.
void RecordStabilityMetrics( void RecordStabilityMetrics(
const std::vector<metrics::MetricsProvider*>& metrics_providers, const std::vector<MetricsProvider*>& metrics_providers,
base::TimeDelta incremental_uptime, base::TimeDelta incremental_uptime,
base::TimeDelta uptime); base::TimeDelta uptime);
// Records general metrics based on the specified |metrics_providers|. // Records general metrics based on the specified |metrics_providers|.
void RecordGeneralMetrics( void RecordGeneralMetrics(
const std::vector<metrics::MetricsProvider*>& metrics_providers); const std::vector<MetricsProvider*>& metrics_providers);
// Stop writing to this record and generate the encoded representation. // Stop writing to this record and generate the encoded representation.
// None of the Record* methods can be called after this is called. // None of the Record* methods can be called after this is called.
...@@ -149,8 +149,8 @@ class MetricsLog { ...@@ -149,8 +149,8 @@ class MetricsLog {
virtual void GetFieldTrialIds( virtual void GetFieldTrialIds(
std::vector<variations::ActiveGroupId>* field_trial_ids) const; std::vector<variations::ActiveGroupId>* field_trial_ids) const;
metrics::ChromeUserMetricsExtension* uma_proto() { return &uma_proto_; } ChromeUserMetricsExtension* uma_proto() { return &uma_proto_; }
const metrics::ChromeUserMetricsExtension* uma_proto() const { const ChromeUserMetricsExtension* uma_proto() const {
return &uma_proto_; return &uma_proto_;
} }
...@@ -182,11 +182,11 @@ class MetricsLog { ...@@ -182,11 +182,11 @@ class MetricsLog {
const LogType log_type_; const LogType log_type_;
// Stores the protocol buffer representation for this log. // Stores the protocol buffer representation for this log.
metrics::ChromeUserMetricsExtension uma_proto_; ChromeUserMetricsExtension uma_proto_;
// Used to interact with the embedder. Weak pointer; must outlive |this| // Used to interact with the embedder. Weak pointer; must outlive |this|
// instance. // instance.
metrics::MetricsServiceClient* const client_; MetricsServiceClient* const client_;
// The time when the current log was created. // The time when the current log was created.
const base::TimeTicks creation_time_; const base::TimeTicks creation_time_;
...@@ -196,4 +196,6 @@ class MetricsLog { ...@@ -196,4 +196,6 @@ class MetricsLog {
DISALLOW_COPY_AND_ASSIGN(MetricsLog); DISALLOW_COPY_AND_ASSIGN(MetricsLog);
}; };
} // namespace metrics
#endif // COMPONENTS_METRICS_METRICS_LOG_H_ #endif // COMPONENTS_METRICS_METRICS_LOG_H_
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
using base::TimeDelta; using base::TimeDelta;
namespace metrics {
namespace { namespace {
// The delay, in seconds, after startup before sending the first log message. // The delay, in seconds, after startup before sending the first log message.
...@@ -158,3 +160,5 @@ void MetricsReportingScheduler::BackOffUploadInterval() { ...@@ -158,3 +160,5 @@ void MetricsReportingScheduler::BackOffUploadInterval() {
upload_interval_ = max_interval; upload_interval_ = max_interval;
} }
} }
} // namespace metrics
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
namespace metrics {
// Scheduler task to drive a MetricsService object's uploading. // Scheduler task to drive a MetricsService object's uploading.
class MetricsReportingScheduler { class MetricsReportingScheduler {
public: public:
...@@ -75,4 +77,6 @@ class MetricsReportingScheduler { ...@@ -75,4 +77,6 @@ class MetricsReportingScheduler {
DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler); DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler);
}; };
} // namespace metrics
#endif // COMPONENTS_METRICS_METRICS_REPORTING_SCHEDULER_H_ #endif // COMPONENTS_METRICS_METRICS_REPORTING_SCHEDULER_H_
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace metrics {
class MetricsReportingSchedulerTest : public testing::Test { class MetricsReportingSchedulerTest : public testing::Test {
public: public:
MetricsReportingSchedulerTest() : callback_call_count_(0) {} MetricsReportingSchedulerTest() : callback_call_count_(0) {}
...@@ -56,3 +58,5 @@ TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteAfterTimer) { ...@@ -56,3 +58,5 @@ TEST_F(MetricsReportingSchedulerTest, InitTaskCompleteAfterTimer) {
scheduler.InitTaskComplete(); scheduler.InitTaskComplete();
EXPECT_EQ(1, callback_call_count()); EXPECT_EQ(1, callback_call_count());
} }
} // namespace metrics
...@@ -191,8 +191,7 @@ ...@@ -191,8 +191,7 @@
#include "components/metrics/metrics_state_manager.h" #include "components/metrics/metrics_state_manager.h"
#include "components/variations/entropy_provider.h" #include "components/variations/entropy_provider.h"
using base::Time; namespace metrics {
using metrics::MetricsLogManager;
namespace { namespace {
...@@ -613,7 +612,7 @@ void MetricsService::InitializeMetricsState() { ...@@ -613,7 +612,7 @@ void MetricsService::InitializeMetricsState() {
// them. metrics::prefs::kStabilityLastTimestampSec may also be useless now. // them. metrics::prefs::kStabilityLastTimestampSec may also be useless now.
// TODO(jar): Delete these if they have no uses. // TODO(jar): Delete these if they have no uses.
local_state_->SetInt64(metrics::prefs::kStabilityLaunchTimeSec, local_state_->SetInt64(metrics::prefs::kStabilityLaunchTimeSec,
Time::Now().ToTimeT()); base::Time::Now().ToTimeT());
// Bookkeeping for the uninstall metrics. // Bookkeeping for the uninstall metrics.
IncrementLongPrefsValue(metrics::prefs::kUninstallLaunchCount); IncrementLongPrefsValue(metrics::prefs::kUninstallLaunchCount);
...@@ -1190,5 +1189,7 @@ void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { ...@@ -1190,5 +1189,7 @@ void MetricsService::RecordBooleanPrefValue(const char* path, bool value) {
void MetricsService::RecordCurrentState(PrefService* pref) { void MetricsService::RecordCurrentState(PrefService* pref) {
pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec,
Time::Now().ToTimeT()); base::Time::Now().ToTimeT());
} }
} // namespace metrics
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#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"
class MetricsReportingScheduler; class MetricsServiceAccessor;
class PrefService; class PrefService;
class PrefRegistrySimple; class PrefRegistrySimple;
...@@ -46,15 +46,16 @@ namespace variations { ...@@ -46,15 +46,16 @@ namespace variations {
struct ActiveGroupId; struct ActiveGroupId;
} }
namespace net {
class URLFetcher;
}
namespace metrics { namespace metrics {
class MetricsLogUploader; class MetricsLogUploader;
class MetricsReportingScheduler;
class MetricsServiceClient; class MetricsServiceClient;
class MetricsStateManager; class MetricsStateManager;
}
namespace net {
class URLFetcher;
}
// A Field Trial and its selected group, which represent a particular // A Field Trial and its selected group, which represent a particular
// Chrome configuration state. For example, the trial name could map to // Chrome configuration state. For example, the trial name could map to
...@@ -68,7 +69,7 @@ struct SyntheticTrialGroup { ...@@ -68,7 +69,7 @@ struct SyntheticTrialGroup {
private: private:
// Synthetic field trial users: // Synthetic field trial users:
friend class MetricsServiceAccessor; friend class ::MetricsServiceAccessor;
friend class MetricsService; friend class MetricsService;
FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial); FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial);
...@@ -97,8 +98,8 @@ class MetricsService : public base::HistogramFlattener { ...@@ -97,8 +98,8 @@ class MetricsService : public base::HistogramFlattener {
// |local_state|. Does not take ownership of the paramaters; instead stores // |local_state|. Does not take ownership of the paramaters; instead stores
// a weak pointer to each. Caller should ensure that the parameters are valid // a weak pointer to each. Caller should ensure that the parameters are valid
// for the lifetime of this class. // for the lifetime of this class.
MetricsService(metrics::MetricsStateManager* state_manager, MetricsService(MetricsStateManager* state_manager,
metrics::MetricsServiceClient* client, MetricsServiceClient* client,
PrefService* local_state); PrefService* local_state);
virtual ~MetricsService(); virtual ~MetricsService();
...@@ -215,7 +216,7 @@ class MetricsService : public base::HistogramFlattener { ...@@ -215,7 +216,7 @@ class MetricsService : public base::HistogramFlattener {
// Register the specified |provider| to provide additional metrics into the // Register the specified |provider| to provide additional metrics into the
// UMA log. Should be called during MetricsService initialization only. // UMA log. Should be called during MetricsService initialization only.
void RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider> provider); void RegisterMetricsProvider(scoped_ptr<MetricsProvider> provider);
// Check if this install was cloned or imaged from another machine. If a // Check if this install was cloned or imaged from another machine. If a
// clone is detected, reset the client id and low entropy source. This // clone is detected, reset the client id and low entropy source. This
...@@ -225,7 +226,7 @@ class MetricsService : public base::HistogramFlattener { ...@@ -225,7 +226,7 @@ class MetricsService : public base::HistogramFlattener {
protected: protected:
// Exposed for testing. // Exposed for testing.
metrics::MetricsLogManager* log_manager() { return &log_manager_; } MetricsLogManager* log_manager() { return &log_manager_; }
private: private:
// The MetricsService has a lifecycle that is stored as a state. // The MetricsService has a lifecycle that is stored as a state.
...@@ -373,21 +374,21 @@ class MetricsService : public base::HistogramFlattener { ...@@ -373,21 +374,21 @@ class MetricsService : public base::HistogramFlattener {
void RecordCurrentStabilityHistograms(); void RecordCurrentStabilityHistograms();
// Manager for the various in-flight logs. // Manager for the various in-flight logs.
metrics::MetricsLogManager log_manager_; MetricsLogManager log_manager_;
// |histogram_snapshot_manager_| prepares histogram deltas for transmission. // |histogram_snapshot_manager_| prepares histogram deltas for transmission.
base::HistogramSnapshotManager histogram_snapshot_manager_; base::HistogramSnapshotManager histogram_snapshot_manager_;
// Used to manage various metrics reporting state prefs, such as client id, // Used to manage various metrics reporting state prefs, such as client id,
// low entropy source and whether metrics reporting is enabled. Weak pointer. // low entropy source and whether metrics reporting is enabled. Weak pointer.
metrics::MetricsStateManager* const state_manager_; MetricsStateManager* const state_manager_;
// Used to interact with the embedder. Weak pointer; must outlive |this| // Used to interact with the embedder. Weak pointer; must outlive |this|
// instance. // instance.
metrics::MetricsServiceClient* const client_; MetricsServiceClient* const client_;
// Registered metrics providers. // Registered metrics providers.
ScopedVector<metrics::MetricsProvider> metrics_providers_; ScopedVector<MetricsProvider> metrics_providers_;
PrefService* local_state_; PrefService* local_state_;
...@@ -416,7 +417,7 @@ class MetricsService : public base::HistogramFlattener { ...@@ -416,7 +417,7 @@ class MetricsService : public base::HistogramFlattener {
scoped_ptr<MetricsLog> initial_metrics_log_; scoped_ptr<MetricsLog> initial_metrics_log_;
// Instance of the helper class for uploading logs. // Instance of the helper class for uploading logs.
scoped_ptr<metrics::MetricsLogUploader> log_uploader_; scoped_ptr<MetricsLogUploader> log_uploader_;
// Whether there is a current log upload in progress. // Whether there is a current log upload in progress.
bool log_upload_in_progress_; bool log_upload_in_progress_;
...@@ -460,7 +461,7 @@ class MetricsService : public base::HistogramFlattener { ...@@ -460,7 +461,7 @@ class MetricsService : public base::HistogramFlattener {
// Confirms single-threaded access to |observers_| in debug builds. // Confirms single-threaded access to |observers_| in debug builds.
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
friend class MetricsServiceAccessor; friend class ::MetricsServiceAccessor;
FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess); FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, IsPluginProcess);
FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver); FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsServiceObserver);
...@@ -471,4 +472,6 @@ class MetricsService : public base::HistogramFlattener { ...@@ -471,4 +472,6 @@ class MetricsService : public base::HistogramFlattener {
DISALLOW_COPY_AND_ASSIGN(MetricsService); DISALLOW_COPY_AND_ASSIGN(MetricsService);
}; };
} // namespace metrics
#endif // COMPONENTS_METRICS_METRICS_SERVICE_H_ #endif // COMPONENTS_METRICS_METRICS_SERVICE_H_
...@@ -4,8 +4,12 @@ ...@@ -4,8 +4,12 @@
#include "components/metrics/metrics_service_observer.h" #include "components/metrics/metrics_service_observer.h"
namespace metrics {
MetricsServiceObserver::MetricsServiceObserver() { MetricsServiceObserver::MetricsServiceObserver() {
} }
MetricsServiceObserver::~MetricsServiceObserver() { MetricsServiceObserver::~MetricsServiceObserver() {
} }
} // namespace metrics
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/macros.h" #include "base/macros.h"
namespace metrics {
// MetricsServiceObserver receives notifications from MetricsService. // MetricsServiceObserver receives notifications from MetricsService.
// An observer must be added, removed, and notified on the same thread. // An observer must be added, removed, and notified on the same thread.
class MetricsServiceObserver { class MetricsServiceObserver {
...@@ -22,4 +24,6 @@ class MetricsServiceObserver { ...@@ -22,4 +24,6 @@ class MetricsServiceObserver {
DISALLOW_COPY_AND_ASSIGN(MetricsServiceObserver); DISALLOW_COPY_AND_ASSIGN(MetricsServiceObserver);
}; };
} // namespace metrics
#endif // COMPONENTS_METRICS_METRICS_SERVICE_OBSERVER_H_ #endif // COMPONENTS_METRICS_METRICS_SERVICE_OBSERVER_H_
...@@ -21,21 +21,21 @@ ...@@ -21,21 +21,21 @@
#include "components/variations/metrics_util.h" #include "components/variations/metrics_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace { namespace metrics {
using metrics::MetricsLogManager; namespace {
void StoreNoClientInfoBackup(const metrics::ClientInfo& /* client_info */) { void StoreNoClientInfoBackup(const ClientInfo& /* client_info */) {
} }
scoped_ptr<metrics::ClientInfo> ReturnNoBackup() { scoped_ptr<ClientInfo> ReturnNoBackup() {
return scoped_ptr<metrics::ClientInfo>(); return scoped_ptr<ClientInfo>();
} }
class TestMetricsService : public MetricsService { class TestMetricsService : public MetricsService {
public: public:
TestMetricsService(metrics::MetricsStateManager* state_manager, TestMetricsService(MetricsStateManager* state_manager,
metrics::MetricsServiceClient* client, MetricsServiceClient* client,
PrefService* local_state) PrefService* local_state)
: MetricsService(state_manager, client, local_state) {} : MetricsService(state_manager, client, local_state) {}
virtual ~TestMetricsService() {} virtual ~TestMetricsService() {}
...@@ -50,7 +50,7 @@ class TestMetricsLog : public MetricsLog { ...@@ -50,7 +50,7 @@ class TestMetricsLog : public MetricsLog {
public: public:
TestMetricsLog(const std::string& client_id, TestMetricsLog(const std::string& client_id,
int session_id, int session_id,
metrics::MetricsServiceClient* client, MetricsServiceClient* client,
PrefService* local_state) PrefService* local_state)
: MetricsLog(client_id, : MetricsLog(client_id,
session_id, session_id,
...@@ -68,7 +68,7 @@ class MetricsServiceTest : public testing::Test { ...@@ -68,7 +68,7 @@ class MetricsServiceTest : public testing::Test {
public: public:
MetricsServiceTest() : is_metrics_reporting_enabled_(false) { MetricsServiceTest() : is_metrics_reporting_enabled_(false) {
MetricsService::RegisterPrefs(testing_local_state_.registry()); MetricsService::RegisterPrefs(testing_local_state_.registry());
metrics_state_manager_ = metrics::MetricsStateManager::Create( metrics_state_manager_ = MetricsStateManager::Create(
GetLocalState(), GetLocalState(),
base::Bind(&MetricsServiceTest::is_metrics_reporting_enabled, base::Bind(&MetricsServiceTest::is_metrics_reporting_enabled,
base::Unretained(this)), base::Unretained(this)),
...@@ -81,7 +81,7 @@ class MetricsServiceTest : public testing::Test { ...@@ -81,7 +81,7 @@ class MetricsServiceTest : public testing::Test {
GetLocalState()); GetLocalState());
} }
metrics::MetricsStateManager* GetMetricsStateManager() { MetricsStateManager* GetMetricsStateManager() {
return metrics_state_manager_.get(); return metrics_state_manager_.get();
} }
...@@ -106,8 +106,8 @@ class MetricsServiceTest : public testing::Test { ...@@ -106,8 +106,8 @@ class MetricsServiceTest : public testing::Test {
const std::vector<variations::ActiveGroupId>& synthetic_trials, const std::vector<variations::ActiveGroupId>& synthetic_trials,
const std::string& trial_name, const std::string& trial_name,
const std::string& trial_group) { const std::string& trial_group) {
uint32 trial_name_hash = metrics::HashName(trial_name); uint32 trial_name_hash = HashName(trial_name);
uint32 trial_group_hash = metrics::HashName(trial_group); uint32 trial_group_hash = HashName(trial_group);
for (std::vector<variations::ActiveGroupId>::const_iterator it = for (std::vector<variations::ActiveGroupId>::const_iterator it =
synthetic_trials.begin(); synthetic_trials.begin();
it != synthetic_trials.end(); ++it) { it != synthetic_trials.end(); ++it) {
...@@ -124,7 +124,7 @@ class MetricsServiceTest : public testing::Test { ...@@ -124,7 +124,7 @@ class MetricsServiceTest : public testing::Test {
bool is_metrics_reporting_enabled_; bool is_metrics_reporting_enabled_;
TestingPrefServiceSimple testing_local_state_; TestingPrefServiceSimple testing_local_state_;
scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_; scoped_ptr<MetricsStateManager> metrics_state_manager_;
base::MessageLoop message_loop; base::MessageLoop message_loop;
DISALLOW_COPY_AND_ASSIGN(MetricsServiceTest); DISALLOW_COPY_AND_ASSIGN(MetricsServiceTest);
...@@ -150,9 +150,9 @@ class TestMetricsServiceObserver : public MetricsServiceObserver { ...@@ -150,9 +150,9 @@ class TestMetricsServiceObserver : public MetricsServiceObserver {
TEST_F(MetricsServiceTest, InitialStabilityLogAfterCleanShutDown) { TEST_F(MetricsServiceTest, InitialStabilityLogAfterCleanShutDown) {
EnableMetricsReporting(); EnableMetricsReporting();
GetLocalState()->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true); GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true);
metrics::TestMetricsServiceClient client; TestMetricsServiceClient client;
TestMetricsService service( TestMetricsService service(
GetMetricsStateManager(), &client, GetLocalState()); GetMetricsStateManager(), &client, GetLocalState());
service.InitializeMetricsRecordingState(); service.InitializeMetricsRecordingState();
...@@ -163,26 +163,26 @@ TEST_F(MetricsServiceTest, InitialStabilityLogAfterCleanShutDown) { ...@@ -163,26 +163,26 @@ TEST_F(MetricsServiceTest, InitialStabilityLogAfterCleanShutDown) {
TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) { TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) {
EnableMetricsReporting(); EnableMetricsReporting();
GetLocalState()->ClearPref(metrics::prefs::kStabilityExitedCleanly); GetLocalState()->ClearPref(prefs::kStabilityExitedCleanly);
// Set up prefs to simulate restarting after a crash. // Set up prefs to simulate restarting after a crash.
// Save an existing system profile to prefs, to correspond to what would be // Save an existing system profile to prefs, to correspond to what would be
// saved from a previous session. // saved from a previous session.
metrics::TestMetricsServiceClient client; TestMetricsServiceClient client;
TestMetricsLog log("client", 1, &client, GetLocalState()); TestMetricsLog log("client", 1, &client, GetLocalState());
log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), log.RecordEnvironment(std::vector<MetricsProvider*>(),
std::vector<variations::ActiveGroupId>(), std::vector<variations::ActiveGroupId>(),
0); 0);
// Record stability build time and version from previous session, so that // Record stability build time and version from previous session, so that
// stability metrics (including exited cleanly flag) won't be cleared. // stability metrics (including exited cleanly flag) won't be cleared.
GetLocalState()->SetInt64(metrics::prefs::kStabilityStatsBuildTime, GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime,
MetricsLog::GetBuildTime()); MetricsLog::GetBuildTime());
GetLocalState()->SetString(metrics::prefs::kStabilityStatsVersion, GetLocalState()->SetString(prefs::kStabilityStatsVersion,
client.GetVersionString()); client.GetVersionString());
GetLocalState()->SetBoolean(metrics::prefs::kStabilityExitedCleanly, false); GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false);
TestMetricsService service( TestMetricsService service(
GetMetricsStateManager(), &client, GetLocalState()); GetMetricsStateManager(), &client, GetLocalState());
...@@ -314,3 +314,5 @@ TEST_F(MetricsServiceTest, MetricsServiceObserver) { ...@@ -314,3 +314,5 @@ TEST_F(MetricsServiceTest, MetricsServiceObserver) {
service.RemoveObserver(&observer2); service.RemoveObserver(&observer2);
} }
} // namespace metrics
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