pref_metrics_service.cc revision bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3
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/profiles/incognito_helpers.h" 10#include "chrome/browser/profiles/profile.h" 11#include "chrome/common/pref_names.h" 12#include "components/browser_context_keyed_service/browser_context_dependency_manager.h" 13 14PrefMetricsService::PrefMetricsService(Profile* profile) 15 : profile_(profile) { 16 RecordLaunchPrefs(); 17} 18 19PrefMetricsService::~PrefMetricsService() { 20} 21 22void PrefMetricsService::RecordLaunchPrefs() { 23 UMA_HISTOGRAM_BOOLEAN("Settings.ShowHomeButton", 24 profile_->GetPrefs()->GetBoolean(prefs::kShowHomeButton)); 25 UMA_HISTOGRAM_BOOLEAN("Settings.HomePageIsNewTabPage", 26 profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)); 27} 28 29// static 30PrefMetricsService::Factory* PrefMetricsService::Factory::GetInstance() { 31 return Singleton<PrefMetricsService::Factory>::get(); 32} 33 34// static 35PrefMetricsService* PrefMetricsService::Factory::GetForProfile( 36 Profile* profile) { 37 return static_cast<PrefMetricsService*>( 38 GetInstance()->GetServiceForBrowserContext(profile, true)); 39} 40 41PrefMetricsService::Factory::Factory() 42 : BrowserContextKeyedServiceFactory( 43 "PrefMetricsService", 44 BrowserContextDependencyManager::GetInstance()) { 45} 46 47PrefMetricsService::Factory::~Factory() { 48} 49 50BrowserContextKeyedService* 51PrefMetricsService::Factory::BuildServiceInstanceFor( 52 content::BrowserContext* profile) const { 53 return new PrefMetricsService(static_cast<Profile*>(profile)); 54} 55 56bool PrefMetricsService::Factory::ServiceIsCreatedWithBrowserContext() const { 57 return true; 58} 59 60bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { 61 return false; 62} 63 64content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( 65 content::BrowserContext* context) const { 66 return chrome::GetBrowserContextRedirectedInIncognito(context); 67} 68