Index: chrome/browser/chromeos/login/enterprise_enrollment_screen.cc |
diff --git a/chrome/browser/chromeos/login/enterprise_enrollment_screen.cc b/chrome/browser/chromeos/login/enterprise_enrollment_screen.cc |
index 6d66eecaaacecd8af7818a571cc3d88bd8577108..f88fcd624552b7c128eb6f01cd217fc735bcda2a 100644 |
--- a/chrome/browser/chromeos/login/enterprise_enrollment_screen.cc |
+++ b/chrome/browser/chromeos/login/enterprise_enrollment_screen.cc |
@@ -4,11 +4,20 @@ |
#include "chrome/browser/chromeos/login/enterprise_enrollment_screen.h" |
+#include "base/compiler_specific.h" |
#include "base/logging.h" |
#include "chrome/browser/browser_process.h" |
+#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.
|
+#include "chrome/browser/chromeos/cros/cros_library.h" |
+#include "chrome/browser/chromeos/cros/system_library.h" |
#include "chrome/browser/chromeos/login/screen_observer.h" |
+#include "chrome/browser/policy/browser_policy_connector.h" |
#include "chrome/common/net/gaia/gaia_constants.h" |
+// MachineInfo key names. |
+const char kMachineInfoSystemHwqual[] = "hardware_class"; |
+const char kMachineInfoSerialNumber[] = "serial_number"; |
+ |
namespace chromeos { |
EnterpriseEnrollmentScreen::EnterpriseEnrollmentScreen( |
@@ -22,6 +31,7 @@ void EnterpriseEnrollmentScreen::Authenticate(const std::string& user, |
const std::string& captcha, |
const std::string& access_code) { |
captcha_token_.clear(); |
+ user_ = user; |
auth_fetcher_.reset( |
new GaiaAuthFetcher(this, GaiaConstants::kChromeSource, |
g_browser_process->system_request_context())); |
@@ -51,10 +61,6 @@ void EnterpriseEnrollmentScreen::CloseConfirmation() { |
observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED); |
} |
-EnterpriseEnrollmentView* EnterpriseEnrollmentScreen::AllocateView() { |
- return new EnterpriseEnrollmentView(this); |
-} |
- |
void EnterpriseEnrollmentScreen::OnClientLoginSuccess( |
const ClientLoginResult& result) { |
auth_fetcher_->StartIssueAuthToken(result.sid, result.lsid, |
@@ -74,12 +80,23 @@ void EnterpriseEnrollmentScreen::OnIssueAuthTokenSuccess( |
return; |
} |
- auth_fetcher_.reset(); |
+ scoped_ptr<GaiaAuthFetcher> auth_fetcher(auth_fetcher_.release()); |
+ |
+ policy::BrowserPolicyConnector* connector = |
+ g_browser_process->browser_policy_connector(); |
+ if (!connector->cloud_policy_subsystem()) { |
+ NOTREACHED() << "Cloud policy subsystem not initialized."; |
+ if (view()) |
+ view()->ShowFatalEnrollmentError(); |
+ return; |
+ } |
- // TODO(mnissler): Trigger actual enrollment here! |
+ registrar_.reset(new policy::CloudPolicySubsystem::ObserverRegistrar( |
+ connector->cloud_policy_subsystem(), this)); |
- if (view()) |
- view()->ShowConfirmationScreen(); |
+ // Push the credentials to the policy infrastructure. It'll start enrollment |
+ // and notify us of progress through CloudPolicySubsystem::Observer. |
+ connector->SetCredentials(user_, auth_token, GetMachineId()); |
} |
void EnterpriseEnrollmentScreen::OnIssueAuthTokenFailure( |
@@ -93,6 +110,46 @@ void EnterpriseEnrollmentScreen::OnIssueAuthTokenFailure( |
HandleAuthError(error); |
} |
+void EnterpriseEnrollmentScreen::OnPolicyStateChanged( |
+ policy::CloudPolicySubsystem::PolicySubsystemState state, |
+ policy::CloudPolicySubsystem::ErrorDetails error_details) { |
+ |
+ if (view()) { |
+ switch (state) { |
+ case policy::CloudPolicySubsystem::UNENROLLED: |
+ // Still working... |
+ return; |
+ case policy::CloudPolicySubsystem::BAD_GAIA_TOKEN: |
+ case policy::CloudPolicySubsystem::LOCAL_ERROR: |
+ view()->ShowFatalEnrollmentError(); |
+ break; |
+ case policy::CloudPolicySubsystem::UNMANAGED: |
+ view()->ShowAccountError(); |
+ break; |
+ case policy::CloudPolicySubsystem::NETWORK_ERROR: |
+ view()->ShowNetworkEnrollmentError(); |
+ break; |
+ case policy::CloudPolicySubsystem::SUCCESS: |
+ // Success! |
+ registrar_.reset(); |
+ view()->ShowConfirmationScreen(); |
+ return; |
+ } |
+ |
+ // We have an error. |
+ LOG(WARNING) << "Policy subsystem error during enrollment: " << state |
+ << " details: " << error_details; |
+ } |
+ |
+ // Stop the policy infrastructure. |
+ registrar_.reset(); |
+ g_browser_process->browser_policy_connector()->StopAutoRetry(); |
+} |
+ |
+EnterpriseEnrollmentView* EnterpriseEnrollmentScreen::AllocateView() { |
+ return new EnterpriseEnrollmentView(this); |
+} |
+ |
void EnterpriseEnrollmentScreen::HandleAuthError( |
const GoogleServiceAuthError& error) { |
scoped_ptr<GaiaAuthFetcher> scoped_killer(auth_fetcher_.release()); |
@@ -126,4 +183,19 @@ void EnterpriseEnrollmentScreen::HandleAuthError( |
NOTREACHED() << error.state(); |
} |
+std::string EnterpriseEnrollmentScreen::GetMachineId() { |
+ chromeos::SystemLibrary* sys_lib = |
+ chromeos::CrosLibrary::Get()->GetSystemLibrary(); |
+ |
+ std::string system_hwqual; |
+ std::string serial_number; |
+ if (!sys_lib->GetMachineStatistic(kMachineInfoSystemHwqual, &system_hwqual) || |
+ !sys_lib->GetMachineStatistic(kMachineInfoSerialNumber, &serial_number)) { |
+ LOG(ERROR) << "Failed to get machine information"; |
+ return ""; |
+ } |
+ |
+ return system_hwqual + " " + serial_number; |
+} |
+ |
} // namespace chromeos |