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

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

Issue 60113002: Add a flag to skip robot token fetching for testing device enrollments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/chrome_switches.h » ('j') | chrome/common/chrome_switches.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/logging.h" 9 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" 12 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
12 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 13 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
13 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 14 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
14 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 15 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
15 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" 16 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h"
16 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" 17 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
18 #include "chrome/common/chrome_switches.h"
17 #include "google_apis/gaia/gaia_urls.h" 19 #include "google_apis/gaia/gaia_urls.h"
18 #include "net/http/http_status_code.h" 20 #include "net/http/http_status_code.h"
19 21
20 namespace em = enterprise_management; 22 namespace em = enterprise_management;
21 23
22 namespace policy { 24 namespace policy {
23 25
24 namespace { 26 namespace {
25 27
26 // Retry for InstallAttrs initialization every 500ms. 28 // Retry for InstallAttrs initialization every 500ms.
27 const int kLockRetryIntervalMs = 500; 29 const int kLockRetryIntervalMs = 500;
28 // Maximum time to retry InstallAttrs initialization before we give up. 30 // Maximum time to retry InstallAttrs initialization before we give up.
29 const int kLockRetryTimeoutMs = 10 * 60 * 1000; // 10 minutes. 31 const int kLockRetryTimeoutMs = 10 * 60 * 1000; // 10 minutes.
30 32
33 // Testing token used when the enrollment-skip-robot-auth is set to skip talking
34 // to GAIA for an actual token. This is needed to be able to run against the
35 // testing DMServer implementations.
36 const char kTestingRobotToken[] = "test-token";
37
31 } // namespace 38 } // namespace
32 39
33 EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS( 40 EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS(
34 DeviceCloudPolicyStoreChromeOS* store, 41 DeviceCloudPolicyStoreChromeOS* store,
35 EnterpriseInstallAttributes* install_attributes, 42 EnterpriseInstallAttributes* install_attributes,
36 scoped_ptr<CloudPolicyClient> client, 43 scoped_ptr<CloudPolicyClient> client,
37 scoped_refptr<base::SequencedTaskRunner> background_task_runner, 44 scoped_refptr<base::SequencedTaskRunner> background_task_runner,
38 const std::string& auth_token, 45 const std::string& auth_token,
39 const std::string& client_id, 46 const std::string& client_id,
40 bool is_auto_enrollment, 47 bool is_auto_enrollment,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 187 }
181 188
182 void EnrollmentHandlerChromeOS::PolicyValidated( 189 void EnrollmentHandlerChromeOS::PolicyValidated(
183 DeviceCloudPolicyValidator* validator) { 190 DeviceCloudPolicyValidator* validator) {
184 CHECK_EQ(STEP_VALIDATION, enrollment_step_); 191 CHECK_EQ(STEP_VALIDATION, enrollment_step_);
185 if (validator->success()) { 192 if (validator->success()) {
186 policy_ = validator->policy().Pass(); 193 policy_ = validator->policy().Pass();
187 username_ = validator->policy_data()->username(); 194 username_ = validator->policy_data()->username();
188 device_id_ = validator->policy_data()->device_id(); 195 device_id_ = validator->policy_data()->device_id();
189 196
197 if (CommandLine::ForCurrentProcess()->HasSwitch(
198 switches::kEnrollmentSkipRobotAuth)) {
199 // For test purposes we allow enrollment to succeed without proper robot
200 // account and use the provided value as a token.
201 refresh_token_ = kTestingRobotToken;
202 enrollment_step_ = STEP_LOCK_DEVICE,
203 StartLockDevice(username_, device_mode_, device_id_);
204 return;
205 }
206
190 enrollment_step_ = STEP_ROBOT_AUTH_FETCH; 207 enrollment_step_ = STEP_ROBOT_AUTH_FETCH;
191 client_->FetchRobotAuthCodes(auth_token_); 208 client_->FetchRobotAuthCodes(auth_token_);
192 } else { 209 } else {
193 ReportResult(EnrollmentStatus::ForValidationError(validator->status())); 210 ReportResult(EnrollmentStatus::ForValidationError(validator->status()));
194 } 211 }
195 } 212 }
196 213
197 void EnrollmentHandlerChromeOS::OnRobotAuthCodesFetched( 214 void EnrollmentHandlerChromeOS::OnRobotAuthCodesFetched(
198 CloudPolicyClient* client) { 215 CloudPolicyClient* client) {
199 DCHECK_EQ(client_.get(), client); 216 DCHECK_EQ(client_.get(), client);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 chromeos::DeviceOAuth2TokenService* token_service) { 344 chromeos::DeviceOAuth2TokenService* token_service) {
328 CHECK_EQ(STEP_STORE_ROBOT_AUTH, enrollment_step_); 345 CHECK_EQ(STEP_STORE_ROBOT_AUTH, enrollment_step_);
329 // Store the robot API auth refresh token. 346 // Store the robot API auth refresh token.
330 if (!token_service) { 347 if (!token_service) {
331 LOG(ERROR) << "Failed to store API refresh token (no token service)."; 348 LOG(ERROR) << "Failed to store API refresh token (no token service).";
332 ReportResult(EnrollmentStatus::ForStatus( 349 ReportResult(EnrollmentStatus::ForStatus(
333 EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED)); 350 EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED));
334 return; 351 return;
335 } 352 }
336 353
337 if (!token_service->SetAndSaveRefreshToken(refresh_token_)) { 354 if (!token_service->SetAndSaveRefreshToken(refresh_token_)) {
Joao da Silva 2013/11/05 16:25:48 I think this block could be skipped when the switc
pastarmovj 2013/11/05 16:38:58 Actually I think it is better to set it to this ob
338 LOG(ERROR) << "Failed to store API refresh token."; 355 LOG(ERROR) << "Failed to store API refresh token.";
339 ReportResult(EnrollmentStatus::ForStatus( 356 ReportResult(EnrollmentStatus::ForStatus(
340 EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED)); 357 EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED));
341 return; 358 return;
342 } 359 }
343 360
344 enrollment_step_ = STEP_STORE_POLICY; 361 enrollment_step_ = STEP_STORE_POLICY;
345 store_->InstallInitialPolicy(*policy_); 362 store_->InstallInitialPolicy(*policy_);
346 } 363 }
347 364
(...skipping 14 matching lines...) Expand all
362 << " " << status.client_status() 379 << " " << status.client_status()
363 << " " << status.validation_status() 380 << " " << status.validation_status()
364 << " " << status.store_status(); 381 << " " << status.store_status();
365 } 382 }
366 383
367 if (!callback.is_null()) 384 if (!callback.is_null())
368 callback.Run(status); 385 callback.Run(status);
369 } 386 }
370 387
371 } // namespace policy 388 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | chrome/common/chrome_switches.h » ('j') | chrome/common/chrome_switches.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698