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_USER_CLOUD_POLICY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ |
| 6 #define CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ | 6 #define CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/policy/cloud_policy_client.h" | 11 #include "chrome/browser/policy/cloud_policy_client.h" |
| 11 #include "chrome/browser/policy/cloud_policy_constants.h" | 12 #include "chrome/browser/policy/cloud_policy_constants.h" |
| 12 #include "chrome/browser/policy/cloud_policy_store.h" | 13 #include "chrome/browser/policy/cloud_policy_manager.h" |
| 13 #include "chrome/browser/policy/configuration_policy_provider.h" | |
| 14 | 14 |
| 15 class PrefService; | 15 class PrefService; |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace policy { | 18 namespace policy { |
| 19 | 19 |
| 20 class CloudPolicyRefreshScheduler; | 20 class CloudPolicyRefreshScheduler; |
| 21 class CloudPolicyService; | 21 class CloudPolicyService; |
|
Joao da Silva
2012/09/07 12:44:13
nit: these 2 are not used
Mattias Nissler (ping if slow)
2012/09/07 13:12:59
Done.
| |
| 22 class DeviceManagementService; | 22 class DeviceManagementService; |
| 23 | 23 |
| 24 // UserCloudPolicyManager keeps track of all things user policy, drives the | 24 // UserCloudPolicyManager keeps track of all things user policy, drives the |
| 25 // corresponding cloud policy service and publishes policy through the | 25 // corresponding cloud policy service and publishes policy through the |
| 26 // ConfigurationPolicyProvider interface. | 26 // ConfigurationPolicyProvider interface. |
| 27 class UserCloudPolicyManager : public ConfigurationPolicyProvider, | 27 class UserCloudPolicyManager : public CloudPolicyManager, |
| 28 public CloudPolicyClient::Observer, | 28 public CloudPolicyClient::Observer { |
| 29 public CloudPolicyStore::Observer { | |
| 30 public: | 29 public: |
| 31 // If |wait_for_policy| fetch is true, IsInitializationComplete() will return | 30 // If |wait_for_policy| fetch is true, IsInitializationComplete() will return |
| 32 // false as long as there hasn't been a successful policy fetch. | 31 // false as long as there hasn't been a successful policy fetch. |
| 33 UserCloudPolicyManager(scoped_ptr<CloudPolicyStore> store, | 32 UserCloudPolicyManager(scoped_ptr<CloudPolicyStore> store, |
| 34 bool wait_for_policy_fetch); | 33 bool wait_for_policy_fetch); |
| 35 virtual ~UserCloudPolicyManager(); | 34 virtual ~UserCloudPolicyManager(); |
| 36 | 35 |
| 37 // Creates a UserCloudPolicyService instance associated with the passed | 36 // Creates a UserCloudPolicyService instance associated with the passed |
|
Joao da Silva
2012/09/07 12:44:13
Creates a UserCloudPolicyManager?
Mattias Nissler (ping if slow)
2012/09/07 13:12:59
Done.
| |
| 38 // |profile|. | 37 // |profile|. |
| 39 static scoped_ptr<UserCloudPolicyManager> Create(Profile* profile, | 38 static scoped_ptr<UserCloudPolicyManager> Create(Profile* profile, |
| 40 bool wait_for_policy_fetch); | 39 bool wait_for_policy_fetch); |
| 41 | 40 |
| 42 // Initializes the cloud connection. |local_prefs| and |service| must stay | 41 // Initializes the cloud connection. |local_state| and |service| must stay |
| 43 // valid until this object is deleted or ShutdownAndRemovePolicy() gets | 42 // valid until this object is deleted or ShutdownAndRemovePolicy() gets |
| 44 // called. Virtual for mocking. | 43 // called. Virtual for mocking. |
| 45 virtual void Initialize(PrefService* local_prefs, | 44 virtual void Initialize(PrefService* local_state, |
| 46 DeviceManagementService* service, | 45 DeviceManagementService* device_management_service, |
| 47 UserAffiliation user_affiliation); | 46 UserAffiliation user_affiliation); |
| 48 | 47 |
| 49 // Shuts down the UserCloudPolicyManager (removes and stops refreshing the | 48 // Shuts down the UserCloudPolicyManager (removes and stops refreshing the |
| 50 // cached cloud policy). This is typically called when a profile is being | 49 // cached cloud policy). This is typically called when a profile is being |
| 51 // disassociated from a given user (e.g. during signout). No policy will be | 50 // disassociated from a given user (e.g. during signout). No policy will be |
| 52 // provided by this object until the next time Initialize() is invoked. | 51 // provided by this object until the next time Initialize() is invoked. |
| 53 void ShutdownAndRemovePolicy(); | 52 void ShutdownAndRemovePolicy(); |
| 54 | 53 |
| 55 // Cancels waiting for the policy fetch and flags the | 54 // Cancels waiting for the policy fetch and flags the |
| 56 // ConfigurationPolicyProvider ready (assuming all other initialization tasks | 55 // ConfigurationPolicyProvider ready (assuming all other initialization tasks |
| 57 // have completed). | 56 // have completed). |
| 58 void CancelWaitForPolicyFetch(); | 57 void CancelWaitForPolicyFetch(); |
| 59 | 58 |
| 60 // Returns true if the underlying CloudPolicyClient is already registered. | 59 // Returns true if the underlying CloudPolicyClient is already registered. |
| 61 // Virtual for mocking. | 60 // Virtual for mocking. |
| 62 virtual bool IsClientRegistered() const; | 61 virtual bool IsClientRegistered() const; |
| 63 | 62 |
| 64 // Register the CloudPolicyClient using the passed OAuth token. | 63 // Register the CloudPolicyClient using the passed OAuth token. |
| 65 void RegisterClient(const std::string& access_token); | 64 void RegisterClient(const std::string& access_token); |
|
Joao da Silva
2012/09/07 12:44:13
#include <string>
Mattias Nissler (ping if slow)
2012/09/07 13:12:59
Done.
| |
| 66 | 65 |
| 67 CloudPolicyService* cloud_policy_service() { return service_.get(); } | |
| 68 | |
| 69 // ConfigurationPolicyProvider: | 66 // ConfigurationPolicyProvider: |
| 70 virtual bool IsInitializationComplete() const OVERRIDE; | 67 virtual bool IsInitializationComplete() const OVERRIDE; |
| 71 virtual void RefreshPolicies() OVERRIDE; | |
| 72 | 68 |
| 73 // CloudPolicyClient::Observer: | 69 // CloudPolicyClient::Observer: |
| 74 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | 70 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; |
| 75 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | 71 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; |
| 76 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | 72 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; |
| 77 | 73 |
| 78 // CloudPolicyStore::Observer: | |
| 79 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; | |
| 80 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; | |
| 81 | |
| 82 private: | 74 private: |
| 83 // Check whether fully initialized and if so, publish policy by calling | |
| 84 // ConfigurationPolicyStore::UpdatePolicy(). | |
| 85 void CheckAndPublishPolicy(); | |
| 86 | |
| 87 // Completion handler for the explicit policy fetch triggered on startup in | 75 // Completion handler for the explicit policy fetch triggered on startup in |
| 88 // case |wait_for_policy_fetch_| is true. | 76 // case |wait_for_policy_fetch_| is true. |
| 89 void OnInitialPolicyFetchComplete(); | 77 void OnInitialPolicyFetchComplete(); |
| 90 | 78 |
| 91 // Completion handler for policy refresh operations. | |
| 92 void OnRefreshComplete(); | |
| 93 | |
| 94 // Frees the CloudPolicyService and stops refreshing policy. Any previously | |
| 95 // cached policy will continue to be served. | |
| 96 void Shutdown(); | |
| 97 | |
| 98 // Whether to wait for a policy fetch to complete before reporting | 79 // Whether to wait for a policy fetch to complete before reporting |
| 99 // IsInitializationComplete(). | 80 // IsInitializationComplete(). |
| 100 bool wait_for_policy_fetch_; | 81 bool wait_for_policy_fetch_; |
| 101 | 82 |
| 102 // Whether there's a policy refresh operation pending, in which case all | |
| 103 // policy update notifications are deferred until after it completes. | |
| 104 bool wait_for_policy_refresh_; | |
| 105 | |
| 106 scoped_ptr<CloudPolicyStore> store_; | |
| 107 scoped_ptr<CloudPolicyService> service_; | |
| 108 scoped_ptr<CloudPolicyRefreshScheduler> refresh_scheduler_; | |
| 109 | |
| 110 // The pref service to pass to the refresh scheduler on initialization. | 83 // The pref service to pass to the refresh scheduler on initialization. |
| 111 PrefService* prefs_; | 84 PrefService* local_state_; |
| 112 | 85 |
| 113 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManager); | 86 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManager); |
| 114 }; | 87 }; |
| 115 | 88 |
| 116 } // namespace policy | 89 } // namespace policy |
| 117 | 90 |
| 118 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ | 91 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_MANAGER_H_ |
| OLD | NEW |