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