Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; | |
|
Joao da Silva
2012/09/07 14:01:42
nit: one space after return
Mattias Nissler (ping if slow)
2012/10/23 15:30:41
Done.
| |
| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 case POLICY_SCOPE_MACHINE: | 180 case POLICY_SCOPE_MACHINE: |
| 162 request->set_policy_type(dm_protocol::kChromeDevicePolicyType); | 181 request->set_policy_type(dm_protocol::kChromeDevicePolicyType); |
| 163 return; | 182 return; |
| 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) { |
| 190 device_mode_ = TranslateProtobufDeviceMode( | |
| 191 response.register_response().enrollment_type()); | |
| 171 if (status == DM_STATUS_SUCCESS && | 192 if (status == DM_STATUS_SUCCESS && |
| 172 (!response.has_register_response() || | 193 (!response.has_register_response() || |
| 173 !response.register_response().has_device_management_token())) { | 194 !response.register_response().has_device_management_token() || |
| 174 LOG(WARNING) << "Empty registration response."; | 195 (device_mode_ != DEVICE_MODE_ENTERPRISE && |
| 196 device_mode_ != DEVICE_MODE_KIOSK))) { | |
|
pastarmovj
2012/09/07 12:16:27
I know that this check is happening only once but
Joao da Silva
2012/09/07 14:01:42
Please add a comment explaining what the device_mo
Mattias Nissler (ping if slow)
2012/10/23 15:30:41
Done.
Mattias Nissler (ping if slow)
2012/10/23 15:30:41
I thought about this some more and ended up re-str
| |
| 197 LOG(WARNING) << "Invalid registration response."; | |
| 175 status = DM_STATUS_RESPONSE_DECODING_ERROR; | 198 status = DM_STATUS_RESPONSE_DECODING_ERROR; |
| 176 } | 199 } |
| 177 | 200 |
| 178 status_ = status; | 201 status_ = status; |
| 179 if (status == DM_STATUS_SUCCESS) { | 202 if (status == DM_STATUS_SUCCESS) { |
| 180 dm_token_ = response.register_response().device_management_token(); | 203 dm_token_ = response.register_response().device_management_token(); |
| 181 NotifyRegistrationStateChanged(); | 204 NotifyRegistrationStateChanged(); |
| 182 } else { | 205 } else { |
| 183 NotifyClientError(); | 206 NotifyClientError(); |
| 184 } | 207 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 | 255 |
| 233 void CloudPolicyClient::NotifyRegistrationStateChanged() { | 256 void CloudPolicyClient::NotifyRegistrationStateChanged() { |
| 234 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); | 257 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); |
| 235 } | 258 } |
| 236 | 259 |
| 237 void CloudPolicyClient::NotifyClientError() { | 260 void CloudPolicyClient::NotifyClientError() { |
| 238 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 261 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); |
| 239 } | 262 } |
| 240 | 263 |
| 241 } // namespace policy | 264 } // namespace policy |
| OLD | NEW |