OLD | NEW |
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/memory/weak_ptr.h" |
10 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
11 #include "chrome/browser/policy/cloud/cloud_policy_validator.h" | 12 #include "chrome/browser/policy/cloud/cloud_policy_validator.h" |
12 #include "chrome/browser/policy/policy_map.h" | 13 #include "chrome/browser/policy/policy_map.h" |
13 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 14 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
14 | 15 |
15 namespace policy { | 16 namespace policy { |
16 | 17 |
| 18 class CloudExternalDataManager; |
| 19 |
17 // Defines the low-level interface used by the cloud policy code to: | 20 // Defines the low-level interface used by the cloud policy code to: |
18 // 1. Validate policy blobs that should be applied locally | 21 // 1. Validate policy blobs that should be applied locally |
19 // 2. Persist policy blobs | 22 // 2. Persist policy blobs |
20 // 3. Decode policy blobs to PolicyMap representation | 23 // 3. Decode policy blobs to PolicyMap representation |
21 class CloudPolicyStore { | 24 class CloudPolicyStore { |
22 public: | 25 public: |
23 // Status codes. | 26 // Status codes. |
24 enum Status { | 27 enum Status { |
25 // Everything is in good order. | 28 // Everything is in good order. |
26 STATUS_OK, | 29 STATUS_OK, |
(...skipping 23 matching lines...) Expand all Loading... |
50 virtual void OnStoreError(CloudPolicyStore* store) = 0; | 53 virtual void OnStoreError(CloudPolicyStore* store) = 0; |
51 }; | 54 }; |
52 | 55 |
53 CloudPolicyStore(); | 56 CloudPolicyStore(); |
54 virtual ~CloudPolicyStore(); | 57 virtual ~CloudPolicyStore(); |
55 | 58 |
56 // Indicates whether the store has been fully initialized. This is | 59 // Indicates whether the store has been fully initialized. This is |
57 // accomplished by calling Load() after startup. | 60 // accomplished by calling Load() after startup. |
58 bool is_initialized() const { return is_initialized_; } | 61 bool is_initialized() const { return is_initialized_; } |
59 | 62 |
| 63 base::WeakPtr<CloudExternalDataManager> external_data_manager() const { |
| 64 return external_data_manager_; |
| 65 } |
| 66 |
60 const PolicyMap& policy_map() const { return policy_map_; } | 67 const PolicyMap& policy_map() const { return policy_map_; } |
61 bool has_policy() const { | 68 bool has_policy() const { |
62 return policy_.get() != NULL; | 69 return policy_.get() != NULL; |
63 } | 70 } |
64 const enterprise_management::PolicyData* policy() const { | 71 const enterprise_management::PolicyData* policy() const { |
65 return policy_.get(); | 72 return policy_.get(); |
66 } | 73 } |
67 bool is_managed() const { | 74 bool is_managed() const { |
68 return policy_.get() && | 75 return policy_.get() && |
69 policy_->state() == enterprise_management::PolicyData::ACTIVE; | 76 policy_->state() == enterprise_management::PolicyData::ACTIVE; |
(...skipping 16 matching lines...) Expand all Loading... |
86 // Upon success, OnStoreLoaded() will be called on the registered observers. | 93 // Upon success, OnStoreLoaded() will be called on the registered observers. |
87 // Otherwise, OnStoreError() reports the reason for failure. | 94 // Otherwise, OnStoreError() reports the reason for failure. |
88 virtual void Load() = 0; | 95 virtual void Load() = 0; |
89 | 96 |
90 // Registers an observer to be notified when policy changes. | 97 // Registers an observer to be notified when policy changes. |
91 void AddObserver(Observer* observer); | 98 void AddObserver(Observer* observer); |
92 | 99 |
93 // Removes the specified observer. | 100 // Removes the specified observer. |
94 void RemoveObserver(Observer* observer); | 101 void RemoveObserver(Observer* observer); |
95 | 102 |
| 103 // Indicate that external data referenced by policies in this store is managed |
| 104 // by |external_data_manager|. The |external_data_manager| will be notified |
| 105 // about policy changes before any other observers. |
| 106 void SetExternalDataManager( |
| 107 base::WeakPtr<CloudExternalDataManager> external_data_manager); |
| 108 |
96 protected: | 109 protected: |
97 // Invokes the corresponding callback on all registered observers. | 110 // Invokes the corresponding callback on all registered observers. |
98 void NotifyStoreLoaded(); | 111 void NotifyStoreLoaded(); |
99 void NotifyStoreError(); | 112 void NotifyStoreError(); |
100 | 113 |
| 114 // Manages external data referenced by policies. |
| 115 base::WeakPtr<CloudExternalDataManager> external_data_manager_; |
| 116 |
101 // Decoded version of the currently effective policy. | 117 // Decoded version of the currently effective policy. |
102 PolicyMap policy_map_; | 118 PolicyMap policy_map_; |
103 | 119 |
104 // Currently effective policy. | 120 // Currently effective policy. |
105 scoped_ptr<enterprise_management::PolicyData> policy_; | 121 scoped_ptr<enterprise_management::PolicyData> policy_; |
106 | 122 |
107 // Latest status code. | 123 // Latest status code. |
108 Status status_; | 124 Status status_; |
109 | 125 |
110 // Latest validation status. | 126 // Latest validation status. |
111 CloudPolicyValidatorBase::Status validation_status_; | 127 CloudPolicyValidatorBase::Status validation_status_; |
112 | 128 |
113 private: | 129 private: |
114 // Whether the store has completed asynchronous initialization, which is | 130 // Whether the store has completed asynchronous initialization, which is |
115 // triggered by calling Load(). | 131 // triggered by calling Load(). |
116 bool is_initialized_; | 132 bool is_initialized_; |
117 | 133 |
118 ObserverList<Observer, true> observers_; | 134 ObserverList<Observer, true> observers_; |
119 | 135 |
120 DISALLOW_COPY_AND_ASSIGN(CloudPolicyStore); | 136 DISALLOW_COPY_AND_ASSIGN(CloudPolicyStore); |
121 }; | 137 }; |
122 | 138 |
123 } // namespace policy | 139 } // namespace policy |
124 | 140 |
125 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_ | 141 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_ |
OLD | NEW |