| 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/login/enrollment/enrollment_screen.h" | 5 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.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/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 "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/browser_process_platform_part.h" | 13 #include "chrome/browser/browser_process_platform_part.h" |
| 14 #include "chrome/browser/chromeos/login/login_utils.h" | 14 #include "chrome/browser/chromeos/login/login_utils.h" |
| 15 #include "chrome/browser/chromeos/login/screen_manager.h" | 15 #include "chrome/browser/chromeos/login/screen_manager.h" |
| 16 #include "chrome/browser/chromeos/login/screens/screen_observer.h" | 16 #include "chrome/browser/chromeos/login/screens/screen_observer.h" |
| 17 #include "chrome/browser/chromeos/login/startup_utils.h" | 17 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 18 #include "chrome/browser/chromeos/login/wizard_controller.h" | 18 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 19 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h" | 19 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h" |
| 20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 21 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" | 21 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" |
| 22 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 22 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 23 #include "chromeos/dbus/cryptohome_client.h" | 23 #include "chromeos/dbus/cryptohome_client.h" |
| 24 #include "chromeos/dbus/dbus_method_call_status.h" | 24 #include "chromeos/dbus/dbus_method_call_status.h" |
| 25 #include "chromeos/dbus/dbus_thread_manager.h" | 25 #include "chromeos/dbus/dbus_thread_manager.h" |
| 26 #include "chromeos/dbus/session_manager_client.h" | 26 #include "chromeos/dbus/session_manager_client.h" |
| 27 #include "components/pairing/controller_pairing_controller.h" |
| 27 #include "google_apis/gaia/gaia_auth_util.h" | 28 #include "google_apis/gaia/gaia_auth_util.h" |
| 28 #include "google_apis/gaia/google_service_auth_error.h" | 29 #include "google_apis/gaia/google_service_auth_error.h" |
| 29 #include "policy/proto/device_management_backend.pb.h" | 30 #include "policy/proto/device_management_backend.pb.h" |
| 30 | 31 |
| 32 using namespace pairing_chromeos; |
| 33 |
| 31 namespace chromeos { | 34 namespace chromeos { |
| 32 | 35 |
| 33 // static | 36 // static |
| 34 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) { | 37 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) { |
| 35 return static_cast<EnrollmentScreen*>( | 38 return static_cast<EnrollmentScreen*>( |
| 36 manager->GetScreen(WizardController::kEnrollmentScreenName)); | 39 manager->GetScreen(WizardController::kEnrollmentScreenName)); |
| 37 } | 40 } |
| 38 | 41 |
| 39 EnrollmentScreen::EnrollmentScreen( | 42 EnrollmentScreen::EnrollmentScreen( |
| 40 ScreenObserver* observer, | 43 ScreenObserver* observer, |
| 41 EnrollmentScreenActor* actor) | 44 EnrollmentScreenActor* actor) |
| 42 : WizardScreen(observer), | 45 : WizardScreen(observer), |
| 46 shark_controller_(NULL), |
| 47 remora_controller_(NULL), |
| 43 actor_(actor), | 48 actor_(actor), |
| 44 enrollment_mode_(EnrollmentScreenActor::ENROLLMENT_MODE_MANUAL), | 49 enrollment_mode_(EnrollmentScreenActor::ENROLLMENT_MODE_MANUAL), |
| 45 enrollment_failed_once_(false), | 50 enrollment_failed_once_(false), |
| 46 remora_token_sent_(false), | 51 remora_token_sent_(false), |
| 47 lockbox_init_duration_(0), | 52 lockbox_init_duration_(0), |
| 48 weak_ptr_factory_(this) { | 53 weak_ptr_factory_(this) { |
| 49 // Init the TPM if it has not been done until now (in debug build we might | 54 // Init the TPM if it has not been done until now (in debug build we might |
| 50 // have not done that yet). | 55 // have not done that yet). |
| 51 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( | 56 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( |
| 52 EmptyVoidDBusMethodCallback()); | 57 EmptyVoidDBusMethodCallback()); |
| 53 } | 58 } |
| 54 | 59 |
| 55 EnrollmentScreen::~EnrollmentScreen() {} | 60 EnrollmentScreen::~EnrollmentScreen() { |
| 61 if (remora_controller_) |
| 62 remora_controller_->RemoveObserver(this); |
| 63 } |
| 56 | 64 |
| 57 void EnrollmentScreen::SetParameters( | 65 void EnrollmentScreen::SetParameters( |
| 58 EnrollmentScreenActor::EnrollmentMode enrollment_mode, | 66 EnrollmentScreenActor::EnrollmentMode enrollment_mode, |
| 59 const std::string& management_domain, | 67 const std::string& management_domain, |
| 60 const std::string& user, | 68 const std::string& user, |
| 61 const std::string& auth_token) { | 69 const std::string& auth_token, |
| 70 pairing_chromeos::ControllerPairingController* shark_controller, |
| 71 pairing_chromeos::HostPairingController* remora_controller) { |
| 62 enrollment_mode_ = enrollment_mode; | 72 enrollment_mode_ = enrollment_mode; |
| 63 user_ = user.empty() ? user : gaia::CanonicalizeEmail(user); | 73 user_ = user.empty() ? user : gaia::CanonicalizeEmail(user); |
| 64 auth_token_ = auth_token; | 74 auth_token_ = auth_token; |
| 75 shark_controller_ = shark_controller; |
| 76 DCHECK(!remora_controller_); |
| 77 remora_controller_ = remora_controller; |
| 78 if (remora_controller_) |
| 79 remora_controller_->AddObserver(this); |
| 65 actor_->SetParameters(this, enrollment_mode_, management_domain); | 80 actor_->SetParameters(this, enrollment_mode_, management_domain); |
| 66 } | 81 } |
| 67 | 82 |
| 68 void EnrollmentScreen::PrepareToShow() { | 83 void EnrollmentScreen::PrepareToShow() { |
| 69 actor_->PrepareToShow(); | 84 actor_->PrepareToShow(); |
| 70 } | 85 } |
| 71 | 86 |
| 72 void EnrollmentScreen::Show() { | 87 void EnrollmentScreen::Show() { |
| 73 if (is_auto_enrollment() && !enrollment_failed_once_) { | 88 if (is_auto_enrollment() && !enrollment_failed_once_) { |
| 74 actor_->Show(); | 89 actor_->Show(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 88 | 103 |
| 89 void EnrollmentScreen::Hide() { | 104 void EnrollmentScreen::Hide() { |
| 90 actor_->Hide(); | 105 actor_->Hide(); |
| 91 weak_ptr_factory_.InvalidateWeakPtrs(); | 106 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 92 } | 107 } |
| 93 | 108 |
| 94 std::string EnrollmentScreen::GetName() const { | 109 std::string EnrollmentScreen::GetName() const { |
| 95 return WizardController::kEnrollmentScreenName; | 110 return WizardController::kEnrollmentScreenName; |
| 96 } | 111 } |
| 97 | 112 |
| 113 void EnrollmentScreen::PairingStageChanged(Stage new_stage) { |
| 114 DCHECK(remora_controller_); |
| 115 if (new_stage == HostPairingController::STAGE_FINISHED) { |
| 116 remora_controller_->RemoveObserver(this); |
| 117 remora_controller_ = NULL; |
| 118 // TODO(zork): Check that this is the best exit status. crbug.com/412798 |
| 119 get_screen_observer()->OnExit( |
| 120 WizardController::ENTERPRISE_AUTO_MAGIC_ENROLLMENT_COMPLETED); |
| 121 } |
| 122 } |
| 123 |
| 124 void EnrollmentScreen::ConfigureHost(bool accepted_eula, |
| 125 const std::string& lang, |
| 126 const std::string& timezone, |
| 127 bool send_reports, |
| 128 const std::string& keyboard_layout) { |
| 129 } |
| 130 |
| 131 void EnrollmentScreen::EnrollHost(const std::string& auth_token) { |
| 132 } |
| 133 |
| 98 void EnrollmentScreen::OnLoginDone(const std::string& user) { | 134 void EnrollmentScreen::OnLoginDone(const std::string& user) { |
| 99 user_ = gaia::CanonicalizeEmail(user); | 135 user_ = gaia::CanonicalizeEmail(user); |
| 100 | 136 |
| 101 if (is_auto_enrollment()) | 137 if (is_auto_enrollment()) |
| 102 UMA(policy::kMetricEnrollmentAutoRetried); | 138 UMA(policy::kMetricEnrollmentAutoRetried); |
| 103 else if (enrollment_failed_once_) | 139 else if (enrollment_failed_once_) |
| 104 UMA(policy::kMetricEnrollmentRetried); | 140 UMA(policy::kMetricEnrollmentRetried); |
| 105 else | 141 else |
| 106 UMA(policy::kMetricEnrollmentStarted); | 142 UMA(policy::kMetricEnrollmentStarted); |
| 107 | 143 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 CHECK(dcp_initializer); | 268 CHECK(dcp_initializer); |
| 233 dcp_initializer->StartEnrollment( | 269 dcp_initializer->StartEnrollment( |
| 234 enterprise_management::PolicyData::ENTERPRISE_MANAGED, | 270 enterprise_management::PolicyData::ENTERPRISE_MANAGED, |
| 235 connector->device_management_service(), | 271 connector->device_management_service(), |
| 236 token, is_auto_enrollment(), device_modes, | 272 token, is_auto_enrollment(), device_modes, |
| 237 base::Bind(&EnrollmentScreen::ReportEnrollmentStatus, | 273 base::Bind(&EnrollmentScreen::ReportEnrollmentStatus, |
| 238 weak_ptr_factory_.GetWeakPtr())); | 274 weak_ptr_factory_.GetWeakPtr())); |
| 239 } | 275 } |
| 240 | 276 |
| 241 void EnrollmentScreen::SendEnrollmentAuthToken(const std::string& token) { | 277 void EnrollmentScreen::SendEnrollmentAuthToken(const std::string& token) { |
| 242 // TODO(achuith, zork): Send token via Bluetooth to remote device. | 278 // TODO(achuith, zork): Extract and send domain. |
| 279 if (shark_controller_) |
| 280 shark_controller_->OnAuthenticationDone("", token); |
| 243 } | 281 } |
| 244 | 282 |
| 245 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess( | 283 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess( |
| 246 const policy::EnrollmentStatus& status) { | 284 const policy::EnrollmentStatus& status) { |
| 247 actor_->ShowEnrollmentStatus(status); | 285 actor_->ShowEnrollmentStatus(status); |
| 248 StartupUtils::MarkOobeCompleted(); | 286 StartupUtils::MarkOobeCompleted(); |
| 249 } | 287 } |
| 250 | 288 |
| 251 void EnrollmentScreen::ReportEnrollmentStatus(policy::EnrollmentStatus status) { | 289 void EnrollmentScreen::ReportEnrollmentStatus(policy::EnrollmentStatus status) { |
| 252 switch (status.status()) { | 290 switch (status.status()) { |
| 253 case policy::EnrollmentStatus::STATUS_SUCCESS: | 291 case policy::EnrollmentStatus::STATUS_SUCCESS: |
| 254 StartupUtils::MarkDeviceRegistered( | 292 StartupUtils::MarkDeviceRegistered( |
| 255 base::Bind(&EnrollmentScreen::ShowEnrollmentStatusOnSuccess, | 293 base::Bind(&EnrollmentScreen::ShowEnrollmentStatusOnSuccess, |
| 256 weak_ptr_factory_.GetWeakPtr(), | 294 weak_ptr_factory_.GetWeakPtr(), |
| 257 status)); | 295 status)); |
| 258 UMA(is_auto_enrollment() ? policy::kMetricEnrollmentAutoOK | 296 UMA(is_auto_enrollment() ? policy::kMetricEnrollmentAutoOK |
| 259 : policy::kMetricEnrollmentOK); | 297 : policy::kMetricEnrollmentOK); |
| 298 if (remora_controller_) |
| 299 remora_controller_->SetEnrollmentComplete(true); |
| 260 return; | 300 return; |
| 261 case policy::EnrollmentStatus::STATUS_REGISTRATION_FAILED: | 301 case policy::EnrollmentStatus::STATUS_REGISTRATION_FAILED: |
| 262 case policy::EnrollmentStatus::STATUS_POLICY_FETCH_FAILED: | 302 case policy::EnrollmentStatus::STATUS_POLICY_FETCH_FAILED: |
| 263 switch (status.client_status()) { | 303 switch (status.client_status()) { |
| 264 case policy::DM_STATUS_SUCCESS: | 304 case policy::DM_STATUS_SUCCESS: |
| 265 case policy::DM_STATUS_REQUEST_INVALID: | 305 case policy::DM_STATUS_REQUEST_INVALID: |
| 266 case policy::DM_STATUS_SERVICE_DEVICE_NOT_FOUND: | 306 case policy::DM_STATUS_SERVICE_DEVICE_NOT_FOUND: |
| 267 case policy::DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID: | 307 case policy::DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID: |
| 268 case policy::DM_STATUS_SERVICE_ACTIVATION_PENDING: | 308 case policy::DM_STATUS_SERVICE_ACTIVATION_PENDING: |
| 269 case policy::DM_STATUS_SERVICE_DEVICE_ID_CONFLICT: | 309 case policy::DM_STATUS_SERVICE_DEVICE_ID_CONFLICT: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 UMAFailure(policy::kMetricEnrollmentRobotRefreshTokenStoreFailed); | 364 UMAFailure(policy::kMetricEnrollmentRobotRefreshTokenStoreFailed); |
| 325 break; | 365 break; |
| 326 case policy::EnrollmentStatus::STATUS_STORE_TOKEN_AND_ID_FAILED: | 366 case policy::EnrollmentStatus::STATUS_STORE_TOKEN_AND_ID_FAILED: |
| 327 // This error should not happen for enterprise enrollment, it only affects | 367 // This error should not happen for enterprise enrollment, it only affects |
| 328 // consumer enrollment. | 368 // consumer enrollment. |
| 329 UMAFailure(policy::kMetricEnrollmentStoreTokenAndIdFailed); | 369 UMAFailure(policy::kMetricEnrollmentStoreTokenAndIdFailed); |
| 330 NOTREACHED(); | 370 NOTREACHED(); |
| 331 break; | 371 break; |
| 332 } | 372 } |
| 333 | 373 |
| 374 if (remora_controller_) |
| 375 remora_controller_->SetEnrollmentComplete(false); |
| 334 enrollment_failed_once_ = true; | 376 enrollment_failed_once_ = true; |
| 335 actor_->ShowEnrollmentStatus(status); | 377 actor_->ShowEnrollmentStatus(status); |
| 336 } | 378 } |
| 337 | 379 |
| 338 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) { | 380 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) { |
| 339 if (enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_RECOVERY) { | 381 if (enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_RECOVERY) { |
| 340 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollmentRecovery, sample, | 382 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollmentRecovery, sample, |
| 341 policy::kMetricEnrollmentSize); | 383 policy::kMetricEnrollmentSize); |
| 342 } else { | 384 } else { |
| 343 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, sample, | 385 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, sample, |
| 344 policy::kMetricEnrollmentSize); | 386 policy::kMetricEnrollmentSize); |
| 345 } | 387 } |
| 346 } | 388 } |
| 347 | 389 |
| 348 void EnrollmentScreen::UMAFailure(policy::MetricEnrollment sample) { | 390 void EnrollmentScreen::UMAFailure(policy::MetricEnrollment sample) { |
| 349 if (is_auto_enrollment()) | 391 if (is_auto_enrollment()) |
| 350 sample = policy::kMetricEnrollmentAutoFailed; | 392 sample = policy::kMetricEnrollmentAutoFailed; |
| 351 UMA(sample); | 393 UMA(sample); |
| 352 } | 394 } |
| 353 | 395 |
| 354 void EnrollmentScreen::ShowSigninScreen() { | 396 void EnrollmentScreen::ShowSigninScreen() { |
| 355 actor_->Show(); | 397 actor_->Show(); |
| 356 actor_->ShowSigninScreen(); | 398 actor_->ShowSigninScreen(); |
| 357 } | 399 } |
| 358 | 400 |
| 359 } // namespace chromeos | 401 } // namespace chromeos |
| OLD | NEW |