OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_RESPONSE_RECORDER_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_RESPONSE_RECORDER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "components/cryptauth/remote_device.h" |
| 13 |
| 14 class PrefService; |
| 15 class PrefRegistrySimple; |
| 16 |
| 17 namespace chromeos { |
| 18 |
| 19 namespace tether { |
| 20 |
| 21 // Records responses from tether hosts in user prefs, which persists these |
| 22 // responses between reboots of the device. When a TetherAvailabilityResponse or |
| 23 // ConnectTetheringResponse is received, it should be recorded using this class. |
| 24 // Responses can be retrieved at a later time via getter methods. |
| 25 class TetherHostResponseRecorder { |
| 26 public: |
| 27 // Note: The PrefService* passed here must be created using the same registry |
| 28 // passed to RegisterPrefs(). |
| 29 TetherHostResponseRecorder(PrefService* pref_service); |
| 30 virtual ~TetherHostResponseRecorder(); |
| 31 |
| 32 // Registers the prefs used by this class to |registry|. Must be called before |
| 33 // this class is utilized. |
| 34 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 35 |
| 36 // Records a TetherAvailabilityResponse. This function should be called each |
| 37 // time that a response is received from a potential host, even if a |
| 38 // connection is not started. |
| 39 virtual void RecordSuccessfulTetherAvailabilityResponse( |
| 40 const cryptauth::RemoteDevice& remote_device); |
| 41 |
| 42 // Gets device IDs corresponding to hosts which have sent |
| 43 // TetherAvailabilityResponses with a response code indicating that tethering |
| 44 // is available. The list is sorted; the IDs of the devices which have |
| 45 // responded most recently are at the front of the list and the IDs of the |
| 46 // devices which have responded least recently are at the end of the list. |
| 47 virtual std::vector<std::string> GetPreviouslyAvailableHostIds() const; |
| 48 |
| 49 // Records a ConnectTetheringResponse. This function should be called each |
| 50 // time that a response is received from a host. |
| 51 virtual void RecordSuccessfulConnectTetheringResponse( |
| 52 const cryptauth::RemoteDevice& remote_device); |
| 53 |
| 54 // Gets device IDs corresponding to hosts which have sent |
| 55 // ConnectTetheringResponses with a response code indicating that they have |
| 56 // successfully turned on their Wi-Fi hotspots. The list is sorted; the IDs of |
| 57 // the devices which have responded most recently are at the front of the list |
| 58 // and the IDs of the devices which have responded least recently are at the |
| 59 // end of the list. |
| 60 virtual std::vector<std::string> GetPreviouslyConnectedHostIds() const; |
| 61 |
| 62 private: |
| 63 void AddRecentResponse(const std::string& device_id, |
| 64 const std::string& pref_name); |
| 65 std::vector<std::string> GetDeviceIdsForPref( |
| 66 const std::string& pref_name) const; |
| 67 |
| 68 PrefService* pref_service_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(TetherHostResponseRecorder); |
| 71 }; |
| 72 |
| 73 } // namespace tether |
| 74 |
| 75 } // namespace chromeos |
| 76 |
| 77 #endif // CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_RESPONSE_RECORDER_H_ |
OLD | NEW |