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 abfdba53f52b6ac6074d4c602cc7950ce4ed37b7..7e841b7ecb7340e6d3e2a729f41878e416adf56f 100644 |
--- a/chrome/browser/policy/cloud/component_cloud_policy_service.h |
+++ b/chrome/browser/policy/cloud/component_cloud_policy_service.h |
@@ -11,8 +11,8 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/weak_ptr.h" |
#include "base/threading/non_thread_safe.h" |
-#include "base/timer/timer.h" |
#include "chrome/browser/policy/cloud/cloud_policy_client.h" |
+#include "chrome/browser/policy/cloud/cloud_policy_core.h" |
#include "chrome/browser/policy/cloud/cloud_policy_store.h" |
#include "chrome/browser/policy/policy_bundle.h" |
#include "chrome/browser/policy/schema_registry.h" |
@@ -37,6 +37,7 @@ class SchemaMap; |
// This class takes care of fetching, validating, storing and updating policy |
// for components. The components to manage come from a SchemaRegistry. |
class ComponentCloudPolicyService : public CloudPolicyClient::Observer, |
+ public CloudPolicyCore::Observer, |
public CloudPolicyStore::Observer, |
public SchemaRegistry::Observer, |
public base::NonThreadSafe { |
@@ -45,34 +46,35 @@ class ComponentCloudPolicyService : public CloudPolicyClient::Observer, |
public: |
virtual ~Delegate(); |
- // Invoked whenever the service has appended new namespaces to fetch to |
- // the CloudPolicyClient, signaling that a policy fetch should be done soon. |
- virtual void OnComponentCloudPolicyRefreshNeeded() = 0; |
- |
// Invoked whenever the policy served by policy() changes. This is also |
// invoked for the first time once the backend is initialized, and |
// is_initialized() becomes true. |
virtual void OnComponentCloudPolicyUpdated() = 0; |
}; |
- // All of these components must outlive this instance. |
+ // The |delegate| is notified of updates to the downloaded policies and must |
+ // outlive this object. |
+ // |
+ // |schema_registry| is used to get the list of components to fetch cloud |
+ // policy for. It must outlive this object. |
+ // |
+ // |core| is used to obtain the CloudPolicyStore and CloudPolicyClient used |
+ // by this service. The store will be the source of the registration status |
+ // and registration credentials; the client will be used to fetch cloud |
+ // policy. It must outlive this object. |
// |
- // 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, |
+ CloudPolicyCore* core, |
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); |
@@ -83,37 +85,40 @@ class ComponentCloudPolicyService : public CloudPolicyClient::Observer, |
// Returns true if the backend is initialized, and the initial policies and |
// components are being served. |
- bool is_initialized() const { return is_initialized_; } |
+ bool is_initialized() const { return loaded_initial_policy_; } |
// Returns the current policies for components. |
const PolicyBundle& policy() const { return policy_; } |
- // CloudPolicyClient::Observer implementation: |
- virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; |
- virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; |
- virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; |
+ // SchemaRegistry::Observer implementation: |
+ virtual void OnSchemaRegistryReady() OVERRIDE; |
+ virtual void OnSchemaRegistryUpdated(bool has_new_schemas) OVERRIDE; |
+ |
+ // CloudPolicyCore::Observer implementation: |
+ virtual void OnCoreConnected(CloudPolicyCore* core) OVERRIDE; |
+ virtual void OnCoreDisconnecting(CloudPolicyCore* core) OVERRIDE; |
+ virtual void OnRefreshSchedulerStarted(CloudPolicyCore* core) OVERRIDE; |
// CloudPolicyStore::Observer implementation: |
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; |
+ // CloudPolicyClient::Observer implementation: |
+ virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; |
+ virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; |
+ virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; |
private: |
class Backend; |
void InitializeIfReady(); |
void OnBackendInitialized(scoped_ptr<PolicyBundle> initial_policy); |
- void SetCurrentSchema(const scoped_refptr<SchemaMap>& new_schema_map, |
- bool send_to_backend); |
+ void SetCurrentSchema(); |
void OnPolicyUpdated(scoped_ptr<PolicyBundle> policy); |
Delegate* delegate_; |
SchemaRegistry* schema_registry_; |
- CloudPolicyStore* store_; |
- CloudPolicyClient* client_; |
+ CloudPolicyCore* core_; |
scoped_refptr<net::URLRequestContextGetter> request_context_; |
scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; |
scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
@@ -140,12 +145,16 @@ class ComponentCloudPolicyService : public CloudPolicyClient::Observer, |
// 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::OneShotTimer<ComponentCloudPolicyService> schema_update_timer_; |
+ // Whether the backend has been initialized with the initial credentials and |
+ // schemas, and this provider is serving the initial policies loaded from the |
+ // cache. |
+ bool loaded_initial_policy_; |
+ |
+ // True if the backend currently has valid cloud policy credentials. This |
+ // can go back to false if the user signs out, and back again to true if the |
+ // user signs in again. |
+ bool is_registered_for_cloud_policy_; |
- bool is_initialized_; |
- bool has_credentials_; |
base::WeakPtrFactory<ComponentCloudPolicyService> weak_ptr_factory_; |
DISALLOW_COPY_AND_ASSIGN(ComponentCloudPolicyService); |