| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "chrome/browser/chromeos/policy/heartbeat_scheduler.h" | 5 #include "chrome/browser/chromeos/policy/heartbeat_scheduler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/macros.h" |
| 13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "components/gcm_driver/gcm_driver.h" | 18 #include "components/gcm_driver/gcm_driver.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 const int kMinHeartbeatIntervalMs = 30 * 1000; // 30 seconds | 21 const int kMinHeartbeatIntervalMs = 30 * 1000; // 30 seconds |
| 21 const int kMaxHeartbeatIntervalMs = 24 * 60 * 60 * 1000; // 24 hours | 22 const int kMaxHeartbeatIntervalMs = 24 * 60 * 60 * 1000; // 24 hours |
| 22 | 23 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 37 | 38 |
| 38 const char* kGcmMessageTypeKey = "type"; | 39 const char* kGcmMessageTypeKey = "type"; |
| 39 const char* kHeartbeatTimestampKey = "timestamp"; | 40 const char* kHeartbeatTimestampKey = "timestamp"; |
| 40 const char* kHeartbeatDomainNameKey = "domain_name"; | 41 const char* kHeartbeatDomainNameKey = "domain_name"; |
| 41 const char* kHeartbeatDeviceIDKey = "device_id"; | 42 const char* kHeartbeatDeviceIDKey = "device_id"; |
| 42 const char* kHeartbeatTypeValue = "hb"; | 43 const char* kHeartbeatTypeValue = "hb"; |
| 43 const char* kUpstreamNotificationNotifyKey = "notify"; | 44 const char* kUpstreamNotificationNotifyKey = "notify"; |
| 44 const char* kUpstreamNotificationRegIdKey = "registration_id"; | 45 const char* kUpstreamNotificationRegIdKey = "registration_id"; |
| 45 | 46 |
| 46 // If we get an error registering with GCM, try again in two minutes. | 47 // If we get an error registering with GCM, try again in two minutes. |
| 47 const int64 kRegistrationRetryDelayMs = 2 * 60 * 1000; | 48 const int64_t kRegistrationRetryDelayMs = 2 * 60 * 1000; |
| 48 | 49 |
| 49 const char* kHeartbeatSchedulerScope = | 50 const char* kHeartbeatSchedulerScope = |
| 50 "policy.heartbeat_scheduler.upstream_notification"; | 51 "policy.heartbeat_scheduler.upstream_notification"; |
| 51 | 52 |
| 52 // Returns the destination ID for GCM heartbeats. | 53 // Returns the destination ID for GCM heartbeats. |
| 53 std::string GetDestinationID() { | 54 std::string GetDestinationID() { |
| 54 std::string receiver_id = kHeartbeatGCMDestinationID; | 55 std::string receiver_id = kHeartbeatGCMDestinationID; |
| 55 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 56 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 56 switches::kMonitoringDestinationID)) { | 57 switches::kMonitoringDestinationID)) { |
| 57 receiver_id = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 58 receiver_id = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 58 switches::kMonitoringDestinationID); | 59 switches::kMonitoringDestinationID); |
| 59 } | 60 } |
| 60 return receiver_id; | 61 return receiver_id; |
| 61 } | 62 } |
| 62 | 63 |
| 63 } // namespace | 64 } // namespace |
| 64 | 65 |
| 65 namespace policy { | 66 namespace policy { |
| 66 | 67 |
| 67 const int64 HeartbeatScheduler::kDefaultHeartbeatIntervalMs = | 68 const int64_t HeartbeatScheduler::kDefaultHeartbeatIntervalMs = |
| 68 2 * 60 * 1000; // 2 minutes | 69 2 * 60 * 1000; // 2 minutes |
| 69 | 70 |
| 70 // Helper class used to manage GCM registration (handles retrying after | 71 // Helper class used to manage GCM registration (handles retrying after |
| 71 // errors, etc). | 72 // errors, etc). |
| 72 class HeartbeatRegistrationHelper { | 73 class HeartbeatRegistrationHelper { |
| 73 public: | 74 public: |
| 74 typedef base::Callback<void(const std::string& registration_id)> | 75 typedef base::Callback<void(const std::string& registration_id)> |
| 75 RegistrationHelperCallback; | 76 RegistrationHelperCallback; |
| 76 | 77 |
| 77 HeartbeatRegistrationHelper( | 78 HeartbeatRegistrationHelper( |
| 78 gcm::GCMDriver* gcm_driver, | 79 gcm::GCMDriver* gcm_driver, |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 void HeartbeatScheduler::OnConnected(const net::IPEndPoint&) { | 441 void HeartbeatScheduler::OnConnected(const net::IPEndPoint&) { |
| 441 SignUpUpstreamNotification(); | 442 SignUpUpstreamNotification(); |
| 442 } | 443 } |
| 443 | 444 |
| 444 void HeartbeatScheduler::OnGcmIdUpdateRequestSent(bool success) { | 445 void HeartbeatScheduler::OnGcmIdUpdateRequestSent(bool success) { |
| 445 // TODO(binjin): Handle the failure, probably by exponential backoff. | 446 // TODO(binjin): Handle the failure, probably by exponential backoff. |
| 446 LOG_IF(WARNING, !success) << "Failed to send GCM id to DM server"; | 447 LOG_IF(WARNING, !success) << "Failed to send GCM id to DM server"; |
| 447 } | 448 } |
| 448 | 449 |
| 449 } // namespace policy | 450 } // namespace policy |
| OLD | NEW |