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

Side by Side Diff: chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc

Issue 12538009: Public Sessions: fetch device robot api token during enterprise enrollment. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 9 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
OLDNEW
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/policy/enrollment_handler_chromeos.h" 5 #include "chrome/browser/chromeos/policy/enrollment_handler_chromeos.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" 11 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
11 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" 12 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
12 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 13 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
13 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 14 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
14 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h" 15 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h"
16 #include "google_apis/gaia/gaia_urls.h"
15 17
16 namespace em = enterprise_management; 18 namespace em = enterprise_management;
17 19
18 namespace policy { 20 namespace policy {
19 21
20 namespace { 22 namespace {
21 23
22 // Retry for InstallAttrs initialization every 500ms. 24 // Retry for InstallAttrs initialization every 500ms.
23 const int kLockRetryIntervalMs = 500; 25 const int kLockRetryIntervalMs = 500;
24 // Maximum time to retry InstallAttrs initialization before we give up. 26 // Maximum time to retry InstallAttrs initialization before we give up.
25 const int kLockRetryTimeoutMs = 10 * 60 * 1000; // 10 minutes. 27 const int kLockRetryTimeoutMs = 10 * 60 * 1000; // 10 minutes.
28 // Number of times to retry fetching the device-level API refresh token.
29 const int kRobotRefreshTokenFetchRetryCount = 2;
26 30
27 } // namespace 31 } // namespace
28 32
29 EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS( 33 EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS(
30 DeviceCloudPolicyStoreChromeOS* store, 34 DeviceCloudPolicyStoreChromeOS* store,
31 EnterpriseInstallAttributes* install_attributes, 35 EnterpriseInstallAttributes* install_attributes,
32 scoped_ptr<CloudPolicyClient> client, 36 scoped_ptr<CloudPolicyClient> client,
33 const std::string& auth_token, 37 const std::string& auth_token,
34 const std::string& client_id, 38 const std::string& client_id,
35 bool is_auto_enrollment, 39 bool is_auto_enrollment,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 validator.release()->StartValidation( 107 validator.release()->StartValidation(
104 base::Bind(&EnrollmentHandlerChromeOS::PolicyValidated, 108 base::Bind(&EnrollmentHandlerChromeOS::PolicyValidated,
105 weak_factory_.GetWeakPtr())); 109 weak_factory_.GetWeakPtr()));
106 } 110 }
107 111
108 void EnrollmentHandlerChromeOS::OnRegistrationStateChanged( 112 void EnrollmentHandlerChromeOS::OnRegistrationStateChanged(
109 CloudPolicyClient* client) { 113 CloudPolicyClient* client) {
110 DCHECK_EQ(client_.get(), client); 114 DCHECK_EQ(client_.get(), client);
111 115
112 if (enrollment_step_ == STEP_REGISTRATION && client_->is_registered()) { 116 if (enrollment_step_ == STEP_REGISTRATION && client_->is_registered()) {
113 enrollment_step_ = STEP_POLICY_FETCH, 117 enrollment_step_ = STEP_ROBOT_AUTH_FETCH,
114 device_mode_ = client_->device_mode(); 118 device_mode_ = client_->device_mode();
115 if (device_mode_ == DEVICE_MODE_NOT_SET) 119 if (device_mode_ == DEVICE_MODE_NOT_SET)
116 device_mode_ = DEVICE_MODE_ENTERPRISE; 120 device_mode_ = DEVICE_MODE_ENTERPRISE;
117 if (!allowed_device_modes_.test(device_mode_)) { 121 if (!allowed_device_modes_.test(device_mode_)) {
118 LOG(ERROR) << "Bad device mode " << device_mode_; 122 LOG(ERROR) << "Bad device mode " << device_mode_;
119 ReportResult(EnrollmentStatus::ForStatus( 123 ReportResult(EnrollmentStatus::ForStatus(
120 EnrollmentStatus::STATUS_REGISTRATION_BAD_MODE)); 124 EnrollmentStatus::STATUS_REGISTRATION_BAD_MODE));
121 return; 125 return;
122 } 126 }
123 client_->FetchPolicy(); 127 client_->FetchRobotAuthTokens(auth_token_);
124 } else { 128 } else {
125 LOG(FATAL) << "Registration state changed to " << client_->is_registered() 129 LOG(FATAL) << "Registration state changed to " << client_->is_registered()
126 << " in step " << enrollment_step_; 130 << " in step " << enrollment_step_;
127 } 131 }
128 } 132 }
129 133
134 void EnrollmentHandlerChromeOS::OnRobotAuthCodesFetched(
135 CloudPolicyClient* client) {
136 DCHECK_EQ(client_.get(), client);
137 CHECK_EQ(STEP_ROBOT_AUTH_FETCH, enrollment_step_);
138
139 enrollment_step_ = STEP_ROBOT_AUTH_REFRESH;
140
141 gaia::OAuthClientInfo client_info;
142 client_info.client_id = GaiaUrls::GetInstance()->oauth2_chrome_client_id();
143 client_info.client_secret =
144 GaiaUrls::GetInstance()->oauth2_chrome_client_secret();
145
146 // Use the system request context to avoid sending user cookies.
147 gaia_oauth_client_.reset(new gaia::GaiaOAuthClient(
148 gaia::kGaiaOAuth2Url,
149 // TODO: use DeviceManagementRequestContextGetter? It seems to just use
150 // the system_request_context internally, an manually return the IO thread
Mattias Nissler (ping if slow) 2013/03/19 06:33:08 grammar
David Roche 2013/04/02 01:59:25 Done.
151 // message loop, but the system_request_context already does this? What
152 // does DeviceManagementRequestContextGetter change?
Mattias Nissler (ping if slow) 2013/03/19 06:33:08 It uses a different user agent, and disables all c
David Roche 2013/04/02 01:59:25 It would make sense for testability if a test depe
Mattias Nissler (ping if slow) 2013/04/02 14:16:46 OK, tell you what: You make sure the test for this
David Roche 2013/04/04 01:39:53 Ah, yes, updating tests. That is on the agenda fo
153 g_browser_process->system_request_context()));
154 gaia_oauth_client_->GetTokensFromAuthCode(client_info,
155 client->robot_api_auth_code(),
156 kRobotRefreshTokenFetchRetryCount,
Mattias Nissler (ping if slow) 2013/03/19 06:33:08 why would we have to retry at all?
David Roche 2013/04/02 01:59:25 I retry b/c other bits of enrollment seem to retry
Mattias Nissler (ping if slow) 2013/04/02 14:16:46 That's an entirely separate issue that covers our
David Roche 2013/04/04 01:39:53 Done.
157 this);
158 }
159
160 // GaiaOAuthClient::Delegate callback for OAuth2 refresh token fetched.
161 void EnrollmentHandlerChromeOS::OnGetTokensResponse(
162 const std::string& refresh_token,
163 const std::string& access_token,
164 int expires_in_seconds) {
165 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_);
166
167 enrollment_step_ = STEP_POLICY_FETCH,
168
169 // TODO: persist token in DeviceOAuth2TokenService when CL 12647008 lands.
170
171 client_->FetchPolicy();
172 }
173
174 // GaiaOAuthClient::Delegate
175 void EnrollmentHandlerChromeOS::OnRefreshTokenResponse(
176 const std::string& access_token,
177 int expires_in_seconds) {
178 // We never use the code that should trigger this callback.
179 NOTREACHED() << "Unexpected callback invoked";
Mattias Nissler (ping if slow) 2013/03/19 06:33:08 either need to notify the delegate, or do a LOG(FA
David Roche 2013/04/02 01:59:25 Done.
180 }
181
182 // GaiaOAuthClient::Delegate OAuth2 error when fetching refresh token request.
183 void EnrollmentHandlerChromeOS::OnOAuthError() {
184 ReportResult(EnrollmentStatus::ForStatus(
185 EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED));
186 }
187
188 // GaiaOAuthClient::Delegate network error when fetching refresh token.
189 void EnrollmentHandlerChromeOS::OnNetworkError(int response_code) {
190 LOG(ERROR) << "Network error while fetching API refresh token: "
191 << response_code;
192 ReportResult(EnrollmentStatus::ForStatus(
193 EnrollmentStatus::STATUS_ROBOT_REFRESH_FETCH_FAILED));
194 }
195
130 void EnrollmentHandlerChromeOS::OnClientError(CloudPolicyClient* client) { 196 void EnrollmentHandlerChromeOS::OnClientError(CloudPolicyClient* client) {
131 DCHECK_EQ(client_.get(), client); 197 DCHECK_EQ(client_.get(), client);
132 198
133 if (enrollment_step_ < STEP_POLICY_FETCH) 199 if (enrollment_step_ == STEP_ROBOT_AUTH_FETCH)
200 ReportResult(EnrollmentStatus::ForRobotAuthError(client_->status()));
201 else if (enrollment_step_ < STEP_POLICY_FETCH)
134 ReportResult(EnrollmentStatus::ForRegistrationError(client_->status())); 202 ReportResult(EnrollmentStatus::ForRegistrationError(client_->status()));
135 else 203 else
136 ReportResult(EnrollmentStatus::ForFetchError(client_->status())); 204 ReportResult(EnrollmentStatus::ForFetchError(client_->status()));
137 } 205 }
138 206
139 void EnrollmentHandlerChromeOS::OnStoreLoaded(CloudPolicyStore* store) { 207 void EnrollmentHandlerChromeOS::OnStoreLoaded(CloudPolicyStore* store) {
140 DCHECK_EQ(store_, store); 208 DCHECK_EQ(store_, store);
141 209
142 if (enrollment_step_ == STEP_LOADING_STORE) { 210 if (enrollment_step_ == STEP_LOADING_STORE) {
211 // If the |store_| wasn't initialized when StartEnrollment() was
212 // called, then AttemptRegistration() bails silently. This gets
213 // registration rolling again after the store finishes loading.
143 AttemptRegistration(); 214 AttemptRegistration();
144 } else if (enrollment_step_ == STEP_STORE_POLICY) { 215 } else if (enrollment_step_ == STEP_STORE_POLICY) {
145 ReportResult(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS)); 216 ReportResult(EnrollmentStatus::ForStatus(EnrollmentStatus::STATUS_SUCCESS));
146 } 217 }
147 } 218 }
148 219
149 void EnrollmentHandlerChromeOS::OnStoreError(CloudPolicyStore* store) { 220 void EnrollmentHandlerChromeOS::OnStoreError(CloudPolicyStore* store) {
150 DCHECK_EQ(store_, store); 221 DCHECK_EQ(store_, store);
151 ReportResult(EnrollmentStatus::ForStoreError(store_->status(), 222 ReportResult(EnrollmentStatus::ForStoreError(store_->status(),
152 store_->validation_status())); 223 store_->validation_status()));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 << " " << status.client_status() 313 << " " << status.client_status()
243 << " " << status.validation_status() 314 << " " << status.validation_status()
244 << " " << status.store_status(); 315 << " " << status.store_status();
245 } 316 }
246 317
247 if (!callback.is_null()) 318 if (!callback.is_null())
248 callback.Run(status); 319 callback.Run(status);
249 } 320 }
250 321
251 } // namespace policy 322 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698