Chromium Code Reviews| 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_CONTROLLER_H_ | |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_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_identity_strategy.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 | |
|
gfeher
2011/02/14 17:28:50
There is no Provide method here. Please update com
Mattias Nissler (ping if slow)
2011/02/15 10:15:16
Also, the whole threading issues mentioned here do
Jakob Kummerow
2011/02/21 12:12:15
Done.
Jakob Kummerow
2011/02/21 12:12:15
Done.
| |
| 31 // methods must be called on the UI thread. | |
| 32 class CloudPolicyController | |
| 33 : public DeviceManagementBackend::DevicePolicyResponseDelegate, | |
| 34 public DeviceTokenFetcher::Observer, | |
| 35 public CloudPolicyIdentityStrategy::Observer { | |
| 36 public: | |
| 37 class Observer { | |
| 38 public: | |
| 39 virtual ~Observer() {} | |
| 40 virtual void OnPolicyUpdated() {} | |
| 41 }; | |
| 42 | |
| 43 CloudPolicyController(CloudPolicyCache* cache, | |
| 44 DeviceManagementBackend* backend, | |
| 45 DeviceTokenFetcher* token_fetcher, | |
| 46 CloudPolicyIdentityStrategy* identity_strategy); | |
| 47 virtual ~CloudPolicyController(); | |
| 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 HandleCloudPolicyResponse( | |
| 56 const em::CloudPolicyResponse& response); | |
| 57 virtual void OnError(DeviceManagementBackend::ErrorCode code); | |
| 58 | |
| 59 // DeviceTokenFetcher::Observer implementation: | |
| 60 virtual void OnDeviceTokenAvailable(); | |
| 61 | |
| 62 // CloudPolicyIdentityStrategy::Observer implementation: | |
| 63 virtual void OnDeviceTokenChanged(); | |
| 64 virtual void OnCredentialsChanged(); | |
| 65 | |
| 66 private: | |
| 67 // Indicates the current state the provider is in. | |
|
gfeher
2011/02/14 17:28:50
provider->controller ?
Jakob Kummerow
2011/02/21 12:12:15
Done.
| |
| 68 enum ClientState { | |
|
Mattias Nissler (ping if slow)
2011/02/15 10:15:16
s/Client/Controller/
Jakob Kummerow
2011/02/21 12:12:15
Done.
| |
| 69 // The provider is initializing, policy information not yet available. | |
| 70 STATE_TOKEN_UNAVAILABLE, | |
| 71 // The token is valid, but policy is yet to be fetched. | |
| 72 STATE_TOKEN_VALID, | |
| 73 // Policy information is available and valid. | |
| 74 STATE_POLICY_VALID, | |
| 75 // The service returned an error when requesting policy, ask again later. | |
| 76 STATE_POLICY_ERROR, | |
| 77 }; | |
| 78 | |
| 79 friend class CloudPolicyControllerTest; | |
| 80 | |
| 81 // More configurable constructor for use by test cases. | |
| 82 CloudPolicyController(CloudPolicyCache* cache, | |
| 83 DeviceManagementBackend* backend, | |
| 84 DeviceTokenFetcher* token_fetcher, | |
| 85 CloudPolicyIdentityStrategy* identity_strategy, | |
| 86 int64 policy_refresh_rate_ms, | |
| 87 int policy_refresh_deviation_factor_percent, | |
| 88 int64 policy_refresh_deviation_max_ms, | |
| 89 int64 policy_refresh_error_delay_ms); | |
| 90 | |
| 91 // Called by constructors to perform shared initialization. | |
| 92 void Initialize(CloudPolicyCache* cache, | |
| 93 DeviceManagementBackend* backend, | |
| 94 DeviceTokenFetcher* token_fetcher, | |
| 95 CloudPolicyIdentityStrategy* identity_strategy, | |
| 96 int64 policy_refresh_rate_ms, | |
| 97 int policy_refresh_deviation_factor_percent, | |
| 98 int64 policy_refresh_deviation_max_ms, | |
| 99 int64 policy_refresh_error_delay_ms); | |
| 100 | |
| 101 // Asks the token fetcher to fetch a new token. | |
| 102 void FetchToken(); | |
| 103 | |
| 104 // Sends a request to the device manager backend to fetch policy if one isn't | |
| 105 // already outstanding. | |
| 106 void SendPolicyRequest(); | |
| 107 | |
| 108 // Called back from the delayed work task. Performs whatever action is | |
| 109 // required in the current state, e.g. refreshing policy. | |
| 110 void DoDelayedWork(); | |
| 111 | |
| 112 // Cancels the delayed work task. | |
| 113 void CancelDelayedWork(); | |
| 114 | |
| 115 // Switches to a new state and triggers any appropriate actions. | |
| 116 void SetState(ClientState new_state); | |
| 117 | |
| 118 // Computes the policy refresh delay to use. | |
| 119 int64 GetRefreshDelay(); | |
| 120 | |
| 121 CloudPolicyCache* cache_; | |
| 122 scoped_ptr<DeviceManagementBackend> backend_; | |
| 123 CloudPolicyIdentityStrategy* identity_strategy_; | |
| 124 DeviceTokenFetcher* token_fetcher_; | |
| 125 ClientState state_; | |
| 126 bool initial_fetch_done_; | |
| 127 bool fallback_to_old_protocol_; | |
| 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<CloudPolicyController> method_factory_; | |
| 137 | |
| 138 DISALLOW_COPY_AND_ASSIGN(CloudPolicyController); | |
| 139 }; | |
| 140 | |
| 141 } // namespace policy | |
| 142 | |
| 143 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ | |
| OLD | NEW |