| 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_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_CHROMEOS_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_CHROMEOS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_CHROMEOS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 17 #include "chrome/browser/policy/cloud/cloud_policy_client.h" | 17 #include "chrome/browser/policy/cloud/cloud_policy_client.h" |
| 18 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 18 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| 19 #include "chrome/browser/policy/cloud/cloud_policy_manager.h" | 19 #include "chrome/browser/policy/cloud/cloud_policy_manager.h" |
| 20 #include "chrome/browser/policy/cloud/cloud_policy_service.h" | 20 #include "chrome/browser/policy/cloud/cloud_policy_service.h" |
| 21 #include "chrome/browser/policy/cloud/component_cloud_policy_service.h" | |
| 22 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 21 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 23 | 22 |
| 24 class GoogleServiceAuthError; | 23 class GoogleServiceAuthError; |
| 25 class PrefService; | 24 class PrefService; |
| 26 | 25 |
| 27 namespace base { | 26 namespace base { |
| 28 class SequencedTaskRunner; | 27 class SequencedTaskRunner; |
| 29 } | 28 } |
| 30 | 29 |
| 31 namespace net { | 30 namespace net { |
| 32 class URLRequestContextGetter; | 31 class URLRequestContextGetter; |
| 33 } | 32 } |
| 34 | 33 |
| 35 namespace policy { | 34 namespace policy { |
| 36 | 35 |
| 37 class CloudExternalDataManager; | 36 class CloudExternalDataManager; |
| 38 class DeviceManagementService; | 37 class DeviceManagementService; |
| 39 class PolicyOAuth2TokenFetcher; | 38 class PolicyOAuth2TokenFetcher; |
| 40 | 39 |
| 41 // UserCloudPolicyManagerChromeOS implements logic for initializing user policy | 40 // UserCloudPolicyManagerChromeOS implements logic for initializing user policy |
| 42 // on Chrome OS. | 41 // on Chrome OS. |
| 43 class UserCloudPolicyManagerChromeOS | 42 class UserCloudPolicyManagerChromeOS |
| 44 : public CloudPolicyManager, | 43 : public CloudPolicyManager, |
| 45 public CloudPolicyClient::Observer, | 44 public CloudPolicyClient::Observer, |
| 46 public CloudPolicyService::Observer, | 45 public CloudPolicyService::Observer, |
| 47 public ComponentCloudPolicyService::Delegate, | |
| 48 public BrowserContextKeyedService { | 46 public BrowserContextKeyedService { |
| 49 public: | 47 public: |
| 50 // |task_runner| is the runner for policy refresh tasks. | |
| 51 // If |wait_for_policy_fetch| is true, IsInitializationComplete() will return | 48 // If |wait_for_policy_fetch| is true, IsInitializationComplete() will return |
| 52 // false as long as there hasn't been a successful policy fetch. | 49 // false as long as there hasn't been a successful policy fetch. |
| 50 // |task_runner| is the runner for policy refresh tasks. |
| 51 // |file_task_runner| is used for file operations. Currently this must be the |
| 52 // FILE BrowserThread. |
| 53 // |io_task_runner| is used for network IO. Currently this must be the IO |
| 54 // BrowserThread. |
| 53 UserCloudPolicyManagerChromeOS( | 55 UserCloudPolicyManagerChromeOS( |
| 54 scoped_ptr<CloudPolicyStore> store, | 56 scoped_ptr<CloudPolicyStore> store, |
| 55 scoped_ptr<CloudExternalDataManager> external_data_manager, | 57 scoped_ptr<CloudExternalDataManager> external_data_manager, |
| 58 const base::FilePath& component_policy_cache_path, |
| 59 bool wait_for_policy_fetch, |
| 60 base::TimeDelta initial_policy_fetch_timeout, |
| 56 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 61 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 57 const base::FilePath& resource_cache_dir, | 62 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner, |
| 58 bool wait_for_policy_fetch, | 63 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner); |
| 59 base::TimeDelta initial_policy_fetch_timeout); | |
| 60 virtual ~UserCloudPolicyManagerChromeOS(); | 64 virtual ~UserCloudPolicyManagerChromeOS(); |
| 61 | 65 |
| 62 // Initializes the cloud connection. |local_state| and | 66 // Initializes the cloud connection. |local_state| and |
| 63 // |device_management_service| must stay valid until this object is deleted. | 67 // |device_management_service| must stay valid until this object is deleted. |
| 64 void Connect(PrefService* local_state, | 68 void Connect(PrefService* local_state, |
| 65 DeviceManagementService* device_management_service, | 69 DeviceManagementService* device_management_service, |
| 66 scoped_refptr<net::URLRequestContextGetter> request_context, | 70 scoped_refptr<net::URLRequestContextGetter> request_context, |
| 67 UserAffiliation user_affiliation); | 71 UserAffiliation user_affiliation); |
| 68 | 72 |
| 69 // This class is one of the policy providers, and must be ready for the | 73 // This class is one of the policy providers, and must be ready for the |
| 70 // creation of the Profile's PrefService; all the other | 74 // creation of the Profile's PrefService; all the other |
| 71 // BrowserContextKeyedServices depend on the PrefService, so this class can't | 75 // BrowserContextKeyedServices depend on the PrefService, so this class can't |
| 72 // depend on other BCKS to avoid a circular dependency. So instead of using | 76 // depend on other BCKS to avoid a circular dependency. So instead of using |
| 73 // the ProfileOAuth2TokenService directly to get the access token, a 3rd | 77 // the ProfileOAuth2TokenService directly to get the access token, a 3rd |
| 74 // service (UserCloudPolicyTokenForwarder) will fetch it later and pass it | 78 // service (UserCloudPolicyTokenForwarder) will fetch it later and pass it |
| 75 // to this method once available. | 79 // to this method once available. |
| 76 // The |access_token| can then be used to authenticate the registration | 80 // The |access_token| can then be used to authenticate the registration |
| 77 // request to the DMServer. | 81 // request to the DMServer. |
| 78 void OnAccessTokenAvailable(const std::string& access_token); | 82 void OnAccessTokenAvailable(const std::string& access_token); |
| 79 | 83 |
| 80 // Returns true if the underlying CloudPolicyClient is already registered. | 84 // Returns true if the underlying CloudPolicyClient is already registered. |
| 81 bool IsClientRegistered() const; | 85 bool IsClientRegistered() const; |
| 82 | 86 |
| 83 // ConfigurationPolicyProvider: | 87 // ConfigurationPolicyProvider: |
| 84 virtual void Shutdown() OVERRIDE; | 88 virtual void Shutdown() OVERRIDE; |
| 85 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; | 89 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; |
| 86 | 90 |
| 87 // CloudPolicyManager: | |
| 88 virtual scoped_ptr<PolicyBundle> CreatePolicyBundle() OVERRIDE; | |
| 89 | |
| 90 // CloudPolicyService::Observer: | 91 // CloudPolicyService::Observer: |
| 91 virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE; | 92 virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE; |
| 92 | 93 |
| 93 // CloudPolicyClient::Observer: | 94 // CloudPolicyClient::Observer: |
| 94 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | 95 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; |
| 95 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | 96 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; |
| 96 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | 97 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; |
| 97 | 98 |
| 98 // ComponentCloudPolicyService::Delegate: | 99 // ComponentCloudPolicyService::Delegate: |
| 99 virtual void OnComponentCloudPolicyUpdated() OVERRIDE; | 100 virtual void OnComponentCloudPolicyUpdated() OVERRIDE; |
| 100 | 101 |
| 101 private: | 102 private: |
| 102 void CreateComponentCloudPolicyService( | |
| 103 const scoped_refptr<net::URLRequestContextGetter>& request_context); | |
| 104 | |
| 105 // Fetches a policy token using the authentication context of the signin | 103 // Fetches a policy token using the authentication context of the signin |
| 106 // Profile, and calls back to OnOAuth2PolicyTokenFetched when done. | 104 // Profile, and calls back to OnOAuth2PolicyTokenFetched when done. |
| 107 void FetchPolicyOAuthTokenUsingSigninProfile(); | 105 void FetchPolicyOAuthTokenUsingSigninProfile(); |
| 108 | 106 |
| 109 // Called once the policy access token is available, and starts the | 107 // Called once the policy access token is available, and starts the |
| 110 // registration with the policy server if the token was successfully fetched. | 108 // registration with the policy server if the token was successfully fetched. |
| 111 void OnOAuth2PolicyTokenFetched(const std::string& policy_token, | 109 void OnOAuth2PolicyTokenFetched(const std::string& policy_token, |
| 112 const GoogleServiceAuthError& error); | 110 const GoogleServiceAuthError& error); |
| 113 | 111 |
| 114 // Completion handler for the explicit policy fetch triggered on startup in | 112 // Completion handler for the explicit policy fetch triggered on startup in |
| 115 // case |wait_for_policy_fetch_| is true. |success| is true if the fetch was | 113 // case |wait_for_policy_fetch_| is true. |success| is true if the fetch was |
| 116 // successful. | 114 // successful. |
| 117 void OnInitialPolicyFetchComplete(bool success); | 115 void OnInitialPolicyFetchComplete(bool success); |
| 118 | 116 |
| 119 // Cancels waiting for the policy fetch and flags the | 117 // Cancels waiting for the policy fetch and flags the |
| 120 // ConfigurationPolicyProvider ready (assuming all other initialization tasks | 118 // ConfigurationPolicyProvider ready (assuming all other initialization tasks |
| 121 // have completed). | 119 // have completed). |
| 122 void CancelWaitForPolicyFetch(); | 120 void CancelWaitForPolicyFetch(); |
| 123 | 121 |
| 124 void StartRefreshSchedulerIfReady(); | 122 void StartRefreshSchedulerIfReady(); |
| 125 | 123 |
| 126 // Owns the store, note that CloudPolicyManager just keeps a plain pointer. | 124 // Owns the store, note that CloudPolicyManager just keeps a plain pointer. |
| 127 scoped_ptr<CloudPolicyStore> store_; | 125 scoped_ptr<CloudPolicyStore> store_; |
| 128 | 126 |
| 129 // Manages external data referenced by policies. | 127 // Manages external data referenced by policies. |
| 130 scoped_ptr<CloudExternalDataManager> external_data_manager_; | 128 scoped_ptr<CloudExternalDataManager> external_data_manager_; |
| 131 | 129 |
| 132 // Handles fetching and storing cloud policy for components. It uses the | 130 // Path where policy for components will be cached. |
| 133 // |store_|, so destroy it first. | 131 base::FilePath component_policy_cache_path_; |
| 134 scoped_ptr<ComponentCloudPolicyService> component_policy_service_; | |
| 135 | |
| 136 // Directory for the ResourceCache, if one is created. | |
| 137 base::FilePath resource_cache_dir_; | |
| 138 | 132 |
| 139 // Whether to wait for a policy fetch to complete before reporting | 133 // Whether to wait for a policy fetch to complete before reporting |
| 140 // IsInitializationComplete(). | 134 // IsInitializationComplete(). |
| 141 bool wait_for_policy_fetch_; | 135 bool wait_for_policy_fetch_; |
| 142 | 136 |
| 143 // A timer that puts a hard limit on the maximum time to wait for the intial | 137 // A timer that puts a hard limit on the maximum time to wait for the intial |
| 144 // policy fetch. | 138 // policy fetch. |
| 145 base::Timer policy_fetch_timeout_; | 139 base::Timer policy_fetch_timeout_; |
| 146 | 140 |
| 147 // The pref service to pass to the refresh scheduler on initialization. | 141 // The pref service to pass to the refresh scheduler on initialization. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 160 base::Time time_init_completed_; | 154 base::Time time_init_completed_; |
| 161 base::Time time_token_available_; | 155 base::Time time_token_available_; |
| 162 base::Time time_client_registered_; | 156 base::Time time_client_registered_; |
| 163 | 157 |
| 164 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOS); | 158 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOS); |
| 165 }; | 159 }; |
| 166 | 160 |
| 167 } // namespace policy | 161 } // namespace policy |
| 168 | 162 |
| 169 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_CHROMEOS_H_ | 163 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_MANAGER_CHROMEOS_H_ |
| OLD | NEW |