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

Side by Side Diff: components/policy/core/common/cloud/cloud_policy_client.h

Issue 762863002: Removed policy::PolicyNamespaceKey. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <utility>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/basictypes.h" 14 #include "base/basictypes.h"
14 #include "base/callback.h" 15 #include "base/callback.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/observer_list.h" 17 #include "base/observer_list.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 19 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
19 #include "components/policy/policy_export.h" 20 #include "components/policy/policy_export.h"
20 #include "policy/proto/device_management_backend.pb.h" 21 #include "policy/proto/device_management_backend.pb.h"
(...skipping 10 matching lines...) Expand all
31 // Implements the core logic required to talk to the device management service. 32 // Implements the core logic required to talk to the device management service.
32 // Also keeps track of the current state of the association with the service, 33 // Also keeps track of the current state of the association with the service,
33 // such as whether there is a valid registration (DMToken is present in that 34 // such as whether there is a valid registration (DMToken is present in that
34 // case) and whether and what errors occurred in the latest request. 35 // case) and whether and what errors occurred in the latest request.
35 // 36 //
36 // Note that CloudPolicyClient doesn't do any validation of policy responses 37 // Note that CloudPolicyClient doesn't do any validation of policy responses
37 // such as signature and time stamp checks. These happen once the policy gets 38 // such as signature and time stamp checks. These happen once the policy gets
38 // installed in the cloud policy cache. 39 // installed in the cloud policy cache.
39 class POLICY_EXPORT CloudPolicyClient { 40 class POLICY_EXPORT CloudPolicyClient {
40 public: 41 public:
41 // Maps a PolicyNamespaceKey to its corresponding PolicyFetchResponse. 42 // Maps a (policy type, settings entity ID) pair to its corresponding
42 typedef std::map<PolicyNamespaceKey, 43 // PolicyFetchResponse.
44 typedef std::map<std::pair<std::string, std::string>,
43 enterprise_management::PolicyFetchResponse*> ResponseMap; 45 enterprise_management::PolicyFetchResponse*> ResponseMap;
44 46
45 // A callback which receives boolean status of an operation. If the operation 47 // A callback which receives boolean status of an operation. If the operation
46 // succeeded, |status| is true. 48 // succeeded, |status| is true.
47 typedef base::Callback<void(bool status)> StatusCallback; 49 typedef base::Callback<void(bool status)> StatusCallback;
48 50
49 // Observer interface for state and policy changes. 51 // Observer interface for state and policy changes.
50 class POLICY_EXPORT Observer { 52 class POLICY_EXPORT Observer {
51 public: 53 public:
52 virtual ~Observer(); 54 virtual ~Observer();
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 163
162 void set_public_key_version(int public_key_version) { 164 void set_public_key_version(int public_key_version) {
163 public_key_version_ = public_key_version; 165 public_key_version_ = public_key_version;
164 public_key_version_valid_ = true; 166 public_key_version_valid_ = true;
165 } 167 }
166 168
167 void clear_public_key_version() { 169 void clear_public_key_version() {
168 public_key_version_valid_ = false; 170 public_key_version_valid_ = false;
169 } 171 }
170 172
171 // FetchPolicy() calls will request this policy namespace. 173 // FetchPolicy() calls will request this policy type.
172 void AddNamespaceToFetch(const PolicyNamespaceKey& policy_ns_key); 174 // If |settings_entity_id| is empty then it won't be set in the
175 // PolicyFetchRequest.
176 void AddPolicyTypeToFetch(const std::string& policy_type,
177 const std::string& settings_entity_id);
173 178
174 // FetchPolicy() calls won't request the given policy namespace anymore. 179 // FetchPolicy() calls won't request the given policy type and optional
175 void RemoveNamespaceToFetch(const PolicyNamespaceKey& policy_ns_key); 180 // |settings_entity_id| anymore.
181 void RemovePolicyTypeToFetch(const std::string& policy_type,
182 const std::string& settings_entity_id);
176 183
177 // Configures a set of device state keys to transfer to the server in the next 184 // Configures a set of device state keys to transfer to the server in the next
178 // policy fetch. If the fetch is successful, the keys will be cleared so they 185 // policy fetch. If the fetch is successful, the keys will be cleared so they
179 // are only uploaded once. 186 // are only uploaded once.
180 void SetStateKeysToUpload(const std::vector<std::string>& keys); 187 void SetStateKeysToUpload(const std::vector<std::string>& keys);
181 188
182 // Whether the client is registered with the device management service. 189 // Whether the client is registered with the device management service.
183 bool is_registered() const { return !dm_token_.empty(); } 190 bool is_registered() const { return !dm_token_.empty(); }
184 191
185 const std::string& dm_token() const { return dm_token_; } 192 const std::string& dm_token() const { return dm_token_; }
186 const std::string& client_id() const { return client_id_; } 193 const std::string& client_id() const { return client_id_; }
187 194
188 // The device mode as received in the registration request. 195 // The device mode as received in the registration request.
189 DeviceMode device_mode() const { return device_mode_; } 196 DeviceMode device_mode() const { return device_mode_; }
190 197
191 // The policy responses as obtained by the last request to the cloud. These 198 // The policy responses as obtained by the last request to the cloud. These
192 // policies haven't gone through verification, so their contents cannot be 199 // policies haven't gone through verification, so their contents cannot be
193 // trusted. Use CloudPolicyStore::policy() and CloudPolicyStore::policy_map() 200 // trusted. Use CloudPolicyStore::policy() and CloudPolicyStore::policy_map()
194 // instead for making policy decisions. 201 // instead for making policy decisions.
195 const ResponseMap& responses() const { 202 const ResponseMap& responses() const {
196 return responses_; 203 return responses_;
197 } 204 }
198 205
199 // Returns the policy response for |policy_ns_key|, if found in |responses()|; 206 // Returns the policy response for the (|policy_type|, |settings_entity_id|)
200 // otherwise returns NULL. 207 // pair if found in |responses()|. Otherwise returns NULL.
201 const enterprise_management::PolicyFetchResponse* GetPolicyFor( 208 const enterprise_management::PolicyFetchResponse* GetPolicyFor(
202 const PolicyNamespaceKey& policy_ns_key) const; 209 const std::string& policy_type,
210 const std::string& settings_entity_id) const;
203 211
204 DeviceManagementStatus status() const { 212 DeviceManagementStatus status() const {
205 return status_; 213 return status_;
206 } 214 }
207 215
208 const std::string& robot_api_auth_code() const { 216 const std::string& robot_api_auth_code() const {
209 return robot_api_auth_code_; 217 return robot_api_auth_code_;
210 } 218 }
211 219
212 // Returns the invalidation version that was used for the last FetchPolicy. 220 // Returns the invalidation version that was used for the last FetchPolicy.
213 // Observers can call this method from their OnPolicyFetched method to 221 // Observers can call this method from their OnPolicyFetched method to
214 // determine which at which invalidation version the policy was fetched. 222 // determine which at which invalidation version the policy was fetched.
215 int64 fetched_invalidation_version() const { 223 int64 fetched_invalidation_version() const {
216 return fetched_invalidation_version_; 224 return fetched_invalidation_version_;
217 } 225 }
218 226
219 scoped_refptr<net::URLRequestContextGetter> GetRequestContext(); 227 scoped_refptr<net::URLRequestContextGetter> GetRequestContext();
220 228
221 protected: 229 protected:
222 // A set of PolicyNamespaceKeys to fetch. 230 // A set of (policy type, settings entity ID) pairs to fetch.
223 typedef std::set<PolicyNamespaceKey> NamespaceSet; 231 typedef std::set<std::pair<std::string, std::string>> TypeToFetchSet;
Mattias Nissler (ping if slow) 2014/11/27 08:34:10 nit: Let's rename this to PolicyTypeSet or somethi
Joao da Silva 2014/11/27 12:19:31 Done.
224 232
225 // Callback for retries of registration requests. 233 // Callback for retries of registration requests.
226 void OnRetryRegister(DeviceManagementRequestJob* job); 234 void OnRetryRegister(DeviceManagementRequestJob* job);
227 235
228 // Callback for registration requests. 236 // Callback for registration requests.
229 void OnRegisterCompleted( 237 void OnRegisterCompleted(
230 DeviceManagementStatus status, 238 DeviceManagementStatus status,
231 int net_error, 239 int net_error,
232 const enterprise_management::DeviceManagementResponse& response); 240 const enterprise_management::DeviceManagementResponse& response);
233 241
(...skipping 26 matching lines...) Expand all
260 void NotifyPolicyFetched(); 268 void NotifyPolicyFetched();
261 void NotifyRegistrationStateChanged(); 269 void NotifyRegistrationStateChanged();
262 void NotifyRobotAuthCodesFetched(); 270 void NotifyRobotAuthCodesFetched();
263 void NotifyClientError(); 271 void NotifyClientError();
264 272
265 // Data necessary for constructing policy requests. 273 // Data necessary for constructing policy requests.
266 const std::string machine_id_; 274 const std::string machine_id_;
267 const std::string machine_model_; 275 const std::string machine_model_;
268 const std::string verification_key_hash_; 276 const std::string verification_key_hash_;
269 const UserAffiliation user_affiliation_; 277 const UserAffiliation user_affiliation_;
270 NamespaceSet namespaces_to_fetch_; 278 TypeToFetchSet types_to_fetch_;
271 std::vector<std::string> state_keys_to_upload_; 279 std::vector<std::string> state_keys_to_upload_;
272 280
273 std::string dm_token_; 281 std::string dm_token_;
274 DeviceMode device_mode_; 282 DeviceMode device_mode_;
275 std::string client_id_; 283 std::string client_id_;
276 bool submit_machine_id_; 284 bool submit_machine_id_;
277 base::Time last_policy_timestamp_; 285 base::Time last_policy_timestamp_;
278 int public_key_version_; 286 int public_key_version_;
279 bool public_key_version_valid_; 287 bool public_key_version_valid_;
280 std::string robot_api_auth_code_; 288 std::string robot_api_auth_code_;
(...skipping 19 matching lines...) Expand all
300 ObserverList<Observer, true> observers_; 308 ObserverList<Observer, true> observers_;
301 scoped_refptr<net::URLRequestContextGetter> request_context_; 309 scoped_refptr<net::URLRequestContextGetter> request_context_;
302 310
303 private: 311 private:
304 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); 312 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient);
305 }; 313 };
306 314
307 } // namespace policy 315 } // namespace policy
308 316
309 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ 317 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698