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.
5 #include "chrome/browser/signin/about_signin_internals_factory.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/signin/account_tracker_service_factory.h"
10 #include "chrome/browser/signin/chrome_signin_client_factory.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "chrome/browser/signin/signin_error_controller_factory.h"
13 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "chrome/common/pref_names.h"
15 #include "components/keyed_service/content/browser_context_dependency_manager.h"
16 #include "components/pref_registry/pref_registry_syncable.h"
17 #include "components/signin/core/browser/about_signin_internals.h"
18 #include "components/signin/core/browser/signin_internals_util.h"
19 #include "components/signin/core/browser/signin_manager.h"
20 #include "google_apis/gaia/gaia_constants.h"
22 using namespace signin_internals_util
;
24 AboutSigninInternalsFactory::AboutSigninInternalsFactory()
25 : BrowserContextKeyedServiceFactory(
26 "AboutSigninInternals",
27 BrowserContextDependencyManager::GetInstance()) {
28 DependsOn(AccountTrackerServiceFactory::GetInstance());
29 DependsOn(ChromeSigninClientFactory::GetInstance());
30 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
31 DependsOn(SigninErrorControllerFactory::GetInstance());
32 DependsOn(SigninManagerFactory::GetInstance());
35 AboutSigninInternalsFactory::~AboutSigninInternalsFactory() {}
38 AboutSigninInternals
* AboutSigninInternalsFactory::GetForProfile(
40 return static_cast<AboutSigninInternals
*>(
41 GetInstance()->GetServiceForBrowserContext(profile
, true));
45 AboutSigninInternalsFactory
* AboutSigninInternalsFactory::GetInstance() {
46 return Singleton
<AboutSigninInternalsFactory
>::get();
49 void AboutSigninInternalsFactory::RegisterProfilePrefs(
50 user_prefs::PrefRegistrySyncable
* user_prefs
) {
51 // SigninManager information for about:signin-internals.
53 // TODO(rogerta): leaving untimed fields here for now because legacy
54 // profiles still have these prefs. In three or four version from M43
55 // we can probably remove them.
56 for (int i
= UNTIMED_FIELDS_BEGIN
; i
< UNTIMED_FIELDS_END
; ++i
) {
57 const std::string pref_path
= SigninStatusFieldToString(
58 static_cast<UntimedSigninStatusField
>(i
));
59 user_prefs
->RegisterStringPref(
62 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
65 for (int i
= TIMED_FIELDS_BEGIN
; i
< TIMED_FIELDS_END
; ++i
) {
66 const std::string value
= SigninStatusFieldToString(
67 static_cast<TimedSigninStatusField
>(i
)) + ".value";
68 const std::string time
= SigninStatusFieldToString(
69 static_cast<TimedSigninStatusField
>(i
)) + ".time";
70 user_prefs
->RegisterStringPref(
73 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
74 user_prefs
->RegisterStringPref(
77 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
81 KeyedService
* AboutSigninInternalsFactory::BuildServiceInstanceFor(
82 content::BrowserContext
* context
) const {
83 Profile
* profile
= Profile::FromBrowserContext(context
);
84 AboutSigninInternals
* service
= new AboutSigninInternals(
85 ProfileOAuth2TokenServiceFactory::GetForProfile(profile
),
86 AccountTrackerServiceFactory::GetForProfile(profile
),
87 SigninManagerFactory::GetForProfile(profile
),
88 SigninErrorControllerFactory::GetForProfile(profile
));
89 service
->Initialize(ChromeSigninClientFactory::GetForProfile(profile
));