OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_ |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/file_path.h" |
| 12 #include "base/observer_list.h" |
| 13 #include "base/scoped_ptr.h" |
| 14 #include "base/task.h" |
| 15 #include "base/time.h" |
| 16 #include "chrome/browser/policy/cloud_policy_controller.h" |
| 17 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 18 #include "chrome/browser/policy/device_management_backend.h" |
| 19 #include "chrome/browser/policy/device_token_fetcher.h" |
| 20 |
| 21 class Profile; |
| 22 class TokenService; |
| 23 |
| 24 namespace policy { |
| 25 |
| 26 class CloudPolicyCache; |
| 27 class DeviceManagementBackend; |
| 28 |
| 29 // 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 |
| 31 // methods must be called on the UI thread. |
| 32 class CloudPolicyClient |
| 33 : public DeviceManagementBackend::DevicePolicyResponseDelegate, |
| 34 public DeviceTokenFetcher::Observer, |
| 35 public CloudPolicyController::Observer { |
| 36 public: |
| 37 class Observer { |
| 38 public: |
| 39 virtual ~Observer() {} |
| 40 virtual void OnPolicyUpdated() {} |
| 41 }; |
| 42 |
| 43 CloudPolicyClient(CloudPolicyCache* cache, |
| 44 DeviceManagementBackend* backend, |
| 45 DeviceTokenFetcher* token_fetcher, |
| 46 CloudPolicyController* controller); |
| 47 virtual ~CloudPolicyClient(); |
| 48 |
| 49 // Sets the refresh rate at which to re-fetch policy information. |
| 50 void SetRefreshRate(int64 refresh_rate_milliseconds); |
| 51 |
| 52 // DevicePolicyResponseDelegate implementation: |
| 53 virtual void HandlePolicyResponse( |
| 54 const em::DevicePolicyResponse& response); |
| 55 virtual void OnError(DeviceManagementBackend::ErrorCode code); |
| 56 |
| 57 // DeviceTokenFetcher::Observer implementation: |
| 58 virtual void OnTokenAvailable(); |
| 59 |
| 60 // CloudPolicyController::Observer implementation: |
| 61 virtual void OnTokenChanged(); |
| 62 virtual void OnCredentialsChanged(); |
| 63 |
| 64 private: |
| 65 // Indicates the current state the provider is in. |
| 66 enum ClientState { |
| 67 // The provider is initializing, policy information not yet available. |
| 68 STATE_TOKEN_UNAVAILABLE, |
| 69 // The token is valid, but policy is yet to be fetched. |
| 70 STATE_TOKEN_VALID, |
| 71 // Policy information is available and valid. |
| 72 STATE_POLICY_VALID, |
| 73 // The service returned an error when requesting policy, ask again later. |
| 74 STATE_POLICY_ERROR, |
| 75 }; |
| 76 |
| 77 friend class CloudPolicyClientTest; |
| 78 |
| 79 // More configurable constructor for use by test cases. |
| 80 CloudPolicyClient(CloudPolicyCache* cache, |
| 81 DeviceManagementBackend* backend, |
| 82 DeviceTokenFetcher* token_fetcher, |
| 83 CloudPolicyController* controller, |
| 84 int64 policy_refresh_rate_ms, |
| 85 int policy_refresh_deviation_factor_percent, |
| 86 int64 policy_refresh_deviation_max_ms, |
| 87 int64 policy_refresh_error_delay_ms); |
| 88 |
| 89 // Called by constructors to perform shared initialization. Initialization |
| 90 // requiring the IOThread must not be performed directly in this method, |
| 91 // rather must be deferred until the IOThread is fully initialized. This is |
| 92 // the case in InitializeAfterIOThreadExists. |
| 93 void Initialize(CloudPolicyCache* cache, |
| 94 DeviceManagementBackend* backend, |
| 95 DeviceTokenFetcher* token_fetcher, |
| 96 CloudPolicyController* controller, |
| 97 int64 policy_refresh_rate_ms, |
| 98 int policy_refresh_deviation_factor_percent, |
| 99 int64 policy_refresh_deviation_max_ms, |
| 100 int64 policy_refresh_error_delay_ms); |
| 101 |
| 102 // Asks the token fetcher to fetch a new token. |
| 103 void FetchToken(); |
| 104 |
| 105 // Sends a request to the device manager backend to fetch policy if one isn't |
| 106 // already outstanding. |
| 107 void SendPolicyRequest(); |
| 108 |
| 109 // Called back from the delayed work task. Performs whatever action is |
| 110 // required in the current state, e.g. refreshing policy. |
| 111 void DoDelayedWork(); |
| 112 |
| 113 // Cancels the delayed work task. |
| 114 void CancelDelayedWork(); |
| 115 |
| 116 // Switches to a new state and triggers any appropriate actions. |
| 117 void SetState(ClientState new_state); |
| 118 |
| 119 // Computes the policy refresh delay to use. |
| 120 int64 GetRefreshDelay(); |
| 121 |
| 122 CloudPolicyCache* cache_; |
| 123 scoped_ptr<DeviceManagementBackend> backend_; |
| 124 CloudPolicyController* controller_; |
| 125 DeviceTokenFetcher* token_fetcher_; |
| 126 ClientState state_; |
| 127 bool initial_fetch_done_; |
| 128 |
| 129 int64 policy_refresh_rate_ms_; |
| 130 int policy_refresh_deviation_factor_percent_; |
| 131 int64 policy_refresh_deviation_max_ms_; |
| 132 int64 policy_refresh_error_delay_ms_; |
| 133 int64 effective_policy_refresh_error_delay_ms_; |
| 134 |
| 135 CancelableTask* delayed_work_task_; |
| 136 ScopedRunnableMethodFactory<CloudPolicyClient> method_factory_; |
| 137 |
| 138 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); |
| 139 }; |
| 140 |
| 141 } // namespace policy |
| 142 |
| 143 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_ |
OLD | NEW |