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