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 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 40 // have not done that yet). | 41 // have not done that yet). |
| 41 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( | 42 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( |
| 42 EmptyVoidDBusMethodCallback()); | 43 EmptyVoidDBusMethodCallback()); |
| 43 } | 44 } |
| 44 | 45 |
| 45 EnrollmentScreen::~EnrollmentScreen() {} | 46 EnrollmentScreen::~EnrollmentScreen() {} |
| 46 | 47 |
| 47 void EnrollmentScreen::SetParameters( | 48 void EnrollmentScreen::SetParameters( |
| 48 EnrollmentScreenActor::EnrollmentMode enrollment_mode, | 49 EnrollmentScreenActor::EnrollmentMode enrollment_mode, |
| 49 const std::string& management_domain, | 50 const std::string& management_domain, |
| 50 const std::string& user) { | 51 const std::string& user, |
| 52 const std::string& auth_token) { | |
| 51 enrollment_mode_ = enrollment_mode; | 53 enrollment_mode_ = enrollment_mode; |
| 52 user_ = user.empty() ? user : gaia::CanonicalizeEmail(user); | 54 user_ = user.empty() ? user : gaia::CanonicalizeEmail(user); |
| 55 auth_token_ = auth_token; | |
| 53 actor_->SetParameters(this, enrollment_mode_, management_domain); | 56 actor_->SetParameters(this, enrollment_mode_, management_domain); |
| 54 } | 57 } |
| 55 | 58 |
| 56 void EnrollmentScreen::PrepareToShow() { | 59 void EnrollmentScreen::PrepareToShow() { |
| 57 actor_->PrepareToShow(); | 60 actor_->PrepareToShow(); |
| 58 } | 61 } |
| 59 | 62 |
| 60 void EnrollmentScreen::Show() { | 63 void EnrollmentScreen::Show() { |
| 61 if (is_auto_enrollment() && !enrollment_failed_once_) { | 64 if (is_auto_enrollment() && !enrollment_failed_once_) { |
| 62 actor_->Show(); | 65 actor_->Show(); |
| 63 UMA(policy::kMetricEnrollmentAutoStarted); | 66 UMA(policy::kMetricEnrollmentAutoStarted); |
| 64 actor_->ShowEnrollmentSpinnerScreen(); | 67 actor_->ShowEnrollmentSpinnerScreen(); |
| 65 actor_->FetchOAuthToken(); | 68 actor_->FetchOAuthToken(); |
| 66 } else { | 69 } else if (auth_token_.empty()) { |
| 67 UMA(policy::kMetricEnrollmentTriggered); | 70 UMA(policy::kMetricEnrollmentTriggered); |
| 68 actor_->ResetAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, | 71 actor_->ResetAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, |
| 69 weak_ptr_factory_.GetWeakPtr())); | 72 weak_ptr_factory_.GetWeakPtr())); |
| 73 } else { | |
| 74 actor_->Show(); | |
| 75 actor_->ShowEnrollmentSpinnerScreen(); | |
| 76 OnOAuthTokenAvailable(auth_token_); | |
| 70 } | 77 } |
| 71 } | 78 } |
| 72 | 79 |
| 73 void EnrollmentScreen::Hide() { | 80 void EnrollmentScreen::Hide() { |
| 74 actor_->Hide(); | 81 actor_->Hide(); |
| 75 weak_ptr_factory_.InvalidateWeakPtrs(); | 82 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 76 } | 83 } |
| 77 | 84 |
| 78 std::string EnrollmentScreen::GetName() const { | 85 std::string EnrollmentScreen::GetName() const { |
| 79 return WizardController::kEnrollmentScreenName; | 86 return WizardController::kEnrollmentScreenName; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 return; | 129 return; |
| 123 case GoogleServiceAuthError::NUM_STATES: | 130 case GoogleServiceAuthError::NUM_STATES: |
| 124 break; | 131 break; |
| 125 } | 132 } |
| 126 | 133 |
| 127 NOTREACHED(); | 134 NOTREACHED(); |
| 128 UMAFailure(policy::kMetricEnrollmentOtherFailed); | 135 UMAFailure(policy::kMetricEnrollmentOtherFailed); |
| 129 } | 136 } |
| 130 | 137 |
| 131 void EnrollmentScreen::OnOAuthTokenAvailable(const std::string& token) { | 138 void EnrollmentScreen::OnOAuthTokenAvailable(const std::string& token) { |
| 132 RegisterForDevicePolicy(token); | 139 VLOG(1) << "OnOAuthTokenAvailable " << token; |
| 140 const bool is_shark = | |
| 141 g_browser_process->platform_part()->browser_policy_connector_chromeos()-> | |
| 142 GetDeviceCloudPolicyManager()->IsSharkRequisition(); | |
|
bartfab (slow)
2014/08/13 14:20:14
Nit: Indent four more spaces.
achuithb
2014/08/13 23:48:39
Done.
| |
| 143 | |
| 144 if (is_shark && auth_token_.empty()) { | |
| 145 // Fetch a second token for shark devices. | |
| 146 auth_token_ = token; | |
| 147 actor_->FetchOAuthToken(); | |
| 148 SendEnrollmentAuthToken(token); | |
| 149 } else { | |
| 150 RegisterForDevicePolicy(token); | |
| 151 } | |
| 133 } | 152 } |
| 134 | 153 |
| 135 void EnrollmentScreen::OnRetry() { | 154 void EnrollmentScreen::OnRetry() { |
| 136 actor_->ResetAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, | 155 actor_->ResetAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, |
| 137 weak_ptr_factory_.GetWeakPtr())); | 156 weak_ptr_factory_.GetWeakPtr())); |
| 138 } | 157 } |
| 139 | 158 |
| 140 void EnrollmentScreen::OnCancel() { | 159 void EnrollmentScreen::OnCancel() { |
| 141 if (enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_FORCED || | 160 if (enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_FORCED || |
| 142 enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_RECOVERY) { | 161 enrollment_mode_ == EnrollmentScreenActor::ENROLLMENT_MODE_RECOVERY) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 connector->GetDeviceCloudPolicyInitializer(); | 224 connector->GetDeviceCloudPolicyInitializer(); |
| 206 CHECK(dcp_initializer); | 225 CHECK(dcp_initializer); |
| 207 dcp_initializer->StartEnrollment( | 226 dcp_initializer->StartEnrollment( |
| 208 enterprise_management::PolicyData::ENTERPRISE_MANAGED, | 227 enterprise_management::PolicyData::ENTERPRISE_MANAGED, |
| 209 connector->device_management_service(), | 228 connector->device_management_service(), |
| 210 token, is_auto_enrollment(), device_modes, | 229 token, is_auto_enrollment(), device_modes, |
| 211 base::Bind(&EnrollmentScreen::ReportEnrollmentStatus, | 230 base::Bind(&EnrollmentScreen::ReportEnrollmentStatus, |
| 212 weak_ptr_factory_.GetWeakPtr())); | 231 weak_ptr_factory_.GetWeakPtr())); |
| 213 } | 232 } |
| 214 | 233 |
| 234 void EnrollmentScreen::SendEnrollmentAuthToken(const std::string& token) { | |
| 235 // TODO(achuith, zork): Send token via bluetooth to remote device. | |
| 236 } | |
| 237 | |
| 215 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess( | 238 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess( |
| 216 const policy::EnrollmentStatus& status) { | 239 const policy::EnrollmentStatus& status) { |
| 217 actor_->ShowEnrollmentStatus(status); | 240 actor_->ShowEnrollmentStatus(status); |
| 218 StartupUtils::MarkOobeCompleted(); | 241 StartupUtils::MarkOobeCompleted(); |
| 219 } | 242 } |
| 220 | 243 |
| 221 void EnrollmentScreen::ReportEnrollmentStatus(policy::EnrollmentStatus status) { | 244 void EnrollmentScreen::ReportEnrollmentStatus(policy::EnrollmentStatus status) { |
| 222 if (status.status() == policy::EnrollmentStatus::STATUS_SUCCESS) { | 245 if (status.status() == policy::EnrollmentStatus::STATUS_SUCCESS) { |
| 223 StartupUtils::MarkDeviceRegistered( | 246 StartupUtils::MarkDeviceRegistered( |
| 224 base::Bind(&EnrollmentScreen::ShowEnrollmentStatusOnSuccess, | 247 base::Bind(&EnrollmentScreen::ShowEnrollmentStatusOnSuccess, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 sample = policy::kMetricEnrollmentAutoFailed; | 344 sample = policy::kMetricEnrollmentAutoFailed; |
| 322 UMA(sample); | 345 UMA(sample); |
| 323 } | 346 } |
| 324 | 347 |
| 325 void EnrollmentScreen::ShowSigninScreen() { | 348 void EnrollmentScreen::ShowSigninScreen() { |
| 326 actor_->Show(); | 349 actor_->Show(); |
| 327 actor_->ShowSigninScreen(); | 350 actor_->ShowSigninScreen(); |
| 328 } | 351 } |
| 329 | 352 |
| 330 } // namespace chromeos | 353 } // namespace chromeos |
| OLD | NEW |