pref_metrics_service.cc revision fb250657ef40d7500f20882d5c9909c1013367d3
1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/prefs/pref_metrics_service.h"
6
7#include "base/metrics/histogram.h"
8#include "base/prefs/pref_service.h"
9#include "chrome/browser/prefs/session_startup_pref.h"
10#include "chrome/browser/profiles/incognito_helpers.h"
11#include "chrome/browser/profiles/profile.h"
12#include "chrome/common/pref_names.h"
13#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
14
15PrefMetricsService::PrefMetricsService(Profile* profile)
16    : profile_(profile) {
17  RecordLaunchPrefs();
18}
19
20PrefMetricsService::~PrefMetricsService() {
21}
22
23void PrefMetricsService::RecordLaunchPrefs() {
24  UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton",
25      profile_->GetPrefs()->GetBoolean(prefs::kShowHomeButton));
26  UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage",
27      profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage));
28
29  int restore_on_startup = profile_->GetPrefs()->GetInteger(
30      prefs::kRestoreOnStartup);
31  UMA_HISTOGRAM_ENUMERATION("Settings.StartupPageLoadSettings",
32      restore_on_startup, SessionStartupPref::kPrefValueMax);
33  if (restore_on_startup == SessionStartupPref::kPrefValueURLs) {
34    const int url_list_size = profile_->GetPrefs()->GetList(
35        prefs::kURLsToRestoreOnStartup)->GetSize();
36    UMA_HISTOGRAM_CUSTOM_COUNTS(
37        "Settings.StartupPageLoadURLs", url_list_size, 1, 50, 20);
38  }
39}
40
41// static
42PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() {
43  return Singleton<PrefMetricsService::Factory>::get();
44}
45
46// static
47PrefMetricsService* PrefMetricsService::Factory::GetForProfile(
48    Profile* profile) {
49  return static_cast<PrefMetricsService*>(
50      GetInstance()->GetServiceForBrowserContext(profile, true));
51}
52
53PrefMetricsService::Factory::Factory()
54    : BrowserContextKeyedServiceFactory(
55        "PrefMetricsService",
56        BrowserContextDependencyManager::GetInstance()) {
57}
58
59PrefMetricsService::Factory::~Factory() {
60}
61
62BrowserContextKeyedService*
63PrefMetricsService::Factory::BuildServiceInstanceFor(
64    content::BrowserContext* profile) const {
65  return new PrefMetricsService(static_cast<Profile*>(profile));
66}
67
68bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const {
69  return true;
70}
71
72bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const {
73  return false;
74}
75
76content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse(
77    content::BrowserContext* context) const {
78  return chrome::GetBrowserContextRedirectedInIncognito(context);
79}
80