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_core.h"
16 #include "components/policy/core/common/cloud/cloud_policy_store.h"
17 #include "components/policy/core/common/cloud/component_cloud_policy_service.h"
18 #include "components/policy/core/common/configuration_policy_provider.h"
19 #include "components/policy/policy_export.h"
23 class SequencedTaskRunner
;
27 class URLRequestContextGetter
;
34 // CloudPolicyManager is the main switching central between cloud policy and the
35 // upper layers of the policy stack. It wires up a CloudPolicyCore to the
36 // ConfigurationPolicyProvider interface.
38 // This class contains the base functionality, there are subclasses that add
39 // functionality specific to user-level and device-level cloud policy, such as
40 // blocking on initial user policy fetch or device enrollment.
41 class POLICY_EXPORT CloudPolicyManager
42 : public ConfigurationPolicyProvider
,
43 public CloudPolicyStore::Observer
,
44 public ComponentCloudPolicyService::Delegate
{
46 // |task_runner| is the runner for policy refresh tasks.
47 // |file_task_runner| is used for file operations. Currently this must be the
48 // FILE BrowserThread.
49 // |io_task_runner| is used for network IO. Currently this must be the IO
52 const std::string
& policy_type
,
53 const std::string
& settings_entity_id
,
54 CloudPolicyStore
* cloud_policy_store
,
55 const scoped_refptr
<base::SequencedTaskRunner
>& task_runner
,
56 const scoped_refptr
<base::SequencedTaskRunner
>& file_task_runner
,
57 const scoped_refptr
<base::SequencedTaskRunner
>& io_task_runner
);
58 ~CloudPolicyManager() override
;
60 CloudPolicyCore
* core() { return &core_
; }
61 const CloudPolicyCore
* core() const { return &core_
; }
63 // ConfigurationPolicyProvider:
64 void Shutdown() override
;
65 bool IsInitializationComplete(PolicyDomain domain
) const override
;
66 void RefreshPolicies() override
;
68 // CloudPolicyStore::Observer:
69 void OnStoreLoaded(CloudPolicyStore
* cloud_policy_store
) override
;
70 void OnStoreError(CloudPolicyStore
* cloud_policy_store
) override
;
72 // ComponentCloudPolicyService::Delegate:
73 void OnComponentCloudPolicyUpdated() override
;
76 // Check whether fully initialized and if so, publish policy by calling
77 // ConfigurationPolicyStore::UpdatePolicy().
78 void CheckAndPublishPolicy();
80 // Writes Chrome policy into |policy_map|. This is intended to be overridden
81 // by subclasses that want to post-process policy before publishing it. The
82 // default implementation just copies over |store()->policy_map()|.
83 virtual void GetChromePolicy(PolicyMap
* policy_map
);
85 void CreateComponentCloudPolicyService(
86 const base::FilePath
& policy_cache_path
,
87 const scoped_refptr
<net::URLRequestContextGetter
>& request_context
,
88 CloudPolicyClient
* client
);
90 void ClearAndDestroyComponentCloudPolicyService();
92 // Convenience accessors to core() components.
93 CloudPolicyClient
* client() { return core_
.client(); }
94 const CloudPolicyClient
* client() const { return core_
.client(); }
95 CloudPolicyStore
* store() { return core_
.store(); }
96 const CloudPolicyStore
* store() const { return core_
.store(); }
97 CloudPolicyService
* service() { return core_
.service(); }
98 const CloudPolicyService
* service() const { return core_
.service(); }
99 ComponentCloudPolicyService
* component_policy_service() const {
100 return component_policy_service_
.get();
104 // Completion handler for policy refresh operations.
105 void OnRefreshComplete(bool success
);
107 CloudPolicyCore core_
;
108 scoped_ptr
<ComponentCloudPolicyService
> component_policy_service_
;
110 // Whether there's a policy refresh operation pending, in which case all
111 // policy update notifications are deferred until after it completes.
112 bool waiting_for_policy_refresh_
;
114 scoped_refptr
<base::SequencedTaskRunner
> file_task_runner_
;
115 scoped_refptr
<base::SequencedTaskRunner
> io_task_runner_
;
117 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManager
);
120 } // namespace policy
122 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_MANAGER_H_