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

Side by Side Diff: chromeos/components/tether/tether_host_response_recorder.h

Issue 2852693004: [CrOS Tether] Create HostScanCache, which caches scan results and inserts them into the network sta… (Closed)
Patch Set: stevenjb@ comments. Created 3 years, 7 months 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_RESPONSE_RECORDER_H_ 5 #ifndef CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_RESPONSE_RECORDER_H_
6 #define CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_RESPONSE_RECORDER_H_ 6 #define CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_RESPONSE_RECORDER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/observer_list.h"
12 #include "components/cryptauth/remote_device.h" 13 #include "components/cryptauth/remote_device.h"
13 14
14 class PrefService; 15 class PrefService;
15 class PrefRegistrySimple; 16 class PrefRegistrySimple;
16 17
17 namespace chromeos { 18 namespace chromeos {
18 19
19 namespace tether { 20 namespace tether {
20 21
21 // Records responses from tether hosts in user prefs, which persists these 22 // Records responses from tether hosts in user prefs, which persists these
22 // responses between reboots of the device. When a TetherAvailabilityResponse or 23 // responses between reboots of the device. When a TetherAvailabilityResponse or
23 // ConnectTetheringResponse is received, it should be recorded using this class. 24 // ConnectTetheringResponse is received, it should be recorded using this class.
24 // Responses can be retrieved at a later time via getter methods. 25 // Responses can be retrieved at a later time via getter methods.
25 class TetherHostResponseRecorder { 26 class TetherHostResponseRecorder {
26 public: 27 public:
27 // Note: The PrefService* passed here must be created using the same registry 28 class Observer {
28 // passed to RegisterPrefs(). 29 public:
29 TetherHostResponseRecorder(PrefService* pref_service); 30 virtual void OnPreviouslyConnectedHostIdsChanged() = 0;
30 virtual ~TetherHostResponseRecorder(); 31 };
31 32
32 // Registers the prefs used by this class to |registry|. Must be called before 33 // Registers the prefs used by this class to |registry|. Must be called before
33 // this class is utilized. 34 // this class is utilized.
34 static void RegisterPrefs(PrefRegistrySimple* registry); 35 static void RegisterPrefs(PrefRegistrySimple* registry);
35 36
37 // Note: The PrefService* passed here must be created using the same registry
38 // passed to RegisterPrefs().
39 explicit TetherHostResponseRecorder(PrefService* pref_service);
40 virtual ~TetherHostResponseRecorder();
41
42 void AddObserver(Observer* observer);
43 void RemoveObserver(Observer* observer);
44
36 // Records a TetherAvailabilityResponse. This function should be called each 45 // Records a TetherAvailabilityResponse. This function should be called each
37 // time that a response is received from a potential host, even if a 46 // time that a response is received from a potential host, even if a
38 // connection is not started. 47 // connection is not started.
39 virtual void RecordSuccessfulTetherAvailabilityResponse( 48 virtual void RecordSuccessfulTetherAvailabilityResponse(
40 const cryptauth::RemoteDevice& remote_device); 49 const cryptauth::RemoteDevice& remote_device);
41 50
42 // Gets device IDs corresponding to hosts which have sent 51 // Gets device IDs corresponding to hosts which have sent
43 // TetherAvailabilityResponses with a response code indicating that tethering 52 // TetherAvailabilityResponses with a response code indicating that tethering
44 // is available. The list is sorted; the IDs of the devices which have 53 // 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 54 // 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. 55 // devices which have responded least recently are at the end of the list.
47 virtual std::vector<std::string> GetPreviouslyAvailableHostIds() const; 56 virtual std::vector<std::string> GetPreviouslyAvailableHostIds() const;
48 57
49 // Records a ConnectTetheringResponse. This function should be called each 58 // Records a ConnectTetheringResponse. This function should be called each
50 // time that a response is received from a host. 59 // time that a response is received from a host.
51 virtual void RecordSuccessfulConnectTetheringResponse( 60 virtual void RecordSuccessfulConnectTetheringResponse(
52 const cryptauth::RemoteDevice& remote_device); 61 const cryptauth::RemoteDevice& remote_device);
53 62
54 // Gets device IDs corresponding to hosts which have sent 63 // Gets device IDs corresponding to hosts which have sent
55 // ConnectTetheringResponses with a response code indicating that they have 64 // ConnectTetheringResponses with a response code indicating that they have
56 // successfully turned on their Wi-Fi hotspots. The list is sorted; the IDs of 65 // 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 66 // 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 67 // and the IDs of the devices which have responded least recently are at the
59 // end of the list. 68 // end of the list.
60 virtual std::vector<std::string> GetPreviouslyConnectedHostIds() const; 69 virtual std::vector<std::string> GetPreviouslyConnectedHostIds() const;
61 70
62 private: 71 private:
63 void AddRecentResponse(const std::string& device_id, 72 friend class HostScanCacheTest;
73
74 void NotifyObserversPreviouslyConnectedHostIdsChanged();
75
76 // Returns whether the list was changed due to adding the response.
77 bool AddRecentResponse(const std::string& device_id,
64 const std::string& pref_name); 78 const std::string& pref_name);
65 std::vector<std::string> GetDeviceIdsForPref( 79 std::vector<std::string> GetDeviceIdsForPref(
66 const std::string& pref_name) const; 80 const std::string& pref_name) const;
67 81
68 PrefService* pref_service_; 82 PrefService* pref_service_;
83 base::ObserverList<Observer> observer_list_;
69 84
70 DISALLOW_COPY_AND_ASSIGN(TetherHostResponseRecorder); 85 DISALLOW_COPY_AND_ASSIGN(TetherHostResponseRecorder);
71 }; 86 };
72 87
73 } // namespace tether 88 } // namespace tether
74 89
75 } // namespace chromeos 90 } // namespace chromeos
76 91
77 #endif // CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_RESPONSE_RECORDER_H_ 92 #endif // CHROMEOS_COMPONENTS_TETHER_TETHER_HOST_RESPONSE_RECORDER_H_
OLDNEW
« no previous file with comments | « chromeos/components/tether/initializer.cc ('k') | chromeos/components/tether/tether_host_response_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698