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