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

Side by Side Diff: chrome/browser/policy/cloud/cloud_policy_store.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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_STORE_H_ 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_ 6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 bool is_managed() const { 67 bool is_managed() const {
68 return policy_.get() && 68 return policy_.get() &&
69 policy_->state() == enterprise_management::PolicyData::ACTIVE; 69 policy_->state() == enterprise_management::PolicyData::ACTIVE;
70 } 70 }
71 Status status() const { return status_; } 71 Status status() const { return status_; }
72 CloudPolicyValidatorBase::Status validation_status() const { 72 CloudPolicyValidatorBase::Status validation_status() const {
73 return validation_status_; 73 return validation_status_;
74 } 74 }
75 75
76 // Returns true if the latest policy loaded was different from the previous
77 // policy.
78 bool policy_changed() const {
79 return policy_changed_;
80 }
81
76 // Store a new policy blob. Pending load/store operations will be canceled. 82 // Store a new policy blob. Pending load/store operations will be canceled.
77 // The store operation may proceed asynchronously and observers are notified 83 // The store operation may proceed asynchronously and observers are notified
78 // once the operation finishes. If successful, OnStoreLoaded() will be invoked 84 // once the operation finishes. If successful, OnStoreLoaded() will be invoked
79 // on the observers and the updated policy can be read through policy(). 85 // on the observers and the updated policy can be read through policy().
80 // Errors generate OnStoreError() notifications. 86 // Errors generate OnStoreError() notifications.
81 virtual void Store( 87 virtual void Store(
82 const enterprise_management::PolicyFetchResponse& policy) = 0; 88 const enterprise_management::PolicyFetchResponse& policy) = 0;
83 89
84 // Load the current policy blob from persistent storage. Pending load/store 90 // Load the current policy blob from persistent storage. Pending load/store
85 // operations will be canceled. This may trigger asynchronous operations. 91 // operations will be canceled. This may trigger asynchronous operations.
86 // Upon success, OnStoreLoaded() will be called on the registered observers. 92 // Upon success, OnStoreLoaded() will be called on the registered observers.
87 // Otherwise, OnStoreError() reports the reason for failure. 93 // Otherwise, OnStoreError() reports the reason for failure.
88 virtual void Load() = 0; 94 virtual void Load() = 0;
89 95
90 // Registers an observer to be notified when policy changes. 96 // Registers an observer to be notified when policy changes.
91 void AddObserver(Observer* observer); 97 void AddObserver(Observer* observer);
92 98
93 // Removes the specified observer. 99 // Removes the specified observer.
94 void RemoveObserver(Observer* observer); 100 void RemoveObserver(Observer* observer);
95 101
102 // The invalidation version of the last policy stored. This value can be read
103 // by observers to determine which version of the policy is now available.
104 int64 invalidation_version() {
105 return invalidation_version_;
106 }
107
108 // Set the invalidation version. This method should be called immediately
109 // before the Store method.
110 void set_invalidation_version(int64 invalidation_version) {
Joao da Silva 2013/07/23 20:44:47 Can this be part of the Store() method? Or maybe h
Steve Condie 2013/07/24 01:42:04 I agree it's better to make it one call. I conside
111 invalidation_version_ = invalidation_version;
112 }
96 protected: 113 protected:
97 // Invokes the corresponding callback on all registered observers. 114 // Invokes the corresponding callback on all registered observers.
98 void NotifyStoreLoaded(); 115 void NotifyStoreLoaded();
99 void NotifyStoreError(); 116 void NotifyStoreError();
100 117
118 // Subclasses for which policy_changed() functionality is desired must call
119 // this method when |policy_| is updated. |hash_value| must contain a hash
120 // value calculated on the policy value, or be zero if there is no policy.
121 void SetPolicyHashValue(uint32 hash_value);
Joao da Silva 2013/07/23 20:44:47 A subclass may forget to call this, or do it in th
Steve Condie 2013/07/24 01:42:04 Done.
122
101 // Decoded version of the currently effective policy. 123 // Decoded version of the currently effective policy.
102 PolicyMap policy_map_; 124 PolicyMap policy_map_;
103 125
104 // Currently effective policy. 126 // Currently effective policy.
105 scoped_ptr<enterprise_management::PolicyData> policy_; 127 scoped_ptr<enterprise_management::PolicyData> policy_;
106 128
107 // Latest status code. 129 // Latest status code.
108 Status status_; 130 Status status_;
109 131
110 // Latest validation status. 132 // Latest validation status.
111 CloudPolicyValidatorBase::Status validation_status_; 133 CloudPolicyValidatorBase::Status validation_status_;
112 134
113 private: 135 private:
114 // Whether the store has completed asynchronous initialization, which is 136 // Whether the store has completed asynchronous initialization, which is
115 // triggered by calling Load(). 137 // triggered by calling Load().
116 bool is_initialized_; 138 bool is_initialized_;
117 139
140 // The hash value of the current policy. This is used to determine when the
141 // policy changes.
142 uint32 hash_value_;
143
144 bool policy_changed_;
145
146 int64 invalidation_version_;
147
118 ObserverList<Observer, true> observers_; 148 ObserverList<Observer, true> observers_;
119 149
120 DISALLOW_COPY_AND_ASSIGN(CloudPolicyStore); 150 DISALLOW_COPY_AND_ASSIGN(CloudPolicyStore);
121 }; 151 };
122 152
123 } // namespace policy 153 } // namespace policy
124 154
125 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_ 155 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698