Chromium Code Reviews| Index: chrome/browser/chromeos/policy/heartbeat_scheduler.cc |
| diff --git a/chrome/browser/chromeos/policy/heartbeat_scheduler.cc b/chrome/browser/chromeos/policy/heartbeat_scheduler.cc |
| index 4e4e4eff22166e6330b726a8238ad42e9256427c..78ea10449696b0b380a32e52a0720cf2c69024d6 100644 |
| --- a/chrome/browser/chromeos/policy/heartbeat_scheduler.cc |
| +++ b/chrome/browser/chromeos/policy/heartbeat_scheduler.cc |
| @@ -6,6 +6,8 @@ |
| #include <string> |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| #include "base/command_line.h" |
| #include "base/location.h" |
| #include "base/sequenced_task_runner.h" |
| @@ -160,6 +162,7 @@ void HeartbeatRegistrationHelper::OnRegisterAttemptComplete( |
| HeartbeatScheduler::HeartbeatScheduler( |
| gcm::GCMDriver* driver, |
| + policy::CloudPolicyClient* cloud_policy_client, |
| const std::string& enrollment_domain, |
| const std::string& device_id, |
| const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
| @@ -167,8 +170,9 @@ HeartbeatScheduler::HeartbeatScheduler( |
| enrollment_domain_(enrollment_domain), |
| device_id_(device_id), |
| heartbeat_enabled_(false), |
| - heartbeat_interval_(base::TimeDelta::FromMilliseconds( |
| - kDefaultHeartbeatIntervalMs)), |
| + heartbeat_interval_( |
| + base::TimeDelta::FromMilliseconds(kDefaultHeartbeatIntervalMs)), |
| + cloud_policy_client_(cloud_policy_client), |
| gcm_driver_(driver), |
| weak_factory_(this) { |
| // If no GCMDriver (e.g. this is loaded as part of an unrelated unit test) |
| @@ -193,6 +197,11 @@ HeartbeatScheduler::HeartbeatScheduler( |
| RefreshHeartbeatSettings(); |
| } |
| +void HeartbeatScheduler::SetCloudPolicyClientForTesting( |
| + policy::CloudPolicyClient* client) { |
| + cloud_policy_client_ = client; |
| +} |
| + |
| void HeartbeatScheduler::RefreshHeartbeatSettings() { |
| // Attempt to fetch the current value of the reporting settings. |
| // If trusted values are not available, register this function to be called |
| @@ -297,6 +306,15 @@ void HeartbeatScheduler::OnRegistrationComplete( |
| registration_helper_.reset(); |
| registration_id_ = registration_id; |
| + if (cloud_policy_client_) { |
| + // TODO(binjin): Avoid sending the same GCM id to the server. |
| + // See http://crbug.com/516375 |
| + cloud_policy_client_->UpdateGcmIdMapping( |
| + registration_id, |
| + base::Bind(&HeartbeatScheduler::OnGcmIdMappingRequestSent, |
| + weak_factory_.GetWeakPtr())); |
| + } |
| + |
| // Now that GCM registration is complete, start sending heartbeats. |
| ScheduleNextHeartbeat(); |
| } |
| @@ -372,4 +390,9 @@ void HeartbeatScheduler::OnSendAcknowledged(const std::string& app_id, |
| DVLOG(1) << "Heartbeat sent with message_id: " << message_id; |
| } |
| +void HeartbeatScheduler::OnGcmIdMappingRequestSent(bool status) { |
|
Andrew T Wilson (Slow)
2015/08/06 09:40:02
nit: rename status -> success to make it clear tha
binjin
2015/08/06 10:19:15
Done.
|
| + // TODO(binjin): Handle the failure, probably by exponential backoff. |
| + LOG_IF(WARNING, !status) << "Failed to send GCM id to DM server"; |
| +} |
| + |
| } // namespace policy |