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

Unified Diff: chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkServiceClient.java

Issue 2974573002: Refactor WebApkServiceConnectionManager. (Closed)
Patch Set: Call the callback on UI thread if bindService() fails. Created 3 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/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkServiceClient.java
diff --git a/chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkServiceClient.java b/chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkServiceClient.java
new file mode 100644
index 0000000000000000000000000000000000000000..78cd05122630ea44d8385521a3ec05a9bec6a9ff
--- /dev/null
+++ b/chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/WebApkServiceClient.java
@@ -0,0 +1,75 @@
+// Copyright 2017 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.webapk.lib.client;
+
+import android.content.Context;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.Log;
+
+import org.chromium.webapk.lib.runtime_library.IWebApkApi;
+
+/**
+ * Manages static global connections between the Chrome application and "WebAPK service". Each
+ * WebAPK has its own "WebAPK service".
+ */
+public class WebApkServiceClient extends WebApkServiceConnectionManager {
+ // Callback which catches RemoteExceptions thrown due to IWebApkApi failure.
+ public abstract static class ApiUseCallback
+ implements WebApkServiceConnectionManager.ConnectionCallback {
+ public abstract void useApi(IWebApkApi api) throws RemoteException;
+
+ @Override
+ public void onConnected(IBinder api) {
+ try {
+ useApi(IWebApkApi.Stub.asInterface(api));
+ } catch (RemoteException e) {
+ Log.w(TAG, "WebApkAPI use failed.", e);
+ }
+ }
+ }
+
+ private static final String CATEGORY_WEBAPK_API = "android.intent.category.WEBAPK_API";
+ private static final String TAG = "cr_WebApk";
+
+ private static WebApkServiceClient sInstance;
+
+ public static WebApkServiceClient getInstance() {
+ if (sInstance == null) {
+ sInstance = new WebApkServiceClient();
+ }
+ return sInstance;
+ }
+
+ private WebApkServiceClient() {
+ super(CATEGORY_WEBAPK_API);
+ }
+
+ /**
+ * Connects to a WebAPK's bound service and calls the callback when the service connection is
+ * established.
+ */
+ public static void notifyNotification(
+ Context appContext, final String webApkPackage, ApiUseCallback callback) {
+ getInstance().connect(appContext, webApkPackage, callback);
+ }
+
+ /** Cancels notification previously shown by WebAPK. */
+ public static void cancelNotification(Context appContext, String webApkPackage,
+ final String platformTag, final int platformID) {
+ final ApiUseCallback connectionCallback = new ApiUseCallback() {
+ @Override
+ public void useApi(IWebApkApi api) throws RemoteException {
+ api.cancelNotification(platformTag, platformID);
+ }
+ };
+
+ getInstance().connect(appContext, webApkPackage, connectionCallback);
+ }
+
+ public static void disconnectWebApkService(Context appContext, String webApkPackageName) {
+ getInstance().disconnect(appContext, webApkPackageName);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698