OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_policy_connector.h" | 5 #include "chrome/browser/policy/browser_policy_connector.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/net/gaia/token_service.h" |
| 10 #include "chrome/browser/policy/cloud_policy_provider.h" |
| 11 #include "chrome/browser/policy/cloud_policy_provider_impl.h" |
10 #include "chrome/browser/policy/cloud_policy_subsystem.h" | 12 #include "chrome/browser/policy/cloud_policy_subsystem.h" |
11 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 13 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
12 #include "chrome/browser/policy/configuration_policy_provider.h" | 14 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 15 #include "chrome/browser/policy/dummy_cloud_policy_provider.h" |
13 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" | 16 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" |
| 17 #include "chrome/browser/policy/user_policy_cache.h" |
| 18 #include "chrome/browser/policy/user_policy_identity_strategy.h" |
14 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/net/gaia/gaia_constants.h" |
16 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "content/common/notification_details.h" |
| 24 #include "content/common/notification_source.h" |
17 | 25 |
18 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
19 #include "chrome/browser/policy/configuration_policy_provider_win.h" | 27 #include "chrome/browser/policy/configuration_policy_provider_win.h" |
20 #elif defined(OS_MACOSX) | 28 #elif defined(OS_MACOSX) |
21 #include "chrome/browser/policy/configuration_policy_provider_mac.h" | 29 #include "chrome/browser/policy/configuration_policy_provider_mac.h" |
22 #elif defined(OS_POSIX) | 30 #elif defined(OS_POSIX) |
23 #include "chrome/browser/policy/config_dir_policy_provider.h" | 31 #include "chrome/browser/policy/config_dir_policy_provider.h" |
24 #endif | 32 #endif |
25 | 33 |
26 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
27 #include "chrome/browser/chromeos/cros/cros_library.h" | 35 #include "chrome/browser/chromeos/cros/cros_library.h" |
28 #include "chrome/browser/policy/device_policy_cache.h" | 36 #include "chrome/browser/policy/device_policy_cache.h" |
29 #include "chrome/browser/policy/device_policy_identity_strategy.h" | 37 #include "chrome/browser/policy/device_policy_identity_strategy.h" |
30 #include "chrome/browser/policy/enterprise_install_attributes.h" | 38 #include "content/common/notification_service.h" |
31 #endif | 39 #endif |
32 | 40 |
33 namespace policy { | 41 namespace policy { |
34 | 42 |
35 namespace { | 43 namespace { |
36 | 44 |
| 45 // Subdirectory in the user's profile for storing user policies. |
| 46 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); |
| 47 // File in the above directory for stroing user policy dmtokens. |
| 48 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); |
| 49 // File in the above directory for storing user policy data. |
| 50 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy"); |
| 51 |
37 // The following constants define delays applied before the initial policy fetch | 52 // The following constants define delays applied before the initial policy fetch |
38 // on startup. (So that displaying Chrome's GUI does not get delayed.) | 53 // on startup. (So that displaying Chrome's GUI does not get delayed.) |
39 // Delay in milliseconds from startup. | 54 // Delay in milliseconds from startup. |
40 const int64 kServiceInitializationStartupDelay = 5000; | 55 const int64 kServiceInitializationStartupDelay = 5000; |
41 | 56 |
42 } // namespace | 57 } // namespace |
43 | 58 |
44 // static | 59 // static |
45 BrowserPolicyConnector* BrowserPolicyConnector::Create() { | 60 BrowserPolicyConnector* BrowserPolicyConnector::Create() { |
46 return new BrowserPolicyConnector(); | 61 return new BrowserPolicyConnector(); |
47 } | 62 } |
48 | 63 |
49 // static | 64 // static |
50 BrowserPolicyConnector* BrowserPolicyConnector::CreateForTests() { | 65 BrowserPolicyConnector* BrowserPolicyConnector::CreateForTests() { |
51 const ConfigurationPolicyProvider::PolicyDefinitionList* | 66 const ConfigurationPolicyProvider::PolicyDefinitionList* |
52 policy_list = ConfigurationPolicyPrefStore:: | 67 policy_list = ConfigurationPolicyPrefStore:: |
53 GetChromePolicyDefinitionList(); | 68 GetChromePolicyDefinitionList(); |
54 return new BrowserPolicyConnector( | 69 return new BrowserPolicyConnector( |
55 new DummyConfigurationPolicyProvider(policy_list), | 70 new policy::DummyConfigurationPolicyProvider(policy_list), |
56 new DummyConfigurationPolicyProvider(policy_list)); | 71 new policy::DummyConfigurationPolicyProvider(policy_list), |
| 72 new policy::DummyCloudPolicyProvider(policy_list), |
| 73 new policy::DummyCloudPolicyProvider(policy_list)); |
57 } | 74 } |
58 | 75 |
59 BrowserPolicyConnector::BrowserPolicyConnector() | 76 BrowserPolicyConnector::BrowserPolicyConnector() |
60 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 77 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
61 managed_platform_provider_.reset(CreateManagedPlatformProvider()); | 78 managed_platform_provider_.reset(CreateManagedPlatformProvider()); |
62 recommended_platform_provider_.reset(CreateRecommendedPlatformProvider()); | 79 recommended_platform_provider_.reset(CreateRecommendedPlatformProvider()); |
63 | 80 |
| 81 managed_cloud_provider_.reset(new CloudPolicyProviderImpl( |
| 82 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), |
| 83 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY)); |
| 84 recommended_cloud_provider_.reset(new CloudPolicyProviderImpl( |
| 85 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(), |
| 86 CloudPolicyCacheBase::POLICY_LEVEL_RECOMMENDED)); |
| 87 |
64 #if defined(OS_CHROMEOS) | 88 #if defined(OS_CHROMEOS) |
65 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 89 InitializeDevicePolicy(); |
66 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) { | |
67 identity_strategy_.reset(new DevicePolicyIdentityStrategy()); | |
68 install_attributes_.reset(new EnterpriseInstallAttributes( | |
69 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary())); | |
70 cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | |
71 identity_strategy_.get(), | |
72 new DevicePolicyCache(identity_strategy_.get(), | |
73 install_attributes_.get()))); | |
74 | |
75 // Initialize the subsystem once the message loops are spinning. | |
76 MessageLoop::current()->PostTask( | |
77 FROM_HERE, | |
78 method_factory_.NewRunnableMethod(&BrowserPolicyConnector::Initialize)); | |
79 } | |
80 #endif | 90 #endif |
81 } | 91 } |
82 | 92 |
83 BrowserPolicyConnector::BrowserPolicyConnector( | 93 BrowserPolicyConnector::BrowserPolicyConnector( |
84 ConfigurationPolicyProvider* managed_platform_provider, | 94 ConfigurationPolicyProvider* managed_platform_provider, |
85 ConfigurationPolicyProvider* recommended_platform_provider) | 95 ConfigurationPolicyProvider* recommended_platform_provider, |
| 96 CloudPolicyProvider* managed_cloud_provider, |
| 97 CloudPolicyProvider* recommended_cloud_provider) |
86 : managed_platform_provider_(managed_platform_provider), | 98 : managed_platform_provider_(managed_platform_provider), |
87 recommended_platform_provider_(recommended_platform_provider), | 99 recommended_platform_provider_(recommended_platform_provider), |
| 100 managed_cloud_provider_(managed_cloud_provider), |
| 101 recommended_cloud_provider_(recommended_cloud_provider), |
88 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} | 102 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {} |
89 | 103 |
90 BrowserPolicyConnector::~BrowserPolicyConnector() { | 104 BrowserPolicyConnector::~BrowserPolicyConnector() { |
91 if (cloud_policy_subsystem_.get()) | 105 // Shutdown device cloud policy. |
92 cloud_policy_subsystem_->Shutdown(); | |
93 cloud_policy_subsystem_.reset(); | |
94 #if defined(OS_CHROMEOS) | 106 #if defined(OS_CHROMEOS) |
95 identity_strategy_.reset(); | 107 if (device_cloud_policy_subsystem_.get()) |
| 108 device_cloud_policy_subsystem_->Shutdown(); |
| 109 device_cloud_policy_subsystem_.reset(); |
| 110 device_identity_strategy_.reset(); |
96 #endif | 111 #endif |
| 112 |
| 113 // Shutdown user cloud policy. |
| 114 if (user_cloud_policy_subsystem_.get()) |
| 115 user_cloud_policy_subsystem_->Shutdown(); |
| 116 user_cloud_policy_subsystem_.reset(); |
| 117 user_identity_strategy_.reset(); |
97 } | 118 } |
98 | 119 |
99 ConfigurationPolicyProvider* | 120 ConfigurationPolicyProvider* |
100 BrowserPolicyConnector::GetManagedPlatformProvider() const { | 121 BrowserPolicyConnector::GetManagedPlatformProvider() const { |
101 return managed_platform_provider_.get(); | 122 return managed_platform_provider_.get(); |
102 } | 123 } |
103 | 124 |
104 ConfigurationPolicyProvider* | 125 ConfigurationPolicyProvider* |
105 BrowserPolicyConnector::GetManagedCloudProvider() const { | 126 BrowserPolicyConnector::GetManagedCloudProvider() const { |
106 if (cloud_policy_subsystem_.get()) | 127 return managed_cloud_provider_.get(); |
107 return cloud_policy_subsystem_->GetManagedPolicyProvider(); | |
108 | |
109 return NULL; | |
110 } | 128 } |
111 | 129 |
112 ConfigurationPolicyProvider* | 130 ConfigurationPolicyProvider* |
113 BrowserPolicyConnector::GetRecommendedPlatformProvider() const { | 131 BrowserPolicyConnector::GetRecommendedPlatformProvider() const { |
114 return recommended_platform_provider_.get(); | 132 return recommended_platform_provider_.get(); |
115 } | 133 } |
116 | 134 |
117 ConfigurationPolicyProvider* | 135 ConfigurationPolicyProvider* |
118 BrowserPolicyConnector::GetRecommendedCloudProvider() const { | 136 BrowserPolicyConnector::GetRecommendedCloudProvider() const { |
119 if (cloud_policy_subsystem_.get()) | 137 return recommended_cloud_provider_.get(); |
120 return cloud_policy_subsystem_->GetRecommendedPolicyProvider(); | |
121 | |
122 return NULL; | |
123 } | 138 } |
124 | 139 |
125 ConfigurationPolicyProvider* | 140 ConfigurationPolicyProvider* |
126 BrowserPolicyConnector::CreateManagedPlatformProvider() { | 141 BrowserPolicyConnector::CreateManagedPlatformProvider() { |
127 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = | 142 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = |
128 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); | 143 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); |
129 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
130 return new ConfigurationPolicyProviderWin(policy_list); | 145 return new ConfigurationPolicyProviderWin(policy_list); |
131 #elif defined(OS_MACOSX) | 146 #elif defined(OS_MACOSX) |
132 return new ConfigurationPolicyProviderMac(policy_list); | 147 return new ConfigurationPolicyProviderMac(policy_list); |
(...skipping 22 matching lines...) Expand all Loading... |
155 policy_list, | 170 policy_list, |
156 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); | 171 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); |
157 } else { | 172 } else { |
158 return new DummyConfigurationPolicyProvider(policy_list); | 173 return new DummyConfigurationPolicyProvider(policy_list); |
159 } | 174 } |
160 #else | 175 #else |
161 return new DummyConfigurationPolicyProvider(policy_list); | 176 return new DummyConfigurationPolicyProvider(policy_list); |
162 #endif | 177 #endif |
163 } | 178 } |
164 | 179 |
165 void BrowserPolicyConnector::SetCredentials(const std::string& owner_email, | 180 void BrowserPolicyConnector::SetDeviceCredentials( |
166 const std::string& gaia_token) { | 181 const std::string& owner_email, |
| 182 const std::string& gaia_token) { |
167 #if defined(OS_CHROMEOS) | 183 #if defined(OS_CHROMEOS) |
168 if (identity_strategy_.get()) | 184 if (device_identity_strategy_.get()) |
169 identity_strategy_->SetAuthCredentials(owner_email, gaia_token); | 185 device_identity_strategy_->SetAuthCredentials(owner_email, gaia_token); |
170 #endif | 186 #endif |
171 } | 187 } |
172 | 188 |
173 bool BrowserPolicyConnector::IsEnterpriseManaged() { | 189 bool BrowserPolicyConnector::IsEnterpriseManaged() { |
174 #if defined(OS_CHROMEOS) | 190 #if defined(OS_CHROMEOS) |
175 return install_attributes_.get() && install_attributes_->IsEnterpriseDevice(); | 191 return install_attributes_.get() && install_attributes_->IsEnterpriseDevice(); |
176 #else | 192 #else |
177 return false; | 193 return false; |
178 #endif | 194 #endif |
179 } | 195 } |
(...skipping 10 matching lines...) Expand all Loading... |
190 | 206 |
191 std::string BrowserPolicyConnector::GetEnterpriseDomain() { | 207 std::string BrowserPolicyConnector::GetEnterpriseDomain() { |
192 #if defined(OS_CHROMEOS) | 208 #if defined(OS_CHROMEOS) |
193 if (install_attributes_.get()) | 209 if (install_attributes_.get()) |
194 return install_attributes_->GetDomain(); | 210 return install_attributes_->GetDomain(); |
195 #endif | 211 #endif |
196 | 212 |
197 return std::string(); | 213 return std::string(); |
198 } | 214 } |
199 | 215 |
200 void BrowserPolicyConnector::StopAutoRetry() { | 216 void BrowserPolicyConnector::DeviceStopAutoRetry() { |
201 if (cloud_policy_subsystem_.get()) | |
202 cloud_policy_subsystem_->StopAutoRetry(); | |
203 } | |
204 | |
205 void BrowserPolicyConnector::FetchPolicy() { | |
206 #if defined(OS_CHROMEOS) | 217 #if defined(OS_CHROMEOS) |
207 if (identity_strategy_.get()) | 218 if (device_cloud_policy_subsystem_.get()) |
208 return identity_strategy_->FetchPolicy(); | 219 device_cloud_policy_subsystem_->StopAutoRetry(); |
209 #endif | 220 #endif |
210 } | 221 } |
211 | 222 |
212 void BrowserPolicyConnector::Initialize() { | 223 void BrowserPolicyConnector::FetchDevicePolicy() { |
213 if (cloud_policy_subsystem_.get()) { | 224 #if defined(OS_CHROMEOS) |
214 cloud_policy_subsystem_->CompleteInitialization( | 225 if (device_identity_strategy_.get()) |
215 prefs::kDevicePolicyRefreshRate, | 226 return device_identity_strategy_->FetchPolicy(); |
| 227 #endif |
| 228 } |
| 229 |
| 230 void BrowserPolicyConnector::InitializeUserPolicy(const std::string& user_name, |
| 231 const FilePath& policy_dir, |
| 232 TokenService* token_service) { |
| 233 DCHECK(token_service); |
| 234 |
| 235 // Throw away the old backend. |
| 236 user_cloud_policy_subsystem_.reset(); |
| 237 user_identity_strategy_.reset(); |
| 238 registrar_.RemoveAll(); |
| 239 |
| 240 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 241 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { |
| 242 token_service_ = token_service; |
| 243 registrar_.Add(this, |
| 244 NotificationType::TOKEN_AVAILABLE, |
| 245 Source<TokenService>(token_service_)); |
| 246 |
| 247 FilePath policy_cache_dir = policy_dir.Append(kPolicyDir); |
| 248 UserPolicyCache* user_policy_cache = |
| 249 new UserPolicyCache(policy_cache_dir.Append(kPolicyCacheFile)); |
| 250 |
| 251 // Prepending user caches meaning they will take precedence of device policy |
| 252 // caches. |
| 253 managed_cloud_provider_->PrependCache(user_policy_cache); |
| 254 recommended_cloud_provider_->PrependCache(user_policy_cache); |
| 255 user_identity_strategy_.reset( |
| 256 new UserPolicyIdentityStrategy( |
| 257 user_name, |
| 258 policy_cache_dir.Append(kTokenCacheFile))); |
| 259 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 260 user_identity_strategy_.get(), |
| 261 user_policy_cache)); |
| 262 |
| 263 // Initiate the DM-Token load. |
| 264 user_identity_strategy_->LoadTokenCache(); |
| 265 |
| 266 if (token_service_->HasTokenForService( |
| 267 GaiaConstants::kDeviceManagementService)) { |
| 268 user_identity_strategy_->SetAuthToken( |
| 269 token_service_->GetTokenForService( |
| 270 GaiaConstants::kDeviceManagementService)); |
| 271 } |
| 272 |
| 273 user_cloud_policy_subsystem_->CompleteInitialization( |
| 274 prefs::kUserPolicyRefreshRate, |
216 kServiceInitializationStartupDelay); | 275 kServiceInitializationStartupDelay); |
217 } | 276 } |
218 } | 277 } |
219 | 278 |
220 void BrowserPolicyConnector::ScheduleServiceInitialization( | 279 void BrowserPolicyConnector::ScheduleServiceInitialization( |
221 int64 delay_milliseconds) { | 280 int64 delay_milliseconds) { |
222 if (cloud_policy_subsystem_.get()) | 281 if (user_cloud_policy_subsystem_.get()) { |
223 cloud_policy_subsystem_->ScheduleServiceInitialization(delay_milliseconds); | 282 user_cloud_policy_subsystem_-> |
| 283 ScheduleServiceInitialization(delay_milliseconds); |
| 284 } |
| 285 #if defined(OS_CHROMEOS) |
| 286 if (device_cloud_policy_subsystem_.get()) { |
| 287 device_cloud_policy_subsystem_-> |
| 288 ScheduleServiceInitialization(delay_milliseconds); |
| 289 } |
| 290 #endif |
| 291 } |
| 292 |
| 293 void BrowserPolicyConnector::InitializeDevicePolicy() { |
| 294 #if defined(OS_CHROMEOS) |
| 295 // Throw away the old backend. |
| 296 device_cloud_policy_subsystem_.reset(); |
| 297 device_identity_strategy_.reset(); |
| 298 |
| 299 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 300 if (command_line->HasSwitch(switches::kEnableDevicePolicy)) { |
| 301 device_identity_strategy_.reset(new DevicePolicyIdentityStrategy()); |
| 302 install_attributes_.reset(new EnterpriseInstallAttributes( |
| 303 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary())); |
| 304 DevicePolicyCache* device_policy_cache = |
| 305 new DevicePolicyCache(device_identity_strategy_.get(), |
| 306 install_attributes_.get()); |
| 307 |
| 308 managed_cloud_provider_->AppendCache(device_policy_cache); |
| 309 recommended_cloud_provider_->AppendCache(device_policy_cache); |
| 310 |
| 311 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
| 312 device_identity_strategy_.get(), |
| 313 device_policy_cache)); |
| 314 |
| 315 // Initialize the subsystem once the message loops are spinning. |
| 316 MessageLoop::current()->PostTask( |
| 317 FROM_HERE, |
| 318 method_factory_.NewRunnableMethod( |
| 319 &BrowserPolicyConnector::InitializeDevicePolicySubsystem)); |
| 320 } |
| 321 #endif |
| 322 } |
| 323 |
| 324 void BrowserPolicyConnector::InitializeDevicePolicySubsystem() { |
| 325 #if defined(OS_CHROMEOS) |
| 326 if (device_cloud_policy_subsystem_.get()) { |
| 327 device_cloud_policy_subsystem_->CompleteInitialization( |
| 328 prefs::kDevicePolicyRefreshRate, |
| 329 kServiceInitializationStartupDelay); |
| 330 } |
| 331 #endif |
| 332 } |
| 333 |
| 334 void BrowserPolicyConnector::Observe(NotificationType type, |
| 335 const NotificationSource& source, |
| 336 const NotificationDetails& details) { |
| 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 338 if (type == NotificationType::TOKEN_AVAILABLE) { |
| 339 const TokenService* token_source = |
| 340 Source<const TokenService>(source).ptr(); |
| 341 DCHECK_EQ(token_service_, token_source); |
| 342 const TokenService::TokenAvailableDetails* token_details = |
| 343 Details<const TokenService::TokenAvailableDetails>(details).ptr(); |
| 344 if (token_details->service() == GaiaConstants::kDeviceManagementService) { |
| 345 if (user_identity_strategy_.get()) { |
| 346 user_identity_strategy_->SetAuthToken(token_details->token()); |
| 347 } |
| 348 } |
| 349 } else { |
| 350 NOTREACHED(); |
| 351 } |
224 } | 352 } |
225 | 353 |
226 } // namespace | 354 } // namespace |
OLD | NEW |