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

Side by Side Diff: chrome/browser/policy/cloud_policy_client.cc

Issue 10928036: Implement Chrome OS device enrollment on the new cloud policy stack. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix CloudPolicyClient error handling. Created 8 years, 2 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) 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/policy/cloud_policy_client.h" 5 #include "chrome/browser/policy/cloud_policy_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/browser/policy/device_management_service.h" 10 #include "chrome/browser/policy/device_management_service.h"
11 #include "chrome/browser/policy/proto/device_management_backend.pb.h" 11 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
12 12
13 namespace em = enterprise_management; 13 namespace em = enterprise_management;
14 14
15 namespace policy { 15 namespace policy {
16 16
17 namespace {
18
19 // Translates the DeviceRegisterResponse::DeviceMode |mode| to the enum used
20 // internally to represent different device modes.
21 DeviceMode TranslateProtobufDeviceMode(
22 em::DeviceRegisterResponse::DeviceMode mode) {
23 switch (mode) {
24 case em::DeviceRegisterResponse::ENTERPRISE:
25 return DEVICE_MODE_ENTERPRISE;
26 case em::DeviceRegisterResponse::RETAIL:
27 return DEVICE_MODE_KIOSK;
28 }
29 LOG(ERROR) << "Unknown enrollment mode in registration response: " << mode;
30 return DEVICE_MODE_NOT_SET;
31 }
32
33 } // namespace
34
17 CloudPolicyClient::Observer::~Observer() {} 35 CloudPolicyClient::Observer::~Observer() {}
18 36
19 CloudPolicyClient::StatusProvider::~StatusProvider() {} 37 CloudPolicyClient::StatusProvider::~StatusProvider() {}
20 38
21 CloudPolicyClient::CloudPolicyClient(const std::string& machine_id, 39 CloudPolicyClient::CloudPolicyClient(const std::string& machine_id,
22 const std::string& machine_model, 40 const std::string& machine_model,
23 UserAffiliation user_affiliation, 41 UserAffiliation user_affiliation,
24 PolicyScope scope, 42 PolicyScope scope,
25 StatusProvider* status_provider, 43 StatusProvider* status_provider,
26 DeviceManagementService* service) 44 DeviceManagementService* service)
27 : machine_id_(machine_id), 45 : machine_id_(machine_id),
28 machine_model_(machine_model), 46 machine_model_(machine_model),
29 user_affiliation_(user_affiliation), 47 user_affiliation_(user_affiliation),
30 scope_(scope), 48 scope_(scope),
49 device_mode_(DEVICE_MODE_NOT_SET),
31 submit_machine_id_(false), 50 submit_machine_id_(false),
32 public_key_version_(-1), 51 public_key_version_(-1),
33 public_key_version_valid_(false), 52 public_key_version_valid_(false),
34 service_(service), // Can be NULL for unit tests. 53 service_(service), // Can be NULL for unit tests.
35 status_provider_(status_provider), // Can be NULL for unit tests. 54 status_provider_(status_provider), // Can be NULL for unit tests.
36 status_(DM_STATUS_SUCCESS) { 55 status_(DM_STATUS_SUCCESS) {
37 } 56 }
38 57
39 CloudPolicyClient::~CloudPolicyClient() {} 58 CloudPolicyClient::~CloudPolicyClient() {}
40 59
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 183 }
165 NOTREACHED() << "Invalid policy scope " << scope_; 184 NOTREACHED() << "Invalid policy scope " << scope_;
166 } 185 }
167 186
168 void CloudPolicyClient::OnRegisterCompleted( 187 void CloudPolicyClient::OnRegisterCompleted(
169 DeviceManagementStatus status, 188 DeviceManagementStatus status,
170 const em::DeviceManagementResponse& response) { 189 const em::DeviceManagementResponse& response) {
171 if (status == DM_STATUS_SUCCESS && 190 if (status == DM_STATUS_SUCCESS &&
172 (!response.has_register_response() || 191 (!response.has_register_response() ||
173 !response.register_response().has_device_management_token())) { 192 !response.register_response().has_device_management_token())) {
174 LOG(WARNING) << "Empty registration response."; 193 LOG(WARNING) << "Invalid registration response.";
175 status = DM_STATUS_RESPONSE_DECODING_ERROR; 194 status = DM_STATUS_RESPONSE_DECODING_ERROR;
176 } 195 }
177 196
178 status_ = status; 197 status_ = status;
179 if (status == DM_STATUS_SUCCESS) { 198 if (status == DM_STATUS_SUCCESS) {
180 dm_token_ = response.register_response().device_management_token(); 199 dm_token_ = response.register_response().device_management_token();
200
201 // Device mode is only relevant for device policy really, it's the
202 // responsibility of the consumer of the field to check validity.
203 device_mode_ = DEVICE_MODE_NOT_SET;
204 if (response.register_response().has_enrollment_type()) {
205 device_mode_ = TranslateProtobufDeviceMode(
206 response.register_response().enrollment_type());
207 }
208
181 NotifyRegistrationStateChanged(); 209 NotifyRegistrationStateChanged();
182 } else { 210 } else {
183 NotifyClientError(); 211 NotifyClientError();
184 } 212 }
185 } 213 }
186 214
187 void CloudPolicyClient::OnPolicyFetchCompleted( 215 void CloudPolicyClient::OnPolicyFetchCompleted(
188 DeviceManagementStatus status, 216 DeviceManagementStatus status,
189 const em::DeviceManagementResponse& response) { 217 const em::DeviceManagementResponse& response) {
190 if (status == DM_STATUS_SUCCESS) { 218 if (status == DM_STATUS_SUCCESS) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 260
233 void CloudPolicyClient::NotifyRegistrationStateChanged() { 261 void CloudPolicyClient::NotifyRegistrationStateChanged() {
234 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); 262 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this));
235 } 263 }
236 264
237 void CloudPolicyClient::NotifyClientError() { 265 void CloudPolicyClient::NotifyClientError() {
238 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); 266 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this));
239 } 267 }
240 268
241 } // namespace policy 269 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_client.h ('k') | chrome/browser/policy/device_cloud_policy_manager_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698