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 COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_MANAGER_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_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/memory/scoped_ptr.h"
14 #include "base/prefs/pref_member.h"
15 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
16 #include "components/policy/core/common/cloud/cloud_policy_core.h"
17 #include "components/policy/core/common/cloud/cloud_policy_store.h"
18 #include "components/policy/core/common/cloud/component_cloud_policy_service.h"
19 #include "components/policy/core/common/configuration_policy_provider.h"
20 #include "components/policy/policy_export.h"
24 class SequencedTaskRunner;
28 class URLRequestContextGetter;
33 // CloudPolicyManager is the main switching central between cloud policy and the
34 // upper layers of the policy stack. It wires up a CloudPolicyCore to the
35 // ConfigurationPolicyProvider interface.
37 // This class contains the base functionality, there are subclasses that add
38 // functionality specific to user-level and device-level cloud policy, such as
39 // blocking on initial user policy fetch or device enrollment.
40 class POLICY_EXPORT CloudPolicyManager
41 : public ConfigurationPolicyProvider,
42 public CloudPolicyStore::Observer,
43 public ComponentCloudPolicyService::Delegate {
45 // |task_runner| is the runner for policy refresh tasks.
46 // |file_task_runner| is used for file operations. Currently this must be the
47 // FILE BrowserThread.
48 // |io_task_runner| is used for network IO. Currently this must be the IO
51 const PolicyNamespaceKey& policy_ns_key,
52 CloudPolicyStore* cloud_policy_store,
53 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
54 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner,
55 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
56 virtual ~CloudPolicyManager();
58 CloudPolicyCore* core() { return &core_; }
59 const CloudPolicyCore* core() const { return &core_; }
61 // ConfigurationPolicyProvider:
62 virtual void Shutdown() OVERRIDE;
63 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE;
64 virtual void RefreshPolicies() OVERRIDE;
66 // CloudPolicyStore::Observer:
67 virtual void OnStoreLoaded(CloudPolicyStore* cloud_policy_store) OVERRIDE;
68 virtual void OnStoreError(CloudPolicyStore* cloud_policy_store) OVERRIDE;
70 // ComponentCloudPolicyService::Delegate:
71 virtual void OnComponentCloudPolicyUpdated() OVERRIDE;
74 // Check whether fully initialized and if so, publish policy by calling
75 // ConfigurationPolicyStore::UpdatePolicy().
76 void CheckAndPublishPolicy();
78 void CreateComponentCloudPolicyService(
79 const base::FilePath& policy_cache_path,
80 const scoped_refptr<net::URLRequestContextGetter>& request_context);
82 void ClearAndDestroyComponentCloudPolicyService();
84 // Convenience accessors to core() components.
85 CloudPolicyClient* client() { return core_.client(); }
86 const CloudPolicyClient* client() const { return core_.client(); }
87 CloudPolicyStore* store() { return core_.store(); }
88 const CloudPolicyStore* store() const { return core_.store(); }
89 CloudPolicyService* service() { return core_.service(); }
90 const CloudPolicyService* service() const { return core_.service(); }
91 ComponentCloudPolicyService* component_policy_service() const {
92 return component_policy_service_.get();
96 // Completion handler for policy refresh operations.
97 void OnRefreshComplete(bool success);
99 CloudPolicyCore core_;
100 scoped_ptr<ComponentCloudPolicyService> component_policy_service_;
102 // Whether there's a policy refresh operation pending, in which case all
103 // policy update notifications are deferred until after it completes.
104 bool waiting_for_policy_refresh_;
106 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
107 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
109 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManager);
112 } // namespace policy
114 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_MANAGER_H_