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

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

Issue 2701333002: Add integration tests for WebAPKs (Closed)
Patch Set: Merge branch 'master' into integration_test 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.webapps; 5 package org.chromium.chrome.browser.webapps;
6 6
7 import android.content.pm.PackageInfo; 7 import android.content.pm.PackageInfo;
8 import android.content.pm.PackageManager; 8 import android.content.pm.PackageManager;
9 import android.graphics.Bitmap; 9 import android.graphics.Bitmap;
10 import android.text.TextUtils; 10 import android.text.TextUtils;
(...skipping 28 matching lines...) Expand all
39 * server if the previous update attempt failed. 39 * server if the previous update attempt failed.
40 */ 40 */
41 public static final long RETRY_UPDATE_DURATION = TimeUnit.HOURS.toMillis(12L ); 41 public static final long RETRY_UPDATE_DURATION = TimeUnit.HOURS.toMillis(12L );
42 42
43 /** 43 /**
44 * Number of times to wait for updating the WebAPK after it is moved to the background prior 44 * Number of times to wait for updating the WebAPK after it is moved to the background prior
45 * to doing the update while the WebAPK is in the foreground. 45 * to doing the update while the WebAPK is in the foreground.
46 */ 46 */
47 private static final int MAX_UPDATE_ATTEMPTS = 3; 47 private static final int MAX_UPDATE_ATTEMPTS = 3;
48 48
49 /** Whether updates are enabled. Some tests disable updates. */
50 private static boolean sUpdatesEnabled = true;
51
49 /** Data extracted from the WebAPK's launch intent and from the WebAPK's And roid Manifest. */ 52 /** Data extracted from the WebAPK's launch intent and from the WebAPK's And roid Manifest. */
50 private WebApkInfo mInfo; 53 private WebApkInfo mInfo;
51 54
52 /** 55 /**
53 * The cached data for a pending update request which needs to be sent after the WebAPK isn't 56 * The cached data for a pending update request which needs to be sent after the WebAPK isn't
54 * running in the foreground. 57 * running in the foreground.
55 */ 58 */
56 private PendingUpdate mPendingUpdate; 59 private PendingUpdate mPendingUpdate;
57 60
58 /** The WebApkActivity which owns the WebApkUpdateManager. */ 61 /** The WebApkActivity which owns the WebApkUpdateManager. */
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 120 }
118 121
119 public void destroy() { 122 public void destroy() {
120 destroyFetcher(); 123 destroyFetcher();
121 } 124 }
122 125
123 public boolean getHasPendingUpdateForTesting() { 126 public boolean getHasPendingUpdateForTesting() {
124 return mPendingUpdate != null; 127 return mPendingUpdate != null;
125 } 128 }
126 129
130 public static void setUpdatesEnabledForTesting(boolean enabled) {
131 sUpdatesEnabled = enabled;
132 }
133
127 @Override 134 @Override
128 public void onWebManifestForInitialUrlNotWebApkCompatible() { 135 public void onWebManifestForInitialUrlNotWebApkCompatible() {
129 onGotManifestData(null, null); 136 onGotManifestData(null, null);
130 } 137 }
131 138
132 @Override 139 @Override
133 public void onGotManifestData(WebApkInfo fetchedInfo, String bestIconUrl) { 140 public void onGotManifestData(WebApkInfo fetchedInfo, String bestIconUrl) {
134 WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataSt orage(mInfo.id()); 141 WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataSt orage(mInfo.id());
135 storage.updateTimeOfLastCheckForUpdatedWebManifest(); 142 storage.updateTimeOfLastCheckForUpdatedWebManifest();
136 143
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 /** 308 /**
302 * Returns whether the Web Manifest should be refetched to check whether it has been updated. 309 * Returns whether the Web Manifest should be refetched to check whether it has been updated.
303 * TODO: Make this method static once there is a static global clock class. 310 * TODO: Make this method static once there is a static global clock class.
304 * @param storage WebappDataStorage with the WebAPK's cached data. 311 * @param storage WebappDataStorage with the WebAPK's cached data.
305 * @param info Meta data from WebAPK's Android Manifest. 312 * @param info Meta data from WebAPK's Android Manifest.
306 * @param previousUpdateSucceeded Whether the previous update attempt succee ded. 313 * @param previousUpdateSucceeded Whether the previous update attempt succee ded.
307 * True if there has not been any update attempts. 314 * True if there has not been any update attempts.
308 */ 315 */
309 private boolean shouldCheckIfWebManifestUpdated( 316 private boolean shouldCheckIfWebManifestUpdated(
310 WebappDataStorage storage, WebApkInfo info, boolean previousUpdateSu cceeded) { 317 WebappDataStorage storage, WebApkInfo info, boolean previousUpdateSu cceeded) {
318 if (!sUpdatesEnabled) {
319 return false;
320 }
321
311 if (CommandLine.getInstance().hasSwitch( 322 if (CommandLine.getInstance().hasSwitch(
312 ChromeSwitches.CHECK_FOR_WEB_MANIFEST_UPDATE_ON_STARTUP)) { 323 ChromeSwitches.CHECK_FOR_WEB_MANIFEST_UPDATE_ON_STARTUP)) {
313 return true; 324 return true;
314 } 325 }
315 326
316 if (!ChromeWebApkHost.areUpdatesEnabled()) return false; 327 if (!ChromeWebApkHost.areUpdatesEnabled()) return false;
317 328
318 if (isShellApkVersionOutOfDate(info)) return true; 329 if (isShellApkVersionOutOfDate(info)) return true;
319 330
320 long now = currentTimeMillis(); 331 long now = currentTimeMillis();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataSt orage(id); 407 WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataSt orage(id);
397 recordUpdate(storage, success); 408 recordUpdate(storage, success);
398 } 409 }
399 410
400 private static native void nativeUpdateAsync(String id, String startUrl, Str ing scope, 411 private static native void nativeUpdateAsync(String id, String startUrl, Str ing scope,
401 String name, String shortName, String bestIconUrl, Bitmap bestIcon, String[] iconUrls, 412 String name, String shortName, String bestIconUrl, Bitmap bestIcon, String[] iconUrls,
402 String[] iconHashes, int displayMode, int orientation, long themeCol or, 413 String[] iconHashes, int displayMode, int orientation, long themeCol or,
403 long backgroundColor, String manifestUrl, String webApkPackage, int webApkVersion, 414 long backgroundColor, String manifestUrl, String webApkPackage, int webApkVersion,
404 boolean isManifestStale); 415 boolean isManifestStale);
405 } 416 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698