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 "components/policy/core/common/cloud/cloud_policy_client.h" | 5 #include "components/policy/core/common/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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 | 101 |
| 102 if (client_id.empty()) { | 102 if (client_id.empty()) { |
| 103 // Generate a new client ID. This is intentionally done on each new | 103 // Generate a new client ID. This is intentionally done on each new |
| 104 // registration request in order to preserve privacy. Reusing IDs would mean | 104 // registration request in order to preserve privacy. Reusing IDs would mean |
| 105 // the server could track clients by their registration attempts. | 105 // the server could track clients by their registration attempts. |
| 106 client_id_ = base::GenerateGUID(); | 106 client_id_ = base::GenerateGUID(); |
| 107 } else { | 107 } else { |
| 108 client_id_ = client_id; | 108 client_id_ = client_id; |
| 109 } | 109 } |
| 110 | 110 |
| 111 // TODO(dcheng): Potentially sketchy. This gets passed to | |
| 112 // DeviceManagementRequestJobImpl, which only keeps a raw pointer to it. | |
|
bartfab (slow)
2014/08/29 08:49:03
The job is owned by |this| and |this| will go away
dcheng
2014/08/29 09:08:36
Done.
| |
| 111 request_job_.reset( | 113 request_job_.reset( |
| 112 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION, | 114 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION, |
| 113 GetRequestContext())); | 115 GetRequestContext().get())); |
| 114 request_job_->SetOAuthToken(auth_token); | 116 request_job_->SetOAuthToken(auth_token); |
| 115 request_job_->SetClientID(client_id_); | 117 request_job_->SetClientID(client_id_); |
| 116 | 118 |
| 117 em::DeviceRegisterRequest* request = | 119 em::DeviceRegisterRequest* request = |
| 118 request_job_->GetRequest()->mutable_register_request(); | 120 request_job_->GetRequest()->mutable_register_request(); |
| 119 if (!client_id.empty()) | 121 if (!client_id.empty()) |
| 120 request->set_reregister(true); | 122 request->set_reregister(true); |
| 121 request->set_type(type); | 123 request->set_type(type); |
| 122 if (!machine_id_.empty()) | 124 if (!machine_id_.empty()) |
| 123 request->set_machine_id(machine_id_); | 125 request->set_machine_id(machine_id_); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 143 invalidation_version_ = version; | 145 invalidation_version_ = version; |
| 144 invalidation_payload_ = payload; | 146 invalidation_payload_ = payload; |
| 145 } | 147 } |
| 146 | 148 |
| 147 void CloudPolicyClient::FetchPolicy() { | 149 void CloudPolicyClient::FetchPolicy() { |
| 148 CHECK(is_registered()); | 150 CHECK(is_registered()); |
| 149 CHECK(!namespaces_to_fetch_.empty()); | 151 CHECK(!namespaces_to_fetch_.empty()); |
| 150 | 152 |
| 151 request_job_.reset( | 153 request_job_.reset( |
| 152 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, | 154 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, |
| 153 GetRequestContext())); | 155 GetRequestContext().get())); |
| 154 request_job_->SetDMToken(dm_token_); | 156 request_job_->SetDMToken(dm_token_); |
| 155 request_job_->SetClientID(client_id_); | 157 request_job_->SetClientID(client_id_); |
| 156 request_job_->SetUserAffiliation(user_affiliation_); | 158 request_job_->SetUserAffiliation(user_affiliation_); |
| 157 | 159 |
| 158 em::DeviceManagementRequest* request = request_job_->GetRequest(); | 160 em::DeviceManagementRequest* request = request_job_->GetRequest(); |
| 159 | 161 |
| 160 // Build policy fetch requests. | 162 // Build policy fetch requests. |
| 161 em::DevicePolicyRequest* policy_request = request->mutable_policy_request(); | 163 em::DevicePolicyRequest* policy_request = request->mutable_policy_request(); |
| 162 for (NamespaceSet::iterator it = namespaces_to_fetch_.begin(); | 164 for (NamespaceSet::iterator it = namespaces_to_fetch_.begin(); |
| 163 it != namespaces_to_fetch_.end(); ++it) { | 165 it != namespaces_to_fetch_.end(); ++it) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 | 222 |
| 221 // Fire the job. | 223 // Fire the job. |
| 222 request_job_->Start(base::Bind(&CloudPolicyClient::OnPolicyFetchCompleted, | 224 request_job_->Start(base::Bind(&CloudPolicyClient::OnPolicyFetchCompleted, |
| 223 base::Unretained(this))); | 225 base::Unretained(this))); |
| 224 } | 226 } |
| 225 | 227 |
| 226 void CloudPolicyClient::FetchRobotAuthCodes(const std::string& auth_token) { | 228 void CloudPolicyClient::FetchRobotAuthCodes(const std::string& auth_token) { |
| 227 CHECK(is_registered()); | 229 CHECK(is_registered()); |
| 228 DCHECK(!auth_token.empty()); | 230 DCHECK(!auth_token.empty()); |
| 229 | 231 |
| 230 request_job_.reset(service_->CreateJob( | 232 request_job_.reset( |
| 231 DeviceManagementRequestJob::TYPE_API_AUTH_CODE_FETCH, | 233 service_->CreateJob(DeviceManagementRequestJob::TYPE_API_AUTH_CODE_FETCH, |
| 232 GetRequestContext())); | 234 GetRequestContext().get())); |
| 233 // The credentials of a domain user are needed in order to mint a new OAuth2 | 235 // The credentials of a domain user are needed in order to mint a new OAuth2 |
| 234 // authorization token for the robot account. | 236 // authorization token for the robot account. |
| 235 request_job_->SetOAuthToken(auth_token); | 237 request_job_->SetOAuthToken(auth_token); |
| 236 request_job_->SetDMToken(dm_token_); | 238 request_job_->SetDMToken(dm_token_); |
| 237 request_job_->SetClientID(client_id_); | 239 request_job_->SetClientID(client_id_); |
| 238 | 240 |
| 239 em::DeviceServiceApiAccessRequest* request = | 241 em::DeviceServiceApiAccessRequest* request = |
| 240 request_job_->GetRequest()->mutable_service_api_access_request(); | 242 request_job_->GetRequest()->mutable_service_api_access_request(); |
| 241 request->set_oauth2_client_id( | 243 request->set_oauth2_client_id( |
| 242 GaiaUrls::GetInstance()->oauth2_chrome_client_id()); | 244 GaiaUrls::GetInstance()->oauth2_chrome_client_id()); |
| 243 request->add_auth_scope(GaiaConstants::kAnyApiOAuth2Scope); | 245 request->add_auth_scope(GaiaConstants::kAnyApiOAuth2Scope); |
| 244 | 246 |
| 245 request_job_->Start( | 247 request_job_->Start( |
| 246 base::Bind(&CloudPolicyClient::OnFetchRobotAuthCodesCompleted, | 248 base::Bind(&CloudPolicyClient::OnFetchRobotAuthCodesCompleted, |
| 247 base::Unretained(this))); | 249 base::Unretained(this))); |
| 248 } | 250 } |
| 249 | 251 |
| 250 void CloudPolicyClient::Unregister() { | 252 void CloudPolicyClient::Unregister() { |
| 251 DCHECK(service_); | 253 DCHECK(service_); |
| 252 request_job_.reset( | 254 request_job_.reset( |
| 253 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, | 255 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION, |
| 254 GetRequestContext())); | 256 GetRequestContext().get())); |
| 255 request_job_->SetDMToken(dm_token_); | 257 request_job_->SetDMToken(dm_token_); |
| 256 request_job_->SetClientID(client_id_); | 258 request_job_->SetClientID(client_id_); |
| 257 request_job_->GetRequest()->mutable_unregister_request(); | 259 request_job_->GetRequest()->mutable_unregister_request(); |
| 258 request_job_->Start(base::Bind(&CloudPolicyClient::OnUnregisterCompleted, | 260 request_job_->Start(base::Bind(&CloudPolicyClient::OnUnregisterCompleted, |
| 259 base::Unretained(this))); | 261 base::Unretained(this))); |
| 260 } | 262 } |
| 261 | 263 |
| 262 void CloudPolicyClient::UploadCertificate( | 264 void CloudPolicyClient::UploadCertificate( |
| 263 const std::string& certificate_data, | 265 const std::string& certificate_data, |
| 264 const CloudPolicyClient::StatusCallback& callback) { | 266 const CloudPolicyClient::StatusCallback& callback) { |
| 265 CHECK(is_registered()); | 267 CHECK(is_registered()); |
| 266 request_job_.reset( | 268 request_job_.reset( |
| 267 service_->CreateJob(DeviceManagementRequestJob::TYPE_UPLOAD_CERTIFICATE, | 269 service_->CreateJob(DeviceManagementRequestJob::TYPE_UPLOAD_CERTIFICATE, |
| 268 GetRequestContext())); | 270 GetRequestContext().get())); |
| 269 request_job_->SetDMToken(dm_token_); | 271 request_job_->SetDMToken(dm_token_); |
| 270 request_job_->SetClientID(client_id_); | 272 request_job_->SetClientID(client_id_); |
| 271 | 273 |
| 272 em::DeviceManagementRequest* request = request_job_->GetRequest(); | 274 em::DeviceManagementRequest* request = request_job_->GetRequest(); |
| 273 request->mutable_cert_upload_request()->set_device_certificate( | 275 request->mutable_cert_upload_request()->set_device_certificate( |
| 274 certificate_data); | 276 certificate_data); |
| 275 | 277 |
| 276 DeviceManagementRequestJob::Callback job_callback = base::Bind( | 278 DeviceManagementRequestJob::Callback job_callback = base::Bind( |
| 277 &CloudPolicyClient::OnCertificateUploadCompleted, | 279 &CloudPolicyClient::OnCertificateUploadCompleted, |
| 278 base::Unretained(this), | 280 base::Unretained(this), |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 | 472 |
| 471 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { | 473 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { |
| 472 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); | 474 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); |
| 473 } | 475 } |
| 474 | 476 |
| 475 void CloudPolicyClient::NotifyClientError() { | 477 void CloudPolicyClient::NotifyClientError() { |
| 476 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 478 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); |
| 477 } | 479 } |
| 478 | 480 |
| 479 } // namespace policy | 481 } // namespace policy |
| OLD | NEW |