cloud_policy_manager.h revision 0529e5d033099cbfc42635f6f6183833b09dff6e
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. 4 5#ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_MANAGER_H_ 6#define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_MANAGER_H_ 7 8#include <string> 9 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" 21 22namespace base { 23class FilePath; 24class SequencedTaskRunner; 25} 26 27namespace net { 28class URLRequestContextGetter; 29} 30 31namespace policy { 32 33class PolicyMap; 34 35// CloudPolicyManager is the main switching central between cloud policy and the 36// upper layers of the policy stack. It wires up a CloudPolicyCore to the 37// ConfigurationPolicyProvider interface. 38// 39// This class contains the base functionality, there are subclasses that add 40// functionality specific to user-level and device-level cloud policy, such as 41// blocking on initial user policy fetch or device enrollment. 42class POLICY_EXPORT CloudPolicyManager 43 : public ConfigurationPolicyProvider, 44 public CloudPolicyStore::Observer, 45 public ComponentCloudPolicyService::Delegate { 46 public: 47 // |task_runner| is the runner for policy refresh tasks. 48 // |file_task_runner| is used for file operations. Currently this must be the 49 // FILE BrowserThread. 50 // |io_task_runner| is used for network IO. Currently this must be the IO 51 // BrowserThread. 52 CloudPolicyManager( 53 const PolicyNamespaceKey& policy_ns_key, 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 virtual ~CloudPolicyManager(); 59 60 CloudPolicyCore* core() { return &core_; } 61 const CloudPolicyCore* core() const { return &core_; } 62 63 // ConfigurationPolicyProvider: 64 virtual void Shutdown() OVERRIDE; 65 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; 66 virtual void RefreshPolicies() OVERRIDE; 67 68 // CloudPolicyStore::Observer: 69 virtual void OnStoreLoaded(CloudPolicyStore* cloud_policy_store) OVERRIDE; 70 virtual void OnStoreError(CloudPolicyStore* cloud_policy_store) OVERRIDE; 71 72 // ComponentCloudPolicyService::Delegate: 73 virtual void OnComponentCloudPolicyUpdated() OVERRIDE; 74 75 protected: 76 // Check whether fully initialized and if so, publish policy by calling 77 // ConfigurationPolicyStore::UpdatePolicy(). 78 void CheckAndPublishPolicy(); 79 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); 84 85 void CreateComponentCloudPolicyService( 86 const base::FilePath& policy_cache_path, 87 const scoped_refptr<net::URLRequestContextGetter>& request_context); 88 89 void ClearAndDestroyComponentCloudPolicyService(); 90 91 // Convenience accessors to core() components. 92 CloudPolicyClient* client() { return core_.client(); } 93 const CloudPolicyClient* client() const { return core_.client(); } 94 CloudPolicyStore* store() { return core_.store(); } 95 const CloudPolicyStore* store() const { return core_.store(); } 96 CloudPolicyService* service() { return core_.service(); } 97 const CloudPolicyService* service() const { return core_.service(); } 98 ComponentCloudPolicyService* component_policy_service() const { 99 return component_policy_service_.get(); 100 } 101 102 private: 103 // Completion handler for policy refresh operations. 104 void OnRefreshComplete(bool success); 105 106 CloudPolicyCore core_; 107 scoped_ptr<ComponentCloudPolicyService> component_policy_service_; 108 109 // Whether there's a policy refresh operation pending, in which case all 110 // policy update notifications are deferred until after it completes. 111 bool waiting_for_policy_refresh_; 112 113 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; 114 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; 115 116 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManager); 117}; 118 119} // namespace policy 120 121#endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_MANAGER_H_ 122