Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.Intent; | 7 import android.content.Intent; |
| 8 import android.os.Bundle; | 8 import android.os.Bundle; |
| 9 import android.os.SystemClock; | 9 import android.os.SystemClock; |
| 10 | 10 |
| 11 import org.chromium.base.ContextUtils; | 11 import org.chromium.base.ContextUtils; |
| 12 import org.chromium.base.library_loader.LibraryProcessType; | 12 import org.chromium.base.library_loader.LibraryProcessType; |
| 13 import org.chromium.base.metrics.RecordHistogram; | 13 import org.chromium.base.metrics.RecordHistogram; |
| 14 import org.chromium.base.process_launcher.ChildProcessCreationParams; | 14 import org.chromium.base.process_launcher.ChildProcessCreationParams; |
| 15 import org.chromium.chrome.browser.ShortcutSource; | |
| 15 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; | 16 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; |
| 17 import org.chromium.chrome.browser.metrics.LaunchMetrics; | |
| 16 import org.chromium.chrome.browser.metrics.WebApkUma; | 18 import org.chromium.chrome.browser.metrics.WebApkUma; |
| 17 import org.chromium.chrome.browser.tab.BrowserControlsVisibilityDelegate; | 19 import org.chromium.chrome.browser.tab.BrowserControlsVisibilityDelegate; |
| 18 import org.chromium.chrome.browser.tab.InterceptNavigationDelegateImpl; | 20 import org.chromium.chrome.browser.tab.InterceptNavigationDelegateImpl; |
| 19 import org.chromium.chrome.browser.tab.Tab; | 21 import org.chromium.chrome.browser.tab.Tab; |
| 20 import org.chromium.chrome.browser.tab.TabDelegateFactory; | 22 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| 21 import org.chromium.chrome.browser.tab.TabRedirectHandler; | 23 import org.chromium.chrome.browser.tab.TabRedirectHandler; |
| 22 import org.chromium.components.navigation_interception.NavigationParams; | 24 import org.chromium.components.navigation_interception.NavigationParams; |
| 23 import org.chromium.webapk.lib.client.WebApkServiceConnectionManager; | 25 import org.chromium.webapk.lib.client.WebApkServiceConnectionManager; |
| 24 | 26 |
| 25 import java.util.concurrent.TimeUnit; | 27 import java.util.concurrent.TimeUnit; |
| 26 | 28 |
| 27 /** | 29 /** |
| 28 * An Activity is designed for WebAPKs (native Android apps) and displays a weba pp in a nearly | 30 * An Activity is designed for WebAPKs (native Android apps) and displays a weba pp in a nearly |
| 29 * UI-less Chrome. | 31 * UI-less Chrome. |
| 30 */ | 32 */ |
| 31 public class WebApkActivity extends WebappActivity { | 33 public class WebApkActivity extends WebappActivity { |
| 32 /** Manages whether to check update for the WebAPK, and starts update check if needed. */ | 34 /** Manages whether to check update for the WebAPK, and starts update check if needed. */ |
| 33 private WebApkUpdateManager mUpdateManager; | 35 private WebApkUpdateManager mUpdateManager; |
| 34 | 36 |
| 35 /** Indicates whether launching renderer in WebAPK process is enabled. */ | 37 /** Indicates whether launching renderer in WebAPK process is enabled. */ |
| 36 private boolean mCanLaunchRendererInWebApkProcess; | 38 private boolean mCanLaunchRendererInWebApkProcess; |
| 37 | 39 |
| 38 private final ChildProcessCreationParams mDefaultParams = | 40 private final ChildProcessCreationParams mDefaultParams = |
| 39 ChildProcessCreationParams.getDefault(); | 41 ChildProcessCreationParams.getDefault(); |
| 40 | 42 |
| 41 /** The start time that the activity becomes focused. */ | 43 /** The start time that the activity becomes focused. */ |
| 42 private long mStartTime; | 44 private long mStartTime; |
| 43 | 45 |
| 46 /** Indicates whether has committed the source info to the launch metrics. * / | |
| 47 private boolean mHasCommitedLaunchMetrics; | |
| 48 | |
| 44 @Override | 49 @Override |
| 45 protected WebappInfo createWebappInfo(Intent intent) { | 50 protected WebappInfo createWebappInfo(Intent intent) { |
| 46 return (intent == null) ? WebApkInfo.createEmpty() : WebApkInfo.create(i ntent); | 51 return (intent == null) ? WebApkInfo.createEmpty() : WebApkInfo.create(i ntent); |
| 47 } | 52 } |
| 48 | 53 |
| 49 @Override | 54 @Override |
| 50 protected void initializeUI(Bundle savedInstance) { | 55 protected void initializeUI(Bundle savedInstance) { |
| 51 super.initializeUI(savedInstance); | 56 super.initializeUI(savedInstance); |
| 52 getActivityTab().setWebappManifestScope(mWebappInfo.scopeUri().toString( )); | 57 getActivityTab().setWebappManifestScope(mWebappInfo.scopeUri().toString( )); |
| 53 } | 58 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 | 123 |
| 119 @Override | 124 @Override |
| 120 public void onResumeWithNative() { | 125 public void onResumeWithNative() { |
| 121 super.onResumeWithNative(); | 126 super.onResumeWithNative(); |
| 122 | 127 |
| 123 // When launching Chrome renderer in WebAPK process is enabled, WebAPK h osts Chrome's | 128 // When launching Chrome renderer in WebAPK process is enabled, WebAPK h osts Chrome's |
| 124 // renderer processes by declaring the Chrome's renderer service in its AndroidManifest.xml | 129 // renderer processes by declaring the Chrome's renderer service in its AndroidManifest.xml |
| 125 // and sets {@link ChildProcessCreationParams} for WebAPK's renderer pro cess so the | 130 // and sets {@link ChildProcessCreationParams} for WebAPK's renderer pro cess so the |
| 126 // {@link ChildProcessLauncher} knows which application's renderer servi ce to connect to. | 131 // {@link ChildProcessLauncher} knows which application's renderer servi ce to connect to. |
| 127 initializeChildProcessCreationParams(mCanLaunchRendererInWebApkProcess); | 132 initializeChildProcessCreationParams(mCanLaunchRendererInWebApkProcess); |
| 133 | |
| 134 // Records launch metrics for the WebAPK. | |
| 135 if (!mHasCommitedLaunchMetrics) { | |
| 136 mHasCommitedLaunchMetrics = true; | |
| 137 int source = mWebappInfo.source(); | |
| 138 if (mWebappInfo.isLaunchedFromHomescreen()) { | |
|
dominickn
2017/05/10 06:04:46
I'm not sure this works. isLaunchedFromHomescreen(
Xi Han
2017/05/10 20:49:58
If the WebAPK is resumed by external Intent or not
| |
| 139 WebappDataStorage storage = | |
| 140 WebappRegistry.getInstance().getWebappDataStorage(mWebap pInfo.id()); | |
| 141 source = storage != null ? storage.getSource(ShortcutSource.WEBA PK_UNKNOWN) | |
| 142 : ShortcutSource.WEBAPK_UNKNOWN; | |
| 143 if (source == ShortcutSource.UNKNOWN) { | |
| 144 source = ShortcutSource.WEBAPK_UNKNOWN; | |
| 145 storage.updateSource(source); | |
| 146 } | |
| 147 } | |
|
pkotwicz
2017/05/09 18:37:36
I think (Dominick might disagree) that we should d
dominickn
2017/05/10 06:04:46
I agree that if possible, we shouldn't explicitly
Xi Han
2017/05/10 20:49:58
Agree, it is neat to have WEBAPK_UNKNOWN as the de
pkotwicz
2017/05/10 21:08:59
I wasn't suggesting changing the default source in
Xi Han
2017/05/11 17:14:28
Ok, I must misunderstood. Revert the default sourc
| |
| 148 LaunchMetrics.recordHomeScreenLaunchIntoStandaloneActivity( | |
| 149 mWebappInfo.uri().toString(), source); | |
| 150 LaunchMetrics.commitLaunchMetrics(getActivityTab().getWebContents()) ; | |
| 151 } | |
| 128 } | 152 } |
| 129 | 153 |
| 130 @Override | 154 @Override |
| 131 public void onResume() { | 155 public void onResume() { |
| 132 super.onResume(); | 156 super.onResume(); |
| 133 mStartTime = SystemClock.elapsedRealtime(); | 157 mStartTime = SystemClock.elapsedRealtime(); |
| 134 } | 158 } |
| 135 | 159 |
| 136 @Override | 160 @Override |
| 137 protected void recordIntentToCreationTime(long timeMs) { | 161 protected void recordIntentToCreationTime(long timeMs) { |
| 138 super.recordIntentToCreationTime(timeMs); | 162 super.recordIntentToCreationTime(timeMs); |
| 139 | 163 |
| 140 RecordHistogram.recordTimesHistogram( | 164 RecordHistogram.recordTimesHistogram( |
| 141 "MobileStartup.IntentToCreationTime.WebApk", timeMs, TimeUnit.MI LLISECONDS); | 165 "MobileStartup.IntentToCreationTime.WebApk", timeMs, TimeUnit.MI LLISECONDS); |
| 142 } | 166 } |
| 143 | 167 |
| 144 @Override | 168 @Override |
| 145 protected void onDeferredStartupWithStorage(WebappDataStorage storage) { | 169 protected void onDeferredStartupWithStorage(WebappDataStorage storage) { |
| 146 super.onDeferredStartupWithStorage(storage); | 170 super.onDeferredStartupWithStorage(storage); |
| 147 | 171 |
| 148 mUpdateManager = new WebApkUpdateManager(WebApkActivity.this, storage); | 172 mUpdateManager = new WebApkUpdateManager(WebApkActivity.this, storage); |
| 149 mUpdateManager.updateIfNeeded(getActivityTab(), | 173 mUpdateManager.updateIfNeeded(getActivityTab(), |
| 150 (WebApkInfo) mWebappInfo); | 174 (WebApkInfo) mWebappInfo); |
| 151 } | 175 } |
| 152 | 176 |
| 153 @Override | 177 @Override |
| 154 protected void onDeferredStartupWithNullStorage() { | 178 protected void onDeferredStartupWithNullStorage() { |
| 155 super.onDeferredStartupWithNullStorage(); | 179 super.onDeferredStartupWithNullStorage(); |
| 156 | 180 |
| 157 // Register the WebAPK. The WebAPK is not registered when it is created so it has to be | 181 // Register the WebAPK. The WebAPK was registered when it was created, b ut may also become |
| 158 // registered now. The WebAPK may also become unregistered after a user clears Chrome's | 182 // unregistered after a user clears Chrome's data. |
| 159 // data. | |
| 160 WebappRegistry.getInstance().register( | 183 WebappRegistry.getInstance().register( |
| 161 mWebappInfo.id(), new WebappRegistry.FetchWebappDataStorageCallb ack() { | 184 mWebappInfo.id(), new WebappRegistry.FetchWebappDataStorageCallb ack() { |
| 162 @Override | 185 @Override |
| 163 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) { | 186 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) { |
| 164 // Initialize the time of the last is-update-needed chec k with the | 187 // Initialize the time of the last is-update-needed chec k with the |
| 165 // registration time. This prevents checking for updates on the first run. | 188 // registration time. This prevents checking for updates on the first run. |
| 166 storage.updateTimeOfLastCheckForUpdatedWebManifest(); | 189 storage.updateTimeOfLastCheckForUpdatedWebManifest(); |
| 167 | 190 |
| 191 storage.updateSource(ShortcutSource.WEBAPK_UNKNOWN); | |
|
dominickn
2017/05/10 06:04:46
As noted above, I agree with Peter that we shouldn
Xi Han
2017/05/10 20:49:58
Removed.
| |
| 168 onDeferredStartupWithStorage(storage); | 192 onDeferredStartupWithStorage(storage); |
| 169 } | 193 } |
| 170 }); | 194 }); |
| 171 } | 195 } |
| 172 | 196 |
| 173 @Override | 197 @Override |
| 174 public void onPause() { | 198 public void onPause() { |
| 175 super.onPause(); | 199 super.onPause(); |
| 176 initializeChildProcessCreationParams(false); | 200 initializeChildProcessCreationParams(false); |
| 177 } | 201 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 201 } | 225 } |
| 202 | 226 |
| 203 @Override | 227 @Override |
| 204 protected void onDestroyInternal() { | 228 protected void onDestroyInternal() { |
| 205 if (mUpdateManager != null) { | 229 if (mUpdateManager != null) { |
| 206 mUpdateManager.destroy(); | 230 mUpdateManager.destroy(); |
| 207 } | 231 } |
| 208 super.onDestroyInternal(); | 232 super.onDestroyInternal(); |
| 209 } | 233 } |
| 210 } | 234 } |
| OLD | NEW |