OLD | NEW |
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 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 // Returns true if there is a pending token request to the device management | 55 // Returns true if there is a pending token request to the device management |
56 // server. | 56 // server. |
57 bool IsTokenPending(); | 57 bool IsTokenPending(); |
58 | 58 |
59 // Returns the device management token for this device, blocking until | 59 // Returns the device management token for this device, blocking until |
60 // outstanding requests to the device management server are satisfied. In the | 60 // 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. | 61 // case that the token could not be fetched, an empty string is returned. |
62 std::string GetDeviceToken(); | 62 std::string GetDeviceToken(); |
63 | 63 |
| 64 // Returns the device ID for this device. If no such ID has been set yet, a |
| 65 // new ID is generated and returned. |
| 66 std::string GetDeviceID(); |
| 67 |
64 // True if the fetcher has a valid AuthToken for the device management server. | 68 // True if the fetcher has a valid AuthToken for the device management server. |
65 bool HasAuthToken() const { return !auth_token_.empty(); } | 69 bool HasAuthToken() const { return !auth_token_.empty(); } |
66 | 70 |
67 // True if the device token has been fetched and is valid. | 71 // True if the device token has been fetched and is valid. |
68 bool IsTokenValid() const; | 72 bool IsTokenValid() const; |
69 | 73 |
70 private: | 74 private: |
71 friend class DeviceTokenFetcherTest; | 75 friend class DeviceTokenFetcherTest; |
72 | 76 |
73 // The different states that the fetcher can be in during the process of | 77 // The different states that the fetcher can be in during the process of |
(...skipping 27 matching lines...) Expand all Loading... |
101 void MakeReadyToRequestDeviceToken(); | 105 void MakeReadyToRequestDeviceToken(); |
102 | 106 |
103 // Issues a registration request to the server if both the fetcher is in the | 107 // Issues a registration request to the server if both the fetcher is in the |
104 // ready-to-request state and the device management server AuthToken is | 108 // ready-to-request state and the device management server AuthToken is |
105 // available. | 109 // available. |
106 void SendServerRequestIfPossible(); | 110 void SendServerRequestIfPossible(); |
107 | 111 |
108 // Saves the device management token to disk once it has been retrieved from | 112 // Saves the device management token to disk once it has been retrieved from |
109 // the server. Must be called on the FILE thread. | 113 // the server. Must be called on the FILE thread. |
110 static void WriteDeviceTokenToDisk(const FilePath& path, | 114 static void WriteDeviceTokenToDisk(const FilePath& path, |
111 const std::string& token); | 115 const std::string& token, |
| 116 const std::string& device_id); |
112 | 117 |
113 // Generates a new device ID used to register the device with the device | 118 // Generates a new device ID used to register the device with the device |
114 // management server and generate the device token. | 119 // management server and generate the device token. |
115 static std::string GenerateNewDeviceID(); | 120 static std::string GenerateNewDeviceID(); |
116 | 121 |
117 FilePath token_path_; | 122 FilePath token_path_; |
118 DeviceManagementBackend* backend_; // weak | 123 DeviceManagementBackend* backend_; // weak |
119 FetcherState state_; | 124 FetcherState state_; |
120 std::string device_token_; | 125 std::string device_token_; |
| 126 std::string device_id_; |
121 | 127 |
122 // Contains the AuthToken for the device management server. Empty if the | 128 // Contains the AuthToken for the device management server. Empty if the |
123 // AuthToken hasn't been issued yet or that was an error getting the | 129 // AuthToken hasn't been issued yet or that was an error getting the |
124 // AuthToken. | 130 // AuthToken. |
125 std::string auth_token_; | 131 std::string auth_token_; |
126 | 132 |
127 // An event that is signaled only once the device token has been fetched | 133 // An event that is signaled only once the device token has been fetched |
128 // or it has been determined that there was an error during fetching. | 134 // or it has been determined that there was an error during fetching. |
129 base::WaitableEvent device_token_load_complete_event_; | 135 base::WaitableEvent device_token_load_complete_event_; |
130 | 136 |
131 // Registers the fetcher for notification of successful Gaia logins. | 137 // Registers the fetcher for notification of successful Gaia logins. |
132 NotificationRegistrar registrar_; | 138 NotificationRegistrar registrar_; |
133 }; | 139 }; |
134 | 140 |
135 } // namespace policy | 141 } // namespace policy |
136 | 142 |
137 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ | 143 #endif // CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_ |
OLD | NEW |