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/cloud_policy_client.h" | 5 #include "chrome/browser/policy/cloud/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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 client_id_ = client_id; | 77 client_id_ = client_id; |
78 request_job_.reset(); | 78 request_job_.reset(); |
79 STLDeleteValues(&responses_); | 79 STLDeleteValues(&responses_); |
80 | 80 |
81 NotifyRegistrationStateChanged(); | 81 NotifyRegistrationStateChanged(); |
82 } | 82 } |
83 | 83 |
84 void CloudPolicyClient::Register(em::DeviceRegisterRequest::Type type, | 84 void CloudPolicyClient::Register(em::DeviceRegisterRequest::Type type, |
85 const std::string& auth_token, | 85 const std::string& auth_token, |
86 const std::string& client_id, | 86 const std::string& client_id, |
87 bool is_auto_enrollement) { | 87 bool is_auto_enrollement, |
| 88 const std::string& requisition) { |
88 DCHECK(service_); | 89 DCHECK(service_); |
89 DCHECK(!auth_token.empty()); | 90 DCHECK(!auth_token.empty()); |
90 DCHECK(!is_registered()); | 91 DCHECK(!is_registered()); |
91 | 92 |
92 if (client_id.empty()) { | 93 if (client_id.empty()) { |
93 // Generate a new client ID. This is intentionally done on each new | 94 // Generate a new client ID. This is intentionally done on each new |
94 // registration request in order to preserve privacy. Reusing IDs would mean | 95 // registration request in order to preserve privacy. Reusing IDs would mean |
95 // the server could track clients by their registration attempts. | 96 // the server could track clients by their registration attempts. |
96 client_id_ = base::GenerateGUID(); | 97 client_id_ = base::GenerateGUID(); |
97 } else { | 98 } else { |
98 client_id_ = client_id; | 99 client_id_ = client_id; |
99 } | 100 } |
100 | 101 |
101 request_job_.reset( | 102 request_job_.reset( |
102 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)); | 103 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION)); |
103 request_job_->SetOAuthToken(auth_token); | 104 request_job_->SetOAuthToken(auth_token); |
104 request_job_->SetClientID(client_id_); | 105 request_job_->SetClientID(client_id_); |
105 | 106 |
106 em::DeviceRegisterRequest* request = | 107 em::DeviceRegisterRequest* request = |
107 request_job_->GetRequest()->mutable_register_request(); | 108 request_job_->GetRequest()->mutable_register_request(); |
108 if (!client_id.empty()) | 109 if (!client_id.empty()) |
109 request->set_reregister(true); | 110 request->set_reregister(true); |
110 request->set_type(type); | 111 request->set_type(type); |
111 if (!machine_id_.empty()) | 112 if (!machine_id_.empty()) |
112 request->set_machine_id(machine_id_); | 113 request->set_machine_id(machine_id_); |
113 if (!machine_model_.empty()) | 114 if (!machine_model_.empty()) |
114 request->set_machine_model(machine_model_); | 115 request->set_machine_model(machine_model_); |
115 if (is_auto_enrollement) | 116 if (is_auto_enrollement) |
116 request->set_auto_enrolled(true); | 117 request->set_auto_enrolled(true); |
| 118 if (!requisition.empty()) |
| 119 request->set_requisition(requisition); |
117 | 120 |
118 request_job_->SetRetryCallback( | 121 request_job_->SetRetryCallback( |
119 base::Bind(&CloudPolicyClient::OnRetryRegister, base::Unretained(this))); | 122 base::Bind(&CloudPolicyClient::OnRetryRegister, base::Unretained(this))); |
120 | 123 |
121 request_job_->Start(base::Bind(&CloudPolicyClient::OnRegisterCompleted, | 124 request_job_->Start(base::Bind(&CloudPolicyClient::OnRegisterCompleted, |
122 base::Unretained(this))); | 125 base::Unretained(this))); |
123 } | 126 } |
124 | 127 |
125 void CloudPolicyClient::FetchPolicy() { | 128 void CloudPolicyClient::FetchPolicy() { |
126 CHECK(is_registered()); | 129 CHECK(is_registered()); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 418 |
416 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { | 419 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { |
417 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); | 420 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); |
418 } | 421 } |
419 | 422 |
420 void CloudPolicyClient::NotifyClientError() { | 423 void CloudPolicyClient::NotifyClientError() { |
421 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 424 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); |
422 } | 425 } |
423 | 426 |
424 } // namespace policy | 427 } // namespace policy |
OLD | NEW |