| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/time.h" |
| 13 #include "base/weak_ptr.h" | 14 #include "base/weak_ptr.h" |
| 14 #include "chrome/browser/policy/configuration_policy_provider.h" | 15 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 15 #include "chrome/browser/policy/device_management_backend.h" | 16 #include "chrome/browser/policy/device_management_backend.h" |
| 16 #include "chrome/common/notification_details.h" | 17 #include "chrome/browser/policy/device_token_fetcher.h" |
| 17 #include "chrome/common/notification_observer.h" | |
| 18 #include "chrome/common/notification_registrar.h" | |
| 19 #include "chrome/common/notification_source.h" | |
| 20 | 18 |
| 21 class TokenService; | 19 class TokenService; |
| 22 | 20 |
| 23 namespace policy { | 21 namespace policy { |
| 24 | 22 |
| 25 class DeviceManagementBackend; | 23 class DeviceManagementBackend; |
| 26 class DeviceManagementPolicyCache; | 24 class DeviceManagementPolicyCache; |
| 27 class DeviceTokenFetcher; | |
| 28 | 25 |
| 29 // Provides policy fetched from the device management server. With the exception | 26 // Provides policy fetched from the device management server. With the exception |
| 30 // of the Provide method, which can be called on the FILE thread, all public | 27 // of the Provide method, which can be called on the FILE thread, all public |
| 31 // methods must be called on the UI thread. | 28 // methods must be called on the UI thread. |
| 32 class DeviceManagementPolicyProvider | 29 class DeviceManagementPolicyProvider |
| 33 : public ConfigurationPolicyProvider, | 30 : public ConfigurationPolicyProvider, |
| 34 public NotificationObserver, | |
| 35 public DeviceManagementBackend::DevicePolicyResponseDelegate, | 31 public DeviceManagementBackend::DevicePolicyResponseDelegate, |
| 36 public base::SupportsWeakPtr<DeviceManagementPolicyProvider> { | 32 public base::SupportsWeakPtr<DeviceManagementPolicyProvider>, |
| 33 public DeviceTokenFetcher::Observer { |
| 37 public: | 34 public: |
| 38 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, | 35 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, |
| 39 DeviceManagementBackend* backend, | 36 DeviceManagementBackend* backend, |
| 40 TokenService* token_service, | 37 TokenService* token_service, |
| 41 const FilePath& storage_dir); | 38 const FilePath& storage_dir); |
| 42 | 39 |
| 43 virtual ~DeviceManagementPolicyProvider(); | 40 virtual ~DeviceManagementPolicyProvider(); |
| 44 | 41 |
| 45 // ConfigurationPolicyProvider implementation: | 42 // ConfigurationPolicyProvider implementation: |
| 46 virtual bool Provide(ConfigurationPolicyStoreInterface* store); | 43 virtual bool Provide(ConfigurationPolicyStoreInterface* store); |
| 47 | 44 |
| 48 // NotificationObserver implementation: | |
| 49 virtual void Observe(NotificationType type, | |
| 50 const NotificationSource& source, | |
| 51 const NotificationDetails& details); | |
| 52 | |
| 53 // DevicePolicyResponseDelegate implementation: | 45 // DevicePolicyResponseDelegate implementation: |
| 54 virtual void HandlePolicyResponse( | 46 virtual void HandlePolicyResponse( |
| 55 const em::DevicePolicyResponse& response); | 47 const em::DevicePolicyResponse& response); |
| 56 virtual void OnError(DeviceManagementBackend::ErrorCode code); | 48 virtual void OnError(DeviceManagementBackend::ErrorCode code); |
| 57 | 49 |
| 50 // DeviceTokenFetcher::Observer implementation: |
| 51 void OnTokenSuccess(); |
| 52 void OnTokenError(); |
| 53 void OnNotManaged(); |
| 54 |
| 58 // True if a policy request has been sent to the device management backend | 55 // True if a policy request has been sent to the device management backend |
| 59 // server and no response or error has yet been received. | 56 // server and no response or error has yet been received. |
| 60 bool IsPolicyRequestPending() const { return policy_request_pending_; } | 57 bool IsPolicyRequestPending() const { return policy_request_pending_; } |
| 61 | 58 |
| 62 // Tells the provider that the passed in token service reference is about to | 59 // Tells the provider that the passed in token service reference is about to |
| 63 // become invalid. | 60 // become invalid. |
| 64 void Shutdown(); | 61 void Shutdown(); |
| 65 | 62 |
| 66 private: | 63 private: |
| 67 class InitializeAfterIOThreadExistsTask; | 64 class InitializeAfterIOThreadExistsTask; |
| 65 class RefreshTask; |
| 66 |
| 67 friend class DeviceManagementPolicyProviderTest; |
| 68 | 68 |
| 69 // Called by constructors to perform shared initialization. Initialization | 69 // Called by constructors to perform shared initialization. Initialization |
| 70 // requiring the IOThread must not be performed directly in this method, | 70 // requiring the IOThread must not be performed directly in this method, |
| 71 // rather must be deferred until the IOThread is fully initialized. This is | 71 // rather must be deferred until the IOThread is fully initialized. This is |
| 72 // the case in InitializeAfterIOThreadExists. | 72 // the case in InitializeAfterIOThreadExists. |
| 73 void Initialize(); | 73 void Initialize(); |
| 74 | 74 |
| 75 // Called by a deferred task posted to the UI thread to complete the portion | 75 // Called by a deferred task posted to the UI thread to complete the portion |
| 76 // of initialization that requires the IOThread. | 76 // of initialization that requires the IOThread. |
| 77 void InitializeAfterIOThreadExists(); | 77 void InitializeAfterIOThreadExists(); |
| 78 | 78 |
| 79 // Sends a request to the device manager backend to fetch policy if one isn't | 79 // Sends a request to the device manager backend to fetch policy if one isn't |
| 80 // already outstanding. | 80 // already outstanding. |
| 81 void SendPolicyRequest(); | 81 void SendPolicyRequest(); |
| 82 | 82 |
| 83 // True if policy must be re-fetched because the cached policy is too old or | 83 // Triggers policy refresh, re-requesting device token and policy information |
| 84 // its time stamp is invalid. | 84 // as necessary. |
| 85 bool IsPolicyStale() const; | 85 void RefreshTaskExecute(); |
| 86 |
| 87 // Schedules a new RefreshTask. |
| 88 void ScheduleRefreshTask(int64 delay_in_milliseconds); |
| 89 |
| 90 // Calculates when the next RefreshTask shall be executed. |
| 91 int64 GetRefreshTaskDelay(); |
| 86 | 92 |
| 87 // Provides the URL at which requests are sent to from the device management | 93 // Provides the URL at which requests are sent to from the device management |
| 88 // backend. | 94 // backend. |
| 89 static std::string GetDeviceManagementURL(); | 95 static std::string GetDeviceManagementURL(); |
| 90 | 96 |
| 91 // Returns the path to the sub-directory in the user data directory | 97 // Returns the path to the sub-directory in the user data directory |
| 92 // in which device management persistent state is stored. | 98 // in which device management persistent state is stored. |
| 93 static FilePath GetOrCreateDeviceManagementDir( | 99 static FilePath GetOrCreateDeviceManagementDir( |
| 94 const FilePath& user_data_dir); | 100 const FilePath& user_data_dir); |
| 95 | 101 |
| 102 // Give unit tests the ability to override timeout settings. |
| 103 void set_policy_refresh_rate_ms(int64 policy_refresh_rate_ms) { |
| 104 policy_refresh_rate_ms_ = policy_refresh_rate_ms; |
| 105 } |
| 106 void set_policy_refresh_max_earlier_ms(int64 policy_refresh_max_earlier_ms) { |
| 107 policy_refresh_max_earlier_ms_ = policy_refresh_max_earlier_ms; |
| 108 } |
| 109 void set_policy_refresh_error_delay_ms(int64 policy_refresh_error_delay_ms) { |
| 110 policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms; |
| 111 } |
| 112 void set_token_fetch_error_delay_ms(int64 token_fetch_error_delay_ms) { |
| 113 token_fetch_error_delay_ms_ = token_fetch_error_delay_ms; |
| 114 } |
| 115 |
| 96 scoped_ptr<DeviceManagementBackend> backend_; | 116 scoped_ptr<DeviceManagementBackend> backend_; |
| 97 TokenService* token_service_; // weak | 117 TokenService* token_service_; // weak |
| 98 scoped_ptr<DeviceManagementPolicyCache> cache_; | 118 scoped_ptr<DeviceManagementPolicyCache> cache_; |
| 99 scoped_refptr<DeviceTokenFetcher> token_fetcher_; | 119 scoped_refptr<DeviceTokenFetcher> token_fetcher_; |
| 100 NotificationRegistrar registrar_; | 120 DeviceTokenFetcher::ObserverRegistrar registrar_; |
| 101 FilePath storage_dir_; | 121 FilePath storage_dir_; |
| 102 bool policy_request_pending_; | 122 bool policy_request_pending_; |
| 123 bool refresh_task_pending_; |
| 124 int64 policy_refresh_rate_ms_; |
| 125 int64 policy_refresh_max_earlier_ms_; |
| 126 int64 policy_refresh_error_delay_ms_; |
| 127 int64 token_fetch_error_delay_ms_; |
| 103 | 128 |
| 104 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); | 129 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); |
| 105 }; | 130 }; |
| 106 | 131 |
| 107 } // namespace policy | 132 } // namespace policy |
| 108 | 133 |
| 109 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 134 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
| OLD | NEW |