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

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

Issue 4960003: Don't register gmail users at the device management server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 10 years 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 #include <vector> 10 #include <vector>
11 11
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/ref_counted.h" 14 #include "base/ref_counted.h"
15 #include "base/waitable_event.h" 15 #include "base/waitable_event.h"
16 #include "chrome/browser/policy/device_management_backend.h" 16 #include "chrome/browser/policy/device_management_backend.h"
17 #include "chrome/common/notification_observer.h" 17 #include "chrome/common/notification_observer.h"
18 #include "chrome/common/notification_registrar.h" 18 #include "chrome/common/notification_registrar.h"
19 19
20 class TokenService; 20 class Profile;
21 21
22 namespace policy { 22 namespace policy {
23 23
24 namespace em = enterprise_management; 24 namespace em = enterprise_management;
25 25
26 // Fetches the device token that can be used for policy requests with the device 26 // 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 27 // management server, either from disk if it already has been successfully
28 // requested, otherwise from the device management server. An instance of the 28 // 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 29 // fetcher is shared as a singleton by all users of the device management token
30 // to ensure they all get the same token. 30 // to ensure they all get the same token.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 private: 63 private:
64 DeviceTokenFetcher* token_fetcher_; 64 DeviceTokenFetcher* token_fetcher_;
65 std::vector<DeviceTokenFetcher::Observer*> observers_; 65 std::vector<DeviceTokenFetcher::Observer*> observers_;
66 }; 66 };
67 67
68 // Requests to the device management server are sent through |backend|. It 68 // Requests to the device management server are sent through |backend|. It
69 // obtains the authentication token from |token_service|. The fetcher stores 69 // obtains the authentication token from |token_service|. The fetcher stores
70 // the device token to |token_path| once it's retrieved from the server. 70 // the device token to |token_path| once it's retrieved from the server.
71 DeviceTokenFetcher(DeviceManagementBackend* backend, 71 DeviceTokenFetcher(DeviceManagementBackend* backend,
72 TokenService* token_service, 72 Profile* profile,
73 const FilePath& token_path); 73 const FilePath& token_path);
74 virtual ~DeviceTokenFetcher() {} 74 virtual ~DeviceTokenFetcher() {}
75 75
76 // NotificationObserver method overrides: 76 // NotificationObserver method overrides:
77 virtual void Observe(NotificationType type, 77 virtual void Observe(NotificationType type,
78 const NotificationSource& source, 78 const NotificationSource& source,
79 const NotificationDetails& details); 79 const NotificationDetails& details);
80 80
81 // DeviceManagementBackend::DeviceRegisterResponseDelegate method overrides: 81 // DeviceManagementBackend::DeviceRegisterResponseDelegate method overrides:
82 virtual void HandleRegisterResponse( 82 virtual void HandleRegisterResponse(
(...skipping 23 matching lines...) Expand all
106 // Returns the device ID for this device. If no such ID has been set yet, a 106 // Returns the device ID for this device. If no such ID has been set yet, a
107 // new ID is generated and returned. 107 // new ID is generated and returned.
108 std::string GetDeviceID(); 108 std::string GetDeviceID();
109 109
110 // True if the fetcher has a valid AuthToken for the device management server. 110 // True if the fetcher has a valid AuthToken for the device management server.
111 bool HasAuthToken() const { return !auth_token_.empty(); } 111 bool HasAuthToken() const { return !auth_token_.empty(); }
112 112
113 // True if the device token has been fetched and is valid. 113 // True if the device token has been fetched and is valid.
114 bool IsTokenValid() const; 114 bool IsTokenValid() const;
115 115
116 protected:
117 // Returns the email address of the currently logged-in user.
118 virtual std::string GetCurrentUser();
119
120 // Used to identify GOOGLE_SIGNIN_SUCCESSFUL notifications from the owning
121 // profile, and to query for the current username.
122 Profile* profile_; // weak
123
116 private: 124 private:
117 friend class DeviceTokenFetcherTest; 125 friend class DeviceTokenFetcherTest;
118 126
119 // The different states that the fetcher can be in during the process of 127 // The different states that the fetcher can be in during the process of
120 // getting the device token. 128 // getting the device token.
121 enum FetcherState { 129 enum FetcherState {
122 kStateNotStarted, 130 kStateNotStarted,
123 kStateLoadDeviceTokenFromDisk, 131 kStateLoadDeviceTokenFromDisk,
124 kStateReadyToRequestDeviceTokenFromServer, 132 kStateReadyToRequestDeviceTokenFromServer,
125 kStateRequestingDeviceTokenFromServer, 133 kStateRequestingDeviceTokenFromServer,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 const std::string& token, 186 const std::string& token,
179 const std::string& device_id); 187 const std::string& device_id);
180 188
181 // Generates a new device ID used to register the device with the device 189 // Generates a new device ID used to register the device with the device
182 // management server and generate the device token. 190 // management server and generate the device token.
183 static std::string GenerateNewDeviceID(); 191 static std::string GenerateNewDeviceID();
184 192
185 ObserverList<Observer, true> observer_list_; 193 ObserverList<Observer, true> observer_list_;
186 FilePath token_path_; 194 FilePath token_path_;
187 DeviceManagementBackend* backend_; // weak 195 DeviceManagementBackend* backend_; // weak
188 TokenService* token_service_;
189 FetcherState state_; 196 FetcherState state_;
190 std::string device_token_; 197 std::string device_token_;
191 std::string device_id_; 198 std::string device_id_;
192 199
193 // Contains the AuthToken for the device management server. Empty if the 200 // Contains the AuthToken for the device management server. Empty if the
194 // AuthToken hasn't been issued yet or that was an error getting the 201 // AuthToken hasn't been issued yet or that was an error getting the
195 // AuthToken. 202 // AuthToken.
196 std::string auth_token_; 203 std::string auth_token_;
197 204
198 // An event that is signaled only once the device token has been fetched 205 // An event that is signaled only once the device token has been fetched
199 // or it has been determined that there was an error during fetching. 206 // or it has been determined that there was an error during fetching.
200 base::WaitableEvent device_token_load_complete_event_; 207 base::WaitableEvent device_token_load_complete_event_;
201 208
202 // Registers the fetcher for notification of successful Gaia logins. 209 // Registers the fetcher for notification of successful Gaia logins.
203 NotificationRegistrar registrar_; 210 NotificationRegistrar registrar_;
204 }; 211 };
205 212
206 } // namespace policy 213 } // namespace policy
207 214
208 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ 215 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698