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

Side by Side Diff: chrome/browser/chromeos/policy/heartbeat_scheduler.h

Issue 1267983002: Signup for GCM upstream notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gcm-registration
Patch Set: add heartbeats bits Created 5 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/heartbeat_scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_HEARTBEAT_SCHEDULER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_HEARTBEAT_SCHEDULER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_HEARTBEAT_SCHEDULER_H_ 6 #define CHROME_BROWSER_CHROMEOS_POLICY_HEARTBEAT_SCHEDULER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/cancelable_callback.h" 11 #include "base/cancelable_callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "chrome/browser/chromeos/settings/cros_settings.h" 16 #include "chrome/browser/chromeos/settings/cros_settings.h"
17 #include "components/gcm_driver/gcm_app_handler.h" 17 #include "components/gcm_driver/gcm_app_handler.h"
18 #include "components/gcm_driver/gcm_client.h" 18 #include "components/gcm_driver/gcm_client.h"
19 #include "components/gcm_driver/gcm_connection_observer.h"
19 #include "components/policy/core/common/cloud/cloud_policy_client.h" 20 #include "components/policy/core/common/cloud/cloud_policy_client.h"
20 21
21 namespace base { 22 namespace base {
22 class SequencedTaskRunner; 23 class SequencedTaskRunner;
23 } 24 }
24 25
25 namespace gcm { 26 namespace gcm {
26 class GCMDriver; 27 class GCMDriver;
27 } 28 }
28 29
29 namespace policy { 30 namespace policy {
30 31
31 class EnterpriseInstallAttributes; 32 class EnterpriseInstallAttributes;
32 class HeartbeatRegistrationHelper; 33 class HeartbeatRegistrationHelper;
33 34
34 // Class responsible for periodically sending heartbeats to the policy service 35 // Class responsible for periodically sending heartbeats to the policy service
35 // for monitoring device connectivity. 36 // for monitoring device connectivity.
36 class HeartbeatScheduler : public gcm::GCMAppHandler { 37 class HeartbeatScheduler : public gcm::GCMAppHandler,
38 gcm::GCMConnectionObserver {
37 public: 39 public:
38 // Default interval for how often we send up a heartbeat. 40 // Default interval for how often we send up a heartbeat.
39 static const int64 kDefaultHeartbeatIntervalMs; 41 static const int64 kDefaultHeartbeatIntervalMs;
40 42
41 // Constructor. |cloud_policy_client| will be used to send registered GCM id 43 // Constructor. |cloud_policy_client| will be used to send registered GCM id
42 // to DM server, and can be null. |driver| can be null for tests. 44 // to DM server, and can be null. |driver| can be null for tests.
43 HeartbeatScheduler( 45 HeartbeatScheduler(
44 gcm::GCMDriver* driver, 46 gcm::GCMDriver* driver,
45 policy::CloudPolicyClient* cloud_policy_client, 47 policy::CloudPolicyClient* cloud_policy_client,
46 const std::string& enrollment_domain, 48 const std::string& enrollment_domain,
47 const std::string& device_id, 49 const std::string& device_id,
48 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 50 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
49 51
50 ~HeartbeatScheduler() override; 52 ~HeartbeatScheduler() override;
51 53
52 // Returns the time of the last heartbeat, or Time(0) if no heartbeat 54 // Returns the time of the last heartbeat, or Time(0) if no heartbeat
53 // has ever happened. 55 // has ever happened.
54 base::Time last_heartbeat() const { return last_heartbeat_; } 56 base::Time last_heartbeat() const { return last_heartbeat_; }
55 57
56 // GCMAppHandler overrides. 58 // GCMAppHandler overrides.
57 void ShutdownHandler() override; 59 void ShutdownHandler() override;
58 void OnMessage(const std::string& app_id, 60 void OnMessage(const std::string& app_id,
59 const gcm::IncomingMessage& message) override; 61 const gcm::IncomingMessage& message) override;
60 void OnMessagesDeleted(const std::string& app_id) override; 62 void OnMessagesDeleted(const std::string& app_id) override;
61 void OnSendError(const std::string& app_id, 63 void OnSendError(const std::string& app_id,
62 const gcm::GCMClient::SendErrorDetails& details) override; 64 const gcm::GCMClient::SendErrorDetails& details) override;
63 void OnSendAcknowledged(const std::string& app_id, 65 void OnSendAcknowledged(const std::string& app_id,
64 const std::string& message_id) override; 66 const std::string& message_id) override;
65 67
68 // GCMConnectionObserver overrides.
69 void OnConnected(const net::IPEndPoint&) override;
70
66 private: 71 private:
67 // Callback invoked periodically to send a heartbeat to the policy service. 72 // Callback invoked periodically to send a heartbeat to the policy service.
68 void SendHeartbeat(); 73 void SendHeartbeat();
69 74
70 // Invoked after GCM registration has successfully completed. 75 // Invoked after GCM registration has successfully completed.
71 void OnRegistrationComplete(const std::string& registration_id); 76 void OnRegistrationComplete(const std::string& registration_id);
72 77
73 // Invoked after a heartbeat has been sent to the server. 78 // Invoked after a heartbeat has been sent to the server.
74 void OnHeartbeatSent(const std::string& message_id, 79 void OnHeartbeatSent(const std::string& message_id,
75 gcm::GCMClient::Result result); 80 gcm::GCMClient::Result result);
76 81
82 // Invoked after a upstream notification sign up message has been sent.
83 void OnUpstreamNotificationSent(const std::string& message_id,
84 gcm::GCMClient::Result result);
85
77 // Helper method that figures out when the next heartbeat should 86 // Helper method that figures out when the next heartbeat should
78 // be scheduled. 87 // be scheduled.
79 void ScheduleNextHeartbeat(); 88 void ScheduleNextHeartbeat();
80 89
81 // Updates the heartbeat-enabled status and frequency from settings and 90 // Updates the heartbeat-enabled status and frequency from settings and
82 // schedules the next heartbeat. 91 // schedules the next heartbeat.
83 void RefreshHeartbeatSettings(); 92 void RefreshHeartbeatSettings();
84 93
85 // Ensures that the passed interval is within a valid range (not too large or 94 // Ensures that the passed interval is within a valid range (not too large or
86 // too small). 95 // too small).
87 base::TimeDelta EnsureValidHeartbeatInterval(const base::TimeDelta& interval); 96 base::TimeDelta EnsureValidHeartbeatInterval(const base::TimeDelta& interval);
88 97
89 // Shuts down our GCM connection (called when heartbeats are disabled). 98 // Shuts down our GCM connection (called when heartbeats are disabled).
90 void ShutdownGCM(); 99 void ShutdownGCM();
91 100
92 // Callback for the GCM id update request. 101 // Callback for the GCM id update request.
93 void OnGcmIdUpdateRequestSent(bool status); 102 void OnGcmIdUpdateRequestSent(bool status);
94 103
104 // Helper function to signup for upstream notification.
105 void SignUpUpstreamNotification();
106
95 // TaskRunner used for scheduling heartbeats. 107 // TaskRunner used for scheduling heartbeats.
96 const scoped_refptr<base::SequencedTaskRunner> task_runner_; 108 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
97 109
98 // The domain that this device is enrolled to. 110 // The domain that this device is enrolled to.
99 const std::string enrollment_domain_; 111 const std::string enrollment_domain_;
100 112
101 // The device_id for this device - sent up with the enrollment domain with 113 // The device_id for this device - sent up with the enrollment domain with
102 // heartbeats to identify the device to the server. 114 // heartbeats to identify the device to the server.
103 const std::string device_id_; 115 const std::string device_id_;
104 116
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Note: This should remain the last member so it'll be destroyed and 153 // Note: This should remain the last member so it'll be destroyed and
142 // invalidate the weak pointers before any other members are destroyed. 154 // invalidate the weak pointers before any other members are destroyed.
143 base::WeakPtrFactory<HeartbeatScheduler> weak_factory_; 155 base::WeakPtrFactory<HeartbeatScheduler> weak_factory_;
144 156
145 DISALLOW_COPY_AND_ASSIGN(HeartbeatScheduler); 157 DISALLOW_COPY_AND_ASSIGN(HeartbeatScheduler);
146 }; 158 };
147 159
148 } // namespace policy 160 } // namespace policy
149 161
150 #endif // CHROME_BROWSER_CHROMEOS_POLICY_HEARTBEAT_SCHEDULER_H_ 162 #endif // CHROME_BROWSER_CHROMEOS_POLICY_HEARTBEAT_SCHEDULER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/heartbeat_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698