1// Copyright (c) 2012 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/signin/about_signin_internals_factory.h" 6 7#include "base/prefs/pref_service.h" 8#include "chrome/browser/signin/about_signin_internals.h" 9#include "chrome/browser/signin/signin_internals_util.h" 10#include "chrome/common/pref_names.h" 11#include "components/browser_context_keyed_service/browser_context_dependency_manager.h" 12#include "components/user_prefs/pref_registry_syncable.h" 13#include "google_apis/gaia/gaia_constants.h" 14 15using namespace signin_internals_util; 16 17AboutSigninInternalsFactory::AboutSigninInternalsFactory() 18 : BrowserContextKeyedServiceFactory( 19 "AboutSigninInternals", 20 BrowserContextDependencyManager::GetInstance()) { 21 DependsOn(SigninManagerFactory::GetInstance()); 22} 23 24AboutSigninInternalsFactory::~AboutSigninInternalsFactory() {} 25 26// static 27AboutSigninInternals* AboutSigninInternalsFactory::GetForProfile( 28 Profile* profile) { 29 return static_cast<AboutSigninInternals*>( 30 GetInstance()->GetServiceForBrowserContext(profile, true)); 31} 32 33// static 34AboutSigninInternalsFactory* AboutSigninInternalsFactory::GetInstance() { 35 return Singleton<AboutSigninInternalsFactory>::get(); 36} 37 38void AboutSigninInternalsFactory::RegisterProfilePrefs( 39 user_prefs::PrefRegistrySyncable* user_prefs) { 40 // SigninManager information for about:signin-internals. 41 for (int i = UNTIMED_FIELDS_BEGIN; i < UNTIMED_FIELDS_END; ++i) { 42 const std::string pref_path = SigninStatusFieldToString( 43 static_cast<UntimedSigninStatusField>(i)); 44 user_prefs->RegisterStringPref( 45 pref_path.c_str(), 46 std::string(), 47 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 48 } 49 for (int i = TIMED_FIELDS_BEGIN; i < TIMED_FIELDS_END; ++i) { 50 const std::string value = SigninStatusFieldToString( 51 static_cast<TimedSigninStatusField>(i)) + ".value"; 52 const std::string time = SigninStatusFieldToString( 53 static_cast<TimedSigninStatusField>(i)) + ".time"; 54 user_prefs->RegisterStringPref( 55 value.c_str(), 56 std::string(), 57 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 58 user_prefs->RegisterStringPref( 59 time.c_str(), 60 std::string(), 61 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 62 } 63} 64 65BrowserContextKeyedService* 66AboutSigninInternalsFactory::BuildServiceInstanceFor( 67 content::BrowserContext* profile) const { 68 AboutSigninInternals* service = new AboutSigninInternals(); 69 service->Initialize(static_cast<Profile*>(profile)); 70 return service; 71} 72