Index: chrome/browser/policy/cloud/component_cloud_policy_service.h |
diff --git a/chrome/browser/policy/cloud/component_cloud_policy_service.h b/chrome/browser/policy/cloud/component_cloud_policy_service.h |
index 774e93da92a5cde088c443204b63fc0f6444af9f..88263461dad4976842c19d68ce1b33a9ab3e640f 100644 |
--- a/chrome/browser/policy/cloud/component_cloud_policy_service.h |
+++ b/chrome/browser/policy/cloud/component_cloud_policy_service.h |
@@ -5,9 +5,8 @@ |
#ifndef CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_SERVICE_H_ |
#define CHROME_BROWSER_POLICY_CLOUD_COMPONENT_CLOUD_POLICY_SERVICE_H_ |
-#include <set> |
- |
#include "base/basictypes.h" |
+#include "base/cancelable_callback.h" |
#include "base/compiler_specific.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
@@ -17,6 +16,7 @@ |
#include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
bartfab (slow)
2013/11/14 14:13:12
Nit: Move to implementation file. No longer needed
Joao da Silva
2013/11/14 14:56:41
Done.
|
#include "chrome/browser/policy/cloud/cloud_policy_store.h" |
#include "chrome/browser/policy/policy_bundle.h" |
+#include "chrome/browser/policy/schema_registry.h" |
#include "components/policy/core/common/policy_namespace.h" |
namespace base { |
@@ -31,19 +31,16 @@ namespace policy { |
class ExternalPolicyDataFetcherBackend; |
class ResourceCache; |
-class SchemaMap; |
bartfab (slow)
2013/11/14 14:13:12
Nit: This is still used in the declaration of SetC
Joao da Silva
2013/11/14 14:56:41
Done.
|
// Manages cloud policy for components. |
// |
// This class takes care of fetching, validating, storing and updating policy |
-// for components. The components to manage have to be explicitly registered. |
+// for components. The components to manage come from a SchemaRegistry. |
class ComponentCloudPolicyService : public CloudPolicyClient::Observer, |
public CloudPolicyStore::Observer, |
+ public SchemaRegistry::Observer, |
public base::NonThreadSafe { |
public: |
- // Key for the ResourceCache where the list of known components is cached. |
- static const char kComponentNamespaceCache[]; |
- |
class Delegate { |
public: |
virtual ~Delegate(); |
@@ -58,15 +55,25 @@ class ComponentCloudPolicyService : public CloudPolicyClient::Observer, |
virtual void OnComponentCloudPolicyUpdated() = 0; |
}; |
+ // All of these components must outlive this instance. |
+ // |
+ // The |delegate| is notified of updates to the downloaded policies, and is |
+ // notified whenever a refresh is needed. |
+ // |schema_registry| contains the list of components to fetch policy for. |
// |store| is used to get the current DMToken and the username. |
// |cache| is used to load and store local copies of the downloaded policies. |
// Download scheduling, validation and caching of policies are done via the |
// |backend_task_runner|, which must support file I/O. Network I/O is done via |
// the |io_task_runner|. |
+ // |client| is updated with the list of components to fetch. |
+ // |request_context| is used by the background URLFetchers. |
ComponentCloudPolicyService( |
Delegate* delegate, |
+ SchemaRegistry* schema_registry, |
CloudPolicyStore* store, |
scoped_ptr<ResourceCache> cache, |
+ CloudPolicyClient* client, |
+ scoped_refptr<net::URLRequestContextGetter> request_context, |
scoped_refptr<base::SequencedTaskRunner> backend_task_runner, |
scoped_refptr<base::SequencedTaskRunner> io_task_runner); |
virtual ~ComponentCloudPolicyService(); |
@@ -81,24 +88,6 @@ class ComponentCloudPolicyService : public CloudPolicyClient::Observer, |
// Returns the current policies for components. |
const PolicyBundle& policy() const { return policy_; } |
- // Connects to the cloud policy service using |client|. |client| must outlive |
- // this object. Only cached policies will be served until a |client| is |
- // connected. |
- // |request_context| is used with the URLFetchers triggered by the updater. |
- void Connect(CloudPolicyClient* client, |
- scoped_refptr<net::URLRequestContextGetter> request_context); |
- |
- // Disconnects from the cloud policy service and stops trying to download |
- // remote policy data. |
- void Disconnect(); |
- |
- // |schema_map| contains the schemas for all the components that this |
- // service should load policy for. |
- // This purges unused components from the cache, and starts updating the |
- // components listed in the map. |
- // Unsupported domains in the map are ignored. |
- void OnSchemasUpdated(const scoped_refptr<SchemaMap>& schema_map); |
- |
// CloudPolicyClient::Observer implementation: |
virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; |
virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; |
@@ -108,24 +97,24 @@ class ComponentCloudPolicyService : public CloudPolicyClient::Observer, |
virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; |
virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; |
+ // SchemaRegistry::Observer implementation: |
+ virtual void OnSchemaRegistryReady() OVERRIDE; |
+ virtual void OnSchemaRegistryUpdated(bool has_new_schemas) OVERRIDE; |
+ |
private: |
class Backend; |
- typedef std::set<PolicyNamespaceKey> PolicyNamespaceKeys; |
- void InitializeBackend(); |
- void OnBackendInitialized(scoped_ptr<PolicyNamespaceKeys> initial_keys, |
- scoped_ptr<PolicyBundle> initial_policy); |
- void InitializeClient(); |
+ void InitializeIfReady(); |
+ void OnBackendInitialized(scoped_ptr<PolicyBundle> initial_policy); |
+ void SetCurrentSchema(const scoped_refptr<SchemaMap>& new_schema_map, |
+ bool send_to_backend); |
void OnPolicyUpdated(scoped_ptr<PolicyBundle> policy); |
- void SetCredentialsAndReloadClient(); |
- bool UpdateClientNamespaces(const PolicyNamespaceKeys& old_keys, |
- const PolicyNamespaceKeys& new_keys); |
- void AddNamespacesToFetch(const PolicyNamespaceKeys& keys); |
- void RemoveNamespacesToFetch(const PolicyNamespaceKeys& keys); |
- |
Delegate* delegate_; |
- |
+ SchemaRegistry* schema_registry_; |
+ CloudPolicyStore* store_; |
+ CloudPolicyClient* client_; |
+ scoped_refptr<net::URLRequestContextGetter> request_context_; |
scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; |
scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
@@ -143,17 +132,20 @@ class ComponentCloudPolicyService : public CloudPolicyClient::Observer, |
// |backend_task_runner_|. |
scoped_ptr<Backend> backend_; |
- CloudPolicyClient* client_; |
- CloudPolicyStore* store_; |
- |
- // The currently registered components for each policy domain. |
- PolicyNamespaceKeys keys_; |
+ // The currently registered components for each policy domain. Used to |
+ // determine which components changed when a new SchemaMap becomes |
+ // available. |
+ scoped_refptr<SchemaMap> current_schema_map_; |
// Contains all the current policies for components. |
PolicyBundle policy_; |
+ // Used to delay changes triggered by updates to the SchemaRegistry. See |
+ // the implementation of OnSchemaRegistryUpdated() for details. |
+ base::CancelableClosure schema_update_calback_; |
+ |
bool is_initialized_; |
- bool has_initial_keys_; |
+ bool has_credentials_; |
base::WeakPtrFactory<ComponentCloudPolicyService> weak_ptr_factory_; |
DISALLOW_COPY_AND_ASSIGN(ComponentCloudPolicyService); |