| 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_POLICY_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/policy/cloud_policy_constants.h" |
| 11 #include "chrome/browser/policy/cloud_policy_data_store.h" | 12 #include "chrome/browser/policy/cloud_policy_data_store.h" |
| 12 #include "chrome/browser/policy/device_management_backend.h" | 13 |
| 14 namespace enterprise_management { |
| 15 class DeviceManagementResponse; |
| 16 } |
| 13 | 17 |
| 14 namespace policy { | 18 namespace policy { |
| 15 | 19 |
| 16 class CloudPolicyCacheBase; | 20 class CloudPolicyCacheBase; |
| 17 class DelayedWorkScheduler; | 21 class DelayedWorkScheduler; |
| 22 class DeviceManagementRequestJob; |
| 18 class DeviceManagementService; | 23 class DeviceManagementService; |
| 19 class DeviceTokenFetcher; | 24 class DeviceTokenFetcher; |
| 20 class PolicyNotifier; | 25 class PolicyNotifier; |
| 21 | 26 |
| 22 // Coordinates the actions of DeviceTokenFetcher, CloudPolicyDataStore, | 27 // Coordinates the actions of DeviceTokenFetcher, CloudPolicyDataStore, |
| 23 // DeviceManagementBackend, and CloudPolicyCache: calls their methods and | 28 // and CloudPolicyCache: calls their methods and listens to their |
| 24 // listens to their callbacks/notifications. | 29 // callbacks/notifications. |
| 25 class CloudPolicyController | 30 class CloudPolicyController : public CloudPolicyDataStore::Observer { |
| 26 : public DeviceManagementBackend::DevicePolicyResponseDelegate, | |
| 27 public CloudPolicyDataStore::Observer { | |
| 28 public: | 31 public: |
| 29 // All parameters are weak pointers. | 32 // All parameters are weak pointers. |
| 30 CloudPolicyController(DeviceManagementService* service, | 33 CloudPolicyController(DeviceManagementService* service, |
| 31 CloudPolicyCacheBase* cache, | 34 CloudPolicyCacheBase* cache, |
| 32 DeviceTokenFetcher* token_fetcher, | 35 DeviceTokenFetcher* token_fetcher, |
| 33 CloudPolicyDataStore* data_store, | 36 CloudPolicyDataStore* data_store, |
| 34 PolicyNotifier* notifier); | 37 PolicyNotifier* notifier); |
| 35 virtual ~CloudPolicyController(); | 38 virtual ~CloudPolicyController(); |
| 36 | 39 |
| 37 // Sets the refresh rate at which to re-fetch policy information. | 40 // Sets the refresh rate at which to re-fetch policy information. |
| 38 void SetRefreshRate(int64 refresh_rate_milliseconds); | 41 void SetRefreshRate(int64 refresh_rate_milliseconds); |
| 39 | 42 |
| 40 // Triggers an immediate retry of the current operation. | 43 // Triggers an immediate retry of the current operation. |
| 41 void Retry(); | 44 void Retry(); |
| 42 | 45 |
| 43 // Stops any pending activity and resets the controller to unenrolled state. | 46 // Stops any pending activity and resets the controller to unenrolled state. |
| 44 void Reset(); | 47 void Reset(); |
| 45 | 48 |
| 46 // Attempts to fetch policies again, if possible. The cache is notified that | 49 // Attempts to fetch policies again, if possible. The cache is notified that |
| 47 // a fetch was attempted. | 50 // a fetch was attempted. |
| 48 void RefreshPolicies(); | 51 void RefreshPolicies(); |
| 49 | 52 |
| 50 // DevicePolicyResponseDelegate implementation: | 53 // Policy request response handler. |
| 51 virtual void HandlePolicyResponse( | 54 void OnPolicyFetchCompleted( |
| 52 const enterprise_management::DevicePolicyResponse& response) OVERRIDE; | 55 DeviceManagementStatus status, |
| 53 virtual void OnError(DeviceManagementBackend::ErrorCode code) OVERRIDE; | 56 const enterprise_management::DeviceManagementResponse& response); |
| 54 | 57 |
| 55 // CloudPolicyDataStore::Observer implementation: | 58 // CloudPolicyDataStore::Observer implementation: |
| 56 virtual void OnDeviceTokenChanged() OVERRIDE; | 59 virtual void OnDeviceTokenChanged() OVERRIDE; |
| 57 virtual void OnCredentialsChanged() OVERRIDE; | 60 virtual void OnCredentialsChanged() OVERRIDE; |
| 58 | 61 |
| 59 private: | 62 private: |
| 60 // Indicates the current state the controller is in. | 63 // Indicates the current state the controller is in. |
| 61 enum ControllerState { | 64 enum ControllerState { |
| 62 // The controller is initializing, policy information not yet available. | 65 // The controller is initializing, policy information not yet available. |
| 63 STATE_TOKEN_UNAVAILABLE, | 66 STATE_TOKEN_UNAVAILABLE, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // Switches to a new state and triggers any appropriate actions. | 116 // Switches to a new state and triggers any appropriate actions. |
| 114 void SetState(ControllerState new_state); | 117 void SetState(ControllerState new_state); |
| 115 | 118 |
| 116 // Computes the policy refresh delay to use. | 119 // Computes the policy refresh delay to use. |
| 117 int64 GetRefreshDelay(); | 120 int64 GetRefreshDelay(); |
| 118 | 121 |
| 119 DeviceManagementService* service_; | 122 DeviceManagementService* service_; |
| 120 CloudPolicyCacheBase* cache_; | 123 CloudPolicyCacheBase* cache_; |
| 121 CloudPolicyDataStore* data_store_; | 124 CloudPolicyDataStore* data_store_; |
| 122 DeviceTokenFetcher* token_fetcher_; | 125 DeviceTokenFetcher* token_fetcher_; |
| 123 scoped_ptr<DeviceManagementBackend> backend_; | 126 scoped_ptr<DeviceManagementRequestJob> request_job_; |
| 124 ControllerState state_; | 127 ControllerState state_; |
| 125 PolicyNotifier* notifier_; | 128 PolicyNotifier* notifier_; |
| 126 | 129 |
| 127 int64 policy_refresh_rate_ms_; | 130 int64 policy_refresh_rate_ms_; |
| 128 int64 effective_policy_refresh_error_delay_ms_; | 131 int64 effective_policy_refresh_error_delay_ms_; |
| 129 | 132 |
| 130 scoped_ptr<DelayedWorkScheduler> scheduler_; | 133 scoped_ptr<DelayedWorkScheduler> scheduler_; |
| 131 | 134 |
| 132 DISALLOW_COPY_AND_ASSIGN(CloudPolicyController); | 135 DISALLOW_COPY_AND_ASSIGN(CloudPolicyController); |
| 133 }; | 136 }; |
| 134 | 137 |
| 135 } // namespace policy | 138 } // namespace policy |
| 136 | 139 |
| 137 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ | 140 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ |
| OLD | NEW |