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

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

Issue 12209070: Fix cloud policy duplicate registrations issue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 10 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 "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 316
304 void CloudPolicyClient::NotifyRegistrationStateChanged() { 317 void CloudPolicyClient::NotifyRegistrationStateChanged() {
305 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); 318 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this));
306 } 319 }
307 320
308 void CloudPolicyClient::NotifyClientError() { 321 void CloudPolicyClient::NotifyClientError() {
309 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); 322 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this));
310 } 323 }
311 324
312 } // namespace policy 325 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698