Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
|
Joao da Silva
2011/07/06 16:45:14
Nit: file_path.h not used
gfeher
2011/07/07 13:51:00
Done.
| |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "base/task.h" | 14 #include "base/task.h" |
|
Joao da Silva
2011/07/06 16:45:14
Nit: task.h and observer_list.h not used
gfeher
2011/07/07 13:51:00
Done.
| |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
|
Joao da Silva
2011/07/06 16:45:14
Nit: time.h only needed on .cc file
gfeher
2011/07/07 13:51:00
Done.
Joao da Silva
2011/07/07 16:54:16
Hmm it seems it's still in the .h, is it required
gfeher
2011/07/08 09:19:14
Sorry. Done.
| |
| 16 #include "chrome/browser/policy/cloud_policy_identity_strategy.h" | 16 #include "chrome/browser/policy/cloud_policy_data.h" |
| 17 #include "chrome/browser/policy/configuration_policy_provider.h" | 17 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 18 #include "chrome/browser/policy/delayed_work_scheduler.h" | 18 #include "chrome/browser/policy/delayed_work_scheduler.h" |
| 19 #include "chrome/browser/policy/device_management_backend.h" | 19 #include "chrome/browser/policy/device_management_backend.h" |
| 20 #include "chrome/browser/policy/device_token_fetcher.h" | 20 #include "chrome/browser/policy/device_token_fetcher.h" |
| 21 | 21 |
| 22 class Profile; | 22 class Profile; |
| 23 class TokenService; | 23 class TokenService; |
|
Joao da Silva
2011/07/06 16:45:14
Nit: Profile and TokenService not used
gfeher
2011/07/07 13:51:00
Done.
| |
| 24 | 24 |
| 25 namespace policy { | 25 namespace policy { |
| 26 | 26 |
| 27 class CloudPolicyData; | |
|
pastarmovj
2011/07/06 12:11:57
Why do you both include the header and forward dec
gfeher
2011/07/06 15:14:20
Done.
| |
| 27 class CloudPolicyCacheBase; | 28 class CloudPolicyCacheBase; |
| 28 class DeviceManagementBackend; | 29 class DeviceManagementBackend; |
|
pastarmovj
2011/07/06 12:11:57
Ditto. Pick one.
gfeher
2011/07/06 15:14:20
Done.
| |
| 29 | 30 |
| 30 // Coordinates the actions of DeviceTokenFetcher, CloudPolicyIdentityStrategy, | 31 // Coordinates the actions of DeviceTokenFetcher, CloudPolicyIdentityStrategy, |
| 31 // DeviceManagementBackend, and CloudPolicyCache: calls their methods and | 32 // DeviceManagementBackend, and CloudPolicyCache: calls their methods and |
| 32 // listens to their callbacks/notifications. | 33 // listens to their callbacks/notifications. |
| 33 class CloudPolicyController | 34 class CloudPolicyController |
| 34 : public DeviceManagementBackend::DevicePolicyResponseDelegate, | 35 : public DeviceManagementBackend::DevicePolicyResponseDelegate, |
| 35 public DeviceTokenFetcher::Observer, | 36 public CloudPolicyData::Observer { |
| 36 public CloudPolicyIdentityStrategy::Observer { | |
| 37 public: | 37 public: |
| 38 // All parameters are weak pointers. | 38 // All parameters are weak pointers. |
| 39 CloudPolicyController(DeviceManagementService* service, | 39 CloudPolicyController(DeviceManagementService* service, |
| 40 CloudPolicyCacheBase* cache, | 40 CloudPolicyCacheBase* cache, |
| 41 DeviceTokenFetcher* token_fetcher, | 41 DeviceTokenFetcher* token_fetcher, |
| 42 CloudPolicyIdentityStrategy* identity_strategy, | 42 CloudPolicyData* data, |
| 43 PolicyNotifier* notifier); | 43 PolicyNotifier* notifier); |
| 44 virtual ~CloudPolicyController(); | 44 virtual ~CloudPolicyController(); |
| 45 | 45 |
| 46 // Sets the refresh rate at which to re-fetch policy information. | 46 // Sets the refresh rate at which to re-fetch policy information. |
| 47 void SetRefreshRate(int64 refresh_rate_milliseconds); | 47 void SetRefreshRate(int64 refresh_rate_milliseconds); |
| 48 | 48 |
| 49 // Triggers an immediate retry of of the current operation. | 49 // Triggers an immediate retry of of the current operation. |
| 50 void Retry(); | 50 void Retry(); |
| 51 | 51 |
| 52 // Stops all auto-retrying error handling behavior inside the policy | 52 // Stops all auto-retrying error handling behavior inside the policy |
| 53 // subsystem. | 53 // subsystem. |
| 54 void StopAutoRetry(); | 54 void StopAutoRetry(); |
| 55 | 55 |
| 56 // DevicePolicyResponseDelegate implementation: | 56 // DevicePolicyResponseDelegate implementation: |
| 57 virtual void HandlePolicyResponse( | 57 virtual void HandlePolicyResponse( |
| 58 const em::DevicePolicyResponse& response); | 58 const em::DevicePolicyResponse& response); |
| 59 virtual void OnError(DeviceManagementBackend::ErrorCode code); | 59 virtual void OnError(DeviceManagementBackend::ErrorCode code); |
|
Joao da Silva
2011/07/06 16:45:14
Nit: OVERRIDE on these 2 methods
gfeher
2011/07/07 13:51:00
Done.
| |
| 60 | 60 |
| 61 // DeviceTokenFetcher::Observer implementation: | 61 // CloudPolicyData::Observer implementation: |
| 62 virtual void OnDeviceTokenAvailable(); | |
| 63 | |
| 64 // CloudPolicyIdentityStrategy::Observer implementation: | |
| 65 virtual void OnDeviceTokenChanged(); | 62 virtual void OnDeviceTokenChanged(); |
| 66 virtual void OnCredentialsChanged(); | 63 virtual void OnCredentialsChanged(); |
| 64 virtual void OnPolicyDataGoingAway(); | |
|
Joao da Silva
2011/07/06 16:45:14
Nit: OVERRIDE on these 3 methods
gfeher
2011/07/07 13:51:00
Done.
| |
| 67 | 65 |
| 68 private: | 66 private: |
| 69 // Indicates the current state the controller is in. | 67 // Indicates the current state the controller is in. |
| 70 enum ControllerState { | 68 enum ControllerState { |
| 71 // The controller is initializing, policy information not yet available. | 69 // The controller is initializing, policy information not yet available. |
| 72 STATE_TOKEN_UNAVAILABLE, | 70 STATE_TOKEN_UNAVAILABLE, |
| 73 // The device is not managed. Should retry fetching the token after delay. | 71 // The device is not managed. Should retry fetching the token after delay. |
| 74 STATE_TOKEN_UNMANAGED, | 72 STATE_TOKEN_UNMANAGED, |
| 75 // The token is not valid and should be refetched with exponential back-off. | 73 // The token is not valid and should be refetched with exponential back-off. |
| 76 STATE_TOKEN_ERROR, | 74 STATE_TOKEN_ERROR, |
| 77 // The token is valid, but policy is yet to be fetched. | 75 // The token is valid, but policy is yet to be fetched. |
| 78 STATE_TOKEN_VALID, | 76 STATE_TOKEN_VALID, |
| 79 // Policy information is available and valid. | 77 // Policy information is available and valid. |
| 80 STATE_POLICY_VALID, | 78 STATE_POLICY_VALID, |
| 81 // The service returned an error when requesting policy, will retry. | 79 // The service returned an error when requesting policy, will retry. |
| 82 STATE_POLICY_ERROR, | 80 STATE_POLICY_ERROR, |
| 83 // The service returned an error that is not going to go away soon. | 81 // The service returned an error that is not going to go away soon. |
| 84 STATE_POLICY_UNAVAILABLE | 82 STATE_POLICY_UNAVAILABLE |
| 85 }; | 83 }; |
| 86 | 84 |
| 87 friend class CloudPolicyControllerTest; | 85 friend class CloudPolicyControllerTest; |
| 88 friend class TestingCloudPolicySubsystem; | 86 friend class TestingCloudPolicySubsystem; |
| 89 | 87 |
| 90 // More configurable constructor for use by test cases. | 88 // More configurable constructor for use by test cases. |
| 91 // Takes ownership of |scheduler|; the other parameters are weak pointers. | 89 // Takes ownership of |scheduler|; the other parameters are weak pointers. |
| 92 CloudPolicyController(DeviceManagementService* service, | 90 CloudPolicyController(DeviceManagementService* service, |
| 93 CloudPolicyCacheBase* cache, | 91 CloudPolicyCacheBase* cache, |
| 94 DeviceTokenFetcher* token_fetcher, | 92 DeviceTokenFetcher* token_fetcher, |
| 95 CloudPolicyIdentityStrategy* identity_strategy, | 93 CloudPolicyData* data, |
| 96 PolicyNotifier* notifier, | 94 PolicyNotifier* notifier, |
| 97 DelayedWorkScheduler* scheduler); | 95 DelayedWorkScheduler* scheduler); |
| 98 | 96 |
| 99 // Called by constructors to perform shared initialization. | 97 // Called by constructors to perform shared initialization. |
| 100 void Initialize(DeviceManagementService* service, | 98 void Initialize(DeviceManagementService* service, |
| 101 CloudPolicyCacheBase* cache, | 99 CloudPolicyCacheBase* cache, |
| 102 DeviceTokenFetcher* token_fetcher, | 100 DeviceTokenFetcher* token_fetcher, |
| 103 CloudPolicyIdentityStrategy* identity_strategy, | 101 CloudPolicyData* data, |
| 104 PolicyNotifier* notifier, | 102 PolicyNotifier* notifier, |
| 105 DelayedWorkScheduler* scheduler); | 103 DelayedWorkScheduler* scheduler); |
| 106 | 104 |
| 107 // Asks the token fetcher to fetch a new token. | 105 // Asks the token fetcher to fetch a new token. |
| 108 void FetchToken(); | 106 void FetchToken(); |
| 109 | 107 |
| 110 // Sends a request to the device management backend to fetch policy if one | 108 // Sends a request to the device management backend to fetch policy if one |
| 111 // isn't already outstanding. | 109 // isn't already outstanding. |
| 112 void SendPolicyRequest(); | 110 void SendPolicyRequest(); |
| 113 | 111 |
| 114 // Called back from |scheduler_|. | 112 // Called back from |scheduler_|. |
| 115 // Performs whatever action is required in the current state, | 113 // Performs whatever action is required in the current state, |
| 116 // e.g. refreshing policy. | 114 // e.g. refreshing policy. |
| 117 void DoWork(); | 115 void DoWork(); |
| 118 | 116 |
| 119 // Switches to a new state and triggers any appropriate actions. | 117 // Switches to a new state and triggers any appropriate actions. |
| 120 void SetState(ControllerState new_state); | 118 void SetState(ControllerState new_state); |
| 121 | 119 |
| 122 // Computes the policy refresh delay to use. | 120 // Computes the policy refresh delay to use. |
| 123 int64 GetRefreshDelay(); | 121 int64 GetRefreshDelay(); |
| 124 | 122 |
| 125 DeviceManagementService* service_; | 123 DeviceManagementService* service_; |
| 126 CloudPolicyCacheBase* cache_; | 124 CloudPolicyCacheBase* cache_; |
| 127 CloudPolicyIdentityStrategy* identity_strategy_; | 125 CloudPolicyData* data_; |
| 128 DeviceTokenFetcher* token_fetcher_; | 126 DeviceTokenFetcher* token_fetcher_; |
| 129 scoped_ptr<DeviceManagementBackend> backend_; | 127 scoped_ptr<DeviceManagementBackend> backend_; |
| 130 ControllerState state_; | 128 ControllerState state_; |
| 131 PolicyNotifier* notifier_; | 129 PolicyNotifier* notifier_; |
| 132 | 130 |
| 133 int64 policy_refresh_rate_ms_; | 131 int64 policy_refresh_rate_ms_; |
| 134 int64 effective_policy_refresh_error_delay_ms_; | 132 int64 effective_policy_refresh_error_delay_ms_; |
| 135 | 133 |
| 136 scoped_ptr<DelayedWorkScheduler> scheduler_; | 134 scoped_ptr<DelayedWorkScheduler> scheduler_; |
| 137 | 135 |
| 138 DISALLOW_COPY_AND_ASSIGN(CloudPolicyController); | 136 DISALLOW_COPY_AND_ASSIGN(CloudPolicyController); |
| 139 }; | 137 }; |
| 140 | 138 |
| 141 } // namespace policy | 139 } // namespace policy |
| 142 | 140 |
| 143 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ | 141 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ |
| OLD | NEW |