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

Unified Diff: remoting/ios/facade/host_list_fetcher.cc

Issue 2912293003: [CRD iOS] Consistent host list order and showing last online time (Closed)
Patch Set: Fix comment 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 side-by-side diff with in-line comments
Download patch
Index: remoting/ios/facade/host_list_fetcher.cc
diff --git a/remoting/ios/facade/host_list_fetcher.cc b/remoting/ios/facade/host_list_fetcher.cc
index 9342399a8890682c74cbd7c59b9512b8c0f9832e..469cbf31b88d113ed85c61042a48d1507644ceca 100644
--- a/remoting/ios/facade/host_list_fetcher.cc
+++ b/remoting/ios/facade/host_list_fetcher.cc
@@ -4,6 +4,7 @@
#include "remoting/ios/facade/host_list_fetcher.h"
+#include <algorithm>
#include <thread>
#include "base/bind.h"
@@ -18,6 +19,27 @@
namespace remoting {
+namespace {
+
+// Returns true if |h1| should sort before |h2|.
+bool compareHost(const HostInfo& h1, const HostInfo& h2) {
+ // Online hosts always sort before offline hosts.
+ if (h1.status != h2.status) {
+ return h1.status == HostStatus::kHostStatusOnline;
+ }
+
+ // Sort by host name.
+ int name_compare = h1.host_name.compare(h2.host_name);
+ if (name_compare != 0) {
+ return name_compare < 0;
+ }
+
+ // Sort by last update time if names are identical.
+ return h1.updated_time < h2.updated_time;
+}
+
+} // namespace
+
HostListFetcher::HostListFetcher(
const scoped_refptr<net::URLRequestContextGetter>&
url_request_context_getter)
@@ -105,6 +127,7 @@ void HostListFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
if (!ProcessResponse(&hostlist)) {
hostlist.clear();
}
+ std::sort(hostlist.begin(), hostlist.end(), &compareHost);
base::ResetAndReturn(&hostlist_callback_).Run(hostlist);
}

Powered by Google App Engine
This is Rietveld 408576698