OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/policy/cloud/user_policy_signin_service_factory.h" | 5 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/policy/browser_policy_connector.h" | 9 #include "chrome/browser/policy/browser_policy_connector.h" |
10 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 10 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
12 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
14 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 15 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
15 #include "components/user_prefs/pref_registry_syncable.h" | 16 #include "components/user_prefs/pref_registry_syncable.h" |
16 | 17 |
17 #if defined(OS_ANDROID) | 18 #if defined(OS_ANDROID) |
18 #include "chrome/browser/policy/cloud/user_policy_signin_service_android.h" | 19 #include "chrome/browser/policy/cloud/user_policy_signin_service_android.h" |
19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | |
20 #else | 20 #else |
21 #include "chrome/browser/policy/cloud/user_policy_signin_service.h" | 21 #include "chrome/browser/policy/cloud/user_policy_signin_service.h" |
22 #include "chrome/browser/signin/token_service_factory.h" | |
23 #endif | 22 #endif |
24 | 23 |
25 namespace policy { | 24 namespace policy { |
26 | 25 |
27 namespace { | 26 namespace { |
28 | 27 |
29 // Used only for testing. | 28 // Used only for testing. |
30 DeviceManagementService* g_device_management_service = NULL; | 29 DeviceManagementService* g_device_management_service = NULL; |
31 | 30 |
32 } // namespace | 31 } // namespace |
33 | 32 |
34 UserPolicySigninServiceFactory::UserPolicySigninServiceFactory() | 33 UserPolicySigninServiceFactory::UserPolicySigninServiceFactory() |
35 : BrowserContextKeyedServiceFactory( | 34 : BrowserContextKeyedServiceFactory( |
36 "UserPolicySigninService", | 35 "UserPolicySigninService", |
37 BrowserContextDependencyManager::GetInstance()) { | 36 BrowserContextDependencyManager::GetInstance()) { |
38 #if defined(OS_ANDROID) | |
39 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 37 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
40 #else | |
41 DependsOn(TokenServiceFactory::GetInstance()); | |
42 #endif | |
43 DependsOn(SigninManagerFactory::GetInstance()); | 38 DependsOn(SigninManagerFactory::GetInstance()); |
44 DependsOn(UserCloudPolicyManagerFactory::GetInstance()); | 39 DependsOn(UserCloudPolicyManagerFactory::GetInstance()); |
45 } | 40 } |
46 | 41 |
47 UserPolicySigninServiceFactory::~UserPolicySigninServiceFactory() {} | 42 UserPolicySigninServiceFactory::~UserPolicySigninServiceFactory() {} |
48 | 43 |
49 // static | 44 // static |
50 UserPolicySigninService* UserPolicySigninServiceFactory::GetForProfile( | 45 UserPolicySigninService* UserPolicySigninServiceFactory::GetForProfile( |
51 Profile* profile) { | 46 Profile* profile) { |
52 return static_cast<UserPolicySigninService*>( | 47 return static_cast<UserPolicySigninService*>( |
53 GetInstance()->GetServiceForBrowserContext(profile, true)); | 48 GetInstance()->GetServiceForBrowserContext(profile, true)); |
54 } | 49 } |
55 | 50 |
56 // static | 51 // static |
57 UserPolicySigninServiceFactory* UserPolicySigninServiceFactory::GetInstance() { | 52 UserPolicySigninServiceFactory* UserPolicySigninServiceFactory::GetInstance() { |
58 return Singleton<UserPolicySigninServiceFactory>::get(); | 53 return Singleton<UserPolicySigninServiceFactory>::get(); |
59 } | 54 } |
60 | 55 |
61 // static | 56 // static |
62 void UserPolicySigninServiceFactory::SetDeviceManagementServiceForTesting( | 57 void UserPolicySigninServiceFactory::SetDeviceManagementServiceForTesting( |
63 DeviceManagementService* device_management_service) { | 58 DeviceManagementService* device_management_service) { |
64 g_device_management_service = device_management_service; | 59 g_device_management_service = device_management_service; |
65 } | 60 } |
66 | 61 |
67 BrowserContextKeyedService* | 62 BrowserContextKeyedService* |
68 UserPolicySigninServiceFactory::BuildServiceInstanceFor( | 63 UserPolicySigninServiceFactory::BuildServiceInstanceFor( |
69 content::BrowserContext* profile) const { | 64 content::BrowserContext* context) const { |
| 65 Profile* profile = static_cast<Profile*>(context); |
70 BrowserPolicyConnector* connector = | 66 BrowserPolicyConnector* connector = |
71 g_browser_process->browser_policy_connector(); | 67 g_browser_process->browser_policy_connector(); |
72 DeviceManagementService* device_management_service = | 68 DeviceManagementService* device_management_service = |
73 g_device_management_service ? g_device_management_service | 69 g_device_management_service ? g_device_management_service |
74 : connector->device_management_service(); | 70 : connector->device_management_service(); |
75 return new UserPolicySigninService(static_cast<Profile*>(profile), | 71 // TODO(atwilson): Inject SigninManager here or remove the dependency |
76 g_browser_process->local_state(), | 72 // entirely. http://crbug.com/276270. |
77 device_management_service); | 73 return new UserPolicySigninService( |
| 74 profile, |
| 75 g_browser_process->local_state(), |
| 76 device_management_service, |
| 77 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)); |
78 } | 78 } |
79 | 79 |
80 bool | 80 bool |
81 UserPolicySigninServiceFactory::ServiceIsCreatedWithBrowserContext() const { | 81 UserPolicySigninServiceFactory::ServiceIsCreatedWithBrowserContext() const { |
82 // Create this object when the profile is created so it can track any | 82 // Create this object when the profile is created so it can track any |
83 // user signin activity. | 83 // user signin activity. |
84 return true; | 84 return true; |
85 } | 85 } |
86 | 86 |
87 void UserPolicySigninServiceFactory::RegisterProfilePrefs( | 87 void UserPolicySigninServiceFactory::RegisterProfilePrefs( |
88 user_prefs::PrefRegistrySyncable* user_prefs) { | 88 user_prefs::PrefRegistrySyncable* user_prefs) { |
89 user_prefs->RegisterBooleanPref( | 89 user_prefs->RegisterBooleanPref( |
90 prefs::kDisableCloudPolicyOnSignin, | 90 prefs::kDisableCloudPolicyOnSignin, |
91 false, | 91 false, |
92 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 92 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
93 #if defined(OS_ANDROID) | 93 #if defined(OS_ANDROID) |
94 user_prefs->RegisterInt64Pref( | 94 user_prefs->RegisterInt64Pref( |
95 prefs::kLastPolicyCheckTime, | 95 prefs::kLastPolicyCheckTime, |
96 0, | 96 0, |
97 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 97 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
98 #endif | 98 #endif |
99 } | 99 } |
100 | 100 |
101 } // namespace policy | 101 } // namespace policy |
OLD | NEW |