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

Unified Diff: chromeos/components/tether/host_scan_device_prioritizer.h

Issue 2713073002: [CrOS Tether] Create HostScanDevicePrioritizer, a class which prioritizes the order of connection a… (Closed)
Patch Set: Add dep. Created 3 years, 10 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
« no previous file with comments | « chromeos/components/tether/BUILD.gn ('k') | chromeos/components/tether/host_scan_device_prioritizer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/components/tether/host_scan_device_prioritizer.h
diff --git a/chromeos/components/tether/host_scan_device_prioritizer.h b/chromeos/components/tether/host_scan_device_prioritizer.h
new file mode 100644
index 0000000000000000000000000000000000000000..0c89f33ec375831a359628d2c759b9debee0302d
--- /dev/null
+++ b/chromeos/components/tether/host_scan_device_prioritizer.h
@@ -0,0 +1,62 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_DEVICE_PRIORITIZER_H_
+#define CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_DEVICE_PRIORITIZER_H_
+
+#include "base/macros.h"
+#include "components/cryptauth/remote_device.h"
+
+class PrefService;
+class PrefRegistrySimple;
+
+namespace chromeos {
+
+namespace tether {
+
+// Prioritizes the order of devices when performing a host scan. To optimize for
+// the most common tethering operations, this class uses the following rules:
+// * The device which has most recently sent a successful
+// ConnectTetheringResponse is always at the front of the queue.
+// * Devices which have most recently sent a successful
+// TetherAvailabilityResponse are next in the order, as long as they do not
+// violate the first rule.
+// * All other devices are left in the order they are passed.
+class HostScanDevicePrioritizer {
+ public:
+ // Note: The PrefService* passed here must be created using the same registry
+ // passed to RegisterPrefs().
+ HostScanDevicePrioritizer(PrefService* pref_service);
+ ~HostScanDevicePrioritizer();
+
+ // Registers the prefs used by this class to |registry|. Must be called before
+ // this class is utilized.
+ static void RegisterPrefs(PrefRegistrySimple* registry);
+
+ // Records a TetherAvailabilityResponse. This function should be called each
+ // time that a response is received from a potential host, even if a
+ // connection is not started.
+ void RecordSuccessfulTetherAvailabilityResponse(
+ const cryptauth::RemoteDevice& remote_device);
+
+ // Records a ConnectTetheringResponse. This function should be called each
+ // time that a response is received from a host.
+ void RecordSuccessfulConnectTetheringResponse(
+ const cryptauth::RemoteDevice& remote_device);
+
+ // Prioritizes |remote_devices| using the rules described above.
+ void SortByHostScanOrder(
+ std::vector<cryptauth::RemoteDevice>* remote_devices) const;
+
+ private:
+ PrefService* pref_service_;
+
+ DISALLOW_COPY_AND_ASSIGN(HostScanDevicePrioritizer);
+};
+
+} // namespace tether
+
+} // namespace chromeos
+
+#endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_DEVICE_PRIORITIZER_H_
« no previous file with comments | « chromeos/components/tether/BUILD.gn ('k') | chromeos/components/tether/host_scan_device_prioritizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698