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.
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/prefs/pref_member.h"
14 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
15 #include "chrome/browser/policy/cloud/cloud_policy_core.h"
16 #include "chrome/browser/policy/cloud/cloud_policy_store.h"
17 #include "chrome/browser/policy/configuration_policy_provider.h"
20 class SequencedTaskRunner;
27 // CloudPolicyManager is the main switching central between cloud policy and the
28 // upper layers of the policy stack. It wires up a CloudPolicyCore to the
29 // ConfigurationPolicyProvider interface.
31 // This class contains the base functionality, there are subclasses that add
32 // functionality specific to user-level and device-level cloud policy, such as
33 // blocking on initial user policy fetch or device enrollment.
34 class CloudPolicyManager : public ConfigurationPolicyProvider,
35 public CloudPolicyStore::Observer {
37 // |task_runner| is the runner for policy refresh tasks.
39 const PolicyNamespaceKey& policy_ns_key,
40 CloudPolicyStore* cloud_policy_store,
41 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
42 virtual ~CloudPolicyManager();
44 CloudPolicyCore* core() { return &core_; }
45 const CloudPolicyCore* core() const { return &core_; }
47 // ConfigurationPolicyProvider:
48 virtual void Shutdown() OVERRIDE;
49 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE;
50 virtual void RefreshPolicies() OVERRIDE;
52 // CloudPolicyStore::Observer:
53 virtual void OnStoreLoaded(CloudPolicyStore* cloud_policy_store) OVERRIDE;
54 virtual void OnStoreError(CloudPolicyStore* cloud_policy_store) OVERRIDE;
57 // Check whether fully initialized and if so, publish policy by calling
58 // ConfigurationPolicyStore::UpdatePolicy().
59 void CheckAndPublishPolicy();
61 // Called by CheckAndPublishPolicy() to create a bundle with the current
63 virtual scoped_ptr<PolicyBundle> CreatePolicyBundle();
65 // Convenience accessors to core() components.
66 CloudPolicyClient* client() { return core_.client(); }
67 const CloudPolicyClient* client() const { return core_.client(); }
68 CloudPolicyStore* store() { return core_.store(); }
69 const CloudPolicyStore* store() const { return core_.store(); }
70 CloudPolicyService* service() { return core_.service(); }
71 const CloudPolicyService* service() const { return core_.service(); }
74 // Completion handler for policy refresh operations.
75 void OnRefreshComplete(bool success);
77 CloudPolicyCore core_;
79 // Whether there's a policy refresh operation pending, in which case all
80 // policy update notifications are deferred until after it completes.
81 bool waiting_for_policy_refresh_;
83 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManager);
88 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_