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

Side by Side Diff: components/policy/core/common/cloud/cloud_policy_client.cc

Issue 1258313002: Send GCM id to DMServer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add tests Created 5 years, 4 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
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 "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/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 request->set_location(location); 370 request->set_location(location);
371 371
372 const DeviceManagementRequestJob::Callback job_callback = 372 const DeviceManagementRequestJob::Callback job_callback =
373 base::Bind(&CloudPolicyClient::OnDeviceAttributeUpdated, 373 base::Bind(&CloudPolicyClient::OnDeviceAttributeUpdated,
374 base::Unretained(this), request_job.get(), callback); 374 base::Unretained(this), request_job.get(), callback);
375 375
376 request_jobs_.push_back(request_job.Pass()); 376 request_jobs_.push_back(request_job.Pass());
377 request_jobs_.back()->Start(job_callback); 377 request_jobs_.back()->Start(job_callback);
378 } 378 }
379 379
380 void CloudPolicyClient::UpdateGcmIdMapping(
381 const std::string& gcm_id,
382 const CloudPolicyClient::StatusCallback& callback) {
383 CHECK(is_registered());
384
385 scoped_ptr<DeviceManagementRequestJob> request_job(service_->CreateJob(
386 DeviceManagementRequestJob::TYPE_GCM_ID_MAPPING, GetRequestContext()));
387
388 request_job->SetDMToken(dm_token_);
389 request_job->SetClientID(client_id_);
390
391 em::GcmIdMappingRequest* const request =
392 request_job->GetRequest()->mutable_gcm_id_mapping_request();
393
394 request->set_gcm_id(gcm_id);
395
396 const DeviceManagementRequestJob::Callback job_callback =
397 base::Bind(&CloudPolicyClient::OnGcmIdMappingUpdated,
398 base::Unretained(this), request_job.get(), callback);
399
400 request_jobs_.push_back(request_job.Pass());
401 request_jobs_.back()->Start(job_callback);
402 }
403
380 void CloudPolicyClient::AddObserver(Observer* observer) { 404 void CloudPolicyClient::AddObserver(Observer* observer) {
381 observers_.AddObserver(observer); 405 observers_.AddObserver(observer);
382 } 406 }
383 407
384 void CloudPolicyClient::RemoveObserver(Observer* observer) { 408 void CloudPolicyClient::RemoveObserver(Observer* observer) {
385 observers_.RemoveObserver(observer); 409 observers_.RemoveObserver(observer);
386 } 410 }
387 411
388 void CloudPolicyClient::AddPolicyTypeToFetch( 412 void CloudPolicyClient::AddPolicyTypeToFetch(
389 const std::string& policy_type, 413 const std::string& policy_type,
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 commands.push_back(command); 682 commands.push_back(command);
659 } else { 683 } else {
660 status = DM_STATUS_RESPONSE_DECODING_ERROR; 684 status = DM_STATUS_RESPONSE_DECODING_ERROR;
661 } 685 }
662 } 686 }
663 callback.Run(status, commands); 687 callback.Run(status, commands);
664 // Must call RemoveJob() last, because it frees |callback|. 688 // Must call RemoveJob() last, because it frees |callback|.
665 RemoveJob(job); 689 RemoveJob(job);
666 } 690 }
667 691
692 void CloudPolicyClient::OnGcmIdMappingUpdated(
693 const DeviceManagementRequestJob* job,
694 const StatusCallback& callback,
695 DeviceManagementStatus status,
696 int net_error,
697 const enterprise_management::DeviceManagementResponse& response) {
698 callback.Run(status == DM_STATUS_SUCCESS);
Andrew T Wilson (Slow) 2015/08/03 13:52:26 Should we call NotifyClientError() and update stat
binjin 2015/08/03 17:54:25 I thought it's not essential. Both onClientError()
699 RemoveJob(job);
700 }
701
668 void CloudPolicyClient::NotifyPolicyFetched() { 702 void CloudPolicyClient::NotifyPolicyFetched() {
669 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyFetched(this)); 703 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyFetched(this));
670 } 704 }
671 705
672 void CloudPolicyClient::NotifyRegistrationStateChanged() { 706 void CloudPolicyClient::NotifyRegistrationStateChanged() {
673 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); 707 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this));
674 } 708 }
675 709
676 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { 710 void CloudPolicyClient::NotifyRobotAuthCodesFetched() {
677 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); 711 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this));
678 } 712 }
679 713
680 void CloudPolicyClient::NotifyClientError() { 714 void CloudPolicyClient::NotifyClientError() {
681 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); 715 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this));
682 } 716 }
683 717
684 } // namespace policy 718 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698