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

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

Issue 2176373007: Use Nearby to background scan for URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make some variables private static final 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/NearbyBackgroundSubscription.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/NearbyBackgroundSubscription.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/NearbyBackgroundSubscription.java
new file mode 100644
index 0000000000000000000000000000000000000000..a14520589cee16573c2b0be2902ea8ef58a2d9e9
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/NearbyBackgroundSubscription.java
@@ -0,0 +1,72 @@
+// 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.app.PendingIntent;
+import android.content.Intent;
+
+import com.google.android.gms.common.api.PendingResult;
+import com.google.android.gms.common.api.Status;
+import com.google.android.gms.nearby.Nearby;
+
+import org.chromium.base.ContextUtils;
+
+
+/**
+ * This class represents a connection to Google Play Services that does background
+ * subscription/unsubscription to Nearby Eddystone-URLs.
+ */
+class NearbyBackgroundSubscription extends NearbySubscription {
+ private static final String TAG = "PhysicalWeb";
+ private final int mAction;
+ private final Runnable mCallback;
+
+ NearbyBackgroundSubscription(int action, Runnable callback) {
+ super(ContextUtils.getApplicationContext());
+ mAction = action;
+ mCallback = callback;
+ }
+
+ NearbyBackgroundSubscription(int action) {
+ this(action, null);
+ }
+
+ private PendingIntent createNearbySubscribeIntent() {
+ Intent intent =
+ new Intent(ContextUtils.getApplicationContext(), NearbyMessageIntentService.class);
+ PendingIntent pendingIntent = PendingIntent.getService(
+ ContextUtils.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ return pendingIntent;
+ }
+
+ @Override
+ protected void onConnected() {
+ PendingResult<Status> pendingResult = null;
+ String actionStr = null;
+ if (mAction == SUBSCRIBE) {
+ pendingResult = Nearby.Messages.subscribe(
+ getGoogleApiClient(), createNearbySubscribeIntent(), createSubscribeOptions());
+ actionStr = "background subscribe";
+ } else {
+ pendingResult = Nearby.Messages.unsubscribe(
+ getGoogleApiClient(), createNearbySubscribeIntent());
+ actionStr = "background unsubscribe";
+ }
+ pendingResult.setResultCallback(new SimpleResultCallback(actionStr) {
+ @Override
+ public void onResult(final Status status) {
+ super.onResult(status);
+ disconnect();
+ if (mCallback != null) {
+ mCallback.run();
+ }
+ }
+ });
+ }
+
+ void run() {
+ connect();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698