Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_SERVICE_H_ |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_SERVICE_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 #include <set> | 8 #include <set> |
| 10 #include <string> | 9 #include <string> |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: No longer used (move to implementation file,
Joao da Silva
2013/11/07 13:15:00
Done.
| |
| 11 | 10 |
| 12 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 17 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
| 18 #include "chrome/browser/policy/cloud/cloud_policy_client.h" | 17 #include "chrome/browser/policy/cloud/cloud_policy_client.h" |
| 19 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | 18 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
| 20 #include "chrome/browser/policy/policy_bundle.h" | 19 #include "chrome/browser/policy/policy_bundle.h" |
| 21 #include "components/policy/core/common/policy_namespace.h" | 20 #include "components/policy/core/common/policy_namespace.h" |
| 22 | 21 |
| 23 namespace base { | 22 namespace base { |
| 24 class SequencedTaskRunner; | 23 class SequencedTaskRunner; |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace net { | 26 namespace net { |
| 28 class URLRequestContextGetter; | 27 class URLRequestContextGetter; |
| 29 } | 28 } |
| 30 | 29 |
| 31 namespace policy { | 30 namespace policy { |
| 32 | 31 |
| 33 class ExternalPolicyDataFetcherBackend; | 32 class ExternalPolicyDataFetcherBackend; |
| 34 class PolicyDomainDescriptor; | |
| 35 class ResourceCache; | 33 class ResourceCache; |
| 34 class SchemaMap; | |
| 36 | 35 |
| 37 // Manages cloud policy for components. | 36 // Manages cloud policy for components. |
| 38 // | 37 // |
| 39 // This class takes care of fetching, validating, storing and updating policy | 38 // This class takes care of fetching, validating, storing and updating policy |
| 40 // for components. The components to manage have to be explicitly registered. | 39 // for components. The components to manage have to be explicitly registered. |
| 41 class ComponentCloudPolicyService : public CloudPolicyClient::Observer, | 40 class ComponentCloudPolicyService : public CloudPolicyClient::Observer, |
| 42 public CloudPolicyStore::Observer, | 41 public CloudPolicyStore::Observer, |
| 43 public base::NonThreadSafe { | 42 public base::NonThreadSafe { |
| 44 public: | 43 public: |
| 45 // Key for the ResourceCache where the list of known components is cached. | 44 // Key for the ResourceCache where the list of known components is cached. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 // this object. Only cached policies will be served until a |client| is | 85 // this object. Only cached policies will be served until a |client| is |
| 87 // connected. | 86 // connected. |
| 88 // |request_context| is used with the URLFetchers triggered by the updater. | 87 // |request_context| is used with the URLFetchers triggered by the updater. |
| 89 void Connect(CloudPolicyClient* client, | 88 void Connect(CloudPolicyClient* client, |
| 90 scoped_refptr<net::URLRequestContextGetter> request_context); | 89 scoped_refptr<net::URLRequestContextGetter> request_context); |
| 91 | 90 |
| 92 // Disconnects from the cloud policy service and stops trying to download | 91 // Disconnects from the cloud policy service and stops trying to download |
| 93 // remote policy data. | 92 // remote policy data. |
| 94 void Disconnect(); | 93 void Disconnect(); |
| 95 | 94 |
| 96 // |descriptor| lists the complete set of components to track for its domain. | 95 // |schema_map| contains the schemas for all the components that this |
| 96 // service should load policy for. | |
| 97 // This purges unused components from the cache, and starts updating the | 97 // This purges unused components from the cache, and starts updating the |
| 98 // components listed in the descriptor. It's only valid to call this for | 98 // components listed in the map. |
| 99 // domains that are supported, i.e. SupportsDomain(domain) is true. | 99 // Unsupported domains in the map are ignored. |
| 100 void RegisterPolicyDomain( | 100 void OnSchemasUpdated(const scoped_refptr<SchemaMap>& schema_map); |
| 101 scoped_refptr<const PolicyDomainDescriptor> descriptor); | |
| 102 | 101 |
| 103 // CloudPolicyClient::Observer implementation: | 102 // CloudPolicyClient::Observer implementation: |
| 104 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | 103 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; |
| 105 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | 104 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; |
| 106 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | 105 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; |
| 107 | 106 |
| 108 // CloudPolicyStore::Observer implementation: | 107 // CloudPolicyStore::Observer implementation: |
| 109 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; | 108 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; |
| 110 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; | 109 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; |
| 111 | 110 |
| 112 private: | 111 private: |
| 113 class Backend; | 112 class Backend; |
| 114 typedef std::set<std::string> StringSet; | 113 typedef std::set<PolicyNamespaceKey> PolicyNamespaceKeys; |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: #include "chrome/browser/policy/cloud/cloud_p
Joao da Silva
2013/11/07 13:15:00
Done.
| |
| 115 typedef std::map<PolicyDomain, StringSet> ComponentMap; | |
| 116 | 114 |
| 117 void InitializeBackend(); | 115 void InitializeBackend(); |
| 118 void OnBackendInitialized(scoped_ptr<ComponentMap> components, | 116 void OnBackendInitialized(scoped_ptr<PolicyNamespaceKeys> initial_keys, |
| 119 scoped_ptr<PolicyBundle> initial_policy); | 117 scoped_ptr<PolicyBundle> initial_policy); |
| 120 void InitializeClient(); | 118 void InitializeClient(); |
| 121 void OnPolicyUpdated(scoped_ptr<PolicyBundle> policy); | 119 void OnPolicyUpdated(scoped_ptr<PolicyBundle> policy); |
| 122 | 120 |
| 123 void SetCredentialsAndReloadClient(); | 121 void SetCredentialsAndReloadClient(); |
| 124 bool UpdateClientNamespaces(PolicyDomain domain, | 122 bool UpdateClientNamespaces(const PolicyNamespaceKeys& old_keys, |
| 125 const StringSet& old_set, | 123 const PolicyNamespaceKeys& new_keys); |
| 126 const StringSet& new_set); | 124 void AddNamespacesToFetch(const PolicyNamespaceKeys& keys); |
| 127 void AddNamespacesToFetch(PolicyDomain domain, const StringSet& set); | 125 void RemoveNamespacesToFetch(const PolicyNamespaceKeys& keys); |
| 128 void RemoveNamespacesToFetch(PolicyDomain domain, const StringSet& set); | |
| 129 | 126 |
| 130 Delegate* delegate_; | 127 Delegate* delegate_; |
| 131 | 128 |
| 132 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; | 129 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; |
| 133 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 130 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
| 134 | 131 |
| 135 // The |external_policy_data_fetcher_backend_| handles network I/O for the | 132 // The |external_policy_data_fetcher_backend_| handles network I/O for the |
| 136 // |backend_| because URLRequestContextGetter and URLFetchers cannot be | 133 // |backend_| because URLRequestContextGetter and URLFetchers cannot be |
| 137 // referenced from background threads. It is instantiated on the thread |this| | 134 // referenced from background threads. It is instantiated on the thread |this| |
| 138 // runs on but after that, must only be accessed and eventually destroyed via | 135 // runs on but after that, must only be accessed and eventually destroyed via |
| 139 // the |io_task_runner_|. | 136 // the |io_task_runner_|. |
| 140 scoped_ptr<ExternalPolicyDataFetcherBackend> | 137 scoped_ptr<ExternalPolicyDataFetcherBackend> |
| 141 external_policy_data_fetcher_backend_; | 138 external_policy_data_fetcher_backend_; |
| 142 | 139 |
| 143 // The |backend_| handles all download scheduling, validation and caching of | 140 // The |backend_| handles all download scheduling, validation and caching of |
| 144 // policies. It is instantiated on the thread |this| runs on but after that, | 141 // policies. It is instantiated on the thread |this| runs on but after that, |
| 145 // must only be accessed and eventually destroyed via the | 142 // must only be accessed and eventually destroyed via the |
| 146 // |backend_task_runner_|. | 143 // |backend_task_runner_|. |
| 147 scoped_ptr<Backend> backend_; | 144 scoped_ptr<Backend> backend_; |
| 148 | 145 |
| 149 CloudPolicyClient* client_; | 146 CloudPolicyClient* client_; |
| 150 CloudPolicyStore* store_; | 147 CloudPolicyStore* store_; |
| 151 | 148 |
| 152 // The currently registered components for each policy domain. If a policy | 149 // The currently registered components for each policy domain. |
| 153 // domain doesn't have an entry in this map then it hasn't registered its | 150 PolicyNamespaceKeys keys_; |
| 154 // component yet. A domain in this map with an empty set of components means | |
| 155 // that the domain is registered, but has no components. | |
| 156 ComponentMap registered_components_; | |
| 157 | 151 |
| 158 // Contains all the current policies for components. | 152 // Contains all the current policies for components. |
| 159 PolicyBundle policy_; | 153 PolicyBundle policy_; |
| 160 | 154 |
| 161 bool is_initialized_; | 155 bool is_initialized_; |
| 156 bool has_initial_keys_; | |
| 162 base::WeakPtrFactory<ComponentCloudPolicyService> weak_ptr_factory_; | 157 base::WeakPtrFactory<ComponentCloudPolicyService> weak_ptr_factory_; |
| 163 | 158 |
| 164 DISALLOW_COPY_AND_ASSIGN(ComponentCloudPolicyService); | 159 DISALLOW_COPY_AND_ASSIGN(ComponentCloudPolicyService); |
| 165 }; | 160 }; |
| 166 | 161 |
| 167 } // namespace policy | 162 } // namespace policy |
| 168 | 163 |
| 169 #endif // CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_SERVICE_H_ | 164 #endif // CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_SERVICE_H_ |
| OLD | NEW |