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

Side by Side Diff: chrome/browser/policy/cloud/cloud_policy_invalidator.h

Issue 213743014: Add an extra delay for policy invalidations to be available. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/policy/cloud/cloud_policy_invalidator.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_ 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_ 6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "components/policy/core/common/cloud/cloud_policy_core.h" 16 #include "components/policy/core/common/cloud/cloud_policy_core.h"
17 #include "components/policy/core/common/cloud/cloud_policy_store.h" 17 #include "components/policy/core/common/cloud/cloud_policy_store.h"
18 #include "google/cacheinvalidation/include/types.h" 18 #include "google/cacheinvalidation/include/types.h"
19 #include "sync/internal_api/public/base/invalidation.h" 19 #include "sync/internal_api/public/base/invalidation.h"
20 #include "sync/notifier/invalidation_handler.h" 20 #include "sync/notifier/invalidation_handler.h"
21 21
22 namespace base { 22 namespace base {
23 class Clock;
23 class SequencedTaskRunner; 24 class SequencedTaskRunner;
24 } 25 }
25 26
26 namespace invalidation { 27 namespace invalidation {
27 class InvalidationService; 28 class InvalidationService;
28 } 29 }
29 30
30 namespace policy { 31 namespace policy {
31 32
32 // Listens for and provides policy invalidations. 33 // Listens for and provides policy invalidations.
33 class CloudPolicyInvalidator : public syncer::InvalidationHandler, 34 class CloudPolicyInvalidator : public syncer::InvalidationHandler,
34 public CloudPolicyCore::Observer, 35 public CloudPolicyCore::Observer,
35 public CloudPolicyStore::Observer { 36 public CloudPolicyStore::Observer {
36 public: 37 public:
37 // The number of minutes to delay a policy refresh after receiving an 38 // The number of minutes to delay a policy refresh after receiving an
38 // invalidation with no payload. 39 // invalidation with no payload.
39 static const int kMissingPayloadDelay; 40 static const int kMissingPayloadDelay;
40 41
41 // The default, min and max values for max_fetch_delay_. 42 // The default, min and max values for max_fetch_delay_.
42 static const int kMaxFetchDelayDefault; 43 static const int kMaxFetchDelayDefault;
43 static const int kMaxFetchDelayMin; 44 static const int kMaxFetchDelayMin;
44 static const int kMaxFetchDelayMax; 45 static const int kMaxFetchDelayMax;
45 46
47 // The grace period, in seconds, to allow for invalidations to be received
48 // once the invalidation service starts up.
49 static const int kInvalidationGracePeriod;
50
46 // |core| is the cloud policy core which connects the various policy objects. 51 // |core| is the cloud policy core which connects the various policy objects.
47 // It must remain valid until Shutdown is called. 52 // It must remain valid until Shutdown is called.
48 // |task_runner| is used for scheduling delayed tasks. It must post tasks to 53 // |task_runner| is used for scheduling delayed tasks. It must post tasks to
49 // the main policy thread. 54 // the main policy thread.
55 // |clock| is used to get the current time. This object takes ownership of the
56 // clock.
50 CloudPolicyInvalidator( 57 CloudPolicyInvalidator(
51 CloudPolicyCore* core, 58 CloudPolicyCore* core,
52 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 59 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
60 base::Clock* clock);
Joao da Silva 2014/04/02 07:16:01 Pass this in a scoped_ptr to make the ownership se
Steve Condie 2014/04/02 18:48:15 Done.
53 virtual ~CloudPolicyInvalidator(); 61 virtual ~CloudPolicyInvalidator();
54 62
55 // Initializes the invalidator. No invalidations will be generated before this 63 // Initializes the invalidator. No invalidations will be generated before this
56 // method is called. This method must only be called once. 64 // method is called. This method must only be called once.
57 // |invalidation_service| is the invalidation service to use and must remain 65 // |invalidation_service| is the invalidation service to use and must remain
58 // valid until Shutdown is called. 66 // valid until Shutdown is called.
59 void Initialize(invalidation::InvalidationService* invalidation_service); 67 void Initialize(invalidation::InvalidationService* invalidation_service);
60 68
61 // Shuts down and disables invalidations. It must be called before the object 69 // Shuts down and disables invalidations. It must be called before the object
62 // is destroyed. 70 // is destroyed.
(...skipping 22 matching lines...) Expand all
85 93
86 private: 94 private:
87 // Handle an invalidation to the policy. 95 // Handle an invalidation to the policy.
88 void HandleInvalidation(const syncer::Invalidation& invalidation); 96 void HandleInvalidation(const syncer::Invalidation& invalidation);
89 97
90 // Update object registration with the invalidation service based on the 98 // Update object registration with the invalidation service based on the
91 // given policy data. 99 // given policy data.
92 void UpdateRegistration(const enterprise_management::PolicyData* policy); 100 void UpdateRegistration(const enterprise_management::PolicyData* policy);
93 101
94 // Registers the given object with the invalidation service. 102 // Registers the given object with the invalidation service.
95 void Register(int64 timestamp, const invalidation::ObjectId& object_id); 103 void Register(const invalidation::ObjectId& object_id);
96 104
97 // Unregisters the current object with the invalidation service. 105 // Unregisters the current object with the invalidation service.
98 void Unregister(); 106 void Unregister();
99 107
100 // Update |max_fetch_delay_| based on the given policy map. 108 // Update |max_fetch_delay_| based on the given policy map.
101 void UpdateMaxFetchDelay(const PolicyMap& policy_map); 109 void UpdateMaxFetchDelay(const PolicyMap& policy_map);
102 void set_max_fetch_delay(int delay); 110 void set_max_fetch_delay(int delay);
103 111
104 // Updates invalidations_enabled_ and calls the invalidation handler if the 112 // Updates invalidations_enabled_ and calls the invalidation handler if the
105 // value changed. 113 // value changed.
106 void UpdateInvalidationsEnabled(); 114 void UpdateInvalidationsEnabled();
107 115
108 // Refresh the policy. 116 // Refresh the policy.
109 // |is_missing_payload| is set to true if the callback is being invoked in 117 // |is_missing_payload| is set to true if the callback is being invoked in
110 // response to an invalidation with a missing payload. 118 // response to an invalidation with a missing payload.
111 void RefreshPolicy(bool is_missing_payload); 119 void RefreshPolicy(bool is_missing_payload);
112 120
113 // Acknowledge the latest invalidation. 121 // Acknowledge the latest invalidation.
114 void AcknowledgeInvalidation(); 122 void AcknowledgeInvalidation();
115 123
116 // Determines if the given policy is different from the policy passed in the 124 // Determines if the given policy is different from the policy passed in the
117 // previous call. 125 // previous call.
118 bool IsPolicyChanged(const enterprise_management::PolicyData* policy); 126 bool IsPolicyChanged(const enterprise_management::PolicyData* policy);
119 127
120 // Get the kMetricPolicyRefresh histogram metric which should be incremented 128 // Get the kMetricPolicyRefresh histogram metric which should be incremented
121 // when a policy is stored. 129 // when a policy is stored.
122 int GetPolicyRefreshMetric(bool policy_changed); 130 int GetPolicyRefreshMetric(bool policy_changed);
123 131
132 // Determine if invalidations have been enabled longer than the grace period.
133 bool GetInvalidationsEnabled();
134
124 // The state of the object. 135 // The state of the object.
125 enum State { 136 enum State {
126 UNINITIALIZED, 137 UNINITIALIZED,
127 STOPPED, 138 STOPPED,
128 STARTED, 139 STARTED,
129 SHUT_DOWN 140 SHUT_DOWN
130 }; 141 };
131 State state_; 142 State state_;
132 143
133 // The cloud policy core. 144 // The cloud policy core.
134 CloudPolicyCore* core_; 145 CloudPolicyCore* core_;
135 146
136 // Schedules delayed tasks. 147 // Schedules delayed tasks.
137 const scoped_refptr<base::SequencedTaskRunner> task_runner_; 148 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
138 149
150 // The clock.
151 scoped_ptr<base::Clock> clock_;
152
139 // The invalidation service. 153 // The invalidation service.
140 invalidation::InvalidationService* invalidation_service_; 154 invalidation::InvalidationService* invalidation_service_;
141 155
142 // Whether the invalidator currently has the ability to receive invalidations. 156 // Whether the invalidator currently has the ability to receive invalidations.
143 // This is true if the invalidation service is enabled and the invalidator 157 // This is true if the invalidation service is enabled and the invalidator
144 // has registered for a policy object. 158 // has registered for a policy object.
145 bool invalidations_enabled_; 159 bool invalidations_enabled_;
146 160
161 // The time that invalidations became enabled.
162 base::Time invalidations_enabled_time_;
163
147 // Whether the invalidation service is currently enabled. 164 // Whether the invalidation service is currently enabled.
148 bool invalidation_service_enabled_; 165 bool invalidation_service_enabled_;
149 166
150 // The timestamp of the PolicyData at which this object registered for policy 167 // Whether this object has registered for policy invalidations.
151 // invalidations. Set to zero if the object has not registered yet. 168 bool is_registered_;
152 int64 registered_timestamp_;
153 169
154 // The object id representing the policy in the invalidation service. 170 // The object id representing the policy in the invalidation service.
155 invalidation::ObjectId object_id_; 171 invalidation::ObjectId object_id_;
156 172
157 // Whether the policy is current invalid. This is set to true when an 173 // Whether the policy is current invalid. This is set to true when an
158 // invalidation is received and reset when the policy fetched due to the 174 // invalidation is received and reset when the policy fetched due to the
159 // invalidation is stored. 175 // invalidation is stored.
160 bool invalid_; 176 bool invalid_;
161 177
162 // The version of the latest invalidation received. This is compared to 178 // The version of the latest invalidation received. This is compared to
(...skipping 23 matching lines...) Expand all
186 // A thread checker to make sure that callbacks are invoked on the correct 202 // A thread checker to make sure that callbacks are invoked on the correct
187 // thread. 203 // thread.
188 base::ThreadChecker thread_checker_; 204 base::ThreadChecker thread_checker_;
189 205
190 DISALLOW_COPY_AND_ASSIGN(CloudPolicyInvalidator); 206 DISALLOW_COPY_AND_ASSIGN(CloudPolicyInvalidator);
191 }; 207 };
192 208
193 } // namespace policy 209 } // namespace policy
194 210
195 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_ 211 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/policy/cloud/cloud_policy_invalidator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698