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

Side by Side Diff: chrome/browser/policy/device_token_fetcher.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: " 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_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>
Joao da Silva 2011/07/06 16:45:14 Nit: string not used
gfeher 2011/07/07 13:51:00 Done.
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"
Joao da Silva 2011/07/06 16:45:14 Nit: observer_list.h and task.h not used
gfeher 2011/07/07 13:51:00 Done.
14 #include "chrome/browser/policy/cloud_policy_data.h"
pastarmovj 2011/07/06 12:11:57 I think you might be able to only Fwd declare this
gfeher 2011/07/06 15:14:20 Done.
14 #include "chrome/browser/policy/delayed_work_scheduler.h" 15 #include "chrome/browser/policy/delayed_work_scheduler.h"
15 #include "chrome/browser/policy/device_management_backend.h" 16 #include "chrome/browser/policy/device_management_backend.h"
16 #include "chrome/browser/policy/policy_notifier.h" 17 #include "chrome/browser/policy/policy_notifier.h"
17 #include "chrome/browser/policy/proto/device_management_backend.pb.h" 18 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
18 19
19 namespace policy { 20 namespace policy {
20 21
21 class CloudPolicyCacheBase; 22 class CloudPolicyCacheBase;
22 class DeviceManagementService; 23 class DeviceManagementService;
23 24
24 namespace em = enterprise_management; 25 namespace em = enterprise_management;
25 26
26 // Fetches the device token that can be used for policy requests with the device 27 // Fetches the device token that can be used for policy requests with the device
27 // management server, either from disk if it already has been successfully 28 // management server, either from disk if it already has been successfully
28 // requested, otherwise from the device management server. An instance of the 29 // requested, otherwise from the device management server. An instance of the
29 // fetcher is shared as a singleton by all users of the device management token 30 // fetcher is shared as a singleton by all users of the device management token
30 // to ensure they all get the same token. 31 // to ensure they all get the same token.
31 class DeviceTokenFetcher 32 class DeviceTokenFetcher
32 : public DeviceManagementBackend::DeviceRegisterResponseDelegate { 33 : public DeviceManagementBackend::DeviceRegisterResponseDelegate {
33 public: 34 public:
34 class Observer {
35 public:
36 virtual ~Observer() {}
37 virtual void OnDeviceTokenAvailable() = 0;
38 };
39
40 // |service| is used to talk to the device management service and |cache| is 35 // |service| is used to talk to the device management service and |cache| is
41 // used to persist whether the device is unmanaged. 36 // used to persist whether the device is unmanaged.
42 DeviceTokenFetcher(DeviceManagementService* service, 37 DeviceTokenFetcher(DeviceManagementService* service,
43 CloudPolicyCacheBase* cache, 38 CloudPolicyCacheBase* cache,
39 CloudPolicyData* data,
44 PolicyNotifier* notifier); 40 PolicyNotifier* notifier);
45 // Version for tests that allows to set timing parameters. 41 // Version for tests that allows to set timing parameters.
46 // Takes ownership of |scheduler|. 42 // Takes ownership of |scheduler|.
47 DeviceTokenFetcher(DeviceManagementService* service, 43 DeviceTokenFetcher(DeviceManagementService* service,
48 CloudPolicyCacheBase* cache, 44 CloudPolicyCacheBase* cache,
45 CloudPolicyData* data,
49 PolicyNotifier* notifier, 46 PolicyNotifier* notifier,
50 DelayedWorkScheduler* scheduler); 47 DelayedWorkScheduler* scheduler);
51 virtual ~DeviceTokenFetcher(); 48 virtual ~DeviceTokenFetcher();
52 49
53 // Starts fetching a token. 50 // Starts fetching a token.
54 // Declared virtual so it can be overridden by mocks. 51 // Declared virtual so it can be overridden by mocks.
55 virtual void FetchToken(const std::string& auth_token, 52 virtual void FetchToken();
56 const std::string& device_id,
57 em::DeviceRegisterRequest_Type policy_type,
58 const std::string& machine_id,
59 const std::string& machine_model);
60 53
61 virtual void SetUnmanagedState(); 54 virtual void SetUnmanagedState();
62 55
63 // Returns the device management token or the empty string if not available.
64 // Declared virtual so it can be overridden by mocks.
65 virtual const std::string& GetDeviceToken();
66
67 // Disables the auto-retry-on-error behavior of this token fetcher. 56 // Disables the auto-retry-on-error behavior of this token fetcher.
68 void StopAutoRetry(); 57 void StopAutoRetry();
69 58
70 void AddObserver(Observer* observer);
71 void RemoveObserver(Observer* observer);
72
73 // DeviceManagementBackend::DeviceRegisterResponseDelegate method overrides: 59 // DeviceManagementBackend::DeviceRegisterResponseDelegate method overrides:
74 virtual void HandleRegisterResponse( 60 virtual void HandleRegisterResponse(
75 const em::DeviceRegisterResponse& response); 61 const em::DeviceRegisterResponse& response);
76 virtual void OnError(DeviceManagementBackend::ErrorCode code); 62 virtual void OnError(DeviceManagementBackend::ErrorCode code);
Joao da Silva 2011/07/06 16:45:14 Nit: add OVERRIDE to these
gfeher 2011/07/07 13:51:00 Done.
77 63
78 private: 64 private:
79 friend class DeviceTokenFetcherTest; 65 friend class DeviceTokenFetcherTest;
80 66
81 // The different states that the fetcher can be in during the process of 67 // The different states that the fetcher can be in during the process of
82 // getting the device token. |state_| is initialized to INACTIVE, depending 68 // getting the device token. |state_| is initialized to INACTIVE, depending
83 // on the result of a token fetching attempt can transition to either of 69 // on the result of a token fetching attempt can transition to either of
84 // TOKEN_AVAILABLE, UNMANAGED, or ERROR. The first attempt must be triggered 70 // TOKEN_AVAILABLE, UNMANAGED, or ERROR. The first attempt must be triggered
85 // externally. When |state_| is UNMANAGED, a new fetching attempt is 71 // externally. When |state_| is UNMANAGED, a new fetching attempt is
86 // performed every |unmanaged_device_refresh_rate_ms_|; when it's ERROR, 72 // performed every |unmanaged_device_refresh_rate_ms_|; when it's ERROR,
87 // a new attempt is done after |effective_token_fetch_error_delay_ms_|. 73 // a new attempt is done after |effective_token_fetch_error_delay_ms_|.
88 enum FetcherState { 74 enum FetcherState {
89 // Fetcher inactive. 75 // Fetcher inactive.
90 STATE_INACTIVE, 76 STATE_INACTIVE,
91 // Token available. 77 // Token available.
92 STATE_TOKEN_AVAILABLE, 78 STATE_TOKEN_AVAILABLE,
93 // Device unmanaged. 79 // Device unmanaged.
94 STATE_UNMANAGED, 80 STATE_UNMANAGED,
95 // Error, retry later. 81 // Error, retry later.
96 STATE_ERROR, 82 STATE_ERROR,
97 // Temporary error. Retry sooner. 83 // Temporary error. Retry sooner.
98 STATE_TEMPORARY_ERROR, 84 STATE_TEMPORARY_ERROR,
99 // Server rejected the auth token. 85 // Server rejected the auth token.
100 STATE_BAD_AUTH 86 STATE_BAD_AUTH
101 }; 87 };
102 88
103 // Common initialization helper. 89 // Common initialization helper.
104 void Initialize(DeviceManagementService* service, 90 void Initialize(DeviceManagementService* service,
105 CloudPolicyCacheBase* cache, 91 CloudPolicyCacheBase* cache,
92 CloudPolicyData* data,
106 PolicyNotifier* notifier, 93 PolicyNotifier* notifier,
107 DelayedWorkScheduler* scheduler); 94 DelayedWorkScheduler* scheduler);
108 95
109 // Moves the fetcher into a new state. 96 // Moves the fetcher into a new state.
110 void SetState(FetcherState state); 97 void SetState(FetcherState state);
111 98
112 // Resets |backend_|, then uses |auth_token_| and |device_id_| to perform 99 // Resets |backend_|, then uses |auth_token_| and |device_id_| to perform
113 // an actual token fetch. 100 // an actual token fetch.
114 void FetchTokenInternal(); 101 void FetchTokenInternal();
115 102
(...skipping 12 matching lines...) Expand all
128 115
129 // Refresh parameters. 116 // Refresh parameters.
130 int64 token_fetch_error_delay_ms_; 117 int64 token_fetch_error_delay_ms_;
131 int64 token_fetch_error_max_delay_ms_; 118 int64 token_fetch_error_max_delay_ms_;
132 int64 effective_token_fetch_error_delay_ms_; 119 int64 effective_token_fetch_error_delay_ms_;
133 int64 unmanaged_device_refresh_rate_ms_; 120 int64 unmanaged_device_refresh_rate_ms_;
134 121
135 // State the fetcher is currently in. 122 // State the fetcher is currently in.
136 FetcherState state_; 123 FetcherState state_;
137 124
138 // Current device token. 125 CloudPolicyData* data_;
139 std::string device_token_;
140
141 // Contains the AuthToken for the device management server.
142 std::string auth_token_;
143 // Device identifier to send to the server.
144 std::string device_id_;
145 // Contains policy type to send to the server.
146 em::DeviceRegisterRequest_Type policy_type_;
147 // Contains physical machine id to send to the server.
148 std::string machine_id_;
149 // Contains physical machine model to send to server.
150 std::string machine_model_;
151 126
152 scoped_ptr<DelayedWorkScheduler> scheduler_; 127 scoped_ptr<DelayedWorkScheduler> scheduler_;
153
154 ObserverList<Observer, true> observer_list_;
155 }; 128 };
156 129
157 } // namespace policy 130 } // namespace policy
158 131
159 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ 132 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698