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/policy/cloud/user_policy_signin_service_factory.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/policy/browser_policy_connector.h"
11 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/browser/signin/signin_manager_factory.h"
15 #include "chrome/common/pref_names.h"
16 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
17 #include "components/user_prefs/pref_registry_syncable.h"
18 #include "net/url_request/url_request_context_getter.h"
20 #if defined(OS_ANDROID)
21 #include "chrome/browser/policy/cloud/user_policy_signin_service_android.h"
23 #include "chrome/browser/policy/cloud/user_policy_signin_service.h"
30 // Used only for testing.
31 DeviceManagementService
* g_device_management_service
= NULL
;
35 UserPolicySigninServiceFactory::UserPolicySigninServiceFactory()
36 : BrowserContextKeyedServiceFactory(
37 "UserPolicySigninService",
38 BrowserContextDependencyManager::GetInstance()) {
39 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
40 DependsOn(SigninManagerFactory::GetInstance());
41 DependsOn(UserCloudPolicyManagerFactory::GetInstance());
44 UserPolicySigninServiceFactory::~UserPolicySigninServiceFactory() {}
47 UserPolicySigninService
* UserPolicySigninServiceFactory::GetForProfile(
49 return static_cast<UserPolicySigninService
*>(
50 GetInstance()->GetServiceForBrowserContext(profile
, true));
54 UserPolicySigninServiceFactory
* UserPolicySigninServiceFactory::GetInstance() {
55 return Singleton
<UserPolicySigninServiceFactory
>::get();
59 void UserPolicySigninServiceFactory::SetDeviceManagementServiceForTesting(
60 DeviceManagementService
* device_management_service
) {
61 g_device_management_service
= device_management_service
;
64 BrowserContextKeyedService
*
65 UserPolicySigninServiceFactory::BuildServiceInstanceFor(
66 content::BrowserContext
* context
) const {
67 Profile
* profile
= static_cast<Profile
*>(context
);
68 BrowserPolicyConnector
* connector
=
69 g_browser_process
->browser_policy_connector();
70 DeviceManagementService
* device_management_service
=
71 g_device_management_service
? g_device_management_service
72 : connector
->device_management_service();
73 UserPolicySigninService
* service
= new UserPolicySigninService(
75 g_browser_process
->local_state(),
76 device_management_service
,
77 UserCloudPolicyManagerFactory::GetForBrowserContext(context
),
78 SigninManagerFactory::GetForProfile(profile
),
79 g_browser_process
->system_request_context(),
80 ProfileOAuth2TokenServiceFactory::GetForProfile(profile
));
85 UserPolicySigninServiceFactory::ServiceIsCreatedWithBrowserContext() const {
86 // Create this object when the profile is created so it can track any
87 // user signin activity.
91 void UserPolicySigninServiceFactory::RegisterProfilePrefs(
92 user_prefs::PrefRegistrySyncable
* user_prefs
) {
93 #if defined(OS_ANDROID)
94 user_prefs
->RegisterInt64Pref(
95 prefs::kLastPolicyCheckTime
,
97 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
101 } // namespace policy