Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1119)

Side by Side Diff: chrome/browser/policy/cloud_policy_controller.h

Issue 7298012: Consolidate data storage and notifications in the cloud policy subsystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/basictypes.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list.h" 13 #include "chrome/browser/policy/cloud_policy_data_store.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" 14 #include "chrome/browser/policy/configuration_policy_provider.h"
18 #include "chrome/browser/policy/delayed_work_scheduler.h" 15 #include "chrome/browser/policy/delayed_work_scheduler.h"
19 #include "chrome/browser/policy/device_management_backend.h"
20 #include "chrome/browser/policy/device_token_fetcher.h" 16 #include "chrome/browser/policy/device_token_fetcher.h"
21 17
22 class Profile;
23 class TokenService;
24
25 namespace policy { 18 namespace policy {
26 19
27 class CloudPolicyCacheBase; 20 class CloudPolicyCacheBase;
28 class DeviceManagementBackend; 21 class DeviceManagementBackend;
29 22
30 // Coordinates the actions of DeviceTokenFetcher, CloudPolicyIdentityStrategy, 23 // Coordinates the actions of DeviceTokenFetcher, CloudPolicyIdentityStrategy,
31 // DeviceManagementBackend, and CloudPolicyCache: calls their methods and 24 // DeviceManagementBackend, and CloudPolicyCache: calls their methods and
32 // listens to their callbacks/notifications. 25 // listens to their callbacks/notifications.
33 class CloudPolicyController 26 class CloudPolicyController
34 : public DeviceManagementBackend::DevicePolicyResponseDelegate, 27 : public DeviceManagementBackend::DevicePolicyResponseDelegate,
35 public DeviceTokenFetcher::Observer, 28 public CloudPolicyDataStore::Observer {
36 public CloudPolicyIdentityStrategy::Observer {
37 public: 29 public:
38 // All parameters are weak pointers. 30 // All parameters are weak pointers.
39 CloudPolicyController(DeviceManagementService* service, 31 CloudPolicyController(DeviceManagementService* service,
40 CloudPolicyCacheBase* cache, 32 CloudPolicyCacheBase* cache,
41 DeviceTokenFetcher* token_fetcher, 33 DeviceTokenFetcher* token_fetcher,
42 CloudPolicyIdentityStrategy* identity_strategy, 34 CloudPolicyDataStore* data_store,
43 PolicyNotifier* notifier); 35 PolicyNotifier* notifier);
44 virtual ~CloudPolicyController(); 36 virtual ~CloudPolicyController();
45 37
46 // Sets the refresh rate at which to re-fetch policy information. 38 // Sets the refresh rate at which to re-fetch policy information.
47 void SetRefreshRate(int64 refresh_rate_milliseconds); 39 void SetRefreshRate(int64 refresh_rate_milliseconds);
48 40
49 // Triggers an immediate retry of of the current operation. 41 // Triggers an immediate retry of of the current operation.
50 void Retry(); 42 void Retry();
51 43
52 // Stops all auto-retrying error handling behavior inside the policy 44 // Stops all auto-retrying error handling behavior inside the policy
53 // subsystem. 45 // subsystem.
54 void StopAutoRetry(); 46 void StopAutoRetry();
55 47
56 // DevicePolicyResponseDelegate implementation: 48 // DevicePolicyResponseDelegate implementation:
57 virtual void HandlePolicyResponse( 49 virtual void HandlePolicyResponse(
58 const em::DevicePolicyResponse& response); 50 const em::DevicePolicyResponse& response) OVERRIDE;
59 virtual void OnError(DeviceManagementBackend::ErrorCode code); 51 virtual void OnError(DeviceManagementBackend::ErrorCode code) OVERRIDE;
60 52
61 // DeviceTokenFetcher::Observer implementation: 53 // CloudPolicyDataStore::Observer implementation:
62 virtual void OnDeviceTokenAvailable(); 54 virtual void OnDeviceTokenChanged() OVERRIDE;
63 55 virtual void OnCredentialsChanged() OVERRIDE;
64 // CloudPolicyIdentityStrategy::Observer implementation: 56 virtual void OnDataStoreGoingAway() OVERRIDE;
65 virtual void OnDeviceTokenChanged();
66 virtual void OnCredentialsChanged();
67 57
68 private: 58 private:
69 // Indicates the current state the controller is in. 59 // Indicates the current state the controller is in.
70 enum ControllerState { 60 enum ControllerState {
71 // The controller is initializing, policy information not yet available. 61 // The controller is initializing, policy information not yet available.
72 STATE_TOKEN_UNAVAILABLE, 62 STATE_TOKEN_UNAVAILABLE,
73 // The device is not managed. Should retry fetching the token after delay. 63 // The device is not managed. Should retry fetching the token after delay.
74 STATE_TOKEN_UNMANAGED, 64 STATE_TOKEN_UNMANAGED,
75 // The token is not valid and should be refetched with exponential back-off. 65 // The token is not valid and should be refetched with exponential back-off.
76 STATE_TOKEN_ERROR, 66 STATE_TOKEN_ERROR,
77 // The token is valid, but policy is yet to be fetched. 67 // The token is valid, but policy is yet to be fetched.
78 STATE_TOKEN_VALID, 68 STATE_TOKEN_VALID,
79 // Policy information is available and valid. 69 // Policy information is available and valid.
80 STATE_POLICY_VALID, 70 STATE_POLICY_VALID,
81 // The service returned an error when requesting policy, will retry. 71 // The service returned an error when requesting policy, will retry.
82 STATE_POLICY_ERROR, 72 STATE_POLICY_ERROR,
83 // The service returned an error that is not going to go away soon. 73 // The service returned an error that is not going to go away soon.
84 STATE_POLICY_UNAVAILABLE 74 STATE_POLICY_UNAVAILABLE
85 }; 75 };
86 76
87 friend class CloudPolicyControllerTest; 77 friend class CloudPolicyControllerTest;
88 friend class TestingCloudPolicySubsystem; 78 friend class TestingCloudPolicySubsystem;
89 79
90 // More configurable constructor for use by test cases. 80 // More configurable constructor for use by test cases.
91 // Takes ownership of |scheduler|; the other parameters are weak pointers. 81 // Takes ownership of |scheduler|; the other parameters are weak pointers.
92 CloudPolicyController(DeviceManagementService* service, 82 CloudPolicyController(DeviceManagementService* service,
93 CloudPolicyCacheBase* cache, 83 CloudPolicyCacheBase* cache,
94 DeviceTokenFetcher* token_fetcher, 84 DeviceTokenFetcher* token_fetcher,
95 CloudPolicyIdentityStrategy* identity_strategy, 85 CloudPolicyDataStore* data_store,
96 PolicyNotifier* notifier, 86 PolicyNotifier* notifier,
97 DelayedWorkScheduler* scheduler); 87 DelayedWorkScheduler* scheduler);
98 88
99 // Called by constructors to perform shared initialization. 89 // Called by constructors to perform shared initialization.
100 void Initialize(DeviceManagementService* service, 90 void Initialize(DeviceManagementService* service,
101 CloudPolicyCacheBase* cache, 91 CloudPolicyCacheBase* cache,
102 DeviceTokenFetcher* token_fetcher, 92 DeviceTokenFetcher* token_fetcher,
103 CloudPolicyIdentityStrategy* identity_strategy, 93 CloudPolicyDataStore* data_store,
104 PolicyNotifier* notifier, 94 PolicyNotifier* notifier,
105 DelayedWorkScheduler* scheduler); 95 DelayedWorkScheduler* scheduler);
106 96
107 // Asks the token fetcher to fetch a new token. 97 // Asks the token fetcher to fetch a new token.
108 void FetchToken(); 98 void FetchToken();
109 99
110 // Sends a request to the device management backend to fetch policy if one 100 // Sends a request to the device management backend to fetch policy if one
111 // isn't already outstanding. 101 // isn't already outstanding.
112 void SendPolicyRequest(); 102 void SendPolicyRequest();
113 103
114 // Called back from |scheduler_|. 104 // Called back from |scheduler_|.
115 // Performs whatever action is required in the current state, 105 // Performs whatever action is required in the current state,
116 // e.g. refreshing policy. 106 // e.g. refreshing policy.
117 void DoWork(); 107 void DoWork();
118 108
119 // Switches to a new state and triggers any appropriate actions. 109 // Switches to a new state and triggers any appropriate actions.
120 void SetState(ControllerState new_state); 110 void SetState(ControllerState new_state);
121 111
122 // Computes the policy refresh delay to use. 112 // Computes the policy refresh delay to use.
123 int64 GetRefreshDelay(); 113 int64 GetRefreshDelay();
124 114
125 DeviceManagementService* service_; 115 DeviceManagementService* service_;
126 CloudPolicyCacheBase* cache_; 116 CloudPolicyCacheBase* cache_;
127 CloudPolicyIdentityStrategy* identity_strategy_; 117 CloudPolicyDataStore* data_store_;
128 DeviceTokenFetcher* token_fetcher_; 118 DeviceTokenFetcher* token_fetcher_;
129 scoped_ptr<DeviceManagementBackend> backend_; 119 scoped_ptr<DeviceManagementBackend> backend_;
130 ControllerState state_; 120 ControllerState state_;
131 PolicyNotifier* notifier_; 121 PolicyNotifier* notifier_;
132 122
133 int64 policy_refresh_rate_ms_; 123 int64 policy_refresh_rate_ms_;
134 int64 effective_policy_refresh_error_delay_ms_; 124 int64 effective_policy_refresh_error_delay_ms_;
135 125
136 scoped_ptr<DelayedWorkScheduler> scheduler_; 126 scoped_ptr<DelayedWorkScheduler> scheduler_;
137 127
138 DISALLOW_COPY_AND_ASSIGN(CloudPolicyController); 128 DISALLOW_COPY_AND_ASSIGN(CloudPolicyController);
139 }; 129 };
140 130
141 } // namespace policy 131 } // namespace policy
142 132
143 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_ 133 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/browser_policy_connector.cc ('k') | chrome/browser/policy/cloud_policy_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698