Commit 394cd0ae authored by hayesjordan's avatar hayesjordan Committed by Commit bot

Add access to Physical Web Service results

To allow access to Physical Web data, the URL info and Physical Web
Service data needs to be paired together. The pairing gives all relevant
information for a scanned URL.

BUG=636490

Committed: https://crrev.com/576c1dde62f1bc26e4366d50b32f76a636a1dbbd
Review-Url: https://codereview.chromium.org/2330253002
Cr-Original-Commit-Position: refs/heads/master@{#419531}
Cr-Commit-Position: refs/heads/master@{#419603}
parent 7d1b2033
// Copyright 2016 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.
package org.chromium.chrome.browser.physicalweb;
import java.util.List;
/**
* A physical web collection stores UrlInfos and PwsResults for scanned URLs.
*/
public class PwCollection {
public final UrlInfo[] urlInfos;
public final PwsResult[] pwsResults;
/**
* Construct a PwCollection.
* @param urlInfos All nearby URL infos.
* @param pwsResults The metadata for nearby URLs.
*/
public PwCollection(List<UrlInfo> urlInfos, List<PwsResult> pwsResults) {
this.urlInfos = urlInfos.toArray(new UrlInfo[0]);
this.pwsResults = pwsResults.toArray(new PwsResult[0]);
}
}
...@@ -251,6 +251,17 @@ class UrlManager { ...@@ -251,6 +251,17 @@ class UrlManager {
return mPwsResultMap.keySet(); return mPwsResultMap.keySet();
} }
/**
* Gets all UrlInfos and PwsResults for resolved URLs.
*/
public PwCollection getPwCollection() {
List<PwsResult> nearbyPwsResults = new ArrayList<>();
for (String url : mNearbyUrls) {
nearbyPwsResults.add(mPwsResultMap.get(url));
}
return new PwCollection(getUrlInfoList(mNearbyUrls), nearbyPwsResults);
}
/** /**
* Forget all stored URLs and clear the notification. * Forget all stored URLs and clear the notification.
*/ */
......
...@@ -690,6 +690,7 @@ chrome_java_sources = [ ...@@ -690,6 +690,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebEnvironment.java", "java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebEnvironment.java",
"java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebOptInActivity.java", "java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebOptInActivity.java",
"java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebUma.java", "java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebUma.java",
"java/src/org/chromium/chrome/browser/physicalweb/PwCollection.java",
"java/src/org/chromium/chrome/browser/physicalweb/PwsClient.java", "java/src/org/chromium/chrome/browser/physicalweb/PwsClient.java",
"java/src/org/chromium/chrome/browser/physicalweb/PwsClientImpl.java", "java/src/org/chromium/chrome/browser/physicalweb/PwsClientImpl.java",
"java/src/org/chromium/chrome/browser/physicalweb/PwsResult.java", "java/src/org/chromium/chrome/browser/physicalweb/PwsResult.java",
......
...@@ -464,4 +464,22 @@ public class UrlManagerTest extends InstrumentationTestCase { ...@@ -464,4 +464,22 @@ public class UrlManagerTest extends InstrumentationTestCase {
assertEquals(UrlManager.getVersion(), assertEquals(UrlManager.getVersion(),
mSharedPreferences.getInt(UrlManager.getVersionKey(), 0)); mSharedPreferences.getInt(UrlManager.getVersionKey(), 0));
} }
@SmallTest
public void testGetPwCollection() {
assertEquals(0, mUrlManager.getPwCollection().urlInfos.length);
assertEquals(0, mUrlManager.getPwCollection().pwsResults.length);
addPwsResult1();
long curTime = System.currentTimeMillis();
mUrlManager.addUrl(new UrlInfo(URL1, 99.5, curTime + 42));
getInstrumentation().waitForIdleSync();
assertEquals(1, mUrlManager.getPwCollection().urlInfos.length);
assertEquals(1, mUrlManager.getPwCollection().pwsResults.length);
addPwsResult2();
mUrlManager.addUrl(new UrlInfo(URL2, 99.5, curTime + 42));
getInstrumentation().waitForIdleSync();
assertEquals(2, mUrlManager.getPwCollection().urlInfos.length);
assertEquals(2, mUrlManager.getPwCollection().pwsResults.length);
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment