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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java

Issue 2974573002: Refactor WebApkServiceConnectionManager. (Closed)
Patch Set: yfriedman@'s comments. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.webapps; 5 package org.chromium.chrome.browser.webapps;
6 6
7 import android.content.Context;
8
9 import org.chromium.base.ApplicationState;
10 import org.chromium.base.ApplicationStatus;
11 import org.chromium.base.ContextUtils;
7 import org.chromium.base.library_loader.LibraryLoader; 12 import org.chromium.base.library_loader.LibraryLoader;
13 import org.chromium.webapk.lib.client.WebApkIdentityServiceClient;
8 import org.chromium.webapk.lib.client.WebApkValidator; 14 import org.chromium.webapk.lib.client.WebApkValidator;
9 15
10 /** 16 /**
11 * Contains functionality needed for Chrome to host WebAPKs. 17 * Contains functionality needed for Chrome to host WebAPKs.
12 */ 18 */
13 public class ChromeWebApkHost { 19 public class ChromeWebApkHost {
14 private static final String TAG = "ChromeWebApkHost"; 20 private static final String TAG = "ChromeWebApkHost";
21 private static ApplicationStatus.ApplicationStateListener sListener;
15 22
16 public static void init() { 23 public static void init() {
17 WebApkValidator.init( 24 WebApkValidator.init(
18 ChromeWebApkHostSignature.EXPECTED_SIGNATURE, ChromeWebApkHostSi gnature.PUBLIC_KEY); 25 ChromeWebApkHostSignature.EXPECTED_SIGNATURE, ChromeWebApkHostSi gnature.PUBLIC_KEY);
19 } 26 }
20 27
21 /* Returns whether launching renderer in WebAPK process is enabled by Chrome . */ 28 /* Returns whether launching renderer in WebAPK process is enabled by Chrome . */
22 public static boolean canLaunchRendererInWebApkProcess() { 29 public static boolean canLaunchRendererInWebApkProcess() {
23 return LibraryLoader.isInitialized() && nativeCanLaunchRendererInWebApkP rocess(); 30 return LibraryLoader.isInitialized() && nativeCanLaunchRendererInWebApkP rocess();
24 } 31 }
25 32
33 /** Checks whether Chrome is the runtime host of the WebAPK asynchronously. */
34 public static void checkChromeBacksWebApkAsync(Context appContext, String we bApkPackageName,
35 WebApkIdentityServiceClient.CheckBacksWebApkCallback callback) {
pkotwicz 2017/07/19 16:09:13 Does the context have to be passed in?
Xi Han 2017/07/21 20:36:33 Done.
36 maybeRegisterListenerForWebApkIdentityServiceClient();
37 WebApkIdentityServiceClient.checkBacksWebApkAsync(appContext, webApkPack ageName, callback);
38 }
39
40 /**
41 * Registers an application listener to disconnect the singleton WebApkIdent ityServiceClient if
42 * it hasn't registered yet.
43 */
pkotwicz 2017/07/19 16:09:13 The comment is out of date. Perhaps: "to disconnec
Xi Han 2017/07/21 20:36:33 Thanks!
44 private static void maybeRegisterListenerForWebApkIdentityServiceClient() {
45 if (sListener != null) return;
46
47 sListener = new ApplicationStatus.ApplicationStateListener() {
48 @Override
49 public void onApplicationStateChange(int newState) {
50 if (newState == ApplicationState.HAS_STOPPED_ACTIVITIES
51 || newState == ApplicationState.HAS_DESTROYED_ACTIVITIES ) {
52 WebApkIdentityServiceClient.disconnectWebApkIdentityService(
53 ContextUtils.getApplicationContext());
54 WebApkServiceClient.disconnectWebApkService(
55 ContextUtils.getApplicationContext());
pkotwicz 2017/07/19 16:09:13 I think that disconnecting from both the WebApkIde
Xi Han 2017/07/21 20:36:33 Acknowledged.
56
57 ApplicationStatus.unregisterApplicationStateListener(sListen er);
58 sListener = null;
59 }
60 }
61 };
62 ApplicationStatus.registerApplicationStateListener(sListener);
63 }
26 64
27 private static native boolean nativeCanLaunchRendererInWebApkProcess(); 65 private static native boolean nativeCanLaunchRendererInWebApkProcess();
28 } 66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698