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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/instantapps/InstantAppsHandler.java

Issue 2727483002: Instant Apps: refactor logic to encapsulate in the Instant Apps Handler. (Closed)
Patch Set: Fix findbugs issue. Created 3 years, 9 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.instantapps; 5 package org.chromium.chrome.browser.instantapps;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.Intent; 8 import android.content.Intent;
9 import android.content.pm.ResolveInfo;
9 import android.net.Uri; 10 import android.net.Uri;
10 import android.os.StrictMode; 11 import android.os.StrictMode;
11 import android.os.SystemClock; 12 import android.os.SystemClock;
12 import android.provider.Browser; 13 import android.provider.Browser;
13 14
14 import org.chromium.base.BuildInfo; 15 import org.chromium.base.BuildInfo;
15 import org.chromium.base.ContextUtils; 16 import org.chromium.base.ContextUtils;
16 import org.chromium.base.Log; 17 import org.chromium.base.Log;
18 import org.chromium.base.VisibleForTesting;
17 import org.chromium.base.metrics.CachedMetrics.EnumeratedHistogramSample; 19 import org.chromium.base.metrics.CachedMetrics.EnumeratedHistogramSample;
18 import org.chromium.base.metrics.CachedMetrics.TimesHistogramSample; 20 import org.chromium.base.metrics.CachedMetrics.TimesHistogramSample;
19 import org.chromium.chrome.browser.AppHooks; 21 import org.chromium.chrome.browser.AppHooks;
20 import org.chromium.chrome.browser.IntentHandler; 22 import org.chromium.chrome.browser.IntentHandler;
21 import org.chromium.chrome.browser.ShortcutHelper; 23 import org.chromium.chrome.browser.ShortcutHelper;
22 import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl; 24 import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl;
23 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; 25 import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
24 import org.chromium.chrome.browser.util.IntentUtils; 26 import org.chromium.chrome.browser.util.IntentUtils;
25 import org.chromium.content_public.browser.WebContents; 27 import org.chromium.content_public.browser.WebContents;
26 28
(...skipping 24 matching lines...) Expand all
51 53
52 protected static final String TRUSTED_REFERRER_PKG_EXTRA = 54 protected static final String TRUSTED_REFERRER_PKG_EXTRA =
53 "com.google.android.gms.instantapps.TRUSTED_REFERRER_PKG"; 55 "com.google.android.gms.instantapps.TRUSTED_REFERRER_PKG";
54 56
55 public static final String IS_GOOGLE_SEARCH_REFERRER = 57 public static final String IS_GOOGLE_SEARCH_REFERRER =
56 "com.google.android.gms.instantapps.IS_GOOGLE_SEARCH_REFERRER"; 58 "com.google.android.gms.instantapps.IS_GOOGLE_SEARCH_REFERRER";
57 59
58 private static final String BROWSER_LAUNCH_REASON = 60 private static final String BROWSER_LAUNCH_REASON =
59 "com.google.android.gms.instantapps.BROWSER_LAUNCH_REASON"; 61 "com.google.android.gms.instantapps.BROWSER_LAUNCH_REASON";
60 62
63 private static final String SUPERVISOR_PKG = "com.google.android.instantapps .supervisor";
64
65 private static final String[] SUPERVISOR_START_ACTIONS = {
66 "com.google.android.instantapps.START", "com.google.android.instanta pps.nmr1.INSTALL",
67 "com.google.android.instantapps.nmr1.VIEW"};
68
69 // Instant Apps system resolver activity on N-MR1+.
70 @VisibleForTesting
71 public static final String EPHEMERAL_INSTALLER_CLASS =
72 "com.google.android.gms.instantapps.routing.EphemeralInstallerActivi ty";
73
61 /** Finch experiment name. */ 74 /** Finch experiment name. */
62 private static final String INSTANT_APPS_EXPERIMENT_NAME = "InstantApps"; 75 private static final String INSTANT_APPS_EXPERIMENT_NAME = "InstantApps";
63 76
64 /** Finch experiment group which is enabled for instant apps. */ 77 /** Finch experiment group which is enabled for instant apps. */
65 private static final String INSTANT_APPS_ENABLED_ARM = "InstantAppsEnabled"; 78 private static final String INSTANT_APPS_ENABLED_ARM = "InstantAppsEnabled";
66 79
67 /** Finch experiment group which is disabled for instant apps. */ 80 /** Finch experiment group which is disabled for instant apps. */
68 private static final String INSTANT_APPS_DISABLED_ARM = "InstantAppsDisabled "; 81 private static final String INSTANT_APPS_DISABLED_ARM = "InstantAppsDisabled ";
69 82
70 /** A histogram to record how long each handleIntent() call took. */ 83 /** A histogram to record how long each handleIntent() call took. */
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 public static InstantAppsHandler getInstance() { 116 public static InstantAppsHandler getInstance() {
104 synchronized (INSTANCE_LOCK) { 117 synchronized (INSTANCE_LOCK) {
105 if (sInstance == null) { 118 if (sInstance == null) {
106 sInstance = AppHooks.get().createInstantAppsHandler(); 119 sInstance = AppHooks.get().createInstantAppsHandler();
107 } 120 }
108 } 121 }
109 return sInstance; 122 return sInstance;
110 } 123 }
111 124
112 /** 125 /**
126 * Checks whether {@param intent} is for an Instant App. Considers both pack age and actions that
127 * would resolve to Supervisor.
128 * @return Whether the given intent is going to open an Instant App.
129 */
130 public static boolean isIntentToInstantApp(Intent intent) {
131 if (SUPERVISOR_PKG.equals(intent.getPackage())) return true;
132
133 String intentAction = intent.getAction();
134 for (String action : SUPERVISOR_START_ACTIONS) {
135 if (action.equals(intentAction)) {
136 return true;
137 }
138 }
139 return false;
140 }
141
142 /**
113 * Record how long the handleIntent() method took. 143 * Record how long the handleIntent() method took.
114 * @param startTime The timestamp for handleIntent start time. 144 * @param startTime The timestamp for handleIntent start time.
115 */ 145 */
116 private void recordHandleIntentDuration(long startTime) { 146 private void recordHandleIntentDuration(long startTime) {
117 sHandleIntentDuration.record(SystemClock.elapsedRealtime() - startTime); 147 sHandleIntentDuration.record(SystemClock.elapsedRealtime() - startTime);
118 } 148 }
119 149
120 /** 150 /**
121 * Record the amount of time spent in the instant apps API call. 151 * Record the amount of time spent in the instant apps API call.
122 * @param startTime The time at which we started doing computations. 152 * @param startTime The time at which we started doing computations.
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 346
317 /** 347 /**
318 * Gets the instant app intent for the given URL if one exists. 348 * Gets the instant app intent for the given URL if one exists.
319 * 349 *
320 * @param url The URL whose instant app this is associated with. 350 * @param url The URL whose instant app this is associated with.
321 * @return An instant app intent for the URL if one exists. 351 * @return An instant app intent for the URL if one exists.
322 */ 352 */
323 public Intent getInstantAppIntentForUrl(String url) { 353 public Intent getInstantAppIntentForUrl(String url) {
324 return null; 354 return null;
325 } 355 }
356
357 /**
358 * Whether the given ResolveInfo object refers to Instant Apps as a launcher .
359 * @param info The resolve info.
360 */
361 public boolean isInstantAppResolveInfo(ResolveInfo info) {
362 if (info == null || info.activityInfo == null) return false;
363 return EPHEMERAL_INSTALLER_CLASS.equals(info.activityInfo.name);
364 }
326 } 365 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698