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/browser_policy_connector.h" | 5 #include "chrome/browser/policy/browser_policy_connector.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/policy/async_policy_provider.h" | 13 #include "chrome/browser/policy/async_policy_provider.h" |
14 #include "chrome/browser/policy/cloud_policy_client.h" | 14 #include "chrome/browser/policy/cloud_policy_client.h" |
15 #include "chrome/browser/policy/cloud_policy_provider.h" | 15 #include "chrome/browser/policy/cloud_policy_provider.h" |
16 #include "chrome/browser/policy/cloud_policy_service.h" | 16 #include "chrome/browser/policy/cloud_policy_service.h" |
17 #include "chrome/browser/policy/cloud_policy_subsystem.h" | 17 #include "chrome/browser/policy/cloud_policy_subsystem.h" |
18 #include "chrome/browser/policy/configuration_policy_provider.h" | 18 #include "chrome/browser/policy/configuration_policy_provider.h" |
19 #include "chrome/browser/policy/device_management_service.h" | 19 #include "chrome/browser/policy/device_management_service.h" |
20 #include "chrome/browser/policy/managed_mode_policy_provider.h" | 20 #include "chrome/browser/policy/managed_mode_policy_provider.h" |
21 #include "chrome/browser/policy/managed_mode_policy_provider_factory.h" | 21 #include "chrome/browser/policy/managed_mode_policy_provider_factory.h" |
22 #include "chrome/browser/policy/policy_service_impl.h" | 22 #include "chrome/browser/policy/policy_service_impl.h" |
23 #include "chrome/browser/policy/user_cloud_policy_manager.h" | 23 #include "chrome/browser/policy/user_cloud_policy_manager.h" |
24 #include "chrome/browser/policy/user_policy_cache.h" | 24 #include "chrome/browser/policy/user_policy_cache.h" |
25 #include "chrome/browser/policy/user_policy_token_cache.h" | 25 #include "chrome/browser/policy/user_policy_token_cache.h" |
26 #include "chrome/browser/profiles/profile.h" | |
27 #include "chrome/browser/signin/token_service.h" | 26 #include "chrome/browser/signin/token_service.h" |
28 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
30 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/net/gaia/gaia_auth_util.h" | |
32 #include "chrome/common/net/gaia/gaia_constants.h" | 30 #include "chrome/common/net/gaia/gaia_constants.h" |
33 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
34 #include "content/public/browser/notification_details.h" | 32 #include "content/public/browser/notification_details.h" |
35 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
36 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
37 #include "policy/policy_constants.h" | 35 #include "policy/policy_constants.h" |
38 | 36 |
39 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
40 #include "chrome/browser/policy/policy_loader_win.h" | 38 #include "chrome/browser/policy/policy_loader_win.h" |
41 #elif defined(OS_MACOSX) | 39 #elif defined(OS_MACOSX) |
42 #include "chrome/browser/policy/policy_loader_mac.h" | 40 #include "chrome/browser/policy/policy_loader_mac.h" |
43 #include "chrome/browser/preferences_mac.h" | 41 #include "chrome/browser/preferences_mac.h" |
44 #elif defined(OS_POSIX) | 42 #elif defined(OS_POSIX) |
45 #include "chrome/browser/policy/config_dir_policy_loader.h" | 43 #include "chrome/browser/policy/config_dir_policy_loader.h" |
46 #endif | 44 #endif |
47 | 45 |
48 #if defined(OS_CHROMEOS) | 46 #if defined(OS_CHROMEOS) |
49 #include "chrome/browser/chromeos/cros/cros_library.h" | 47 #include "chrome/browser/chromeos/cros/cros_library.h" |
50 #include "chrome/browser/chromeos/login/authenticator.h" | |
51 #include "chrome/browser/chromeos/login/user_manager.h" | |
52 #include "chrome/browser/chromeos/system/statistics_provider.h" | 48 #include "chrome/browser/chromeos/system/statistics_provider.h" |
53 #include "chrome/browser/policy/app_pack_updater.h" | 49 #include "chrome/browser/policy/app_pack_updater.h" |
54 #include "chrome/browser/policy/cros_user_policy_cache.h" | 50 #include "chrome/browser/policy/cros_user_policy_cache.h" |
55 #include "chrome/browser/policy/device_policy_cache.h" | 51 #include "chrome/browser/policy/device_policy_cache.h" |
56 #include "chromeos/dbus/dbus_thread_manager.h" | 52 #include "chromeos/dbus/dbus_thread_manager.h" |
57 #endif | 53 #endif |
58 | 54 |
59 using content::BrowserThread; | 55 using content::BrowserThread; |
60 | 56 |
61 namespace policy { | 57 namespace policy { |
62 | 58 |
63 namespace { | 59 namespace { |
64 | 60 |
65 // Subdirectory in the user's profile for storing user policies. | 61 // Subdirectory in the user's profile for storing user policies. |
66 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); | 62 const FilePath::CharType kPolicyDir[] = FILE_PATH_LITERAL("Device Management"); |
67 // File in the above directory for stroing user policy dmtokens. | 63 // File in the above directory for stroing user policy dmtokens. |
68 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); | 64 const FilePath::CharType kTokenCacheFile[] = FILE_PATH_LITERAL("Token"); |
69 // File in the above directory for storing user policy data. | 65 // File in the above directory for storing user policy data. |
70 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy"); | 66 const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy"); |
71 | 67 |
72 // The following constants define delays applied before the initial policy fetch | 68 // The following constants define delays applied before the initial policy fetch |
73 // on startup. (So that displaying Chrome's GUI does not get delayed.) | 69 // on startup. (So that displaying Chrome's GUI does not get delayed.) |
74 // Delay in milliseconds from startup. | 70 // Delay in milliseconds from startup. |
75 const int64 kServiceInitializationStartupDelay = 5000; | 71 const int64 kServiceInitializationStartupDelay = 5000; |
76 | 72 |
77 // The URL for the device management server. | |
78 const char kDefaultDeviceManagementServerUrl[] = | |
79 "https://m.google.com/devicemanagement/data/api"; | |
80 | |
81 #if defined(OS_CHROMEOS) | 73 #if defined(OS_CHROMEOS) |
82 // MachineInfo key names. | 74 // MachineInfo key names. |
83 const char kMachineInfoSystemHwqual[] = "hardware_class"; | 75 const char kMachineInfoSystemHwqual[] = "hardware_class"; |
84 | 76 |
85 // These are the machine serial number keys that we check in order until we | 77 // These are the machine serial number keys that we check in order until we |
86 // find a non-empty serial number. The VPD spec says the serial number should be | 78 // find a non-empty serial number. The VPD spec says the serial number should be |
87 // in the "serial_number" key for v2+ VPDs. However, legacy devices used a | 79 // in the "serial_number" key for v2+ VPDs. However, legacy devices used a |
88 // different keys to report their serial number, which we fall back to if | 80 // different keys to report their serial number, which we fall back to if |
89 // "serial_number" is not present. | 81 // "serial_number" is not present. |
90 const char* kMachineInfoSerialNumberKeys[] = { | 82 const char* kMachineInfoSerialNumberKeys[] = { |
(...skipping 24 matching lines...) Expand all Loading... |
115 device_data_store_.reset(); | 107 device_data_store_.reset(); |
116 #endif | 108 #endif |
117 | 109 |
118 // Shutdown user cloud policy. | 110 // Shutdown user cloud policy. |
119 if (user_cloud_policy_subsystem_.get()) | 111 if (user_cloud_policy_subsystem_.get()) |
120 user_cloud_policy_subsystem_->Shutdown(); | 112 user_cloud_policy_subsystem_->Shutdown(); |
121 user_cloud_policy_subsystem_.reset(); | 113 user_cloud_policy_subsystem_.reset(); |
122 user_policy_token_cache_.reset(); | 114 user_policy_token_cache_.reset(); |
123 user_data_store_.reset(); | 115 user_data_store_.reset(); |
124 | 116 |
| 117 if (user_cloud_policy_manager_.get()) |
| 118 user_cloud_policy_manager_->Shutdown(); |
| 119 user_cloud_policy_manager_.reset(); |
| 120 |
125 device_management_service_.reset(); | 121 device_management_service_.reset(); |
126 } | 122 } |
127 | 123 |
128 void BrowserPolicyConnector::Init() { | 124 void BrowserPolicyConnector::Init() { |
129 DCHECK(!device_management_service_.get()) << | 125 platform_provider_.reset(CreatePlatformProvider()); |
130 "BrowserPolicyConnector::Init() called twice."; | |
131 // Don't create platform providers if running in a unit test, since | |
132 // AsyncPlatformLoader requires deletion on the FILE thread. | |
133 if (MessageLoop::current()) | |
134 platform_provider_.reset(CreatePlatformProvider()); | |
135 | |
136 device_management_service_.reset( | |
137 new DeviceManagementService(GetDeviceManagementUrl())); | |
138 | 126 |
139 #if defined(OS_CHROMEOS) | 127 #if defined(OS_CHROMEOS) |
| 128 // The CloudPolicyProvider blocks asynchronous Profile creation until a login |
| 129 // is performed. This is used to ensure that the Profile's PrefService sees |
| 130 // managed preferences on managed Chrome OS devices. However, this also |
| 131 // prevents creation of new Profiles in Desktop Chrome. The implementation of |
| 132 // cloud policy on the Desktop requires a refactoring of the cloud provider, |
| 133 // but for now it just isn't created. |
140 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 134 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
141 if (!command_line->HasSwitch(switches::kEnableCloudPolicyService)) { | 135 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { |
142 managed_cloud_provider_.reset(new CloudPolicyProvider( | 136 device_management_service_.reset( |
143 this, | 137 new DeviceManagementService( |
144 POLICY_LEVEL_MANDATORY)); | 138 command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl))); |
145 recommended_cloud_provider_.reset(new CloudPolicyProvider( | 139 if (!command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
146 this, | 140 managed_cloud_provider_.reset(new CloudPolicyProvider( |
147 POLICY_LEVEL_RECOMMENDED)); | 141 this, |
| 142 POLICY_LEVEL_MANDATORY)); |
| 143 recommended_cloud_provider_.reset(new CloudPolicyProvider( |
| 144 this, |
| 145 POLICY_LEVEL_RECOMMENDED)); |
| 146 } |
148 } | 147 } |
149 | 148 |
150 InitializeDevicePolicy(); | 149 InitializeDevicePolicy(); |
151 | 150 |
152 // Don't bother updating the cache if this is a unit test. | |
153 if (!MessageLoop::current()) | |
154 return; | |
155 | |
156 // Create the AppPackUpdater to start updating the cache. It requires the | 151 // Create the AppPackUpdater to start updating the cache. It requires the |
157 // system request context, which isn't available yet; therefore it is | 152 // system request context, which isn't available yet; therefore it is |
158 // created only once the loops are running. | 153 // created only once the loops are running. |
159 MessageLoop::current()->PostTask( | 154 MessageLoop::current()->PostTask( |
160 FROM_HERE, | 155 FROM_HERE, |
161 base::Bind(base::IgnoreResult(&BrowserPolicyConnector::GetAppPackUpdater), | 156 base::Bind(base::IgnoreResult(&BrowserPolicyConnector::GetAppPackUpdater), |
162 weak_ptr_factory_.GetWeakPtr())); | 157 weak_ptr_factory_.GetWeakPtr())); |
163 #endif | 158 #endif |
164 } | 159 } |
165 | 160 |
166 scoped_ptr<UserCloudPolicyManager> | 161 PolicyService* BrowserPolicyConnector::CreatePolicyService( |
167 BrowserPolicyConnector::CreateCloudPolicyManager(Profile* profile) { | |
168 scoped_ptr<UserCloudPolicyManager> manager; | |
169 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
170 if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { | |
171 bool wait_for_policy_fetch = false; | |
172 #if defined(OS_CHROMEOS) | |
173 // TODO(mnissler): Revisit once Chrome OS gains multi-profiles support. | |
174 // Don't wait for a policy fetch if there's no logged in user. | |
175 if (chromeos::UserManager::Get()->IsUserLoggedIn()) { | |
176 wait_for_policy_fetch = | |
177 g_browser_process->browser_policy_connector()->GetUserAffiliation( | |
178 chromeos::UserManager::Get()->GetLoggedInUser().email()) == | |
179 policy::USER_AFFILIATION_MANAGED; | |
180 } | |
181 #else | |
182 // On desktop, there's no way to figure out if a user is logged in yet | |
183 // because prefs are not yet initialized. So we do not block waiting for | |
184 // the policy fetch to happen (because that would inhibit startup for | |
185 // non-signed-in users) and instead rely on the fact that a signed-in | |
186 // profile will already have policy downloaded. If no policy is available | |
187 // (due to a previous fetch failing), the normal policy refresh mechanism | |
188 // will cause it to get downloaded eventually. | |
189 #endif | |
190 manager = UserCloudPolicyManager::Create(profile, wait_for_policy_fetch); | |
191 } | |
192 return manager.Pass(); | |
193 } | |
194 | |
195 scoped_ptr<PolicyService> BrowserPolicyConnector::CreatePolicyService( | |
196 Profile* profile) { | 162 Profile* profile) { |
197 // |providers| in decreasing order of priority. | 163 // |providers| in decreasing order of priority. |
198 PolicyServiceImpl::Providers providers; | 164 PolicyServiceImpl::Providers providers; |
199 if (g_testing_provider) | 165 if (g_testing_provider) |
200 providers.push_back(g_testing_provider); | 166 providers.push_back(g_testing_provider); |
201 if (platform_provider_.get()) | 167 if (platform_provider_.get()) |
202 providers.push_back(platform_provider_.get()); | 168 providers.push_back(platform_provider_.get()); |
203 if (managed_cloud_provider_.get()) | 169 if (managed_cloud_provider_.get()) |
204 providers.push_back(managed_cloud_provider_.get()); | 170 providers.push_back(managed_cloud_provider_.get()); |
205 if (recommended_cloud_provider_.get()) | 171 if (recommended_cloud_provider_.get()) |
206 providers.push_back(recommended_cloud_provider_.get()); | 172 providers.push_back(recommended_cloud_provider_.get()); |
207 | 173 |
208 // The global policy service uses the proxy provider to allow for swapping in | 174 // The global policy service uses the proxy provider to allow for swapping in |
209 // user policy after startup, while profiles use |user_cloud_policy_manager_| | 175 // user policy after startup, while profiles use |user_cloud_policy_manager_| |
210 // directly as their provider, which may also block initialization on a policy | 176 // directly as their provider, which may also block initialization on a policy |
211 // fetch at login time. | 177 // fetch at login time. |
212 if (profile) { | 178 if (profile) { |
213 UserCloudPolicyManager* manager = profile->GetUserCloudPolicyManager(); | 179 if (user_cloud_policy_manager_.get()) |
214 if (manager) | 180 providers.push_back(user_cloud_policy_manager_.get()); |
215 providers.push_back(manager); | |
216 | 181 |
217 providers.push_back( | 182 providers.push_back( |
218 ManagedModePolicyProviderFactory::GetForProfile(profile)); | 183 ManagedModePolicyProviderFactory::GetForProfile(profile)); |
219 } else { | 184 } else { |
220 providers.push_back(&user_cloud_policy_provider_); | 185 providers.push_back(&user_cloud_policy_provider_); |
221 } | 186 } |
222 | 187 |
223 return scoped_ptr<PolicyService>(new PolicyServiceImpl(providers)).Pass(); | 188 return new PolicyServiceImpl(providers); |
224 } | 189 } |
225 | 190 |
226 void BrowserPolicyConnector::RegisterForDevicePolicy( | 191 void BrowserPolicyConnector::RegisterForDevicePolicy( |
227 const std::string& owner_email, | 192 const std::string& owner_email, |
228 const std::string& token, | 193 const std::string& token, |
229 bool known_machine_id, | 194 bool known_machine_id, |
230 bool reregister) { | 195 bool reregister) { |
231 #if defined(OS_CHROMEOS) | 196 #if defined(OS_CHROMEOS) |
232 if (device_data_store_.get()) { | 197 if (device_data_store_.get()) { |
233 if (!device_data_store_->device_token().empty()) { | 198 if (!device_data_store_->device_token().empty()) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 user_cloud_policy_subsystem_-> | 295 user_cloud_policy_subsystem_-> |
331 ScheduleServiceInitialization(delay_milliseconds); | 296 ScheduleServiceInitialization(delay_milliseconds); |
332 } | 297 } |
333 #if defined(OS_CHROMEOS) | 298 #if defined(OS_CHROMEOS) |
334 if (device_cloud_policy_subsystem_.get()) { | 299 if (device_cloud_policy_subsystem_.get()) { |
335 device_cloud_policy_subsystem_-> | 300 device_cloud_policy_subsystem_-> |
336 ScheduleServiceInitialization(delay_milliseconds); | 301 ScheduleServiceInitialization(delay_milliseconds); |
337 } | 302 } |
338 #endif | 303 #endif |
339 } | 304 } |
340 | |
341 void BrowserPolicyConnector::InitializeUserPolicy( | 305 void BrowserPolicyConnector::InitializeUserPolicy( |
342 const std::string& user_name, | 306 const std::string& user_name, |
343 bool wait_for_policy_fetch) { | 307 bool wait_for_policy_fetch) { |
344 // Throw away the old backend. | 308 // Throw away the old backend. |
| 309 user_cloud_policy_manager_.reset(); |
| 310 |
345 user_cloud_policy_subsystem_.reset(); | 311 user_cloud_policy_subsystem_.reset(); |
346 user_policy_token_cache_.reset(); | 312 user_policy_token_cache_.reset(); |
347 user_data_store_.reset(); | 313 user_data_store_.reset(); |
348 token_service_ = NULL; | 314 token_service_ = NULL; |
349 registrar_.RemoveAll(); | 315 registrar_.RemoveAll(); |
350 | 316 |
351 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 317 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
352 | 318 |
353 int64 startup_delay = | 319 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) { |
354 wait_for_policy_fetch ? 0 : kServiceInitializationStartupDelay; | 320 int64 startup_delay = |
| 321 wait_for_policy_fetch ? 0 : kServiceInitializationStartupDelay; |
355 | 322 |
356 if (!command_line->HasSwitch(switches::kEnableCloudPolicyService)) { | 323 if (command_line->HasSwitch(switches::kEnableCloudPolicyService)) { |
357 FilePath profile_dir; | |
358 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); | |
359 #if defined(OS_CHROMEOS) | 324 #if defined(OS_CHROMEOS) |
360 profile_dir = profile_dir.Append( | 325 user_cloud_policy_manager_ = |
361 command_line->GetSwitchValuePath(switches::kLoginProfile)); | 326 UserCloudPolicyManager::Create(wait_for_policy_fetch); |
| 327 user_cloud_policy_manager_->Initialize(g_browser_process->local_state(), |
| 328 device_management_service_.get(), |
| 329 GetUserAffiliation(user_name)); |
| 330 user_cloud_policy_provider_.SetDelegate(user_cloud_policy_manager_.get()); |
| 331 |
| 332 device_management_service_->ScheduleInitialization(startup_delay); |
362 #endif | 333 #endif |
363 const FilePath policy_dir = profile_dir.Append(kPolicyDir); | 334 } else { |
364 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); | 335 FilePath profile_dir; |
365 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); | 336 PathService::Get(chrome::DIR_USER_DATA, &profile_dir); |
366 CloudPolicyCacheBase* user_policy_cache = NULL; | 337 #if defined(OS_CHROMEOS) |
| 338 profile_dir = profile_dir.Append( |
| 339 command_line->GetSwitchValuePath(switches::kLoginProfile)); |
| 340 #endif |
| 341 const FilePath policy_dir = profile_dir.Append(kPolicyDir); |
| 342 const FilePath policy_cache_file = policy_dir.Append(kPolicyCacheFile); |
| 343 const FilePath token_cache_file = policy_dir.Append(kTokenCacheFile); |
| 344 CloudPolicyCacheBase* user_policy_cache = NULL; |
367 | 345 |
368 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); | 346 user_data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); |
369 #if defined(OS_CHROMEOS) | 347 #if defined(OS_CHROMEOS) |
370 user_policy_cache = | 348 user_policy_cache = |
371 new CrosUserPolicyCache( | 349 new CrosUserPolicyCache( |
372 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), | 350 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), |
373 user_data_store_.get(), | 351 user_data_store_.get(), |
374 wait_for_policy_fetch, | 352 wait_for_policy_fetch, |
375 token_cache_file, | 353 token_cache_file, |
376 policy_cache_file); | 354 policy_cache_file); |
377 #else | 355 #else |
378 user_policy_cache = new UserPolicyCache(policy_cache_file, | 356 user_policy_cache = new UserPolicyCache(policy_cache_file, |
379 wait_for_policy_fetch); | 357 wait_for_policy_fetch); |
380 user_policy_token_cache_.reset( | 358 user_policy_token_cache_.reset( |
381 new UserPolicyTokenCache(user_data_store_.get(), token_cache_file)); | 359 new UserPolicyTokenCache(user_data_store_.get(), token_cache_file)); |
382 | 360 |
383 // Initiate the DM-Token load. | 361 // Initiate the DM-Token load. |
384 user_policy_token_cache_->Load(); | 362 user_policy_token_cache_->Load(); |
385 #endif | 363 #endif |
386 | 364 |
387 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 365 user_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
388 user_data_store_.get(), | 366 user_data_store_.get(), |
389 user_policy_cache, | 367 user_policy_cache)); |
390 GetDeviceManagementUrl())); | |
391 | 368 |
392 user_data_store_->set_user_name(user_name); | 369 user_data_store_->set_user_name(user_name); |
393 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); | 370 user_data_store_->set_user_affiliation(GetUserAffiliation(user_name)); |
394 | 371 |
395 user_cloud_policy_subsystem_->CompleteInitialization( | 372 user_cloud_policy_subsystem_->CompleteInitialization( |
396 prefs::kUserPolicyRefreshRate, | 373 prefs::kUserPolicyRefreshRate, |
397 startup_delay); | 374 startup_delay); |
398 | 375 |
399 managed_cloud_provider_->SetUserPolicyCache(user_policy_cache); | 376 managed_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
400 recommended_cloud_provider_->SetUserPolicyCache(user_policy_cache); | 377 recommended_cloud_provider_->SetUserPolicyCache(user_policy_cache); |
| 378 } |
401 } | 379 } |
402 } | 380 } |
403 | 381 |
404 void BrowserPolicyConnector::SetUserPolicyTokenService( | 382 void BrowserPolicyConnector::SetUserPolicyTokenService( |
405 TokenService* token_service) { | 383 TokenService* token_service) { |
406 token_service_ = token_service; | 384 token_service_ = token_service; |
407 registrar_.Add(this, | 385 registrar_.Add(this, |
408 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 386 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
409 content::Source<TokenService>(token_service_)); | 387 content::Source<TokenService>(token_service_)); |
410 | 388 |
(...skipping 11 matching lines...) Expand all Loading... |
422 // the user policy cache of this, so that a potential blocked login | 400 // the user policy cache of this, so that a potential blocked login |
423 // proceeds without waiting for user policy. | 401 // proceeds without waiting for user policy. |
424 if (user_cloud_policy_subsystem_.get()) { | 402 if (user_cloud_policy_subsystem_.get()) { |
425 user_cloud_policy_subsystem_->GetCloudPolicyCacheBase()-> | 403 user_cloud_policy_subsystem_->GetCloudPolicyCacheBase()-> |
426 SetFetchingDone(); | 404 SetFetchingDone(); |
427 } | 405 } |
428 } else { | 406 } else { |
429 if (user_data_store_.get()) | 407 if (user_data_store_.get()) |
430 user_data_store_->SetOAuthToken(oauth_token); | 408 user_data_store_->SetOAuthToken(oauth_token); |
431 } | 409 } |
| 410 if (user_cloud_policy_manager_.get()) { |
| 411 CloudPolicyService* service = |
| 412 user_cloud_policy_manager_->cloud_policy_service(); |
| 413 if (service->client() && |
| 414 !service->client()->is_registered() && |
| 415 !oauth_token.empty()) { |
| 416 service->client()->Register(oauth_token); |
| 417 } else { |
| 418 user_cloud_policy_manager_->CancelWaitForPolicyFetch(); |
| 419 } |
| 420 } |
432 } | 421 } |
433 | 422 |
434 CloudPolicyDataStore* BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() { | 423 CloudPolicyDataStore* BrowserPolicyConnector::GetDeviceCloudPolicyDataStore() { |
435 #if defined(OS_CHROMEOS) | 424 #if defined(OS_CHROMEOS) |
436 return device_data_store_.get(); | 425 return device_data_store_.get(); |
437 #else | 426 #else |
438 return NULL; | 427 return NULL; |
439 #endif | 428 #endif |
440 } | 429 } |
441 | 430 |
442 CloudPolicyDataStore* BrowserPolicyConnector::GetUserCloudPolicyDataStore() { | 431 CloudPolicyDataStore* BrowserPolicyConnector::GetUserCloudPolicyDataStore() { |
443 return user_data_store_.get(); | 432 return user_data_store_.get(); |
444 } | 433 } |
445 | 434 |
446 const ConfigurationPolicyHandlerList* | 435 const ConfigurationPolicyHandlerList* |
447 BrowserPolicyConnector::GetHandlerList() const { | 436 BrowserPolicyConnector::GetHandlerList() const { |
448 return &handler_list_; | 437 return &handler_list_; |
449 } | 438 } |
450 | 439 |
451 UserAffiliation BrowserPolicyConnector::GetUserAffiliation( | 440 UserAffiliation BrowserPolicyConnector::GetUserAffiliation( |
452 const std::string& user_name) { | 441 const std::string& user_name) { |
453 #if defined(OS_CHROMEOS) | 442 #if defined(OS_CHROMEOS) |
454 if (install_attributes_.get()) { | 443 if (install_attributes_.get()) { |
455 std::string canonicalized_user_name(gaia::CanonicalizeEmail(user_name)); | 444 size_t pos = user_name.find('@'); |
456 size_t pos = canonicalized_user_name.find('@'); | |
457 if (pos != std::string::npos && | 445 if (pos != std::string::npos && |
458 canonicalized_user_name.substr(pos + 1) == | 446 user_name.substr(pos + 1) == install_attributes_->GetDomain()) { |
459 install_attributes_->GetDomain()) { | |
460 return USER_AFFILIATION_MANAGED; | 447 return USER_AFFILIATION_MANAGED; |
461 } | 448 } |
462 } | 449 } |
463 #endif | 450 #endif |
464 | 451 |
465 return USER_AFFILIATION_NONE; | 452 return USER_AFFILIATION_NONE; |
466 } | 453 } |
467 | 454 |
468 AppPackUpdater* BrowserPolicyConnector::GetAppPackUpdater() { | 455 AppPackUpdater* BrowserPolicyConnector::GetAppPackUpdater() { |
469 #if defined(OS_CHROMEOS) | 456 #if defined(OS_CHROMEOS) |
(...skipping 10 matching lines...) Expand all Loading... |
480 #endif | 467 #endif |
481 } | 468 } |
482 | 469 |
483 // static | 470 // static |
484 void BrowserPolicyConnector::SetPolicyProviderForTesting( | 471 void BrowserPolicyConnector::SetPolicyProviderForTesting( |
485 ConfigurationPolicyProvider* provider) { | 472 ConfigurationPolicyProvider* provider) { |
486 DCHECK(!g_testing_provider); | 473 DCHECK(!g_testing_provider); |
487 g_testing_provider = provider; | 474 g_testing_provider = provider; |
488 } | 475 } |
489 | 476 |
490 // static | |
491 std::string BrowserPolicyConnector::GetDeviceManagementUrl() { | |
492 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
493 if (command_line->HasSwitch(switches::kDeviceManagementUrl)) | |
494 return command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl); | |
495 else | |
496 return kDefaultDeviceManagementServerUrl; | |
497 } | |
498 | |
499 void BrowserPolicyConnector::Observe( | 477 void BrowserPolicyConnector::Observe( |
500 int type, | 478 int type, |
501 const content::NotificationSource& source, | 479 const content::NotificationSource& source, |
502 const content::NotificationDetails& details) { | 480 const content::NotificationDetails& details) { |
503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
504 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { | 482 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { |
505 const TokenService* token_source = | 483 const TokenService* token_source = |
506 content::Source<const TokenService>(source).ptr(); | 484 content::Source<const TokenService>(source).ptr(); |
507 DCHECK_EQ(token_service_, token_source); | 485 DCHECK_EQ(token_service_, token_source); |
508 const TokenService::TokenAvailableDetails* token_details = | 486 const TokenService::TokenAvailableDetails* token_details = |
(...skipping 27 matching lines...) Expand all Loading... |
536 install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); | 514 install_attributes_.reset(new EnterpriseInstallAttributes(cryptohome)); |
537 DevicePolicyCache* device_policy_cache = | 515 DevicePolicyCache* device_policy_cache = |
538 new DevicePolicyCache(device_data_store_.get(), | 516 new DevicePolicyCache(device_data_store_.get(), |
539 install_attributes_.get()); | 517 install_attributes_.get()); |
540 | 518 |
541 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 519 managed_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
542 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); | 520 recommended_cloud_provider_->SetDevicePolicyCache(device_policy_cache); |
543 | 521 |
544 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( | 522 device_cloud_policy_subsystem_.reset(new CloudPolicySubsystem( |
545 device_data_store_.get(), | 523 device_data_store_.get(), |
546 device_policy_cache, | 524 device_policy_cache)); |
547 GetDeviceManagementUrl())); | |
548 | |
549 // Skip the final initialization if this is a unit test. | |
550 if (!MessageLoop::current()) | |
551 return; | |
552 | 525 |
553 // Initialize the subsystem once the message loops are spinning. | 526 // Initialize the subsystem once the message loops are spinning. |
554 MessageLoop::current()->PostTask( | 527 MessageLoop::current()->PostTask( |
555 FROM_HERE, | 528 FROM_HERE, |
556 base::Bind(&BrowserPolicyConnector::CompleteInitialization, | 529 base::Bind(&BrowserPolicyConnector::CompleteInitialization, |
557 weak_ptr_factory_.GetWeakPtr())); | 530 weak_ptr_factory_.GetWeakPtr())); |
558 } | 531 } |
559 } | 532 } |
560 #endif | 533 #endif |
561 } | 534 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 return new AsyncPolicyProvider(loader.Pass()); | 589 return new AsyncPolicyProvider(loader.Pass()); |
617 } else { | 590 } else { |
618 return NULL; | 591 return NULL; |
619 } | 592 } |
620 #else | 593 #else |
621 return NULL; | 594 return NULL; |
622 #endif | 595 #endif |
623 } | 596 } |
624 | 597 |
625 } // namespace policy | 598 } // namespace policy |
OLD | NEW |