Commit 576c1dde 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

Review-Url: https://codereview.chromium.org/2330253002
Cr-Commit-Position: refs/heads/master@{#419531}
parent 4f1f3f15
// 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;
/**
* 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(UrlInfo[] urlInfos, PwsResult[] pwsResults) {
this.urlInfos = urlInfos;
this.pwsResults = pwsResults;
}
}
......@@ -251,6 +251,18 @@ class UrlManager {
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).toArray(new UrlInfo[0]),
nearbyPwsResults.toArray(new PwsResult[0]));
}
/**
* Forget all stored URLs and clear the notification.
*/
......
......@@ -690,6 +690,7 @@ chrome_java_sources = [
"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/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/PwsClientImpl.java",
"java/src/org/chromium/chrome/browser/physicalweb/PwsResult.java",
......
......@@ -464,4 +464,22 @@ public class UrlManagerTest extends InstrumentationTestCase {
assertEquals(UrlManager.getVersion(),
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