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

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

Issue 6705031: Send policy blobs to session_manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nits Created 9 years, 9 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_DEVICE_TOKEN_FETCHER_H_ 5 #ifndef CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_
6 #define CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ 6 #define CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "base/task.h" 13 #include "base/task.h"
14 #include "chrome/browser/policy/device_management_backend.h" 14 #include "chrome/browser/policy/device_management_backend.h"
15 #include "chrome/browser/policy/proto/device_management_backend.pb.h" 15 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
16 16
17 namespace policy { 17 namespace policy {
18 18
19 class CloudPolicyCache; 19 class CloudPolicyCacheBase;
20 class DeviceManagementService; 20 class DeviceManagementService;
21 21
22 namespace em = enterprise_management; 22 namespace em = enterprise_management;
23 23
24 // Fetches the device token that can be used for policy requests with the device 24 // Fetches the device token that can be used for policy requests with the device
25 // management server, either from disk if it already has been successfully 25 // management server, either from disk if it already has been successfully
26 // requested, otherwise from the device management server. An instance of the 26 // requested, otherwise from the device management server. An instance of the
27 // fetcher is shared as a singleton by all users of the device management token 27 // fetcher is shared as a singleton by all users of the device management token
28 // to ensure they all get the same token. 28 // to ensure they all get the same token.
29 class DeviceTokenFetcher 29 class DeviceTokenFetcher
30 : public DeviceManagementBackend::DeviceRegisterResponseDelegate { 30 : public DeviceManagementBackend::DeviceRegisterResponseDelegate {
31 public: 31 public:
32 class Observer { 32 class Observer {
33 public: 33 public:
34 virtual ~Observer() {} 34 virtual ~Observer() {}
35 virtual void OnDeviceTokenAvailable() = 0; 35 virtual void OnDeviceTokenAvailable() = 0;
36 }; 36 };
37 37
38 // |service| is used to talk to the device management service and |cache| is 38 // |service| is used to talk to the device management service and |cache| is
39 // used to persist whether the device is unmanaged. 39 // used to persist whether the device is unmanaged.
40 DeviceTokenFetcher(DeviceManagementService* service, 40 DeviceTokenFetcher(DeviceManagementService* service,
41 CloudPolicyCache* cache); 41 CloudPolicyCacheBase* cache);
42 // Version for tests that allows to set timing paramters. 42 // Version for tests that allows to set timing paramters.
43 DeviceTokenFetcher(DeviceManagementService* service, 43 DeviceTokenFetcher(DeviceManagementService* service,
44 CloudPolicyCache* cache, 44 CloudPolicyCacheBase* cache,
45 int64 token_fetch_error_delay_ms, 45 int64 token_fetch_error_delay_ms,
46 int64 token_fetch_error_max_delay_ms, 46 int64 token_fetch_error_max_delay_ms,
47 int64 unmanaged_device_refresh_rate_ms); 47 int64 unmanaged_device_refresh_rate_ms);
48 virtual ~DeviceTokenFetcher(); 48 virtual ~DeviceTokenFetcher();
49 49
50 // Starts fetching a token. 50 // Starts fetching a token.
51 // Declared virtual so it can be overridden by mocks. 51 // Declared virtual so it can be overridden by mocks.
52 virtual void FetchToken(const std::string& auth_token, 52 virtual void FetchToken(const std::string& auth_token,
53 const std::string& device_id, 53 const std::string& device_id,
54 em::DeviceRegisterRequest_Type policy_type, 54 em::DeviceRegisterRequest_Type policy_type,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // Device unmanaged. 86 // Device unmanaged.
87 STATE_UNMANAGED, 87 STATE_UNMANAGED,
88 // Error, retry later. 88 // Error, retry later.
89 STATE_ERROR, 89 STATE_ERROR,
90 // Temporary error. Retry sooner. 90 // Temporary error. Retry sooner.
91 STATE_TEMPORARY_ERROR 91 STATE_TEMPORARY_ERROR
92 }; 92 };
93 93
94 // Common initialization helper. 94 // Common initialization helper.
95 void Initialize(DeviceManagementService* service, 95 void Initialize(DeviceManagementService* service,
96 CloudPolicyCache* cache, 96 CloudPolicyCacheBase* cache,
97 int64 token_fetch_error_delay_ms, 97 int64 token_fetch_error_delay_ms,
98 int64 token_fetch_error_max_delay_ms, 98 int64 token_fetch_error_max_delay_ms,
99 int64 unmanaged_device_refresh_rate_ms); 99 int64 unmanaged_device_refresh_rate_ms);
100 100
101 // Moves the fetcher into a new state. 101 // Moves the fetcher into a new state.
102 void SetState(FetcherState state); 102 void SetState(FetcherState state);
103 103
104 // Resets |backend_|, then uses |auth_token_| and |device_id_| to perform 104 // Resets |backend_|, then uses |auth_token_| and |device_id_| to perform
105 // an actual token fetch. 105 // an actual token fetch.
106 void FetchTokenInternal(); 106 void FetchTokenInternal();
107 107
108 // Called back from the |retry_task_|. 108 // Called back from the |retry_task_|.
109 void ExecuteRetryTask(); 109 void ExecuteRetryTask();
110 110
111 // Cancels the |retry_task_|. 111 // Cancels the |retry_task_|.
112 void CancelRetryTask(); 112 void CancelRetryTask();
113 113
114 // Service and backend. A new backend is created whenever the fetcher gets 114 // Service and backend. A new backend is created whenever the fetcher gets
115 // reset. 115 // reset.
116 DeviceManagementService* service_; // weak 116 DeviceManagementService* service_; // weak
117 scoped_ptr<DeviceManagementBackend> backend_; 117 scoped_ptr<DeviceManagementBackend> backend_;
118 118
119 // Reference to the cache. Used to persist and read unmanaged state. 119 // Reference to the cache. Used to persist and read unmanaged state.
120 CloudPolicyCache* cache_; 120 CloudPolicyCacheBase* cache_;
121 121
122 // Refresh parameters. 122 // Refresh parameters.
123 int64 token_fetch_error_delay_ms_; 123 int64 token_fetch_error_delay_ms_;
124 int64 token_fetch_error_max_delay_ms_; 124 int64 token_fetch_error_max_delay_ms_;
125 int64 effective_token_fetch_error_delay_ms_; 125 int64 effective_token_fetch_error_delay_ms_;
126 int64 unmanaged_device_refresh_rate_ms_; 126 int64 unmanaged_device_refresh_rate_ms_;
127 127
128 // State the fetcher is currently in. 128 // State the fetcher is currently in.
129 FetcherState state_; 129 FetcherState state_;
130 130
(...skipping 13 matching lines...) Expand all
144 CancelableTask* retry_task_; 144 CancelableTask* retry_task_;
145 145
146 ScopedRunnableMethodFactory<DeviceTokenFetcher> method_factory_; 146 ScopedRunnableMethodFactory<DeviceTokenFetcher> method_factory_;
147 147
148 ObserverList<Observer, true> observer_list_; 148 ObserverList<Observer, true> observer_list_;
149 }; 149 };
150 150
151 } // namespace policy 151 } // namespace policy
152 152
153 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ 153 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_policy_cache_unittest.cc ('k') | chrome/browser/policy/device_token_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698