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

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

Issue 1276853003: Revert of Send GCM id to DMServer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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) 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/policy/core/common/cloud/cloud_policy_client.h"
20 19
21 namespace base { 20 namespace base {
22 class SequencedTaskRunner; 21 class SequencedTaskRunner;
23 } 22 }
24 23
25 namespace gcm { 24 namespace gcm {
26 class GCMDriver; 25 class GCMDriver;
27 } 26 }
28 27
29 namespace policy { 28 namespace policy {
30 29
31 class EnterpriseInstallAttributes; 30 class EnterpriseInstallAttributes;
32 class HeartbeatRegistrationHelper; 31 class HeartbeatRegistrationHelper;
33 32
34 // Class responsible for periodically sending heartbeats to the policy service 33 // Class responsible for periodically sending heartbeats to the policy service
35 // for monitoring device connectivity. 34 // for monitoring device connectivity.
36 class HeartbeatScheduler : public gcm::GCMAppHandler { 35 class HeartbeatScheduler : public gcm::GCMAppHandler {
37 public: 36 public:
38 // Default interval for how often we send up a heartbeat. 37 // Default interval for how often we send up a heartbeat.
39 static const int64 kDefaultHeartbeatIntervalMs; 38 static const int64 kDefaultHeartbeatIntervalMs;
40 39
41 // Constructor. |cloud_policy_client| will be used to send registered GCM id 40 // Constructor. |driver| can be null for tests.
42 // to DM server, and can be null. |driver| can be null for tests.
43 HeartbeatScheduler( 41 HeartbeatScheduler(
44 gcm::GCMDriver* driver, 42 gcm::GCMDriver* driver,
45 policy::CloudPolicyClient* cloud_policy_client,
46 const std::string& enrollment_domain, 43 const std::string& enrollment_domain,
47 const std::string& device_id, 44 const std::string& device_id,
48 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 45 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
49 46
50 ~HeartbeatScheduler() override; 47 ~HeartbeatScheduler() override;
51 48
52 // Returns the time of the last heartbeat, or Time(0) if no heartbeat 49 // Returns the time of the last heartbeat, or Time(0) if no heartbeat
53 // has ever happened. 50 // has ever happened.
54 base::Time last_heartbeat() const { return last_heartbeat_; } 51 base::Time last_heartbeat() const { return last_heartbeat_; }
55 52
(...skipping 26 matching lines...) Expand all
82 // schedules the next heartbeat. 79 // schedules the next heartbeat.
83 void RefreshHeartbeatSettings(); 80 void RefreshHeartbeatSettings();
84 81
85 // Ensures that the passed interval is within a valid range (not too large or 82 // Ensures that the passed interval is within a valid range (not too large or
86 // too small). 83 // too small).
87 base::TimeDelta EnsureValidHeartbeatInterval(const base::TimeDelta& interval); 84 base::TimeDelta EnsureValidHeartbeatInterval(const base::TimeDelta& interval);
88 85
89 // Shuts down our GCM connection (called when heartbeats are disabled). 86 // Shuts down our GCM connection (called when heartbeats are disabled).
90 void ShutdownGCM(); 87 void ShutdownGCM();
91 88
92 // Callback for the GCM id update request.
93 void OnGcmIdUpdateRequestSent(bool status);
94
95 // TaskRunner used for scheduling heartbeats. 89 // TaskRunner used for scheduling heartbeats.
96 const scoped_refptr<base::SequencedTaskRunner> task_runner_; 90 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
97 91
98 // The domain that this device is enrolled to. 92 // The domain that this device is enrolled to.
99 const std::string enrollment_domain_; 93 const std::string enrollment_domain_;
100 94
101 // The device_id for this device - sent up with the enrollment domain with 95 // The device_id for this device - sent up with the enrollment domain with
102 // heartbeats to identify the device to the server. 96 // heartbeats to identify the device to the server.
103 const std::string device_id_; 97 const std::string device_id_;
104 98
(...skipping 10 matching lines...) Expand all
115 heartbeat_frequency_observer_; 109 heartbeat_frequency_observer_;
116 scoped_ptr<chromeos::CrosSettings::ObserverSubscription> 110 scoped_ptr<chromeos::CrosSettings::ObserverSubscription>
117 heartbeat_enabled_observer_; 111 heartbeat_enabled_observer_;
118 112
119 // The time the last heartbeat was sent. 113 // The time the last heartbeat was sent.
120 base::Time last_heartbeat_; 114 base::Time last_heartbeat_;
121 115
122 // Callback invoked via a delay to send a heartbeat. 116 // Callback invoked via a delay to send a heartbeat.
123 base::CancelableClosure heartbeat_callback_; 117 base::CancelableClosure heartbeat_callback_;
124 118
125 policy::CloudPolicyClient* cloud_policy_client_;
126
127 // The GCMDriver used to send heartbeat messages. 119 // The GCMDriver used to send heartbeat messages.
128 gcm::GCMDriver* const gcm_driver_; 120 gcm::GCMDriver* const gcm_driver_;
129 121
130 // The GCM registration ID - if empty, we are not registered yet. 122 // The GCM registration ID - if empty, we are not registered yet.
131 std::string registration_id_; 123 std::string registration_id_;
132 124
133 // If true, we are already registered with GCM and should unregister when 125 // If true, we are already registered with GCM and should unregister when
134 // destroyed. 126 // destroyed.
135 bool registered_app_handler_ = false; 127 bool registered_app_handler_ = false;
136 128
137 // Helper class to manage registering with the GCM server, including 129 // Helper class to manage registering with the GCM server, including
138 // retries, etc. 130 // retries, etc.
139 scoped_ptr<HeartbeatRegistrationHelper> registration_helper_; 131 scoped_ptr<HeartbeatRegistrationHelper> registration_helper_;
140 132
141 // Note: This should remain the last member so it'll be destroyed and 133 // Note: This should remain the last member so it'll be destroyed and
142 // invalidate the weak pointers before any other members are destroyed. 134 // invalidate the weak pointers before any other members are destroyed.
143 base::WeakPtrFactory<HeartbeatScheduler> weak_factory_; 135 base::WeakPtrFactory<HeartbeatScheduler> weak_factory_;
144 136
145 DISALLOW_COPY_AND_ASSIGN(HeartbeatScheduler); 137 DISALLOW_COPY_AND_ASSIGN(HeartbeatScheduler);
146 }; 138 };
147 139
148 } // namespace policy 140 } // namespace policy
149 141
150 #endif // CHROME_BROWSER_CHROMEOS_POLICY_HEARTBEAT_SCHEDULER_H_ 142 #endif // CHROME_BROWSER_CHROMEOS_POLICY_HEARTBEAT_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698