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 "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 if (!client_id.empty()) | 103 if (!client_id.empty()) |
104 request->set_reregister(true); | 104 request->set_reregister(true); |
105 request->set_type(type); | 105 request->set_type(type); |
106 if (!machine_id_.empty()) | 106 if (!machine_id_.empty()) |
107 request->set_machine_id(machine_id_); | 107 request->set_machine_id(machine_id_); |
108 if (!machine_model_.empty()) | 108 if (!machine_model_.empty()) |
109 request->set_machine_model(machine_model_); | 109 request->set_machine_model(machine_model_); |
110 if (is_auto_enrollement) | 110 if (is_auto_enrollement) |
111 request->set_auto_enrolled(true); | 111 request->set_auto_enrolled(true); |
112 | 112 |
| 113 request_job_->SetRetryCallback( |
| 114 base::Bind(&CloudPolicyClient::OnRetryRegister, base::Unretained(this))); |
| 115 |
113 request_job_->Start(base::Bind(&CloudPolicyClient::OnRegisterCompleted, | 116 request_job_->Start(base::Bind(&CloudPolicyClient::OnRegisterCompleted, |
114 base::Unretained(this))); | 117 base::Unretained(this))); |
115 } | 118 } |
116 | 119 |
117 void CloudPolicyClient::FetchPolicy() { | 120 void CloudPolicyClient::FetchPolicy() { |
118 CHECK(is_registered()); | 121 CHECK(is_registered()); |
119 CHECK(!namespaces_to_fetch_.empty()); | 122 CHECK(!namespaces_to_fetch_.empty()); |
120 | 123 |
121 request_job_.reset( | 124 request_job_.reset( |
122 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)); | 125 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 void CloudPolicyClient::RemoveNamespaceToFetch(const PolicyNamespaceKey& key) { | 203 void CloudPolicyClient::RemoveNamespaceToFetch(const PolicyNamespaceKey& key) { |
201 namespaces_to_fetch_.erase(key); | 204 namespaces_to_fetch_.erase(key); |
202 } | 205 } |
203 | 206 |
204 const em::PolicyFetchResponse* CloudPolicyClient::GetPolicyFor( | 207 const em::PolicyFetchResponse* CloudPolicyClient::GetPolicyFor( |
205 const PolicyNamespaceKey& key) const { | 208 const PolicyNamespaceKey& key) const { |
206 ResponseMap::const_iterator it = responses_.find(key); | 209 ResponseMap::const_iterator it = responses_.find(key); |
207 return it == responses_.end() ? NULL : it->second; | 210 return it == responses_.end() ? NULL : it->second; |
208 } | 211 } |
209 | 212 |
| 213 void CloudPolicyClient::OnRetryRegister(DeviceManagementRequestJob* job) { |
| 214 DCHECK_EQ(request_job_.get(), job); |
| 215 // If the initial request managed to get to the server but the response didn't |
| 216 // arrive at the client then retrying with the same client ID will fail. |
| 217 // Set the re-registration flag so that the server accepts it. |
| 218 // If the server hasn't seen the client ID before then it will also accept |
| 219 // the re-registration. |
| 220 job->GetRequest()->mutable_register_request()->set_reregister(true); |
| 221 } |
| 222 |
210 void CloudPolicyClient::OnRegisterCompleted( | 223 void CloudPolicyClient::OnRegisterCompleted( |
211 DeviceManagementStatus status, | 224 DeviceManagementStatus status, |
212 const em::DeviceManagementResponse& response) { | 225 const em::DeviceManagementResponse& response) { |
213 if (status == DM_STATUS_SUCCESS && | 226 if (status == DM_STATUS_SUCCESS && |
214 (!response.has_register_response() || | 227 (!response.has_register_response() || |
215 !response.register_response().has_device_management_token())) { | 228 !response.register_response().has_device_management_token())) { |
216 LOG(WARNING) << "Invalid registration response."; | 229 LOG(WARNING) << "Invalid registration response."; |
217 status = DM_STATUS_RESPONSE_DECODING_ERROR; | 230 status = DM_STATUS_RESPONSE_DECODING_ERROR; |
218 } | 231 } |
219 | 232 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 317 |
305 void CloudPolicyClient::NotifyRegistrationStateChanged() { | 318 void CloudPolicyClient::NotifyRegistrationStateChanged() { |
306 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); | 319 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); |
307 } | 320 } |
308 | 321 |
309 void CloudPolicyClient::NotifyClientError() { | 322 void CloudPolicyClient::NotifyClientError() { |
310 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 323 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); |
311 } | 324 } |
312 | 325 |
313 } // namespace policy | 326 } // namespace policy |
OLD | NEW |