| 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/chromeos/login/login_utils.h" | 14 #include "chrome/browser/chromeos/login/login_utils.h" |
| 14 #include "chrome/browser/chromeos/login/screens/screen_observer.h" | 15 #include "chrome/browser/chromeos/login/screens/screen_observer.h" |
| 15 #include "chrome/browser/chromeos/login/startup_utils.h" | 16 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 16 #include "chrome/browser/chromeos/login/wizard_controller.h" | 17 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 17 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h" | 18 #include "chrome/browser/chromeos/policy/auto_enrollment_client.h" |
| 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 19 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" | 20 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" |
| 21 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 20 #include "chromeos/dbus/cryptohome_client.h" | 22 #include "chromeos/dbus/cryptohome_client.h" |
| 21 #include "chromeos/dbus/dbus_method_call_status.h" | 23 #include "chromeos/dbus/dbus_method_call_status.h" |
| 22 #include "chromeos/dbus/dbus_thread_manager.h" | 24 #include "chromeos/dbus/dbus_thread_manager.h" |
| 23 #include "chromeos/dbus/session_manager_client.h" | 25 #include "chromeos/dbus/session_manager_client.h" |
| 24 #include "google_apis/gaia/gaia_auth_util.h" | 26 #include "google_apis/gaia/gaia_auth_util.h" |
| 25 #include "google_apis/gaia/google_service_auth_error.h" | 27 #include "google_apis/gaia/google_service_auth_error.h" |
| 26 #include "policy/proto/device_management_backend.pb.h" | 28 #include "policy/proto/device_management_backend.pb.h" |
| 27 | 29 |
| 28 namespace chromeos { | 30 namespace chromeos { |
| 29 | 31 |
| 30 EnrollmentScreen::EnrollmentScreen( | 32 EnrollmentScreen::EnrollmentScreen( |
| 31 ScreenObserver* observer, | 33 ScreenObserver* observer, |
| 32 EnrollmentScreenActor* actor) | 34 EnrollmentScreenActor* actor) |
| 33 : WizardScreen(observer), | 35 : WizardScreen(observer), |
| 34 actor_(actor), | 36 actor_(actor), |
| 35 enrollment_mode_(EnrollmentScreenActor::ENROLLMENT_MODE_MANUAL), | 37 enrollment_mode_(EnrollmentScreenActor::ENROLLMENT_MODE_MANUAL), |
| 36 enrollment_failed_once_(false), | 38 enrollment_failed_once_(false), |
| 39 remora_token_sent_(false), |
| 37 lockbox_init_duration_(0), | 40 lockbox_init_duration_(0), |
| 38 weak_ptr_factory_(this) { | 41 weak_ptr_factory_(this) { |
| 39 // Init the TPM if it has not been done until now (in debug build we might | 42 // Init the TPM if it has not been done until now (in debug build we might |
| 40 // have not done that yet). | 43 // have not done that yet). |
| 41 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( | 44 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( |
| 42 EmptyVoidDBusMethodCallback()); | 45 EmptyVoidDBusMethodCallback()); |
| 43 } | 46 } |
| 44 | 47 |
| 45 EnrollmentScreen::~EnrollmentScreen() {} | 48 EnrollmentScreen::~EnrollmentScreen() {} |
| 46 | 49 |
| 47 void EnrollmentScreen::SetParameters( | 50 void EnrollmentScreen::SetParameters( |
| 48 EnrollmentScreenActor::EnrollmentMode enrollment_mode, | 51 EnrollmentScreenActor::EnrollmentMode enrollment_mode, |
| 49 const std::string& management_domain, | 52 const std::string& management_domain, |
| 50 const std::string& user) { | 53 const std::string& user, |
| 54 const std::string& auth_token) { |
| 51 enrollment_mode_ = enrollment_mode; | 55 enrollment_mode_ = enrollment_mode; |
| 52 user_ = user.empty() ? user : gaia::CanonicalizeEmail(user); | 56 user_ = user.empty() ? user : gaia::CanonicalizeEmail(user); |
| 57 auth_token_ = auth_token; |
| 53 actor_->SetParameters(this, enrollment_mode_, management_domain); | 58 actor_->SetParameters(this, enrollment_mode_, management_domain); |
| 54 } | 59 } |
| 55 | 60 |
| 56 void EnrollmentScreen::PrepareToShow() { | 61 void EnrollmentScreen::PrepareToShow() { |
| 57 actor_->PrepareToShow(); | 62 actor_->PrepareToShow(); |
| 58 } | 63 } |
| 59 | 64 |
| 60 void EnrollmentScreen::Show() { | 65 void EnrollmentScreen::Show() { |
| 61 if (is_auto_enrollment() && !enrollment_failed_once_) { | 66 if (is_auto_enrollment() && !enrollment_failed_once_) { |
| 62 actor_->Show(); | 67 actor_->Show(); |
| 63 UMA(policy::kMetricEnrollmentAutoStarted); | 68 UMA(policy::kMetricEnrollmentAutoStarted); |
| 64 actor_->ShowEnrollmentSpinnerScreen(); | 69 actor_->ShowEnrollmentSpinnerScreen(); |
| 65 actor_->FetchOAuthToken(); | 70 actor_->FetchOAuthToken(); |
| 66 } else { | 71 } else if (auth_token_.empty()) { |
| 67 UMA(policy::kMetricEnrollmentTriggered); | 72 UMA(policy::kMetricEnrollmentTriggered); |
| 68 actor_->ResetAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, | 73 actor_->ResetAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, |
| 69 weak_ptr_factory_.GetWeakPtr())); | 74 weak_ptr_factory_.GetWeakPtr())); |
| 75 } else { |
| 76 actor_->Show(); |
| 77 actor_->ShowEnrollmentSpinnerScreen(); |
| 78 OnOAuthTokenAvailable(auth_token_); |
| 70 } | 79 } |
| 71 } | 80 } |
| 72 | 81 |
| 73 void EnrollmentScreen::Hide() { | 82 void EnrollmentScreen::Hide() { |
| 74 actor_->Hide(); | 83 actor_->Hide(); |
| 75 weak_ptr_factory_.InvalidateWeakPtrs(); | 84 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 76 } | 85 } |
| 77 | 86 |
| 78 std::string EnrollmentScreen::GetName() const { | 87 std::string EnrollmentScreen::GetName() const { |
| 79 return WizardController::kEnrollmentScreenName; | 88 return WizardController::kEnrollmentScreenName; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 return; | 131 return; |
| 123 case GoogleServiceAuthError::NUM_STATES: | 132 case GoogleServiceAuthError::NUM_STATES: |
| 124 break; | 133 break; |
| 125 } | 134 } |
| 126 | 135 |
| 127 NOTREACHED(); | 136 NOTREACHED(); |
| 128 UMAFailure(policy::kMetricEnrollmentOtherFailed); | 137 UMAFailure(policy::kMetricEnrollmentOtherFailed); |
| 129 } | 138 } |
| 130 | 139 |
| 131 void EnrollmentScreen::OnOAuthTokenAvailable(const std::string& token) { | 140 void EnrollmentScreen::OnOAuthTokenAvailable(const std::string& token) { |
| 132 RegisterForDevicePolicy(token); | 141 VLOG(1) << "OnOAuthTokenAvailable " << token; |
| 142 const bool is_shark = |
| 143 g_browser_process->platform_part()->browser_policy_connector_chromeos()-> |
| 144 GetDeviceCloudPolicyManager()->IsSharkRequisition(); |
| 145 |
| 146 if (is_shark && !remora_token_sent_) { |
| 147 // Fetch a second token for shark devices. |
| 148 remora_token_sent_ = true; |
| 149 SendEnrollmentAuthToken(token); |
| 150 actor_->FetchOAuthToken(); |
| 151 } else { |
| 152 RegisterForDevicePolicy(token); |
| 153 } |
| 133 } | 154 } |
| 134 | 155 |
| 135 void EnrollmentScreen::OnRetry() { | 156 void EnrollmentScreen::OnRetry() { |
| 136 actor_->ResetAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, | 157 actor_->ResetAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, |
| 137 weak_ptr_factory_.GetWeakPtr())); | 158 weak_ptr_factory_.GetWeakPtr())); |
| 138 } | 159 } |
| 139 | 160 |
| 140 void EnrollmentScreen::OnCancel() { | 161 void EnrollmentScreen::OnCancel() { |
| 141 if (enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_FORCED || | 162 if (enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_FORCED || |
| 142 enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_RECOVERY) { | 163 enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_RECOVERY) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 connector->GetDeviceCloudPolicyInitializer(); | 226 connector->GetDeviceCloudPolicyInitializer(); |
| 206 CHECK(dcp_initializer); | 227 CHECK(dcp_initializer); |
| 207 dcp_initializer->StartEnrollment( | 228 dcp_initializer->StartEnrollment( |
| 208 enterprise_management::PolicyData::ENTERPRISE_MANAGED, | 229 enterprise_management::PolicyData::ENTERPRISE_MANAGED, |
| 209 connector->device_management_service(), | 230 connector->device_management_service(), |
| 210 token, is_auto_enrollment(), device_modes, | 231 token, is_auto_enrollment(), device_modes, |
| 211 base::Bind(&EnrollmentScreen::ReportEnrollmentStatus, | 232 base::Bind(&EnrollmentScreen::ReportEnrollmentStatus, |
| 212 weak_ptr_factory_.GetWeakPtr())); | 233 weak_ptr_factory_.GetWeakPtr())); |
| 213 } | 234 } |
| 214 | 235 |
| 236 void EnrollmentScreen::SendEnrollmentAuthToken(const std::string& token) { |
| 237 // TODO(achuith, zork): Send token via Bluetooth to remote device. |
| 238 } |
| 239 |
| 215 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess( | 240 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess( |
| 216 const policy::EnrollmentStatus& status) { | 241 const policy::EnrollmentStatus& status) { |
| 217 actor_->ShowEnrollmentStatus(status); | 242 actor_->ShowEnrollmentStatus(status); |
| 218 StartupUtils::MarkOobeCompleted(); | 243 StartupUtils::MarkOobeCompleted(); |
| 219 } | 244 } |
| 220 | 245 |
| 221 void EnrollmentScreen::ReportEnrollmentStatus(policy::EnrollmentStatus status) { | 246 void EnrollmentScreen::ReportEnrollmentStatus(policy::EnrollmentStatus status) { |
| 222 if (status.status() == policy::EnrollmentStatus::STATUS_SUCCESS) { | 247 if (status.status() == policy::EnrollmentStatus::STATUS_SUCCESS) { |
| 223 StartupUtils::MarkDeviceRegistered( | 248 StartupUtils::MarkDeviceRegistered( |
| 224 base::Bind(&EnrollmentScreen::ShowEnrollmentStatusOnSuccess, | 249 base::Bind(&EnrollmentScreen::ShowEnrollmentStatusOnSuccess, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 sample = policy::kMetricEnrollmentAutoFailed; | 352 sample = policy::kMetricEnrollmentAutoFailed; |
| 328 UMA(sample); | 353 UMA(sample); |
| 329 } | 354 } |
| 330 | 355 |
| 331 void EnrollmentScreen::ShowSigninScreen() { | 356 void EnrollmentScreen::ShowSigninScreen() { |
| 332 actor_->Show(); | 357 actor_->Show(); |
| 333 actor_->ShowSigninScreen(); | 358 actor_->ShowSigninScreen(); |
| 334 } | 359 } |
| 335 | 360 |
| 336 } // namespace chromeos | 361 } // namespace chromeos |
| OLD | NEW |