Chromium Code Reviews| 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/compiler_specific.h" | |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/browser_process.h" | |
|
Jakob Kummerow
2011/04/11 20:49:01
nit: duplicate include
Mattias Nissler (ping if slow)
2011/04/12 08:40:04
Done.
| |
| 11 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 12 #include "chrome/browser/chromeos/cros/system_library.h" | |
| 9 #include "chrome/browser/chromeos/login/screen_observer.h" | 13 #include "chrome/browser/chromeos/login/screen_observer.h" |
| 14 #include "chrome/browser/policy/browser_policy_connector.h" | |
| 10 #include "chrome/common/net/gaia/gaia_constants.h" | 15 #include "chrome/common/net/gaia/gaia_constants.h" |
| 11 | 16 |
| 17 // MachineInfo key names. | |
| 18 const char kMachineInfoSystemHwqual[] = "hardware_class"; | |
| 19 const char kMachineInfoSerialNumber[] = "serial_number"; | |
| 20 | |
| 12 namespace chromeos { | 21 namespace chromeos { |
| 13 | 22 |
| 14 EnterpriseEnrollmentScreen::EnterpriseEnrollmentScreen( | 23 EnterpriseEnrollmentScreen::EnterpriseEnrollmentScreen( |
| 15 WizardScreenDelegate* delegate) | 24 WizardScreenDelegate* delegate) |
| 16 : ViewScreen<EnterpriseEnrollmentView>(delegate) {} | 25 : ViewScreen<EnterpriseEnrollmentView>(delegate) {} |
| 17 | 26 |
| 18 EnterpriseEnrollmentScreen::~EnterpriseEnrollmentScreen() {} | 27 EnterpriseEnrollmentScreen::~EnterpriseEnrollmentScreen() {} |
| 19 | 28 |
| 20 void EnterpriseEnrollmentScreen::Authenticate(const std::string& user, | 29 void EnterpriseEnrollmentScreen::Authenticate(const std::string& user, |
| 21 const std::string& password, | 30 const std::string& password, |
| 22 const std::string& captcha, | 31 const std::string& captcha, |
| 23 const std::string& access_code) { | 32 const std::string& access_code) { |
| 24 captcha_token_.clear(); | 33 captcha_token_.clear(); |
| 34 user_ = user; | |
| 25 auth_fetcher_.reset( | 35 auth_fetcher_.reset( |
| 26 new GaiaAuthFetcher(this, GaiaConstants::kChromeSource, | 36 new GaiaAuthFetcher(this, GaiaConstants::kChromeSource, |
| 27 g_browser_process->system_request_context())); | 37 g_browser_process->system_request_context())); |
| 28 | 38 |
| 29 if (access_code.empty()) { | 39 if (access_code.empty()) { |
| 30 auth_fetcher_->StartClientLogin(user, password, | 40 auth_fetcher_->StartClientLogin(user, password, |
| 31 GaiaConstants::kDeviceManagementService, | 41 GaiaConstants::kDeviceManagementService, |
| 32 captcha_token_, captcha, | 42 captcha_token_, captcha, |
| 33 GaiaAuthFetcher::HostedAccountsAllowed); | 43 GaiaAuthFetcher::HostedAccountsAllowed); |
| 34 } else { | 44 } else { |
| 35 auth_fetcher_->StartClientLogin(user, access_code, | 45 auth_fetcher_->StartClientLogin(user, access_code, |
| 36 GaiaConstants::kDeviceManagementService, | 46 GaiaConstants::kDeviceManagementService, |
| 37 std::string(), std::string(), | 47 std::string(), std::string(), |
| 38 GaiaAuthFetcher::HostedAccountsAllowed); | 48 GaiaAuthFetcher::HostedAccountsAllowed); |
| 39 } | 49 } |
| 40 } | 50 } |
| 41 | 51 |
| 42 void EnterpriseEnrollmentScreen::CancelEnrollment() { | 52 void EnterpriseEnrollmentScreen::CancelEnrollment() { |
| 43 auth_fetcher_.reset(); | 53 auth_fetcher_.reset(); |
| 44 ScreenObserver* observer = delegate()->GetObserver(this); | 54 ScreenObserver* observer = delegate()->GetObserver(this); |
| 45 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_CANCELLED); | 55 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_CANCELLED); |
| 46 } | 56 } |
| 47 | 57 |
| 48 void EnterpriseEnrollmentScreen::CloseConfirmation() { | 58 void EnterpriseEnrollmentScreen::CloseConfirmation() { |
| 49 auth_fetcher_.reset(); | 59 auth_fetcher_.reset(); |
| 50 ScreenObserver* observer = delegate()->GetObserver(this); | 60 ScreenObserver* observer = delegate()->GetObserver(this); |
| 51 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED); | 61 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED); |
| 52 } | 62 } |
| 53 | 63 |
| 54 EnterpriseEnrollmentView* EnterpriseEnrollmentScreen::AllocateView() { | |
| 55 return new EnterpriseEnrollmentView(this); | |
| 56 } | |
| 57 | |
| 58 void EnterpriseEnrollmentScreen::OnClientLoginSuccess( | 64 void EnterpriseEnrollmentScreen::OnClientLoginSuccess( |
| 59 const ClientLoginResult& result) { | 65 const ClientLoginResult& result) { |
| 60 auth_fetcher_->StartIssueAuthToken(result.sid, result.lsid, | 66 auth_fetcher_->StartIssueAuthToken(result.sid, result.lsid, |
| 61 GaiaConstants::kDeviceManagementService); | 67 GaiaConstants::kDeviceManagementService); |
| 62 } | 68 } |
| 63 | 69 |
| 64 void EnterpriseEnrollmentScreen::OnClientLoginFailure( | 70 void EnterpriseEnrollmentScreen::OnClientLoginFailure( |
| 65 const GoogleServiceAuthError& error) { | 71 const GoogleServiceAuthError& error) { |
| 66 HandleAuthError(error); | 72 HandleAuthError(error); |
| 67 } | 73 } |
| 68 | 74 |
| 69 void EnterpriseEnrollmentScreen::OnIssueAuthTokenSuccess( | 75 void EnterpriseEnrollmentScreen::OnIssueAuthTokenSuccess( |
| 70 const std::string& service, | 76 const std::string& service, |
| 71 const std::string& auth_token) { | 77 const std::string& auth_token) { |
| 72 if (service != GaiaConstants::kDeviceManagementService) { | 78 if (service != GaiaConstants::kDeviceManagementService) { |
| 73 NOTREACHED() << service; | 79 NOTREACHED() << service; |
| 74 return; | 80 return; |
| 75 } | 81 } |
| 76 | 82 |
| 77 auth_fetcher_.reset(); | 83 scoped_ptr<GaiaAuthFetcher> auth_fetcher(auth_fetcher_.release()); |
| 78 | 84 |
| 79 // TODO(mnissler): Trigger actual enrollment here! | 85 policy::BrowserPolicyConnector* connector = |
| 86 g_browser_process->browser_policy_connector(); | |
| 87 if (!connector->cloud_policy_subsystem()) { | |
| 88 NOTREACHED() << "Cloud policy subsystem not initialized."; | |
| 89 if (view()) | |
| 90 view()->ShowFatalEnrollmentError(); | |
| 91 return; | |
| 92 } | |
| 80 | 93 |
| 81 if (view()) | 94 registrar_.reset(new policy::CloudPolicySubsystem::ObserverRegistrar( |
| 82 view()->ShowConfirmationScreen(); | 95 connector->cloud_policy_subsystem(), this)); |
| 96 | |
| 97 // Push the credentials to the policy infrastructure. It'll start enrollment | |
| 98 // and notify us of progress through CloudPolicySubsystem::Observer. | |
| 99 connector->SetCredentials(user_, auth_token, GetMachineId()); | |
| 83 } | 100 } |
| 84 | 101 |
| 85 void EnterpriseEnrollmentScreen::OnIssueAuthTokenFailure( | 102 void EnterpriseEnrollmentScreen::OnIssueAuthTokenFailure( |
| 86 const std::string& service, | 103 const std::string& service, |
| 87 const GoogleServiceAuthError& error) { | 104 const GoogleServiceAuthError& error) { |
| 88 if (service != GaiaConstants::kDeviceManagementService) { | 105 if (service != GaiaConstants::kDeviceManagementService) { |
| 89 NOTREACHED() << service; | 106 NOTREACHED() << service; |
| 90 return; | 107 return; |
| 91 } | 108 } |
| 92 | 109 |
| 93 HandleAuthError(error); | 110 HandleAuthError(error); |
| 94 } | 111 } |
| 95 | 112 |
| 113 void EnterpriseEnrollmentScreen::OnPolicyStateChanged( | |
| 114 policy::CloudPolicySubsystem::PolicySubsystemState state, | |
| 115 policy::CloudPolicySubsystem::ErrorDetails error_details) { | |
| 116 | |
| 117 if (view()) { | |
| 118 switch (state) { | |
| 119 case policy::CloudPolicySubsystem::UNENROLLED: | |
| 120 // Still working... | |
| 121 return; | |
| 122 case policy::CloudPolicySubsystem::BAD_GAIA_TOKEN: | |
| 123 case policy::CloudPolicySubsystem::LOCAL_ERROR: | |
| 124 view()->ShowFatalEnrollmentError(); | |
| 125 break; | |
| 126 case policy::CloudPolicySubsystem::UNMANAGED: | |
| 127 view()->ShowAccountError(); | |
| 128 break; | |
| 129 case policy::CloudPolicySubsystem::NETWORK_ERROR: | |
| 130 view()->ShowNetworkEnrollmentError(); | |
| 131 break; | |
| 132 case policy::CloudPolicySubsystem::SUCCESS: | |
| 133 // Success! | |
| 134 registrar_.reset(); | |
| 135 view()->ShowConfirmationScreen(); | |
| 136 return; | |
| 137 } | |
| 138 | |
| 139 // We have an error. | |
| 140 LOG(WARNING) << "Policy subsystem error during enrollment: " << state | |
| 141 << " details: " << error_details; | |
| 142 } | |
| 143 | |
| 144 // Stop the policy infrastructure. | |
| 145 registrar_.reset(); | |
| 146 g_browser_process->browser_policy_connector()->StopAutoRetry(); | |
| 147 } | |
| 148 | |
| 149 EnterpriseEnrollmentView* EnterpriseEnrollmentScreen::AllocateView() { | |
| 150 return new EnterpriseEnrollmentView(this); | |
| 151 } | |
| 152 | |
| 96 void EnterpriseEnrollmentScreen::HandleAuthError( | 153 void EnterpriseEnrollmentScreen::HandleAuthError( |
| 97 const GoogleServiceAuthError& error) { | 154 const GoogleServiceAuthError& error) { |
| 98 scoped_ptr<GaiaAuthFetcher> scoped_killer(auth_fetcher_.release()); | 155 scoped_ptr<GaiaAuthFetcher> scoped_killer(auth_fetcher_.release()); |
| 99 | 156 |
| 100 if (!view()) | 157 if (!view()) |
| 101 return; | 158 return; |
| 102 | 159 |
| 103 switch (error.state()) { | 160 switch (error.state()) { |
| 104 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: | 161 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: |
| 105 case GoogleServiceAuthError::CONNECTION_FAILED: | 162 case GoogleServiceAuthError::CONNECTION_FAILED: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 119 // fall through. | 176 // fall through. |
| 120 case GoogleServiceAuthError::REQUEST_CANCELED: | 177 case GoogleServiceAuthError::REQUEST_CANCELED: |
| 121 LOG(ERROR) << "Unexpected GAIA auth error: " << error.state(); | 178 LOG(ERROR) << "Unexpected GAIA auth error: " << error.state(); |
| 122 view()->ShowFatalAuthError(); | 179 view()->ShowFatalAuthError(); |
| 123 return; | 180 return; |
| 124 } | 181 } |
| 125 | 182 |
| 126 NOTREACHED() << error.state(); | 183 NOTREACHED() << error.state(); |
| 127 } | 184 } |
| 128 | 185 |
| 186 std::string EnterpriseEnrollmentScreen::GetMachineId() { | |
| 187 chromeos::SystemLibrary* sys_lib = | |
| 188 chromeos::CrosLibrary::Get()->GetSystemLibrary(); | |
| 189 | |
| 190 std::string system_hwqual; | |
| 191 std::string serial_number; | |
| 192 if (!sys_lib->GetMachineStatistic(kMachineInfoSystemHwqual, &system_hwqual) || | |
| 193 !sys_lib->GetMachineStatistic(kMachineInfoSerialNumber, &serial_number)) { | |
| 194 LOG(ERROR) << "Failed to get machine information"; | |
| 195 return ""; | |
| 196 } | |
| 197 | |
| 198 return system_hwqual + " " + serial_number; | |
| 199 } | |
| 200 | |
| 129 } // namespace chromeos | 201 } // namespace chromeos |
| OLD | NEW |