Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc

Issue 769703003: SetManagementSettings() is moved to OwnerSettingsServiceChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/chromeos/policy/enrollment_handler_chromeos.h" 5 #include "chrome/browser/chromeos/policy/enrollment_handler_chromeos.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" 12 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h"
13 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
14 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
13 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" 15 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 16 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
15 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" 17 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h"
16 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 19 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
17 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 20 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
18 #include "chrome/browser/chromeos/settings/device_settings_service.h" 21 #include "chrome/browser/chromeos/settings/device_settings_service.h"
22 #include "chrome/browser/profiles/profile.h"
19 #include "chromeos/chromeos_switches.h" 23 #include "chromeos/chromeos_switches.h"
24 #include "components/user_manager/user_manager.h"
20 #include "google_apis/gaia/gaia_urls.h" 25 #include "google_apis/gaia/gaia_urls.h"
21 #include "net/http/http_status_code.h" 26 #include "net/http/http_status_code.h"
22 27
23 namespace em = enterprise_management; 28 namespace em = enterprise_management;
24 29
30 using chromeos::OwnerSettingsServiceChromeOS;
31 using chromeos::OwnerSettingsServiceChromeOSFactory;
32 using user_manager::UserManager;
33
25 namespace policy { 34 namespace policy {
26 35
27 namespace { 36 namespace {
28 37
29 // Retry for InstallAttrs initialization every 500ms. 38 // Retry for InstallAttrs initialization every 500ms.
30 const int kLockRetryIntervalMs = 500; 39 const int kLockRetryIntervalMs = 500;
31 // Maximum time to retry InstallAttrs initialization before we give up. 40 // Maximum time to retry InstallAttrs initialization before we give up.
32 const int kLockRetryTimeoutMs = 10 * 60 * 1000; // 10 minutes. 41 const int kLockRetryTimeoutMs = 10 * 60 * 1000; // 10 minutes.
33 42
34 // Testing token used when the enrollment-skip-robot-auth is set to skip talking 43 // Testing token used when the enrollment-skip-robot-auth is set to skip talking
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // then StartRegistration() bails silently. This gets registration rolling 207 // then StartRegistration() bails silently. This gets registration rolling
199 // again after the store finishes loading. 208 // again after the store finishes loading.
200 StartRegistration(); 209 StartRegistration();
201 } else if (enrollment_step_ == STEP_STORE_POLICY) { 210 } else if (enrollment_step_ == STEP_STORE_POLICY) {
202 ReportResult(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)); 211 ReportResult(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS));
203 } 212 }
204 } 213 }
205 214
206 void EnrollmentHandlerChromeOS::OnStoreError(CloudPolicyStore* store) { 215 void EnrollmentHandlerChromeOS::OnStoreError(CloudPolicyStore* store) {
207 DCHECK_EQ(store_, store); 216 DCHECK_EQ(store_, store);
208 if (enrollment_step_ == STEP_STORE_TOKEN_AND_ID) { 217 if (enrollment_step_ == STEP_STORE_TOKEN_AND_ID) {
Mattias Nissler (ping if slow) 2014/12/03 09:07:54 Side note: This bailout path should only be enable
209 // Calling DeviceSettingsService::SetManagementSettings() on a non- 218 // Calling OwnerSettingsServiceChromeOS::SetManagementSettings()
210 // enterprise-managed device will trigger OnStoreError(), as 219 // on a non- enterprise-managed device will fail as
211 // DeviceCloudPolicyStore listens to all changes on DeviceSettingsService, 220 // DeviceCloudPolicyStore listens to all changes on device
212 // and it calls OnStoreError() when the device is not enterprise-managed. 221 // settings, and it calls OnStoreError() when the device is not
222 // enterprise-managed.
213 return; 223 return;
214 } 224 }
215 ReportResult(EnrollmentStatus::ForStoreError(store_->status(), 225 ReportResult(EnrollmentStatus::ForStoreError(store_->status(),
216 store_->validation_status())); 226 store_->validation_status()));
217 } 227 }
218 228
219 void EnrollmentHandlerChromeOS::HandleStateKeysResult( 229 void EnrollmentHandlerChromeOS::HandleStateKeysResult(
220 const std::vector<std::string>& state_keys) { 230 const std::vector<std::string>& state_keys) {
221 CHECK_EQ(STEP_STATE_KEYS, enrollment_step_); 231 CHECK_EQ(STEP_STATE_KEYS, enrollment_step_);
222 232
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 349
340 void EnrollmentHandlerChromeOS::StartLockDevice() { 350 void EnrollmentHandlerChromeOS::StartLockDevice() {
341 CHECK_EQ(STEP_LOCK_DEVICE, enrollment_step_); 351 CHECK_EQ(STEP_LOCK_DEVICE, enrollment_step_);
342 // Since this method is also called directly. 352 // Since this method is also called directly.
343 weak_ptr_factory_.InvalidateWeakPtrs(); 353 weak_ptr_factory_.InvalidateWeakPtrs();
344 354
345 if (management_mode_ == MANAGEMENT_MODE_CONSUMER_MANAGED) { 355 if (management_mode_ == MANAGEMENT_MODE_CONSUMER_MANAGED) {
346 // Consumer device enrollment doesn't use install attributes. Instead, 356 // Consumer device enrollment doesn't use install attributes. Instead,
347 // we put the information in the owners settings. 357 // we put the information in the owners settings.
348 enrollment_step_ = STEP_STORE_TOKEN_AND_ID; 358 enrollment_step_ = STEP_STORE_TOKEN_AND_ID;
349 device_settings_service_->SetManagementSettings( 359 const user_manager::User* user = UserManager::Get()->FindUser(username_);
350 em::PolicyData::CONSUMER_MANAGED, request_token_, device_id_, 360 CHECK(user);
351 base::Bind(&EnrollmentHandlerChromeOS::HandleSetManagementSettingsDone, 361 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user);
352 weak_ptr_factory_.GetWeakPtr())); 362 CHECK(profile);
363 OwnerSettingsServiceChromeOS* service =
364 OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(profile);
365 if (service) {
366 OwnerSettingsServiceChromeOS::ManagementSettings settings;
367 settings.management_mode = management_mode_;
368 settings.request_token = request_token_;
369 settings.device_id = device_id_;
370 service->SetManagementSettings(
371 settings,
372 base::Bind(
373 &EnrollmentHandlerChromeOS::HandleSetManagementSettingsDone,
374 weak_ptr_factory_.GetWeakPtr()));
375 }
353 } else { 376 } else {
354 install_attributes_->LockDevice( 377 install_attributes_->LockDevice(
355 username_, device_mode_, device_id_, 378 username_, device_mode_, device_id_,
356 base::Bind(&EnrollmentHandlerChromeOS::HandleLockDeviceResult, 379 base::Bind(&EnrollmentHandlerChromeOS::HandleLockDeviceResult,
357 weak_ptr_factory_.GetWeakPtr())); 380 weak_ptr_factory_.GetWeakPtr()));
358 } 381 }
359 } 382 }
360 383
361 void EnrollmentHandlerChromeOS::HandleSetManagementSettingsDone() { 384 void EnrollmentHandlerChromeOS::HandleSetManagementSettingsDone(bool success) {
362 CHECK_EQ(STEP_STORE_TOKEN_AND_ID, enrollment_step_); 385 CHECK_EQ(STEP_STORE_TOKEN_AND_ID, enrollment_step_);
363 if (device_settings_service_->status() != 386 if (!success) {
364 chromeos::DeviceSettingsService::STORE_SUCCESS) {
365 ReportResult(EnrollmentStatus::ForStatus( 387 ReportResult(EnrollmentStatus::ForStatus(
366 EnrollmentStatus::STATUS_STORE_TOKEN_AND_ID_FAILED)); 388 EnrollmentStatus::STATUS_STORE_TOKEN_AND_ID_FAILED));
367 return; 389 return;
368 } 390 }
369 391
370 StartStoreRobotAuth(); 392 StartStoreRobotAuth();
371 } 393 }
372 394
373 void EnrollmentHandlerChromeOS::HandleLockDeviceResult( 395 void EnrollmentHandlerChromeOS::HandleLockDeviceResult(
374 EnterpriseInstallAttributes::LockResult lock_result) { 396 EnterpriseInstallAttributes::LockResult lock_result) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 << ", validation: " << status.validation_status() 475 << ", validation: " << status.validation_status()
454 << ", store: " << status.store_status() 476 << ", store: " << status.store_status()
455 << ", lock: " << status.lock_status(); 477 << ", lock: " << status.lock_status();
456 } 478 }
457 479
458 if (!callback.is_null()) 480 if (!callback.is_null())
459 callback.Run(status); 481 callback.Run(status);
460 } 482 }
461 483
462 } // namespace policy 484 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698