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..6dbe2c8c1f7ccf9e7d4c9fcc1e38ddccdac8fdf3 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,13 @@ void HeartbeatScheduler::OnRegistrationComplete( |
| registration_helper_.reset(); |
| registration_id_ = registration_id; |
| + if (cloud_policy_client_) { |
| + cloud_policy_client_->UpdateGcmIdMapping( |
|
Andrew T Wilson (Slow)
2015/08/03 13:52:26
Log a bug and add a TODO() here to avoid unnecessa
binjin
2015/08/03 17:54:25
Done.
|
| + registration_id, |
| + base::Bind(&HeartbeatScheduler::OnGcmIdMappingRequestSent, |
| + base::Unretained(this))); |
|
Andrew T Wilson (Slow)
2015/08/03 13:52:26
Use a weak pointer here instead of Unretained().
binjin
2015/08/03 17:54:25
Done.
|
| + } |
| + |
| // Now that GCM registration is complete, start sending heartbeats. |
| ScheduleNextHeartbeat(); |
| } |
| @@ -372,4 +388,10 @@ void HeartbeatScheduler::OnSendAcknowledged(const std::string& app_id, |
| DVLOG(1) << "Heartbeat sent with message_id: " << message_id; |
| } |
| +void HeartbeatScheduler::OnGcmIdMappingRequestSent(bool status) { |
| + latest_gcm_id_mapping_succeeded_ = status; |
|
Andrew T Wilson (Slow)
2015/08/03 13:52:26
Why do we bother having a callback here at all? We
binjin
2015/08/03 17:54:25
Okay, removed the latest_gcm_id_mapping_succeeded
|
| + if (!status) |
| + LOG(WARNING) << "Failed to send GCM id to DM server"; |
|
Andrew T Wilson (Slow)
2015/08/03 13:52:26
Use LOG_IF() instead of if() { LOG() }
binjin
2015/08/03 17:54:25
Done.
|
| +} |
| + |
| } // namespace policy |