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 | 122 |
120 request_job_.reset( | 123 request_job_.reset( |
121 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)); | 124 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)); |
122 request_job_->SetDMToken(dm_token_); | 125 request_job_->SetDMToken(dm_token_); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 void CloudPolicyClient::RemoveNamespaceToFetch(const PolicyNamespaceKey& key) { | 197 void CloudPolicyClient::RemoveNamespaceToFetch(const PolicyNamespaceKey& key) { |
195 namespaces_to_fetch_.erase(key); | 198 namespaces_to_fetch_.erase(key); |
196 } | 199 } |
197 | 200 |
198 const em::PolicyFetchResponse* CloudPolicyClient::GetPolicyFor( | 201 const em::PolicyFetchResponse* CloudPolicyClient::GetPolicyFor( |
199 const PolicyNamespaceKey& key) const { | 202 const PolicyNamespaceKey& key) const { |
200 ResponseMap::const_iterator it = responses_.find(key); | 203 ResponseMap::const_iterator it = responses_.find(key); |
201 return it == responses_.end() ? NULL : it->second; | 204 return it == responses_.end() ? NULL : it->second; |
202 } | 205 } |
203 | 206 |
207 void CloudPolicyClient::OnRetryRegister(DeviceManagementRequestJob* job) { | |
208 DCHECK_EQ(request_job_.get(), job); | |
209 // If the initial request managed to get to the server but the response didn't | |
210 // arrive to the client then retrying with the same device-id will fail. | |
Mattias Nissler (ping if slow)
2013/02/11 11:30:37
nit: s/to/at/
Mattias Nissler (ping if slow)
2013/02/11 11:30:37
nit: s/device-id/client ID/ (for consistency with
Joao da Silva
2013/02/11 17:38:19
Done.
Joao da Silva
2013/02/11 17:38:19
Done.
| |
211 // Set the re-registration flag so that the server accepts it. | |
212 // If the server hasn't seen the device-id before then it will also accept | |
Mattias Nissler (ping if slow)
2013/02/11 11:30:37
ditto
Joao da Silva
2013/02/11 17:38:19
Done.
| |
213 // the re-registration. | |
214 job->GetRequest()->mutable_register_request()->set_reregister(true); | |
215 } | |
216 | |
204 void CloudPolicyClient::OnRegisterCompleted( | 217 void CloudPolicyClient::OnRegisterCompleted( |
205 DeviceManagementStatus status, | 218 DeviceManagementStatus status, |
206 const em::DeviceManagementResponse& response) { | 219 const em::DeviceManagementResponse& response) { |
207 if (status == DM_STATUS_SUCCESS && | 220 if (status == DM_STATUS_SUCCESS && |
208 (!response.has_register_response() || | 221 (!response.has_register_response() || |
209 !response.register_response().has_device_management_token())) { | 222 !response.register_response().has_device_management_token())) { |
210 LOG(WARNING) << "Invalid registration response."; | 223 LOG(WARNING) << "Invalid registration response."; |
211 status = DM_STATUS_RESPONSE_DECODING_ERROR; | 224 status = DM_STATUS_RESPONSE_DECODING_ERROR; |
212 } | 225 } |
213 | 226 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 | 310 |
298 void CloudPolicyClient::NotifyRegistrationStateChanged() { | 311 void CloudPolicyClient::NotifyRegistrationStateChanged() { |
299 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); | 312 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); |
300 } | 313 } |
301 | 314 |
302 void CloudPolicyClient::NotifyClientError() { | 315 void CloudPolicyClient::NotifyClientError() { |
303 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 316 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); |
304 } | 317 } |
305 | 318 |
306 } // namespace policy | 319 } // namespace policy |
OLD | NEW |