Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_CLOUD_POLICY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_ |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | |
| 12 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/prefs/pref_member.h" | 13 #include "base/prefs/pref_member.h" |
| 14 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 14 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| 15 #include "chrome/browser/policy/cloud/cloud_policy_core.h" | 15 #include "chrome/browser/policy/cloud/cloud_policy_core.h" |
| 16 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h" | 16 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h" |
| 17 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | 17 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
| 18 #include "chrome/browser/policy/configuration_policy_provider.h" | 18 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 19 | 19 |
| 20 namespace policy { | 20 namespace policy { |
| 21 | 21 |
| 22 class PolicyBundle; | 22 class PolicyBundle; |
| 23 | 23 |
| 24 // CloudPolicyManager is the main switching central between cloud policy and the | 24 // CloudPolicyManager is the main switching central between cloud policy and the |
| 25 // upper layers of the policy stack. It wires up a CloudPolicyCore to the | 25 // upper layers of the policy stack. It wires up a CloudPolicyCore to the |
| 26 // ConfigurationPolicyProvider interface. | 26 // ConfigurationPolicyProvider interface. |
| 27 // | 27 // |
| 28 // This class contains the base functionality, there are subclasses that add | 28 // This class contains the base functionality, there are subclasses that add |
| 29 // functionality specific to user-level and device-level cloud policy, such as | 29 // functionality specific to user-level and device-level cloud policy, such as |
| 30 // blocking on initial user policy fetch or device enrollment. | 30 // blocking on initial user policy fetch or device enrollment. |
| 31 class CloudPolicyManager : public ConfigurationPolicyProvider, | 31 class CloudPolicyManager : public ConfigurationPolicyProvider, |
| 32 public CloudPolicyStore::Observer, | 32 public CloudPolicyStore::Observer, |
| 33 public CloudPolicyInvalidationHandler { | 33 public CloudPolicyInvalidationHandler { |
| 34 public: | 34 public: |
| 35 CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, | 35 CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, |
| 36 CloudPolicyStore* cloud_policy_store); | 36 CloudPolicyStore* cloud_policy_store); |
| 37 virtual ~CloudPolicyManager(); | 37 virtual ~CloudPolicyManager(); |
| 38 | 38 |
| 39 CloudPolicyCore* core() { return &core_; } | 39 CloudPolicyCore* core() { return &core_; } |
| 40 const CloudPolicyCore* core() const { return &core_; } | 40 const CloudPolicyCore* core() const { return &core_; } |
| 41 | 41 |
| 42 // Enables invalidations to the cloud policy. This method must only be | 42 // Sets the cloud policy invalidator used to enable invalidations to the |
| 43 // called once. | 43 // cloud policy. This method must only be called once. |
| 44 // |initialize_invalidator| should initialize the invalidator when invoked. | 44 void SetInvalidator(const base::WeakPtr<CloudPolicyInvalidator>& invalidator); |
|
Mattias Nissler (ping if slow)
2013/08/29 16:02:30
I'd favor a design where CloudPolicyManager doesn'
Steve Condie
2013/08/30 00:16:35
Done. In the latest patch nothing calls into the i
Mattias Nissler (ping if slow)
2013/09/02 11:54:52
Thanks, the new approach seems a lot cleaner (no w
| |
| 45 // If the manager is ready to receive invalidations, it will be invoked | |
| 46 // immediately; otherwise, it will be invoked upon becoming ready. | |
| 47 void EnableInvalidations(const base::Closure& initialize_invalidator); | |
| 48 | 45 |
| 49 // ConfigurationPolicyProvider: | 46 // ConfigurationPolicyProvider: |
| 50 virtual void Shutdown() OVERRIDE; | 47 virtual void Shutdown() OVERRIDE; |
| 51 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; | 48 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; |
| 52 virtual void RefreshPolicies() OVERRIDE; | 49 virtual void RefreshPolicies() OVERRIDE; |
| 53 | 50 |
| 54 // CloudPolicyStore::Observer: | 51 // CloudPolicyStore::Observer: |
| 55 virtual void OnStoreLoaded(CloudPolicyStore* cloud_policy_store) OVERRIDE; | 52 virtual void OnStoreLoaded(CloudPolicyStore* cloud_policy_store) OVERRIDE; |
| 56 virtual void OnStoreError(CloudPolicyStore* cloud_policy_store) OVERRIDE; | 53 virtual void OnStoreError(CloudPolicyStore* cloud_policy_store) OVERRIDE; |
| 57 | 54 |
| 58 // CloudPolicyInvalidationHandler: | 55 // CloudPolicyInvalidationHandler: |
| 59 virtual void SetInvalidationInfo( | 56 virtual void SetInvalidationInfo( |
| 60 int64 version, | 57 int64 version, |
| 61 const std::string& payload) OVERRIDE; | 58 const std::string& payload) OVERRIDE; |
| 62 virtual void InvalidatePolicy() OVERRIDE; | 59 virtual void InvalidatePolicy() OVERRIDE; |
| 63 virtual void OnInvalidatorStateChanged(bool invalidations_enabled) OVERRIDE; | 60 virtual void OnInvalidatorStateChanged(bool invalidations_enabled) OVERRIDE; |
| 64 | 61 |
| 65 protected: | 62 protected: |
| 66 // Check whether fully initialized and if so, publish policy by calling | 63 // Check whether fully initialized and if so, publish policy by calling |
| 67 // ConfigurationPolicyStore::UpdatePolicy(). | 64 // ConfigurationPolicyStore::UpdatePolicy(). |
| 68 void CheckAndPublishPolicy(); | 65 void CheckAndPublishPolicy(); |
| 69 | 66 |
| 70 // Starts the policy refresh scheduler. This must be called instead of calling | 67 // Starts the policy invalidator. The invalidator must not be started and the |
| 71 // enabling the scheduler on core() directly so that invalidations are | 68 // cloud policy refresh scheduler must be running. If the cloud policy core |
| 72 // enabled correctly. | 69 // is disconnected before shutdown, then StopCloudPolicyInvalidator must be |
| 73 void StartRefreshScheduler(); | 70 // called before disconnecting. |
| 71 void StartInvalidator(); | |
| 72 | |
| 73 // Stops the policy invalidator. If the invalidator was started, then this | |
| 74 // method must be called before disconnecting the cloud policy core (except | |
| 75 // during a normal shutdown). | |
| 76 void StopInvalidator(); | |
| 74 | 77 |
| 75 // Called by CheckAndPublishPolicy() to create a bundle with the current | 78 // Called by CheckAndPublishPolicy() to create a bundle with the current |
| 76 // policies. | 79 // policies. |
| 77 virtual scoped_ptr<PolicyBundle> CreatePolicyBundle(); | 80 virtual scoped_ptr<PolicyBundle> CreatePolicyBundle(); |
| 78 | 81 |
| 79 // Convenience accessors to core() components. | 82 // Convenience accessors to core() components. |
| 80 CloudPolicyClient* client() { return core_.client(); } | 83 CloudPolicyClient* client() { return core_.client(); } |
| 81 const CloudPolicyClient* client() const { return core_.client(); } | 84 const CloudPolicyClient* client() const { return core_.client(); } |
| 82 CloudPolicyStore* store() { return core_.store(); } | 85 CloudPolicyStore* store() { return core_.store(); } |
| 83 const CloudPolicyStore* store() const { return core_.store(); } | 86 const CloudPolicyStore* store() const { return core_.store(); } |
| 84 CloudPolicyService* service() { return core_.service(); } | 87 CloudPolicyService* service() { return core_.service(); } |
| 85 const CloudPolicyService* service() const { return core_.service(); } | 88 const CloudPolicyService* service() const { return core_.service(); } |
| 86 | 89 |
| 87 private: | 90 private: |
| 88 // Completion handler for policy refresh operations. | 91 // Completion handler for policy refresh operations. |
| 89 void OnRefreshComplete(bool success); | 92 void OnRefreshComplete(bool success); |
| 90 | 93 |
| 91 CloudPolicyCore core_; | 94 CloudPolicyCore core_; |
| 92 | 95 |
| 93 // Whether there's a policy refresh operation pending, in which case all | 96 // Whether there's a policy refresh operation pending, in which case all |
| 94 // policy update notifications are deferred until after it completes. | 97 // policy update notifications are deferred until after it completes. |
| 95 bool waiting_for_policy_refresh_; | 98 bool waiting_for_policy_refresh_; |
| 96 | 99 |
| 97 // Used to initialize the policy invalidator once the refresh scheduler | 100 // The cloud policy invalidator. |
| 98 // starts. | 101 base::WeakPtr<CloudPolicyInvalidator> invalidator_; |
| 99 base::Closure initialize_invalidator_; | 102 |
| 103 // Whether the invalidator should be started. This is needed since a subclass | |
| 104 // may call StartInvalidator before the invalidator has been set. | |
| 105 bool invalidator_started_; | |
| 100 | 106 |
| 101 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManager); | 107 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManager); |
| 102 }; | 108 }; |
| 103 | 109 |
| 104 } // namespace policy | 110 } // namespace policy |
| 105 | 111 |
| 106 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_ | 112 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_ |
| OLD | NEW |