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

Unified Diff: chromeos/components/tether/tether_host_response_recorder.cc

Issue 2852693004: [CrOS Tether] Create HostScanCache, which caches scan results and inserts them into the network sta… (Closed)
Patch Set: Rebased. Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/components/tether/tether_host_response_recorder.cc
diff --git a/chromeos/components/tether/tether_host_response_recorder.cc b/chromeos/components/tether/tether_host_response_recorder.cc
index 7012fa67009c47235e8de8c8c90a70e82593526e..4c71bff0c3501918bf6f2baa29069f50ec1b652a 100644
--- a/chromeos/components/tether/tether_host_response_recorder.cc
+++ b/chromeos/components/tether/tether_host_response_recorder.cc
@@ -26,6 +26,14 @@ TetherHostResponseRecorder::TetherHostResponseRecorder(
TetherHostResponseRecorder::~TetherHostResponseRecorder() {}
+void TetherHostResponseRecorder::AddObserver(Observer* observer) {
+ observer_list_.AddObserver(observer);
+}
+
+void TetherHostResponseRecorder::RemoveObserver(Observer* observer) {
+ observer_list_.RemoveObserver(observer);
+}
+
void TetherHostResponseRecorder::RecordSuccessfulTetherAvailabilityResponse(
const cryptauth::RemoteDevice& remote_device) {
AddRecentResponse(remote_device.GetDeviceId(),
@@ -39,8 +47,13 @@ TetherHostResponseRecorder::GetPreviouslyAvailableHostIds() const {
void TetherHostResponseRecorder::RecordSuccessfulConnectTetheringResponse(
const cryptauth::RemoteDevice& remote_device) {
- AddRecentResponse(remote_device.GetDeviceId(),
- prefs::kMostRecentConnectTetheringResponderIds);
+ bool changed =
+ AddRecentResponse(remote_device.GetDeviceId(),
+ prefs::kMostRecentConnectTetheringResponderIds);
+
+ if (changed) {
stevenjb 2017/05/01 18:26:12 local not needed
Kyle Horimoto 2017/05/01 21:14:44 Done.
+ NotifyObserversPreviouslyConnectedHostIdsChanged();
+ }
}
std::vector<std::string>
@@ -48,11 +61,26 @@ TetherHostResponseRecorder::GetPreviouslyConnectedHostIds() const {
return GetDeviceIdsForPref(prefs::kMostRecentConnectTetheringResponderIds);
}
-void TetherHostResponseRecorder::AddRecentResponse(
+void TetherHostResponseRecorder::
+ NotifyObserversPreviouslyConnectedHostIdsChanged() {
+ for (Observer& observer : observer_list_) {
+ observer.OnPreviouslyConnectedHostIdsChanged();
+ }
+}
+
+bool TetherHostResponseRecorder::AddRecentResponse(
const std::string& device_id,
const std::string& pref_name) {
const base::ListValue* ids = pref_service_->GetList(pref_name);
+ std::string first_device_id_in_list;
+ ids->GetString(0u, &first_device_id_in_list);
+ if (device_id == first_device_id_in_list) {
+ // If the device ID that is being inserted is already at the front of the
+ // list, there is nothing to do.
+ return false;
+ }
+
// Create a mutable copy of the stored IDs, or create one if it has yet to be
// stored.
std::unique_ptr<base::ListValue> updated_ids =
@@ -68,6 +96,8 @@ void TetherHostResponseRecorder::AddRecentResponse(
// Store the updated list back in |pref_service_|.
pref_service_->Set(pref_name, *updated_ids);
+
+ return true;
}
std::vector<std::string> TetherHostResponseRecorder::GetDeviceIdsForPref(

Powered by Google App Engine
This is Rietveld 408576698