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

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

Issue 19733003: Implement cloud policy invalidations using the invalidation service framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_
7
8 #include <string>
Joao da Silva 2013/07/23 20:44:47 Not used
Steve Condie 2013/07/24 01:42:04 Done.
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
Joao da Silva 2013/07/23 20:44:47 Not used
Steve Condie 2013/07/24 01:42:04 Done.
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread_checker.h"
16 #include "chrome/browser/policy/cloud/cloud_policy_store.h"
17 #include "sync/notifier/invalidation_handler.h"
18
19 namespace base {
20 class SequencedTaskRunner;
21 }
22
23 namespace invalidation {
24 class InvalidationService;
25 }
26
27 namespace policy {
28
29 class CloudPolicyClient;
30 class CloudPolicyStore;
Joao da Silva 2013/07/23 20:44:47 cloud_policy_store.h already included
Steve Condie 2013/07/24 01:42:04 Done.
31
32 // Listens for and provides user policy invalidations.
33 class CloudPolicyInvalidator : public syncer::InvalidationHandler,
34 public CloudPolicyStore::Observer {
rlarocque 2013/07/23 17:43:08 nit: indentation.
Steve Condie 2013/07/24 01:42:04 Done.
35 public:
36 // The number of minutes to delay a policy refresh after receiving an
37 // invalidation with no payload.
38 static const int kMissingPayloadDelay;
39
40 // The default, min and max values for max_fetch_delay_.
41 static const int kMaxFetchDelayDefault;
42 static const int kMaxFetchDelayMin;
43 static const int kMaxFetchDelayMax;
44
45 // |invalidation_service| is the invalidation service which generates the
46 // invalidations and must remain valid during the lifetime of this object.
47 // |client| is cloud policy client. It must remain valid during the lifetime
48 // of this object.
49 // |store| is cloud policy store. It must remain valid during the lifetime
50 // of this object.
51 // |task_runner| is used for scheduling delayed tasks. It must post tasks to
52 // the main policy thread.
53 // |invalidate| is called when a user policy invalidation is
54 // received and must remain callable during the lifetime of this object.
55 // This callback should schedule a policy refresh in the near future to
56 // fetch the updated policy.
57 CloudPolicyInvalidator(
58 invalidation::InvalidationService* invalidation_service,
59 CloudPolicyClient* client,
60 CloudPolicyStore* store,
61 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
62 const base::Closure& invalidate);
63 ~CloudPolicyInvalidator();
Joao da Silva 2013/07/23 20:44:47 virtual
Steve Condie 2013/07/24 01:42:04 Done. Trybot caught this for me as well.
64
65 // Unregisters the policy object from the invalidation service. This method
66 // should only be called when policy is no longer applied; it should not be
67 // called for normal browser shutdown. This object should be destroyed
68 // immediately after calling this method.
69 void Unregister();
70
71 // syncer::InvalidationHandler:
72 virtual void OnInvalidatorStateChange(
73 syncer::InvalidatorState state) OVERRIDE;
74 virtual void OnIncomingInvalidation(
75 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE;
76
77 // CloudPolicyStore::Observer:
78 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE;
79 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE;
80
81 private:
82 // Handle an invalidation to the policy.
83 void HandleInvalidation(const syncer::Invalidation& invalidation);
84
85 // Update object registration with the invalidation service based on the
86 // given policy data.
87 void UpdateRegistration(const enterprise_management::PolicyData* policy);
88
89 // Update |max_fetch_delay_| based on the given policy map.
90 void UpdateMaxFetchDelay(const PolicyMap& policy_map);
91 void set_max_fetch_delay(int delay);
92
93 // Run the invalidate callback. is_missing_payload is set to true if the
94 // callback is being invoked in response to an invalidation with a missing
95 // payload.
96 void RunInvalidateCallback(bool is_missing_payload);
97
98 // Acknowledge the latest invalidation.
99 void AcknowledgeInvalidation();
100
101 // Get the kMetricPolicyRefresh histogram metric which should be incremented
102 // when a policy is stored.
103 int GetPolicyRefreshMetric();
104
105 // The invalidation service.
106 invalidation::InvalidationService* invalidation_service_;
107
108 // The cloud policy client.
109 CloudPolicyClient* client_;
110
111 // The cloud policy store.
112 CloudPolicyStore* store_;
113
114 // Schedules delayed tasks.
115 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
116
117 // The callback called when a user policy invalidation is received.
118 base::Closure invalidate_;
119
120 // The timestamp of the PolicyData at which this object registered for policy
121 // invalidations. Set to zero if the object has not registered yet.
122 int64 registered_timestamp_;
rlarocque 2013/07/23 17:43:08 Make this a base::Time?
Steve Condie 2013/07/24 01:42:04 Since this variable is used to do an equality comp
123
124 // The object id representing the policy in the invalidation service.
125 invalidation::ObjectId object_id_;
126
127 // Whether the policy is current invalid. This is set to true when an
128 // invalidation is received and reset when the policy fetched due to the
129 // invalidation is stored.
130 bool invalid_;
131
132 // The version of the latest invalidation received. This is compared to
133 // the invalidation version of policy stored to determine when the
134 // invalidated policy is up-to-date.
135 int64 invalidation_version_;
136
137 // The number of invalidations with unknown version received. Since such
138 // invalidations do not provide a version number, this count is used to set
139 // invalidation_version_ when such invalidations occur.
140 int unknown_version_invalidation_count_;
141
142 // The acknowledgment handle for the current invalidation.
143 syncer::AckHandle ack_handle_;
144
145 // WeakPtrFactory used to create callbacks to this object.
146 base::WeakPtrFactory<CloudPolicyInvalidator> weak_factory_;
147
148 // The maximum random delay, in ms, between receiving an invalidation and
149 // fetching the new policy.
150 int max_fetch_delay_;
151
152 // A thread checker to make sure that callbacks are invoked on the correct
153 // thread.
154 base::ThreadChecker thread_checker_;
Joao da Silva 2013/07/23 20:44:47 It's more common to inherit from NonThreadSafe and
Steve Condie 2013/07/24 01:42:04 From thread_checker.h: // The choice between havin
155
156 DISALLOW_COPY_AND_ASSIGN(CloudPolicyInvalidator);
157 };
158
159 } // namespace policy
160
161 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698