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

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

Issue 5174006: Move DeviceManagementPolicyProvider into the profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback. Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/file_path.h" 11 #include "base/file_path.h"
12 #include "base/ref_counted.h" 12 #include "base/ref_counted.h"
13 #include "base/waitable_event.h" 13 #include "base/waitable_event.h"
14 #include "chrome/browser/policy/device_management_backend.h" 14 #include "chrome/browser/policy/device_management_backend.h"
15 #include "chrome/common/notification_observer.h" 15 #include "chrome/common/notification_observer.h"
16 #include "chrome/common/notification_registrar.h" 16 #include "chrome/common/notification_registrar.h"
17 17
18 class TokenService;
19
18 namespace policy { 20 namespace policy {
19 21
20 namespace em = enterprise_management; 22 namespace em = enterprise_management;
21 23
22 // 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
23 // management server, either from disk if it already has been successfully 25 // management server, either from disk if it already has been successfully
24 // requested, otherwise from the device management server. An instance of the 26 // requested, otherwise from the device management server. An instance of the
25 // 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
26 // to ensure they all get the same token. 28 // to ensure they all get the same token.
27 class DeviceTokenFetcher 29 class DeviceTokenFetcher
28 : public NotificationObserver, 30 : public NotificationObserver,
29 public DeviceManagementBackend::DeviceRegisterResponseDelegate, 31 public DeviceManagementBackend::DeviceRegisterResponseDelegate,
30 public base::RefCountedThreadSafe<DeviceTokenFetcher> { 32 public base::RefCountedThreadSafe<DeviceTokenFetcher> {
31 public: 33 public:
32 // Requests to the device management server are sent through |backend|, which 34 // Requests to the device management server are sent through |backend|, which
33 // is passed in explicitly to simplify mocking of the backend for unit 35 // is passed in explicitly to simplify mocking of the backend for unit
34 // testing. The fetcher uses the directory in |token_dir| in which to store 36 // testing. The fetcher uses the directory in |token_dir| in which to store
markusheintz_ 2010/11/19 11:00:46 I guess this should be token_path. Pls also addres
Mattias Nissler (ping if slow) 2010/11/19 11:40:02 Done.
35 // the device token once it's retrieved from the server. Should only be called 37 // the device token once it's retrieved from the server. Should only be called
36 // by unit tests. 38 // by unit tests.
37 DeviceTokenFetcher(DeviceManagementBackend* backend, 39 DeviceTokenFetcher(DeviceManagementBackend* backend,
40 TokenService* token_service,
markusheintz_ 2010/11/19 11:00:46 Please add an explaination for this parameter to t
Mattias Nissler (ping if slow) 2010/11/19 11:40:02 Done.
38 const FilePath& token_path); 41 const FilePath& token_path);
39 virtual ~DeviceTokenFetcher() {} 42 virtual ~DeviceTokenFetcher() {}
40 43
41 // NotificationObserver method overrides: 44 // NotificationObserver method overrides:
42 virtual void Observe(NotificationType type, 45 virtual void Observe(NotificationType type,
43 const NotificationSource& source, 46 const NotificationSource& source,
44 const NotificationDetails& details); 47 const NotificationDetails& details);
45 48
46 // DeviceManagementBackend::DeviceRegisterResponseDelegate method overrides: 49 // DeviceManagementBackend::DeviceRegisterResponseDelegate method overrides:
47 virtual void HandleRegisterResponse( 50 virtual void HandleRegisterResponse(
48 const em::DeviceRegisterResponse& response); 51 const em::DeviceRegisterResponse& response);
49 virtual void OnError(DeviceManagementBackend::ErrorCode code); 52 virtual void OnError(DeviceManagementBackend::ErrorCode code);
50 53
51 // Called by subscribers of the device management token to indicate that they 54 // Called by subscribers of the device management token to indicate that they
52 // will need the token in the future. Must be called on the UI thread. 55 // will need the token in the future. Must be called on the UI thread.
53 void StartFetching(); 56 void StartFetching();
54 57
58 // Instructs the fetcher to shut down, before the backend and token service
59 // references become stale.
60 void Shutdown();
61
55 // Returns true if there is a pending token request to the device management 62 // Returns true if there is a pending token request to the device management
56 // server. 63 // server.
57 bool IsTokenPending(); 64 bool IsTokenPending();
58 65
59 // Returns the device management token for this device, blocking until 66 // Returns the device management token for this device, blocking until
60 // outstanding requests to the device management server are satisfied. In the 67 // outstanding requests to the device management server are satisfied. In the
61 // case that the token could not be fetched, an empty string is returned. 68 // case that the token could not be fetched, an empty string is returned.
62 std::string GetDeviceToken(); 69 std::string GetDeviceToken();
63 70
64 // Returns the device ID for this device. If no such ID has been set yet, a 71 // Returns the device ID for this device. If no such ID has been set yet, a
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 static void WriteDeviceTokenToDisk(const FilePath& path, 121 static void WriteDeviceTokenToDisk(const FilePath& path,
115 const std::string& token, 122 const std::string& token,
116 const std::string& device_id); 123 const std::string& device_id);
117 124
118 // Generates a new device ID used to register the device with the device 125 // Generates a new device ID used to register the device with the device
119 // management server and generate the device token. 126 // management server and generate the device token.
120 static std::string GenerateNewDeviceID(); 127 static std::string GenerateNewDeviceID();
121 128
122 FilePath token_path_; 129 FilePath token_path_;
123 DeviceManagementBackend* backend_; // weak 130 DeviceManagementBackend* backend_; // weak
131 TokenService* token_service_;
124 FetcherState state_; 132 FetcherState state_;
125 std::string device_token_; 133 std::string device_token_;
126 std::string device_id_; 134 std::string device_id_;
127 135
128 // Contains the AuthToken for the device management server. Empty if the 136 // Contains the AuthToken for the device management server. Empty if the
129 // AuthToken hasn't been issued yet or that was an error getting the 137 // AuthToken hasn't been issued yet or that was an error getting the
130 // AuthToken. 138 // AuthToken.
131 std::string auth_token_; 139 std::string auth_token_;
132 140
133 // An event that is signaled only once the device token has been fetched 141 // An event that is signaled only once the device token has been fetched
134 // or it has been determined that there was an error during fetching. 142 // or it has been determined that there was an error during fetching.
135 base::WaitableEvent device_token_load_complete_event_; 143 base::WaitableEvent device_token_load_complete_event_;
136 144
137 // Registers the fetcher for notification of successful Gaia logins. 145 // Registers the fetcher for notification of successful Gaia logins.
138 NotificationRegistrar registrar_; 146 NotificationRegistrar registrar_;
139 }; 147 };
140 148
141 } // namespace policy 149 } // namespace policy
142 150
143 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ 151 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698