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

Side by Side Diff: chrome/browser/policy/cloud_policy_cache_base.h

Issue 11946017: Remove old cloud policy code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits. Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_
7
8 #include "base/observer_list.h"
9 #include "base/threading/non_thread_safe.h"
10 #include "base/time.h"
11 #include "chrome/browser/policy/cloud_policy_subsystem.h"
12 #include "chrome/browser/policy/policy_map.h"
13 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
14
15 namespace policy {
16
17 class PolicyNotifier;
18
19 // Caches policy information, as set by calls to |SetPolicy()|, persists
20 // it to disk or session_manager (depending on subclass implementation),
21 // and makes it available via policy providers.
22 class CloudPolicyCacheBase : public base::NonThreadSafe {
23 public:
24 class Observer {
25 public:
26 virtual ~Observer() {}
27 virtual void OnCacheUpdate(CloudPolicyCacheBase*) = 0;
28 };
29
30 CloudPolicyCacheBase();
31 virtual ~CloudPolicyCacheBase();
32
33 void set_policy_notifier(PolicyNotifier* notifier) {
34 notifier_ = notifier;
35 }
36
37 // Loads persisted policy information.
38 virtual void Load() = 0;
39
40 // Resets the policy information. Returns true if |policy| was accepted and
41 // stored.
42 virtual bool SetPolicy(
43 const enterprise_management::PolicyFetchResponse& policy) = 0;
44
45 virtual void SetUnmanaged() = 0;
46
47 // Invoked whenever an attempt to fetch policy has been completed. The fetch
48 // may or may not have suceeded. This can be triggered by failed attempts to
49 // fetch oauth tokens, register with dmserver or fetch policy.
50 virtual void SetFetchingDone();
51
52 bool is_unmanaged() const {
53 return is_unmanaged_;
54 }
55
56 // Returns the time at which the policy was last fetched.
57 base::Time last_policy_refresh_time() const {
58 return last_policy_refresh_time_;
59 }
60
61 bool machine_id_missing() const {
62 return machine_id_missing_;
63 }
64
65 // Get the version of the encryption key currently used for decoding policy.
66 // Returns true if the version is available, in which case |version| is filled
67 // in.
68 bool GetPublicKeyVersion(int* version);
69
70 void AddObserver(Observer* observer);
71 void RemoveObserver(Observer* observer);
72
73 // Accessor for the underlying PolicyMap.
74 const PolicyMap* policy() { return &policies_; }
75
76 // Resets the cache, clearing the policy currently stored in memory and the
77 // last refresh time.
78 void Reset();
79
80 // true if the cache contains data that is ready to be served as policies.
81 // This usually means that the local policy storage has been loaded.
82 // Note that Profile creation will block until the cache is ready.
83 // On enrolled devices and for users of the enrolled domain, the cache only
84 // becomes ready after a user policy fetch is completed.
85 bool IsReady();
86
87 protected:
88 // Wraps public key version and validity.
89 struct PublicKeyVersion {
90 int version;
91 bool valid;
92 };
93
94 // Decodes the given |policy| using |DecodePolicyResponse()|, applies the
95 // contents to |policies_|, and notifies observers.
96 // |timestamp| returns the timestamp embedded in |policy|, callers can pass
97 // NULL if they don't care. |check_for_timestamp_validity| tells this method
98 // to discard policy data with a timestamp from the future.
99 // Returns true upon success.
100 bool SetPolicyInternal(
101 const enterprise_management::PolicyFetchResponse& policy,
102 base::Time* timestamp,
103 bool check_for_timestamp_validity);
104
105 void SetUnmanagedInternal(const base::Time& timestamp);
106
107 // Indicates that initialization is now complete. Observers will be notified.
108 void SetReady();
109
110 // Decodes |policy_data|, populating |mandatory| and |recommended| with
111 // the results.
112 virtual bool DecodePolicyData(
113 const enterprise_management::PolicyData& policy_data,
114 PolicyMap* policies) = 0;
115
116 // Decodes a PolicyFetchResponse into two PolicyMaps and a timestamp.
117 // Also performs verification, returns NULL if any check fails.
118 bool DecodePolicyResponse(
119 const enterprise_management::PolicyFetchResponse& policy_response,
120 PolicyMap* policies,
121 base::Time* timestamp,
122 PublicKeyVersion* public_key_version);
123
124 // Notifies observers if the cache IsReady().
125 void NotifyObservers();
126
127 void InformNotifier(CloudPolicySubsystem::PolicySubsystemState state,
128 CloudPolicySubsystem::ErrorDetails error_details);
129
130 void set_last_policy_refresh_time(base::Time timestamp) {
131 last_policy_refresh_time_ = timestamp;
132 }
133
134 private:
135 friend class DevicePolicyCacheTest;
136 friend class UserPolicyCacheTest;
137 friend class MockCloudPolicyCache;
138
139 // Policy key-value information.
140 PolicyMap policies_;
141
142 PolicyNotifier* notifier_;
143
144 // The time at which the policy was last refreshed. Is updated both upon
145 // successful and unsuccessful refresh attempts.
146 base::Time last_policy_refresh_time_;
147
148 // Whether initialization has been completed. This is the case when we have
149 // valid policy, learned that the device is unmanaged or ran into
150 // unrecoverable errors.
151 bool initialization_complete_;
152
153 // Whether the the server has indicated this device is unmanaged.
154 bool is_unmanaged_;
155
156 // Flag indicating whether the server claims that a valid machine identifier
157 // is missing on the server side. Read directly from the policy blob.
158 bool machine_id_missing_;
159
160 // Currently used public key version, if available.
161 PublicKeyVersion public_key_version_;
162
163 // Cache observers that are registered with this cache.
164 ObserverList<Observer, true> observer_list_;
165
166 DISALLOW_COPY_AND_ASSIGN(CloudPolicyCacheBase);
167 };
168
169 } // namespace policy
170
171 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CACHE_BASE_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_browsertest.cc ('k') | chrome/browser/policy/cloud_policy_cache_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698