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

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

Issue 6520008: Device policy infrastructure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nits Created 9 years, 10 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
(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 // Coordinates the actions of DeviceTokenFetcher, CloudPolicyIdentityStrategy,
30 // DeviceManagementBackend, and CloudPolicyCache: calls their methods and
31 // listens to their callbacks/notifications.
32 class CloudPolicyController
33 : public DeviceManagementBackend::DevicePolicyResponseDelegate,
34 public DeviceTokenFetcher::Observer,
35 public CloudPolicyIdentityStrategy::Observer {
36 public:
37 // Takes ownership of |backend|; the other parameters are weak pointers.
38 CloudPolicyController(CloudPolicyCache* cache,
39 DeviceManagementBackend* backend,
40 DeviceTokenFetcher* token_fetcher,
41 CloudPolicyIdentityStrategy* identity_strategy);
42 virtual ~CloudPolicyController();
43
44 // Sets the refresh rate at which to re-fetch policy information.
45 void SetRefreshRate(int64 refresh_rate_milliseconds);
46
47 // DevicePolicyResponseDelegate implementation:
48 virtual void HandlePolicyResponse(
49 const em::DevicePolicyResponse& response);
50 virtual void HandleCloudPolicyResponse(
51 const em::CloudPolicyResponse& response);
52 virtual void OnError(DeviceManagementBackend::ErrorCode code);
53
54 // DeviceTokenFetcher::Observer implementation:
55 virtual void OnDeviceTokenAvailable();
56
57 // CloudPolicyIdentityStrategy::Observer implementation:
58 virtual void OnDeviceTokenChanged();
59 virtual void OnCredentialsChanged();
60
61 private:
62 // Indicates the current state the controller is in.
63 enum ControllerState {
64 // The controller is initializing, policy information not yet available.
65 STATE_TOKEN_UNAVAILABLE,
66 // The token is valid, but policy is yet to be fetched.
67 STATE_TOKEN_VALID,
68 // Policy information is available and valid.
69 STATE_POLICY_VALID,
70 // The service returned an error when requesting policy, ask again later.
71 STATE_POLICY_ERROR,
72 };
73
74 friend class CloudPolicyControllerTest;
75
76 // More configurable constructor for use by test cases.
77 CloudPolicyController(CloudPolicyCache* cache,
78 DeviceManagementBackend* backend,
79 DeviceTokenFetcher* token_fetcher,
80 CloudPolicyIdentityStrategy* identity_strategy,
81 int64 policy_refresh_rate_ms,
82 int policy_refresh_deviation_factor_percent,
83 int64 policy_refresh_deviation_max_ms,
84 int64 policy_refresh_error_delay_ms);
85
86 // Called by constructors to perform shared initialization.
87 void Initialize(CloudPolicyCache* cache,
88 DeviceManagementBackend* backend,
89 DeviceTokenFetcher* token_fetcher,
90 CloudPolicyIdentityStrategy* identity_strategy,
91 int64 policy_refresh_rate_ms,
92 int policy_refresh_deviation_factor_percent,
93 int64 policy_refresh_deviation_max_ms,
94 int64 policy_refresh_error_delay_ms);
95
96 // Asks the token fetcher to fetch a new token.
97 void FetchToken();
98
99 // Sends a request to the device management backend to fetch policy if one
100 // isn't already outstanding.
101 void SendPolicyRequest();
102
103 // Called back from the delayed work task. Performs whatever action is
104 // required in the current state, e.g. refreshing policy.
105 void DoDelayedWork();
106
107 // Cancels the delayed work task.
108 void CancelDelayedWork();
109
110 // Switches to a new state and triggers any appropriate actions.
111 void SetState(ControllerState new_state);
112
113 // Computes the policy refresh delay to use.
114 int64 GetRefreshDelay();
115
116 CloudPolicyCache* cache_;
117 scoped_ptr<DeviceManagementBackend> backend_;
118 CloudPolicyIdentityStrategy* identity_strategy_;
119 DeviceTokenFetcher* token_fetcher_;
120 ControllerState state_;
121 bool initial_fetch_done_;
122 bool fallback_to_old_protocol_;
123
124 int64 policy_refresh_rate_ms_;
125 int policy_refresh_deviation_factor_percent_;
126 int64 policy_refresh_deviation_max_ms_;
127 int64 policy_refresh_error_delay_ms_;
128 int64 effective_policy_refresh_error_delay_ms_;
129
130 CancelableTask* delayed_work_task_;
131 ScopedRunnableMethodFactory<CloudPolicyController> method_factory_;
132
133 DISALLOW_COPY_AND_ASSIGN(CloudPolicyController);
134 };
135
136 } // namespace policy
137
138 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698