Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/browser/chromeos/login/enterprise_enrollment_screen.cc

Issue 6821045: Connect enrollment screen to cloud policy subsystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix duplicate include Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/chromeos/cros/cros_library.h"
11 #include "chrome/browser/chromeos/cros/system_library.h"
9 #include "chrome/browser/chromeos/login/screen_observer.h" 12 #include "chrome/browser/chromeos/login/screen_observer.h"
13 #include "chrome/browser/policy/browser_policy_connector.h"
10 #include "chrome/common/net/gaia/gaia_constants.h" 14 #include "chrome/common/net/gaia/gaia_constants.h"
11 15
16 // MachineInfo key names.
17 const char kMachineInfoSystemHwqual[] = "hardware_class";
18 const char kMachineInfoSerialNumber[] = "serial_number";
19
12 namespace chromeos { 20 namespace chromeos {
13 21
14 EnterpriseEnrollmentScreen::EnterpriseEnrollmentScreen( 22 EnterpriseEnrollmentScreen::EnterpriseEnrollmentScreen(
15 WizardScreenDelegate* delegate) 23 WizardScreenDelegate* delegate)
16 : ViewScreen<EnterpriseEnrollmentView>(delegate) {} 24 : ViewScreen<EnterpriseEnrollmentView>(delegate) {}
17 25
18 EnterpriseEnrollmentScreen::~EnterpriseEnrollmentScreen() {} 26 EnterpriseEnrollmentScreen::~EnterpriseEnrollmentScreen() {}
19 27
20 void EnterpriseEnrollmentScreen::Authenticate(const std::string& user, 28 void EnterpriseEnrollmentScreen::Authenticate(const std::string& user,
21 const std::string& password, 29 const std::string& password,
22 const std::string& captcha, 30 const std::string& captcha,
23 const std::string& access_code) { 31 const std::string& access_code) {
24 captcha_token_.clear(); 32 captcha_token_.clear();
33 user_ = user;
25 auth_fetcher_.reset( 34 auth_fetcher_.reset(
26 new GaiaAuthFetcher(this, GaiaConstants::kChromeSource, 35 new GaiaAuthFetcher(this, GaiaConstants::kChromeSource,
27 g_browser_process->system_request_context())); 36 g_browser_process->system_request_context()));
28 37
29 if (access_code.empty()) { 38 if (access_code.empty()) {
30 auth_fetcher_->StartClientLogin(user, password, 39 auth_fetcher_->StartClientLogin(user, password,
31 GaiaConstants::kDeviceManagementService, 40 GaiaConstants::kDeviceManagementService,
32 captcha_token_, captcha, 41 captcha_token_, captcha,
33 GaiaAuthFetcher::HostedAccountsAllowed); 42 GaiaAuthFetcher::HostedAccountsAllowed);
34 } else { 43 } else {
35 auth_fetcher_->StartClientLogin(user, access_code, 44 auth_fetcher_->StartClientLogin(user, access_code,
36 GaiaConstants::kDeviceManagementService, 45 GaiaConstants::kDeviceManagementService,
37 std::string(), std::string(), 46 std::string(), std::string(),
38 GaiaAuthFetcher::HostedAccountsAllowed); 47 GaiaAuthFetcher::HostedAccountsAllowed);
39 } 48 }
40 } 49 }
41 50
42 void EnterpriseEnrollmentScreen::CancelEnrollment() { 51 void EnterpriseEnrollmentScreen::CancelEnrollment() {
43 auth_fetcher_.reset(); 52 auth_fetcher_.reset();
44 ScreenObserver* observer = delegate()->GetObserver(this); 53 ScreenObserver* observer = delegate()->GetObserver(this);
45 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_CANCELLED); 54 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_CANCELLED);
Nikita (slow) 2011/04/12 12:49:30 We don't need to call g_browser_process->browser_p
Mattias Nissler (ping if slow) 2011/04/12 14:07:15 You have a point. We should definitely make the St
46 } 55 }
47 56
48 void EnterpriseEnrollmentScreen::CloseConfirmation() { 57 void EnterpriseEnrollmentScreen::CloseConfirmation() {
49 auth_fetcher_.reset(); 58 auth_fetcher_.reset();
50 ScreenObserver* observer = delegate()->GetObserver(this); 59 ScreenObserver* observer = delegate()->GetObserver(this);
51 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED); 60 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED);
52 } 61 }
53 62
54 EnterpriseEnrollmentView* EnterpriseEnrollmentScreen::AllocateView() {
55 return new EnterpriseEnrollmentView(this);
56 }
57
58 void EnterpriseEnrollmentScreen::OnClientLoginSuccess( 63 void EnterpriseEnrollmentScreen::OnClientLoginSuccess(
59 const ClientLoginResult& result) { 64 const ClientLoginResult& result) {
60 auth_fetcher_->StartIssueAuthToken(result.sid, result.lsid, 65 auth_fetcher_->StartIssueAuthToken(result.sid, result.lsid,
61 GaiaConstants::kDeviceManagementService); 66 GaiaConstants::kDeviceManagementService);
62 } 67 }
63 68
64 void EnterpriseEnrollmentScreen::OnClientLoginFailure( 69 void EnterpriseEnrollmentScreen::OnClientLoginFailure(
65 const GoogleServiceAuthError& error) { 70 const GoogleServiceAuthError& error) {
66 HandleAuthError(error); 71 HandleAuthError(error);
67 } 72 }
68 73
69 void EnterpriseEnrollmentScreen::OnIssueAuthTokenSuccess( 74 void EnterpriseEnrollmentScreen::OnIssueAuthTokenSuccess(
70 const std::string& service, 75 const std::string& service,
71 const std::string& auth_token) { 76 const std::string& auth_token) {
72 if (service != GaiaConstants::kDeviceManagementService) { 77 if (service != GaiaConstants::kDeviceManagementService) {
73 NOTREACHED() << service; 78 NOTREACHED() << service;
74 return; 79 return;
75 } 80 }
76 81
77 auth_fetcher_.reset(); 82 scoped_ptr<GaiaAuthFetcher> auth_fetcher(auth_fetcher_.release());
78 83
79 // TODO(mnissler): Trigger actual enrollment here! 84 policy::BrowserPolicyConnector* connector =
85 g_browser_process->browser_policy_connector();
86 if (!connector->cloud_policy_subsystem()) {
87 NOTREACHED() << "Cloud policy subsystem not initialized.";
88 if (view())
89 view()->ShowFatalEnrollmentError();
90 return;
91 }
80 92
81 if (view()) 93 registrar_.reset(new policy::CloudPolicySubsystem::ObserverRegistrar(
82 view()->ShowConfirmationScreen(); 94 connector->cloud_policy_subsystem(), this));
95
96 // Push the credentials to the policy infrastructure. It'll start enrollment
97 // and notify us of progress through CloudPolicySubsystem::Observer.
98 connector->SetCredentials(user_, auth_token, GetMachineId());
Nikita (slow) 2011/04/12 12:46:22 Is this process somehow shown to user, like spinne
Mattias Nissler (ping if slow) 2011/04/12 14:07:15 It's just the login spinner on the GAIA login box,
83 } 99 }
84 100
85 void EnterpriseEnrollmentScreen::OnIssueAuthTokenFailure( 101 void EnterpriseEnrollmentScreen::OnIssueAuthTokenFailure(
86 const std::string& service, 102 const std::string& service,
87 const GoogleServiceAuthError& error) { 103 const GoogleServiceAuthError& error) {
88 if (service != GaiaConstants::kDeviceManagementService) { 104 if (service != GaiaConstants::kDeviceManagementService) {
89 NOTREACHED() << service; 105 NOTREACHED() << service;
90 return; 106 return;
91 } 107 }
92 108
93 HandleAuthError(error); 109 HandleAuthError(error);
94 } 110 }
95 111
112 void EnterpriseEnrollmentScreen::OnPolicyStateChanged(
113 policy::CloudPolicySubsystem::PolicySubsystemState state,
114 policy::CloudPolicySubsystem::ErrorDetails error_details) {
115
116 if (view()) {
117 switch (state) {
118 case policy::CloudPolicySubsystem::UNENROLLED:
119 // Still working...
120 return;
121 case policy::CloudPolicySubsystem::BAD_GAIA_TOKEN:
122 case policy::CloudPolicySubsystem::LOCAL_ERROR:
123 view()->ShowFatalEnrollmentError();
124 break;
125 case policy::CloudPolicySubsystem::UNMANAGED:
126 view()->ShowAccountError();
127 break;
128 case policy::CloudPolicySubsystem::NETWORK_ERROR:
129 view()->ShowNetworkEnrollmentError();
130 break;
131 case policy::CloudPolicySubsystem::SUCCESS:
132 // Success!
133 registrar_.reset();
134 view()->ShowConfirmationScreen();
135 return;
136 }
137
138 // We have an error.
139 LOG(WARNING) << "Policy subsystem error during enrollment: " << state
140 << " details: " << error_details;
141 }
142
143 // Stop the policy infrastructure.
144 registrar_.reset();
145 g_browser_process->browser_policy_connector()->StopAutoRetry();
146 }
147
148 EnterpriseEnrollmentView* EnterpriseEnrollmentScreen::AllocateView() {
149 return new EnterpriseEnrollmentView(this);
150 }
151
96 void EnterpriseEnrollmentScreen::HandleAuthError( 152 void EnterpriseEnrollmentScreen::HandleAuthError(
97 const GoogleServiceAuthError& error) { 153 const GoogleServiceAuthError& error) {
98 scoped_ptr<GaiaAuthFetcher> scoped_killer(auth_fetcher_.release()); 154 scoped_ptr<GaiaAuthFetcher> scoped_killer(auth_fetcher_.release());
99 155
100 if (!view()) 156 if (!view())
101 return; 157 return;
102 158
103 switch (error.state()) { 159 switch (error.state()) {
104 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: 160 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS:
105 case GoogleServiceAuthError::CONNECTION_FAILED: 161 case GoogleServiceAuthError::CONNECTION_FAILED:
(...skipping 13 matching lines...) Expand all
119 // fall through. 175 // fall through.
120 case GoogleServiceAuthError::REQUEST_CANCELED: 176 case GoogleServiceAuthError::REQUEST_CANCELED:
121 LOG(ERROR) << "Unexpected GAIA auth error: " << error.state(); 177 LOG(ERROR) << "Unexpected GAIA auth error: " << error.state();
122 view()->ShowFatalAuthError(); 178 view()->ShowFatalAuthError();
123 return; 179 return;
124 } 180 }
125 181
126 NOTREACHED() << error.state(); 182 NOTREACHED() << error.state();
127 } 183 }
128 184
185 std::string EnterpriseEnrollmentScreen::GetMachineId() {
186 chromeos::SystemLibrary* sys_lib =
187 chromeos::CrosLibrary::Get()->GetSystemLibrary();
188
189 std::string system_hwqual;
190 std::string serial_number;
191 if (!sys_lib->GetMachineStatistic(kMachineInfoSystemHwqual, &system_hwqual) ||
Nikita (slow) 2011/04/12 12:46:22 Just FYI, this information is only accessible duri
Mattias Nissler (ping if slow) 2011/04/12 14:07:15 That's fine, since we can only enroll if the devic
192 !sys_lib->GetMachineStatistic(kMachineInfoSerialNumber, &serial_number)) {
193 LOG(ERROR) << "Failed to get machine information";
194 return "";
195 }
196
197 return system_hwqual + " " + serial_number;
198 }
199
129 } // namespace chromeos 200 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698