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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/UrlManager.java

Issue 2015523003: Sort Physical Web URLs by distance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 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
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/UrlManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/UrlManager.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/UrlManager.java
index ce25e72dc48f550ea078523104278f42820d33a2..7b6d9f323cbc561ca6e02adcca0ba745226d18ca 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/UrlManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/UrlManager.java
@@ -79,6 +79,7 @@ class UrlManager {
private PwsClient mPwsClient;
private final Comparator<String> mScanTimestampComparator = new Comparator<String>() {
+ @Override
public int compare(String url1, String url2) {
UrlInfo urlInfo1 = mUrlInfoMap.get(url1);
UrlInfo urlInfo2 = mUrlInfoMap.get(url2);
@@ -156,7 +157,10 @@ class UrlManager {
putCachedUrlInfoMap();
recordUpdate();
- if (mNearbyUrls.contains(urlInfo.getUrl())) {
+ if (mNearbyUrls.contains(urlInfo.getUrl())
+ // In the rare event that our entry is immediately garbage collected from the cache,
+ // we should stop here.
+ || !mUrlInfoMap.containsKey(urlInfo.getUrl())) {
return;
}
mNearbyUrls.add(urlInfo.getUrl());
@@ -210,7 +214,6 @@ class UrlManager {
* Get the list of URLs which are both nearby and resolved through PWS.
* @return A set of nearby and resolved URLs, sorted by distance.
*/
- // TODO(conleyo) We will need to provide sorted URLs after distance is in place.
@VisibleForTesting
public List<UrlInfo> getUrls() {
return getUrls(false);
@@ -220,7 +223,7 @@ class UrlManager {
* Get the list of URLs which are both nearby and resolved through PWS.
* @param allowUnresolved If true, include unresolved URLs only if the
* resolved URL list is empty.
- * @return A set of nearby URLs.
+ * @return A set of nearby URLs, sorted by distance.
*/
@VisibleForTesting
public List<UrlInfo> getUrls(boolean allowUnresolved) {
@@ -229,11 +232,19 @@ class UrlManager {
Log.d(TAG, "Get URLs With: %d nearby, %d resolved, and %d in intersection.",
mNearbyUrls.size(), mResolvedUrls.size(), intersection.size());
+ List<UrlInfo> urlInfos = null;
if (allowUnresolved && mResolvedUrls.isEmpty()) {
- return getUrlInfoList(mNearbyUrls);
+ urlInfos = getUrlInfoList(mNearbyUrls);
+ } else {
+ urlInfos = getUrlInfoList(intersection);
}
-
- return getUrlInfoList(intersection);
+ Collections.sort(urlInfos, new Comparator<UrlInfo>() {
+ @Override
+ public int compare(UrlInfo urlInfo1, UrlInfo urlInfo2) {
+ return Double.compare(urlInfo1.getDistance(), urlInfo2.getDistance());
+ }
+ });
+ return urlInfos;
}
public Set<String> getNearbyUrls() {
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/physicalweb/UrlManagerTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698