Chromium Code Reviews| Index: chrome/browser/policy/cloud_policy_store.h |
| diff --git a/chrome/browser/policy/cloud_policy_store.h b/chrome/browser/policy/cloud_policy_store.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..130af659f22af3e23013e2214fb1a413eba556c8 |
| --- /dev/null |
| +++ b/chrome/browser/policy/cloud_policy_store.h |
| @@ -0,0 +1,89 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_STORE_H_ |
| +#define CHROME_BROWSER_POLICY_CLOUD_POLICY_STORE_H_ |
| +#pragma once |
| + |
| +#include "base/basictypes.h" |
| +#include "base/observer_list.h" |
| +#include "chrome/browser/policy/policy_map.h" |
| +#include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| + |
| +namespace policy { |
| + |
| +// Defines the low-level interface used by the cloud policy code to: |
| +// 1. Validate policy blobs that should be applied locally |
| +// 2. Persist policy blobs |
| +// 3. Decode policy blobs to PolicyMap representation |
| +class CloudPolicyStore { |
| + public: |
| + // Status codes. |
| + enum Status { |
| + // Everything is in good order. |
| + STATUS_SUCCESS, |
| + }; |
| + |
| + // Callbacks for policy store events. Most importantly, policy updates. |
| + class Observer { |
| + public: |
| + virtual ~Observer(); |
| + |
| + // Called on changes to store->policy(). |
| + virtual void OnPolicyLoaded(CloudPolicyStore* store) = 0; |
|
Joao da Silva
2012/04/17 00:30:58
The comments refer to this as OnPolicyUpdated(). S
Mattias Nissler (ping if slow)
2012/05/22 14:14:26
Done.
|
| + |
| + // Called upon encountering errors. |
| + virtual void OnStoreError(CloudPolicyStore* store) = 0; |
| + }; |
| + |
| + CloudPolicyStore(); |
| + virtual ~CloudPolicyStore(); |
| + |
| + const PolicyMap& policy_map() const { return policy_map_; } |
| + const enterprise_management::PolicyData& policy() const { return policy_; } |
| + const Status status() const { return status_; } |
| + |
| + // Store a new policy blob. Pending store operations will be canceled. The |
| + // store operation may proceed asynchronously and observers are notified once |
| + // the operation finishes. If successful, OnPolicyUpdated() will be invoked on |
| + // the observers and the updated policy can be read through policy(). Errors |
| + // generate OnStoreError() notifications. |
| + virtual void Store( |
| + const enterprise_management::PolicyFetchResponse& policy) = 0; |
| + |
| + // Load the current policy blob from persistent storage. This may trigger |
| + // asynchronous operations. Upon success, OnPolicyUpdated() will be called on |
| + // the registered observers. Otherwise, OnStoreError() reports the reason for |
| + // failure. |
| + virtual void Load() = 0; |
| + |
| + // Registers an observer to be notified when policy changes. |
| + void AddObserver(Observer* observer); |
| + |
| + // Removes the specified observer. |
| + void RemoveObserver(Observer* observer); |
| + |
| + protected: |
| + // Decoded version of the currently effective policy. |
| + PolicyMap policy_map_; |
| + |
| + // Currently effective policy. |
| + enterprise_management::PolicyData policy_; |
| + |
| + // Latest status code. |
| + Status status_; |
| + |
| + // Invokes the corresponding callback on all registered observers. |
| + void NotifyPolicyLoaded(); |
| + void NotifyStoreError(); |
| + |
| + private: |
| + ObserverList<Observer, true> observers_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CloudPolicyStore); |
| +}; |
| + |
| +} // namespace policy |
| + |
| +#endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_STORE_H_ |