OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/login/enrollment/enterprise_enrollment_helper_
impl.h" | 5 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_
impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.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" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 CHECK(dcp_initializer); | 180 CHECK(dcp_initializer); |
181 dcp_initializer->StartEnrollment( | 181 dcp_initializer->StartEnrollment( |
182 policy::MANAGEMENT_MODE_ENTERPRISE_MANAGED, | 182 policy::MANAGEMENT_MODE_ENTERPRISE_MANAGED, |
183 connector->device_management_service(), | 183 connector->device_management_service(), |
184 nullptr /* owner_settings_service */, enrollment_config_, token, | 184 nullptr /* owner_settings_service */, enrollment_config_, token, |
185 device_modes, | 185 device_modes, |
186 base::Bind(&EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished, | 186 base::Bind(&EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished, |
187 weak_ptr_factory_.GetWeakPtr())); | 187 weak_ptr_factory_.GetWeakPtr())); |
188 } | 188 } |
189 | 189 |
| 190 void EnterpriseEnrollmentHelperImpl::GetDeviceAttributeUpdatePermission() { |
| 191 policy::BrowserPolicyConnectorChromeOS* connector = |
| 192 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 193 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = |
| 194 connector->GetDeviceCloudPolicyManager(); |
| 195 policy::CloudPolicyClient* client = policy_manager->core()->client(); |
| 196 |
| 197 client->GetDeviceAttributeUpdatePermission( |
| 198 GetOAuthToken(), |
| 199 base::Bind( |
| 200 &EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUpdatePermission, |
| 201 weak_ptr_factory_.GetWeakPtr())); |
| 202 } |
| 203 |
| 204 void EnterpriseEnrollmentHelperImpl::UpdateDeviceAttributes( |
| 205 const std::string& asset_id, |
| 206 const std::string& location) { |
| 207 policy::BrowserPolicyConnectorChromeOS* connector = |
| 208 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 209 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = |
| 210 connector->GetDeviceCloudPolicyManager(); |
| 211 policy::CloudPolicyClient* client = policy_manager->core()->client(); |
| 212 |
| 213 client->UpdateDeviceAttributes( |
| 214 GetOAuthToken(), asset_id, location, |
| 215 base::Bind( |
| 216 &EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUploadCompleted, |
| 217 weak_ptr_factory_.GetWeakPtr())); |
| 218 } |
| 219 |
190 void EnterpriseEnrollmentHelperImpl::OnTokenFetched( | 220 void EnterpriseEnrollmentHelperImpl::OnTokenFetched( |
191 size_t fetcher_index, | 221 size_t fetcher_index, |
192 const std::string& token, | 222 const std::string& token, |
193 const GoogleServiceAuthError& error) { | 223 const GoogleServiceAuthError& error) { |
194 CHECK_LT(fetcher_index, oauth_fetchers_.size()); | 224 CHECK_LT(fetcher_index, oauth_fetchers_.size()); |
195 | 225 |
196 if (error.state() != GoogleServiceAuthError::NONE) | 226 if (error.state() != GoogleServiceAuthError::NONE) |
197 last_auth_error_ = error; | 227 last_auth_error_ = error; |
198 | 228 |
199 ++oauth_fetchers_finished_; | 229 ++oauth_fetchers_finished_; |
(...skipping 18 matching lines...) Expand all Loading... |
218 finished_ = true; | 248 finished_ = true; |
219 if (status.status() == policy::EnrollmentStatus::STATUS_SUCCESS) { | 249 if (status.status() == policy::EnrollmentStatus::STATUS_SUCCESS) { |
220 success_ = true; | 250 success_ = true; |
221 DCHECK(!fetch_additional_token_ || !additional_token_.empty()); | 251 DCHECK(!fetch_additional_token_ || !additional_token_.empty()); |
222 status_consumer()->OnDeviceEnrolled(additional_token_); | 252 status_consumer()->OnDeviceEnrolled(additional_token_); |
223 } else { | 253 } else { |
224 status_consumer()->OnEnrollmentError(status); | 254 status_consumer()->OnEnrollmentError(status); |
225 } | 255 } |
226 } | 256 } |
227 | 257 |
| 258 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUpdatePermission( |
| 259 bool status) { |
| 260 status_consumer()->OnDeviceAttributeUpdatePermission(status); |
| 261 } |
| 262 |
| 263 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUploadCompleted( |
| 264 bool status) { |
| 265 status_consumer()->OnDeviceAttributeUploadCompleted(status); |
| 266 } |
| 267 |
228 void EnterpriseEnrollmentHelperImpl::ReportAuthStatus( | 268 void EnterpriseEnrollmentHelperImpl::ReportAuthStatus( |
229 const GoogleServiceAuthError& error) { | 269 const GoogleServiceAuthError& error) { |
230 switch (error.state()) { | 270 switch (error.state()) { |
231 case GoogleServiceAuthError::NONE: | 271 case GoogleServiceAuthError::NONE: |
232 case GoogleServiceAuthError::CAPTCHA_REQUIRED: | 272 case GoogleServiceAuthError::CAPTCHA_REQUIRED: |
233 case GoogleServiceAuthError::TWO_FACTOR: | 273 case GoogleServiceAuthError::TWO_FACTOR: |
234 case GoogleServiceAuthError::HOSTED_NOT_ALLOWED: | 274 case GoogleServiceAuthError::HOSTED_NOT_ALLOWED: |
235 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: | 275 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: |
236 case GoogleServiceAuthError::REQUEST_CANCELED: | 276 case GoogleServiceAuthError::REQUEST_CANCELED: |
237 case GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE: | 277 case GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE: |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 break; | 411 break; |
372 case policy::EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED: | 412 case policy::EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED: |
373 UMA(policy::kMetricEnrollmentRobotRefreshTokenStoreFailed); | 413 UMA(policy::kMetricEnrollmentRobotRefreshTokenStoreFailed); |
374 break; | 414 break; |
375 case policy::EnrollmentStatus::STATUS_STORE_TOKEN_AND_ID_FAILED: | 415 case policy::EnrollmentStatus::STATUS_STORE_TOKEN_AND_ID_FAILED: |
376 // This error should not happen for enterprise enrollment, it only affects | 416 // This error should not happen for enterprise enrollment, it only affects |
377 // consumer enrollment. | 417 // consumer enrollment. |
378 UMA(policy::kMetricEnrollmentStoreTokenAndIdFailed); | 418 UMA(policy::kMetricEnrollmentStoreTokenAndIdFailed); |
379 NOTREACHED(); | 419 NOTREACHED(); |
380 break; | 420 break; |
| 421 case policy::EnrollmentStatus::STATUS_ATTRIBUTE_UPDATE_FAILED: |
| 422 UMA(policy::kMetricEnrollmentAttributeUpdateFailed); |
| 423 break; |
381 } | 424 } |
382 } | 425 } |
383 | 426 |
384 void EnterpriseEnrollmentHelperImpl::UMA(policy::MetricEnrollment sample) { | 427 void EnterpriseEnrollmentHelperImpl::UMA(policy::MetricEnrollment sample) { |
385 EnrollmentUMA(sample, enrollment_config_.mode); | 428 EnrollmentUMA(sample, enrollment_config_.mode); |
386 } | 429 } |
387 | 430 |
388 void EnterpriseEnrollmentHelperImpl::OnBrowsingDataRemoverDone() { | 431 void EnterpriseEnrollmentHelperImpl::OnBrowsingDataRemoverDone() { |
389 browsing_data_remover_->RemoveObserver(this); | 432 browsing_data_remover_->RemoveObserver(this); |
390 | 433 |
391 // BrowsingDataRemover deletes itself. | 434 // BrowsingDataRemover deletes itself. |
392 browsing_data_remover_ = nullptr; | 435 browsing_data_remover_ = nullptr; |
393 | 436 |
394 auth_data_cleared_ = true; | 437 auth_data_cleared_ = true; |
395 | 438 |
396 std::vector<base::Closure> callbacks_to_run; | 439 std::vector<base::Closure> callbacks_to_run; |
397 callbacks_to_run.swap(auth_clear_callbacks_); | 440 callbacks_to_run.swap(auth_clear_callbacks_); |
398 for (std::vector<base::Closure>::iterator callback(callbacks_to_run.begin()); | 441 for (std::vector<base::Closure>::iterator callback(callbacks_to_run.begin()); |
399 callback != callbacks_to_run.end(); | 442 callback != callbacks_to_run.end(); |
400 ++callback) { | 443 ++callback) { |
401 callback->Run(); | 444 callback->Run(); |
402 } | 445 } |
403 } | 446 } |
404 | 447 |
| 448 const std::string& EnterpriseEnrollmentHelperImpl::GetOAuthToken() { |
| 449 DCHECK(oauth_fetchers_.size() > 0); |
| 450 return oauth_fetchers_[0]->oauth2_access_token(); |
| 451 } |
| 452 |
405 } // namespace chromeos | 453 } // namespace chromeos |
OLD | NEW |