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/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 "chromeos/chromeos_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 Loading... |
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 chromeos::switches::kEnterpriseEnrollmentSkipRobotAuth)) { |
| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |