Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/prefs/pref_metrics_service.h" | 5 #include "chrome/browser/prefs/pref_metrics_service.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/prefs/session_startup_pref.h" | |
| 9 #include "chrome/browser/profiles/incognito_helpers.h" | 10 #include "chrome/browser/profiles/incognito_helpers.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 12 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | 13 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" |
| 13 | 14 |
| 14 PrefMetricsService::PrefMetricsService(Profile* profile) | 15 PrefMetricsService::PrefMetricsService(Profile* profile) |
| 15 : profile_(profile) { | 16 : profile_(profile) { |
| 16 RecordLaunchPrefs(); | 17 RecordLaunchPrefs(); |
| 17 } | 18 } |
| 18 | 19 |
| 19 PrefMetricsService::~PrefMetricsService() { | 20 PrefMetricsService::~PrefMetricsService() { |
| 20 } | 21 } |
| 21 | 22 |
| 23 enum StartupPagePref { | |
|
bbudge
2013/12/04 20:05:09
Also, since it's private to this file, could this
| |
| 24 NONE = 0, | |
| 25 HOMEPAGE = 1, | |
| 26 NEWTAB = 2, | |
| 27 LAST = 3, | |
| 28 ZERO_URLS = 4, | |
| 29 ONE_URL = 5, | |
| 30 MULTIPLE_URLS = 6, | |
| 31 TYPE_COUNT = 7 | |
| 32 }; | |
| 33 | |
| 34 StartupPagePref GetStartupPagePref(Profile* profile) { | |
| 35 int restore_on_startup = | |
| 36 profile->GetPrefs()->GetInteger(prefs::kRestoreOnStartup); | |
| 37 int url_list_size = 0; | |
| 38 switch (restore_on_startup) { | |
| 39 case SessionStartupPref::kPrefValueHomePage: | |
| 40 return HOMEPAGE; | |
| 41 case SessionStartupPref::kPrefValueLast: | |
| 42 return LAST; | |
| 43 case SessionStartupPref::kPrefValueNewTab: | |
| 44 return NEWTAB; | |
| 45 case SessionStartupPref::kPrefValueURLs: | |
| 46 url_list_size = profile->GetPrefs()->GetList( | |
| 47 prefs::kURLsToRestoreOnStartup)->GetSize(); | |
| 48 if (url_list_size == 0) { | |
| 49 return ZERO_URLS; | |
| 50 } else if (url_list_size == 1) { | |
| 51 return ONE_URL; | |
| 52 } else { | |
| 53 return MULTIPLE_URLS; | |
| 54 } | |
| 55 default: | |
| 56 return NONE; | |
| 57 } | |
| 58 } | |
| 59 | |
| 22 void PrefMetricsService::RecordLaunchPrefs() { | 60 void PrefMetricsService::RecordLaunchPrefs() { |
| 23 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", | 61 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", |
| 24 profile_->GetPrefs()->GetBoolean(prefs::kShowHomeButton)); | 62 profile_->GetPrefs()->GetBoolean(prefs::kShowHomeButton)); |
| 25 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", | 63 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", |
| 26 profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)); | 64 profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)); |
| 65 UMA_HISTOGRAM_ENUMERATION("Settings.SessionRestoreOnStartup", | |
| 66 GetStartupPagePref(profile_), TYPE_COUNT); | |
| 27 } | 67 } |
| 28 | 68 |
| 29 // static | 69 // static |
| 30 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() { | 70 PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() { |
| 31 return Singleton<PrefMetricsService::Factory>::get(); | 71 return Singleton<PrefMetricsService::Factory>::get(); |
| 32 } | 72 } |
| 33 | 73 |
| 34 // static | 74 // static |
| 35 PrefMetricsService* PrefMetricsService::Factory::GetForProfile( | 75 PrefMetricsService* PrefMetricsService::Factory::GetForProfile( |
| 36 Profile* profile) { | 76 Profile* profile) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 58 } | 98 } |
| 59 | 99 |
| 60 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { | 100 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { |
| 61 return false; | 101 return false; |
| 62 } | 102 } |
| 63 | 103 |
| 64 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( | 104 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( |
| 65 content::BrowserContext* context) const { | 105 content::BrowserContext* context) const { |
| 66 return chrome::GetBrowserContextRedirectedInIncognito(context); | 106 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 67 } | 107 } |
| OLD | NEW |