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

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

Issue 10092010: Add CloudPolicyService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nit. Created 8 years, 7 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_STORE_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_STORE_H_
7 #pragma once
8
9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.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 // Defines the low-level interface used by the cloud policy code to:
18 // 1. Validate policy blobs that should be applied locally
19 // 2. Persist policy blobs
20 // 3. Decode policy blobs to PolicyMap representation
21 class CloudPolicyStore {
22 public:
23 // Status codes.
24 enum Status {
25 // Everything is in good order.
26 STATUS_OK,
27 // Loading policy from the underlying data store failed.
28 STATUS_PERSIST_LOAD_ERROR,
29 // Failed to store policy to the data store.
30 STATUS_PERSIST_STORE_ERROR,
31 // Failed to parse the policy read from the data store.
32 STATUS_PERSIST_PARSE_ERROR,
33 // Failed to serialize policy for storage.
34 STATUS_PERSIST_SERIALIZE_ERROR,
35 // Validation failure: Bad signature.
36 STATUS_VALIDATION_BAD_SIGNATURE,
37 // Validation failure: Policy blob contains error code.
38 STATUS_VALIDATION_ERROR_CODE_PRESENT,
39 // Validation failure: Policy payload failed to decode.
40 STATUS_VALIDATION_PAYLOAD_PARSE_ERROR,
41 // Validation failure: Unexpected policy type.
42 STATUS_VALIDATION_POLICY_TYPE,
43 // Validation failure: Time stamp from the future.
44 STATUS_VALIDATION_TIMESTAMP,
45 // Validation failure: Token doesn't match.
46 STATUS_VALIDATION_TOKEN,
47 // Validation failure: Username doesn't match.
48 STATUS_VALIDATION_USERNAME,
49 // Policy protobuf parse error.
50 STATUS_VALIDATION_POLICY_PARSE_ERROR,
51 };
52
53 // Callbacks for policy store events. Most importantly, policy updates.
54 class Observer {
55 public:
56 virtual ~Observer();
57
58 // Called on changes to store->policy() and/or store->policy_map().
59 virtual void OnStoreLoaded(CloudPolicyStore* store) = 0;
60
61 // Called upon encountering errors.
62 virtual void OnStoreError(CloudPolicyStore* store) = 0;
63 };
64
65 CloudPolicyStore();
66 virtual ~CloudPolicyStore();
67
68 // Indicates whether the store has been fully initialized. This is
69 // accomplished by calling Load() after startup.
70 bool is_initialized() const { return is_initialized_; }
71
72 const PolicyMap& policy_map() const { return policy_map_; }
73 bool has_policy() const {
74 return policy_.get() != NULL;
75 }
76 const enterprise_management::PolicyData* policy() const {
77 return policy_.get();
78 }
79 bool is_managed() const {
80 return policy_.get() &&
81 policy_->state() == enterprise_management::PolicyData::ACTIVE;
82 }
83 Status status() const { return status_; }
84
85 // Store a new policy blob. Pending store operations will be canceled. The
86 // store operation may proceed asynchronously and observers are notified once
87 // the operation finishes. If successful, OnStoreLoaded() will be invoked on
88 // the observers and the updated policy can be read through policy(). Errors
89 // generate OnStoreError() notifications.
90 virtual void Store(
91 const enterprise_management::PolicyFetchResponse& policy) = 0;
92
93 // Load the current policy blob from persistent storage. This may trigger
94 // asynchronous operations. Upon success, OnStoreLoaded() will be called on
95 // the registered observers. Otherwise, OnStoreError() reports the reason for
96 // failure.
97 virtual void Load() = 0;
98
99 // Registers an observer to be notified when policy changes.
100 void AddObserver(Observer* observer);
101
102 // Removes the specified observer.
103 void RemoveObserver(Observer* observer);
104
105 protected:
106 // Invokes the corresponding callback on all registered observers.
107 void NotifyStoreLoaded();
108 void NotifyStoreError();
109
110 // Decoded version of the currently effective policy.
111 PolicyMap policy_map_;
112
113 // Currently effective policy.
114 scoped_ptr<enterprise_management::PolicyData> policy_;
115
116 // Latest status code.
117 Status status_;
118
119 private:
120 // Whether the store has completed asynchronous initialization, which is
121 // triggered by calling Load().
122 bool is_initialized_;
123
124 ObserverList<Observer, true> observers_;
125
126 DISALLOW_COPY_AND_ASSIGN(CloudPolicyStore);
127 };
128
129 } // namespace policy
130
131 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_STORE_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_service_unittest.cc ('k') | chrome/browser/policy/cloud_policy_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698