| 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 27 matching lines...) Expand all Loading... |
| 38 type == GetChromeUserPolicyType(); | 38 type == GetChromeUserPolicyType(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 CloudPolicyClient::Observer::~Observer() {} | 43 CloudPolicyClient::Observer::~Observer() {} |
| 44 | 44 |
| 45 void CloudPolicyClient::Observer::OnRobotAuthCodesFetched( | 45 void CloudPolicyClient::Observer::OnRobotAuthCodesFetched( |
| 46 CloudPolicyClient* client) {} | 46 CloudPolicyClient* client) {} |
| 47 | 47 |
| 48 CloudPolicyClient::StatusProvider::~StatusProvider() {} | |
| 49 | |
| 50 CloudPolicyClient::CloudPolicyClient( | 48 CloudPolicyClient::CloudPolicyClient( |
| 51 const std::string& machine_id, | 49 const std::string& machine_id, |
| 52 const std::string& machine_model, | 50 const std::string& machine_model, |
| 53 const std::string& verification_key_hash, | 51 const std::string& verification_key_hash, |
| 54 UserAffiliation user_affiliation, | 52 UserAffiliation user_affiliation, |
| 55 DeviceManagementService* service, | 53 DeviceManagementService* service, |
| 56 scoped_refptr<net::URLRequestContextGetter> request_context) | 54 scoped_refptr<net::URLRequestContextGetter> request_context) |
| 57 : machine_id_(machine_id), | 55 : machine_id_(machine_id), |
| 58 machine_model_(machine_model), | 56 machine_model_(machine_model), |
| 59 verification_key_hash_(verification_key_hash), | 57 verification_key_hash_(verification_key_hash), |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 last_policy_timestamp_ - base::Time::UnixEpoch()); | 177 last_policy_timestamp_ - base::Time::UnixEpoch()); |
| 180 fetch_request->set_timestamp(timestamp.InMilliseconds()); | 178 fetch_request->set_timestamp(timestamp.InMilliseconds()); |
| 181 } | 179 } |
| 182 if (!invalidation_payload_.empty()) { | 180 if (!invalidation_payload_.empty()) { |
| 183 fetch_request->set_invalidation_version(invalidation_version_); | 181 fetch_request->set_invalidation_version(invalidation_version_); |
| 184 fetch_request->set_invalidation_payload(invalidation_payload_); | 182 fetch_request->set_invalidation_payload(invalidation_payload_); |
| 185 } | 183 } |
| 186 } | 184 } |
| 187 } | 185 } |
| 188 | 186 |
| 189 // Add status data. | |
| 190 if (status_provider_) { | |
| 191 if (!status_provider_->GetDeviceStatus( | |
| 192 request->mutable_device_status_report_request())) { | |
| 193 request->clear_device_status_report_request(); | |
| 194 } | |
| 195 if (!status_provider_->GetSessionStatus( | |
| 196 request->mutable_session_status_report_request())) { | |
| 197 request->clear_session_status_report_request(); | |
| 198 } | |
| 199 } | |
| 200 | |
| 201 // Add device state keys. | 187 // Add device state keys. |
| 202 if (!state_keys_to_upload_.empty()) { | 188 if (!state_keys_to_upload_.empty()) { |
| 203 em::DeviceStateKeyUpdateRequest* key_update_request = | 189 em::DeviceStateKeyUpdateRequest* key_update_request = |
| 204 request->mutable_device_state_key_update_request(); | 190 request->mutable_device_state_key_update_request(); |
| 205 for (std::vector<std::string>::const_iterator key( | 191 for (std::vector<std::string>::const_iterator key( |
| 206 state_keys_to_upload_.begin()); | 192 state_keys_to_upload_.begin()); |
| 207 key != state_keys_to_upload_.end(); | 193 key != state_keys_to_upload_.end(); |
| 208 ++key) { | 194 ++key) { |
| 209 key_update_request->add_server_backed_state_key(*key); | 195 key_update_request->add_server_backed_state_key(*key); |
| 210 } | 196 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 request->mutable_cert_upload_request()->set_device_certificate( | 255 request->mutable_cert_upload_request()->set_device_certificate( |
| 270 certificate_data); | 256 certificate_data); |
| 271 | 257 |
| 272 DeviceManagementRequestJob::Callback job_callback = base::Bind( | 258 DeviceManagementRequestJob::Callback job_callback = base::Bind( |
| 273 &CloudPolicyClient::OnCertificateUploadCompleted, | 259 &CloudPolicyClient::OnCertificateUploadCompleted, |
| 274 base::Unretained(this), | 260 base::Unretained(this), |
| 275 callback); | 261 callback); |
| 276 request_job_->Start(job_callback); | 262 request_job_->Start(job_callback); |
| 277 } | 263 } |
| 278 | 264 |
| 265 scoped_ptr<DeviceManagementRequestJob> CloudPolicyClient::CreateUploadStatusJob( |
| 266 const em::DeviceStatusReportRequest* device_status, |
| 267 const em::SessionStatusReportRequest* session_status) { |
| 268 CHECK(is_registered()); |
| 269 // Should pass in at least one type of status. |
| 270 DCHECK(device_status || session_status); |
| 271 scoped_ptr<DeviceManagementRequestJob> job( |
| 272 service_->CreateJob(DeviceManagementRequestJob::TYPE_UPLOAD_STATUS, |
| 273 GetRequestContext())); |
| 274 job->SetDMToken(dm_token_); |
| 275 job->SetClientID(client_id_); |
| 276 |
| 277 em::DeviceManagementRequest* request = job->GetRequest(); |
| 278 if (device_status) |
| 279 *request->mutable_device_status_report_request() = *device_status; |
| 280 if (session_status) |
| 281 *request->mutable_session_status_report_request() = *session_status; |
| 282 |
| 283 return job; |
| 284 } |
| 285 |
| 279 void CloudPolicyClient::AddObserver(Observer* observer) { | 286 void CloudPolicyClient::AddObserver(Observer* observer) { |
| 280 observers_.AddObserver(observer); | 287 observers_.AddObserver(observer); |
| 281 } | 288 } |
| 282 | 289 |
| 283 void CloudPolicyClient::RemoveObserver(Observer* observer) { | 290 void CloudPolicyClient::RemoveObserver(Observer* observer) { |
| 284 observers_.RemoveObserver(observer); | 291 observers_.RemoveObserver(observer); |
| 285 } | 292 } |
| 286 | 293 |
| 287 void CloudPolicyClient::SetStatusProvider(scoped_ptr<StatusProvider> provider) { | |
| 288 status_provider_ = provider.Pass(); | |
| 289 } | |
| 290 | |
| 291 bool CloudPolicyClient::HasStatusProviderForTest() { | |
| 292 return status_provider_; | |
| 293 } | |
| 294 | |
| 295 void CloudPolicyClient::AddPolicyTypeToFetch( | 294 void CloudPolicyClient::AddPolicyTypeToFetch( |
| 296 const std::string& policy_type, | 295 const std::string& policy_type, |
| 297 const std::string& settings_entity_id) { | 296 const std::string& settings_entity_id) { |
| 298 types_to_fetch_.insert(std::make_pair(policy_type, settings_entity_id)); | 297 types_to_fetch_.insert(std::make_pair(policy_type, settings_entity_id)); |
| 299 } | 298 } |
| 300 | 299 |
| 301 void CloudPolicyClient::RemovePolicyTypeToFetch( | 300 void CloudPolicyClient::RemovePolicyTypeToFetch( |
| 302 const std::string& policy_type, | 301 const std::string& policy_type, |
| 303 const std::string& settings_entity_id) { | 302 const std::string& settings_entity_id) { |
| 304 types_to_fetch_.erase(std::make_pair(policy_type, settings_entity_id)); | 303 types_to_fetch_.erase(std::make_pair(policy_type, settings_entity_id)); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 if (policy_data.has_settings_entity_id()) | 415 if (policy_data.has_settings_entity_id()) |
| 417 entity_id = policy_data.settings_entity_id(); | 416 entity_id = policy_data.settings_entity_id(); |
| 418 std::pair<std::string, std::string> key(type, entity_id); | 417 std::pair<std::string, std::string> key(type, entity_id); |
| 419 if (ContainsKey(responses_, key)) { | 418 if (ContainsKey(responses_, key)) { |
| 420 LOG(WARNING) << "Duplicate PolicyFetchResponse for type: " | 419 LOG(WARNING) << "Duplicate PolicyFetchResponse for type: " |
| 421 << type << ", entity: " << entity_id << ", ignoring"; | 420 << type << ", entity: " << entity_id << ", ignoring"; |
| 422 continue; | 421 continue; |
| 423 } | 422 } |
| 424 responses_[key] = new em::PolicyFetchResponse(response); | 423 responses_[key] = new em::PolicyFetchResponse(response); |
| 425 } | 424 } |
| 426 if (status_provider_) | |
| 427 status_provider_->OnSubmittedSuccessfully(); | |
| 428 state_keys_to_upload_.clear(); | 425 state_keys_to_upload_.clear(); |
| 429 NotifyPolicyFetched(); | 426 NotifyPolicyFetched(); |
| 430 } else { | 427 } else { |
| 431 NotifyClientError(); | 428 NotifyClientError(); |
| 432 } | 429 } |
| 433 } | 430 } |
| 434 | 431 |
| 435 void CloudPolicyClient::OnUnregisterCompleted( | 432 void CloudPolicyClient::OnUnregisterCompleted( |
| 436 DeviceManagementStatus status, | 433 DeviceManagementStatus status, |
| 437 int net_error, | 434 int net_error, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 | 477 |
| 481 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { | 478 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { |
| 482 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); | 479 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); |
| 483 } | 480 } |
| 484 | 481 |
| 485 void CloudPolicyClient::NotifyClientError() { | 482 void CloudPolicyClient::NotifyClientError() { |
| 486 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 483 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); |
| 487 } | 484 } |
| 488 | 485 |
| 489 } // namespace policy | 486 } // namespace policy |
| OLD | NEW |