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

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

Issue 2171053002: Scan through Nearby when listing PW URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update a comment Created 4 years, 5 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: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/NearbyForegroundSubscription.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/NearbyForegroundSubscription.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/NearbyForegroundSubscription.java
new file mode 100644
index 0000000000000000000000000000000000000000..d32a4b557b91dec8989974ce417bbc9c8388fb17
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/NearbyForegroundSubscription.java
@@ -0,0 +1,58 @@
+// 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 android.content.Context;
+
+import com.google.android.gms.nearby.Nearby;
+import com.google.android.gms.nearby.messages.MessageListener;
+
+
+/**
+ * This class represents a connection to Google Play Services that does foreground
+ * subscription/unsubscription to Nearby Eddystone-URLs.
+ * To use this class, one should:
+ * 1. connect,
+ * 2. subscribe,
+ * 3. unsubscribe,
+ * 4. repeat steps 2-3 as desired, and
+ * 5. disconnect.
+ */
+class NearbyForegroundSubscription extends NearbySubscription {
+ private static final String TAG = "PhysicalWeb";
+ private final MessageListener mMessageListener;
+ private boolean mShouldSubscribe;
+
+ NearbyForegroundSubscription(Context context) {
+ super(context);
+ mMessageListener = PhysicalWebBleClient.getInstance().createForegroundMessageListener();
+ mShouldSubscribe = false;
+ }
+
+ @Override
+ protected void onConnected() {
+ if (mShouldSubscribe) {
+ subscribe();
+ }
+ }
+
+ void subscribe() {
+ if (!getGoogleApiClient().isConnected()) {
+ mShouldSubscribe = true;
+ return;
+ }
+ Nearby.Messages.subscribe(getGoogleApiClient(), mMessageListener, createSubscribeOptions())
+ .setResultCallback(new SimpleResultCallback("foreground subscribe"));
+ }
+
+ void unsubscribe() {
+ if (!getGoogleApiClient().isConnected()) {
+ mShouldSubscribe = false;
+ return;
+ }
+ Nearby.Messages.unsubscribe(getGoogleApiClient(), mMessageListener)
+ .setResultCallback(new SimpleResultCallback("foreground unsubscribe"));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698