| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/enterprise_enrollment_screen.h" | 5 #include "chrome/browser/chromeos/login/enterprise_enrollment_screen.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" |
| 8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 11 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 11 #include "chrome/browser/chromeos/login/screen_observer.h" | 12 #include "chrome/browser/chromeos/login/screen_observer.h" |
| 12 #include "chrome/browser/policy/browser_policy_connector.h" | 13 #include "chrome/browser/policy/browser_policy_connector.h" |
| 14 #include "chrome/browser/policy/enterprise_metrics.h" |
| 13 #include "chrome/common/net/gaia/gaia_constants.h" | 15 #include "chrome/common/net/gaia/gaia_constants.h" |
| 14 | 16 |
| 15 namespace chromeos { | 17 namespace chromeos { |
| 16 | 18 |
| 17 // Retry for InstallAttrs initialization every 500ms. | 19 // Retry for InstallAttrs initialization every 500ms. |
| 18 const int kLockRetryIntervalMs = 500; | 20 const int kLockRetryIntervalMs = 500; |
| 19 | 21 |
| 20 EnterpriseEnrollmentScreen::EnterpriseEnrollmentScreen( | 22 EnterpriseEnrollmentScreen::EnterpriseEnrollmentScreen( |
| 21 ViewScreenDelegate* delegate) | 23 ViewScreenDelegate* delegate) |
| 22 : ViewScreen<EnterpriseEnrollmentView>(delegate), | 24 : ViewScreen<EnterpriseEnrollmentView>(delegate), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 33 } | 35 } |
| 34 } | 36 } |
| 35 } | 37 } |
| 36 | 38 |
| 37 EnterpriseEnrollmentScreen::~EnterpriseEnrollmentScreen() {} | 39 EnterpriseEnrollmentScreen::~EnterpriseEnrollmentScreen() {} |
| 38 | 40 |
| 39 void EnterpriseEnrollmentScreen::Authenticate(const std::string& user, | 41 void EnterpriseEnrollmentScreen::Authenticate(const std::string& user, |
| 40 const std::string& password, | 42 const std::string& password, |
| 41 const std::string& captcha, | 43 const std::string& captcha, |
| 42 const std::string& access_code) { | 44 const std::string& access_code) { |
| 45 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 46 policy::kMetricEnrollmentStarted, |
| 47 policy::kMetricEnrollmentSize); |
| 43 captcha_token_.clear(); | 48 captcha_token_.clear(); |
| 44 user_ = user; | 49 user_ = user; |
| 45 auth_fetcher_.reset( | 50 auth_fetcher_.reset( |
| 46 new GaiaAuthFetcher(this, GaiaConstants::kChromeSource, | 51 new GaiaAuthFetcher(this, GaiaConstants::kChromeSource, |
| 47 g_browser_process->system_request_context())); | 52 g_browser_process->system_request_context())); |
| 48 | 53 |
| 49 if (access_code.empty()) { | 54 if (access_code.empty()) { |
| 50 auth_fetcher_->StartClientLogin(user, password, | 55 auth_fetcher_->StartClientLogin(user, password, |
| 51 GaiaConstants::kDeviceManagementService, | 56 GaiaConstants::kDeviceManagementService, |
| 52 captcha_token_, captcha, | 57 captcha_token_, captcha, |
| 53 GaiaAuthFetcher::HostedAccountsAllowed); | 58 GaiaAuthFetcher::HostedAccountsAllowed); |
| 54 } else { | 59 } else { |
| 55 auth_fetcher_->StartClientLogin(user, access_code, | 60 auth_fetcher_->StartClientLogin(user, access_code, |
| 56 GaiaConstants::kDeviceManagementService, | 61 GaiaConstants::kDeviceManagementService, |
| 57 std::string(), std::string(), | 62 std::string(), std::string(), |
| 58 GaiaAuthFetcher::HostedAccountsAllowed); | 63 GaiaAuthFetcher::HostedAccountsAllowed); |
| 59 } | 64 } |
| 60 } | 65 } |
| 61 | 66 |
| 62 void EnterpriseEnrollmentScreen::CancelEnrollment() { | 67 void EnterpriseEnrollmentScreen::CancelEnrollment() { |
| 68 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 69 policy::kMetricEnrollmentCancelled, |
| 70 policy::kMetricEnrollmentSize); |
| 63 auth_fetcher_.reset(); | 71 auth_fetcher_.reset(); |
| 64 registrar_.reset(); | 72 registrar_.reset(); |
| 65 g_browser_process->browser_policy_connector()->DeviceStopAutoRetry(); | 73 g_browser_process->browser_policy_connector()->DeviceStopAutoRetry(); |
| 66 ScreenObserver* observer = delegate()->GetObserver(); | 74 ScreenObserver* observer = delegate()->GetObserver(); |
| 67 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_CANCELLED); | 75 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_CANCELLED); |
| 68 } | 76 } |
| 69 | 77 |
| 70 void EnterpriseEnrollmentScreen::CloseConfirmation() { | 78 void EnterpriseEnrollmentScreen::CloseConfirmation() { |
| 71 auth_fetcher_.reset(); | 79 auth_fetcher_.reset(); |
| 72 ScreenObserver* observer = delegate()->GetObserver(); | 80 ScreenObserver* observer = delegate()->GetObserver(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 114 |
| 107 void EnterpriseEnrollmentScreen::OnClientLoginFailure( | 115 void EnterpriseEnrollmentScreen::OnClientLoginFailure( |
| 108 const GoogleServiceAuthError& error) { | 116 const GoogleServiceAuthError& error) { |
| 109 HandleAuthError(error); | 117 HandleAuthError(error); |
| 110 } | 118 } |
| 111 | 119 |
| 112 void EnterpriseEnrollmentScreen::OnIssueAuthTokenSuccess( | 120 void EnterpriseEnrollmentScreen::OnIssueAuthTokenSuccess( |
| 113 const std::string& service, | 121 const std::string& service, |
| 114 const std::string& auth_token) { | 122 const std::string& auth_token) { |
| 115 if (service != GaiaConstants::kDeviceManagementService) { | 123 if (service != GaiaConstants::kDeviceManagementService) { |
| 124 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 125 policy::kMetricEnrollmentOtherFailed, |
| 126 policy::kMetricEnrollmentSize); |
| 116 NOTREACHED() << service; | 127 NOTREACHED() << service; |
| 117 return; | 128 return; |
| 118 } | 129 } |
| 119 | 130 |
| 120 scoped_ptr<GaiaAuthFetcher> auth_fetcher(auth_fetcher_.release()); | 131 scoped_ptr<GaiaAuthFetcher> auth_fetcher(auth_fetcher_.release()); |
| 121 | 132 |
| 122 policy::BrowserPolicyConnector* connector = | 133 policy::BrowserPolicyConnector* connector = |
| 123 g_browser_process->browser_policy_connector(); | 134 g_browser_process->browser_policy_connector(); |
| 124 if (!connector->device_cloud_policy_subsystem()) { | 135 if (!connector->device_cloud_policy_subsystem()) { |
| 125 NOTREACHED() << "Cloud policy subsystem not initialized."; | 136 NOTREACHED() << "Cloud policy subsystem not initialized."; |
| 137 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 138 policy::kMetricEnrollmentOtherFailed, |
| 139 policy::kMetricEnrollmentSize); |
| 126 if (view()) | 140 if (view()) |
| 127 view()->ShowFatalEnrollmentError(); | 141 view()->ShowFatalEnrollmentError(); |
| 128 return; | 142 return; |
| 129 } | 143 } |
| 130 | 144 |
| 131 connector->ScheduleServiceInitialization(0); | 145 connector->ScheduleServiceInitialization(0); |
| 132 registrar_.reset(new policy::CloudPolicySubsystem::ObserverRegistrar( | 146 registrar_.reset(new policy::CloudPolicySubsystem::ObserverRegistrar( |
| 133 connector->device_cloud_policy_subsystem(), this)); | 147 connector->device_cloud_policy_subsystem(), this)); |
| 134 | 148 |
| 135 // Push the credentials to the policy infrastructure. It'll start enrollment | 149 // Push the credentials to the policy infrastructure. It'll start enrollment |
| 136 // and notify us of progress through CloudPolicySubsystem::Observer. | 150 // and notify us of progress through CloudPolicySubsystem::Observer. |
| 137 connector->SetDeviceCredentials(user_, auth_token); | 151 connector->SetDeviceCredentials(user_, auth_token); |
| 138 } | 152 } |
| 139 | 153 |
| 140 void EnterpriseEnrollmentScreen::OnIssueAuthTokenFailure( | 154 void EnterpriseEnrollmentScreen::OnIssueAuthTokenFailure( |
| 141 const std::string& service, | 155 const std::string& service, |
| 142 const GoogleServiceAuthError& error) { | 156 const GoogleServiceAuthError& error) { |
| 143 if (service != GaiaConstants::kDeviceManagementService) { | 157 if (service != GaiaConstants::kDeviceManagementService) { |
| 144 NOTREACHED() << service; | 158 NOTREACHED() << service; |
| 159 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 160 policy::kMetricEnrollmentOtherFailed, |
| 161 policy::kMetricEnrollmentSize); |
| 145 return; | 162 return; |
| 146 } | 163 } |
| 147 | 164 |
| 148 HandleAuthError(error); | 165 HandleAuthError(error); |
| 149 } | 166 } |
| 150 | 167 |
| 151 void EnterpriseEnrollmentScreen::OnPolicyStateChanged( | 168 void EnterpriseEnrollmentScreen::OnPolicyStateChanged( |
| 152 policy::CloudPolicySubsystem::PolicySubsystemState state, | 169 policy::CloudPolicySubsystem::PolicySubsystemState state, |
| 153 policy::CloudPolicySubsystem::ErrorDetails error_details) { | 170 policy::CloudPolicySubsystem::ErrorDetails error_details) { |
| 154 | 171 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 166 break; | 183 break; |
| 167 case policy::CloudPolicySubsystem::NETWORK_ERROR: | 184 case policy::CloudPolicySubsystem::NETWORK_ERROR: |
| 168 view()->ShowNetworkEnrollmentError(); | 185 view()->ShowNetworkEnrollmentError(); |
| 169 break; | 186 break; |
| 170 case policy::CloudPolicySubsystem::TOKEN_FETCHED: | 187 case policy::CloudPolicySubsystem::TOKEN_FETCHED: |
| 171 WriteInstallAttributesData(); | 188 WriteInstallAttributesData(); |
| 172 return; | 189 return; |
| 173 case policy::CloudPolicySubsystem::SUCCESS: | 190 case policy::CloudPolicySubsystem::SUCCESS: |
| 174 // Success! | 191 // Success! |
| 175 registrar_.reset(); | 192 registrar_.reset(); |
| 193 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 194 policy::kMetricEnrollmentOK, |
| 195 policy::kMetricEnrollmentSize); |
| 176 view()->ShowConfirmationScreen(); | 196 view()->ShowConfirmationScreen(); |
| 177 return; | 197 return; |
| 178 } | 198 } |
| 179 | 199 |
| 180 // We have an error. | 200 // We have an error. |
| 201 if (state == policy::CloudPolicySubsystem::UNMANAGED) { |
| 202 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 203 policy::kMetricEnrollmentNotSupported, |
| 204 policy::kMetricEnrollmentSize); |
| 205 } else { |
| 206 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 207 policy::kMetricEnrollmentPolicyFailed, |
| 208 policy::kMetricEnrollmentSize); |
| 209 } |
| 181 LOG(WARNING) << "Policy subsystem error during enrollment: " << state | 210 LOG(WARNING) << "Policy subsystem error during enrollment: " << state |
| 182 << " details: " << error_details; | 211 << " details: " << error_details; |
| 183 } | 212 } |
| 184 | 213 |
| 185 // Stop the policy infrastructure. | 214 // Stop the policy infrastructure. |
| 186 registrar_.reset(); | 215 registrar_.reset(); |
| 187 g_browser_process->browser_policy_connector()->DeviceStopAutoRetry(); | 216 g_browser_process->browser_policy_connector()->DeviceStopAutoRetry(); |
| 188 } | 217 } |
| 189 | 218 |
| 190 EnterpriseEnrollmentView* EnterpriseEnrollmentScreen::AllocateView() { | 219 EnterpriseEnrollmentView* EnterpriseEnrollmentScreen::AllocateView() { |
| 191 return new EnterpriseEnrollmentView(this); | 220 return new EnterpriseEnrollmentView(this); |
| 192 } | 221 } |
| 193 | 222 |
| 194 void EnterpriseEnrollmentScreen::HandleAuthError( | 223 void EnterpriseEnrollmentScreen::HandleAuthError( |
| 195 const GoogleServiceAuthError& error) { | 224 const GoogleServiceAuthError& error) { |
| 196 scoped_ptr<GaiaAuthFetcher> scoped_killer(auth_fetcher_.release()); | 225 scoped_ptr<GaiaAuthFetcher> scoped_killer(auth_fetcher_.release()); |
| 197 | 226 |
| 198 if (!view()) | 227 if (!view()) |
| 199 return; | 228 return; |
| 200 | 229 |
| 201 switch (error.state()) { | 230 switch (error.state()) { |
| 231 case GoogleServiceAuthError::CONNECTION_FAILED: |
| 232 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 233 policy::kMetricEnrollmentNetworkFailed, |
| 234 policy::kMetricEnrollmentSize); |
| 235 view()->ShowNetworkEnrollmentError(); |
| 236 return; |
| 202 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: | 237 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: |
| 203 case GoogleServiceAuthError::CONNECTION_FAILED: | |
| 204 case GoogleServiceAuthError::CAPTCHA_REQUIRED: | 238 case GoogleServiceAuthError::CAPTCHA_REQUIRED: |
| 205 case GoogleServiceAuthError::TWO_FACTOR: | 239 case GoogleServiceAuthError::TWO_FACTOR: |
| 240 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: |
| 241 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 242 policy::kMetricEnrollmentLoginFailed, |
| 243 policy::kMetricEnrollmentSize); |
| 206 view()->ShowAuthError(error); | 244 view()->ShowAuthError(error); |
| 207 return; | 245 return; |
| 208 case GoogleServiceAuthError::USER_NOT_SIGNED_UP: | 246 case GoogleServiceAuthError::USER_NOT_SIGNED_UP: |
| 209 case GoogleServiceAuthError::ACCOUNT_DELETED: | 247 case GoogleServiceAuthError::ACCOUNT_DELETED: |
| 210 case GoogleServiceAuthError::ACCOUNT_DISABLED: | 248 case GoogleServiceAuthError::ACCOUNT_DISABLED: |
| 211 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: | 249 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 250 policy::kMetricEnrollmentNotSupported, |
| 251 policy::kMetricEnrollmentSize); |
| 212 view()->ShowAccountError(); | 252 view()->ShowAccountError(); |
| 213 return; | 253 return; |
| 214 case GoogleServiceAuthError::NONE: | 254 case GoogleServiceAuthError::NONE: |
| 215 case GoogleServiceAuthError::HOSTED_NOT_ALLOWED: | 255 case GoogleServiceAuthError::HOSTED_NOT_ALLOWED: |
| 216 NOTREACHED() << error.state(); | 256 NOTREACHED() << error.state(); |
| 217 // fall through. | 257 // fall through. |
| 218 case GoogleServiceAuthError::REQUEST_CANCELED: | 258 case GoogleServiceAuthError::REQUEST_CANCELED: |
| 219 LOG(ERROR) << "Unexpected GAIA auth error: " << error.state(); | 259 LOG(ERROR) << "Unexpected GAIA auth error: " << error.state(); |
| 260 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 261 policy::kMetricEnrollmentNetworkFailed, |
| 262 policy::kMetricEnrollmentSize); |
| 220 view()->ShowFatalAuthError(); | 263 view()->ShowFatalAuthError(); |
| 221 return; | 264 return; |
| 222 } | 265 } |
| 223 | 266 |
| 224 NOTREACHED() << error.state(); | 267 NOTREACHED() << error.state(); |
| 268 UMA_HISTOGRAM_ENUMERATION(policy::kMetricEnrollment, |
| 269 policy::kMetricEnrollmentOtherFailed, |
| 270 policy::kMetricEnrollmentSize); |
| 225 } | 271 } |
| 226 | 272 |
| 227 void EnterpriseEnrollmentScreen::WriteInstallAttributesData() { | 273 void EnterpriseEnrollmentScreen::WriteInstallAttributesData() { |
| 228 // Since this method is also called directly. | 274 // Since this method is also called directly. |
| 229 runnable_method_factory_.RevokeAll(); | 275 runnable_method_factory_.RevokeAll(); |
| 230 | 276 |
| 231 if (!view()) | 277 if (!view()) |
| 232 return; | 278 return; |
| 233 | 279 |
| 234 switch (g_browser_process->browser_policy_connector()->LockDevice(user_)) { | 280 switch (g_browser_process->browser_policy_connector()->LockDevice(user_)) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 312 } |
| 267 | 313 |
| 268 void EnterpriseEnrollmentScreen::Show() { | 314 void EnterpriseEnrollmentScreen::Show() { |
| 269 ViewScreen<EnterpriseEnrollmentView>::Show(); | 315 ViewScreen<EnterpriseEnrollmentView>::Show(); |
| 270 // Make the focus go initially to the DOMView, so that the email input field | 316 // Make the focus go initially to the DOMView, so that the email input field |
| 271 // receives the focus. | 317 // receives the focus. |
| 272 view()->RequestFocus(); | 318 view()->RequestFocus(); |
| 273 } | 319 } |
| 274 | 320 |
| 275 } // namespace chromeos | 321 } // namespace chromeos |
| OLD | NEW |