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.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 | 10 |
| 11 import org.chromium.base.CommandLine; | 11 import org.chromium.base.CommandLine; |
| 12 import org.chromium.base.ContextUtils; | 12 import org.chromium.base.ContextUtils; |
| 13 import org.chromium.base.Log; | 13 import org.chromium.base.Log; |
| 14 import org.chromium.base.annotations.CalledByNative; | 14 import org.chromium.base.annotations.CalledByNative; |
| 15 import org.chromium.chrome.browser.ChromeSwitches; | 15 import org.chromium.chrome.browser.ChromeSwitches; |
| 16 import org.chromium.chrome.browser.tab.Tab; | 16 import org.chromium.chrome.browser.tab.Tab; |
| 17 import org.chromium.webapk.lib.client.WebApkVersion; | 17 import org.chromium.webapk.lib.client.WebApkVersion; |
| 18 | 18 |
| 19 import java.util.Set; | |
| 19 import java.util.concurrent.TimeUnit; | 20 import java.util.concurrent.TimeUnit; |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * WebApkUpdateManager manages when to check for updates to the WebAPK's Web Man ifest, and sends | 23 * WebApkUpdateManager manages when to check for updates to the WebAPK's Web Man ifest, and sends |
| 23 * an update request to the WebAPK Server when an update is needed. | 24 * an update request to the WebAPK Server when an update is needed. |
| 24 */ | 25 */ |
| 25 public class WebApkUpdateManager implements ManifestUpgradeDetector.Callback { | 26 public class WebApkUpdateManager implements ManifestUpgradeDetector.Callback { |
| 26 private static final String TAG = "WebApkUpdateManager"; | 27 private static final String TAG = "WebApkUpdateManager"; |
| 27 | 28 |
| 28 /** Number of milliseconds between checks for whether the WebAPK's Web Manif est has changed. */ | 29 /** Number of milliseconds between checks for whether the WebAPK's Web Manif est has changed. */ |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 recordUpdate(storage, true); | 119 recordUpdate(storage, true); |
| 119 } | 120 } |
| 120 return; | 121 return; |
| 121 } | 122 } |
| 122 | 123 |
| 123 // Set WebAPK update as having failed in case that Chrome is killed prio r to | 124 // Set WebAPK update as having failed in case that Chrome is killed prio r to |
| 124 // {@link onBuiltWebApk} being called. | 125 // {@link onBuiltWebApk} being called. |
| 125 recordUpdate(storage, false); | 126 recordUpdate(storage, false); |
| 126 | 127 |
| 127 if (data != null) { | 128 if (data != null) { |
| 128 updateAsync(data.startUrl, data.scopeUrl, data.name, data.shortName, data.iconUrl, | 129 updateAsync(data.startUrl, data.scopeUrl, data.name, data.shortName, data.bestIconUrl, |
| 129 data.iconMurmur2Hash, data.icon, data.displayMode, data.orie ntation, | 130 data.bestIconMurmur2Hash, data.bestIcon, data.iconUrls, data .displayMode, |
| 130 data.themeColor, data.backgroundColor); | 131 data.orientation, data.themeColor, data.backgroundColor); |
| 131 return; | 132 return; |
| 132 } | 133 } |
| 133 | 134 |
| 134 updateAsyncUsingAndroidManifestMetaData(); | 135 updateAsyncUsingAndroidManifestMetaData(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 /** | 138 /** |
| 138 * Builds {@link ManifestUpgradeDetector}. In a separate function for the sa ke of tests. | 139 * Builds {@link ManifestUpgradeDetector}. In a separate function for the sa ke of tests. |
| 139 */ | 140 */ |
| 140 protected ManifestUpgradeDetector buildManifestUpgradeDetector( | 141 protected ManifestUpgradeDetector buildManifestUpgradeDetector( |
| 141 Tab tab, WebApkMetaData metaData) { | 142 Tab tab, WebApkMetaData metaData) { |
| 142 return new ManifestUpgradeDetector(tab, metaData, this); | 143 return new ManifestUpgradeDetector(tab, metaData, this); |
| 143 } | 144 } |
| 144 | 145 |
| 145 /** | 146 /** |
| 146 * Sends a request to WebAPK Server to update WebAPK using the meta data fro m the WebAPK's | 147 * Sends a request to WebAPK Server to update WebAPK using the meta data fro m the WebAPK's |
| 147 * Android Manifest. | 148 * Android Manifest. |
| 148 */ | 149 */ |
| 149 private void updateAsyncUsingAndroidManifestMetaData() { | 150 private void updateAsyncUsingAndroidManifestMetaData() { |
|
pkotwicz
2016/11/11 21:04:19
Please add a comment why you are passing in an emp
Xi Han
2016/11/14 19:36:09
Done.
| |
| 150 updateAsync(mMetaData.startUrl, mMetaData.scope, mMetaData.name, mMetaDa ta.shortName, | 151 updateAsync(mMetaData.startUrl, mMetaData.scope, mMetaData.name, mMetaDa ta.shortName, |
| 151 mMetaData.iconUrl, mMetaData.iconMurmur2Hash, mIcon, mMetaData.d isplayMode, | 152 "", "", mIcon, mMetaData.iconURLAndHashMap.keySet(), mMetaData.d isplayMode, |
| 152 mMetaData.orientation, mMetaData.themeColor, mMetaData.backgroun dColor); | 153 mMetaData.orientation, mMetaData.themeColor, mMetaData.backgroun dColor); |
| 153 } | 154 } |
| 154 | 155 |
| 155 /** | 156 /** |
| 156 * Sends request to WebAPK Server to update WebAPK. | 157 * Sends request to WebAPK Server to update WebAPK. |
| 157 */ | 158 */ |
| 158 protected void updateAsync(String startUrl, String scopeUrl, String name, St ring shortName, | 159 protected void updateAsync(String startUrl, String scopeUrl, String name, St ring shortName, |
| 159 String iconUrl, String iconMurmur2Hash, Bitmap icon, int displayMode , int orientation, | 160 String bestIconUrl, String bestIconMurmur2Hash, Bitmap icon, Set<Str ing> iconUrls, |
|
pkotwicz
2016/11/11 21:04:19
Nit: icon -> bestIcon
Xi Han
2016/11/14 19:36:10
Done.
| |
| 160 long themeColor, long backgroundColor) { | 161 int displayMode, int orientation, long themeColor, long backgroundCo lor) { |
| 161 int versionCode = readVersionCodeFromAndroidManifest(mWebApkPackageName) ; | 162 int versionCode = readVersionCodeFromAndroidManifest(mWebApkPackageName) ; |
| 162 nativeUpdateAsync(mId, startUrl, scopeUrl, name, shortName, iconUrl, ico nMurmur2Hash, icon, | 163 nativeUpdateAsync(mId, startUrl, scopeUrl, name, shortName, bestIconUrl, |
| 163 displayMode, orientation, themeColor, backgroundColor, mMetaData .manifestUrl, | 164 bestIconMurmur2Hash, icon, iconUrls.toArray(new String[0]), disp layMode, |
| 164 mWebApkPackageName, versionCode); | 165 orientation, themeColor, backgroundColor, mMetaData.manifestUrl, mWebApkPackageName, |
| 166 versionCode); | |
| 165 } | 167 } |
| 166 | 168 |
| 167 /** | 169 /** |
| 168 * Destroys {@link mUpgradeDetector}. In a separate function for the sake of tests. | 170 * Destroys {@link mUpgradeDetector}. In a separate function for the sake of tests. |
| 169 */ | 171 */ |
| 170 protected void destroyUpgradeDetector() { | 172 protected void destroyUpgradeDetector() { |
| 171 if (mUpgradeDetector == null) return; | 173 if (mUpgradeDetector == null) return; |
| 172 | 174 |
| 173 mUpgradeDetector.destroy(); | 175 mUpgradeDetector.destroy(); |
| 174 mUpgradeDetector = null; | 176 mUpgradeDetector = null; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 * Called after either a request to update the WebAPK has been sent or the u pdate process | 258 * Called after either a request to update the WebAPK has been sent or the u pdate process |
| 257 * fails. | 259 * fails. |
| 258 */ | 260 */ |
| 259 @CalledByNative | 261 @CalledByNative |
| 260 private static void onBuiltWebApk(String id, boolean success) { | 262 private static void onBuiltWebApk(String id, boolean success) { |
| 261 WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataSt orage(id); | 263 WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataSt orage(id); |
| 262 recordUpdate(storage, success); | 264 recordUpdate(storage, success); |
| 263 } | 265 } |
| 264 | 266 |
| 265 private static native void nativeUpdateAsync(String id, String startUrl, Str ing scope, | 267 private static native void nativeUpdateAsync(String id, String startUrl, Str ing scope, |
| 266 String name, String shortName, String iconUrl, String iconMurmur2Has h, Bitmap icon, | 268 String name, String shortName, String bestIconUrl, String bestIconMu rmur2Hash, |
| 267 int displayMode, int orientation, long themeColor, long backgroundCo lor, | 269 Bitmap icon, String[] iconUrls, int displayMode, int orientation, lo ng themeColor, |
|
pkotwicz
2016/11/11 21:04:19
Nit: icon -> bestIcon
Xi Han
2016/11/14 19:36:10
Done.
| |
| 268 String manifestUrl, String webApkPackage, int webApkVersion); | 270 long backgroundColor, String manifestUrl, String webApkPackage, int webApkVersion); |
| 269 } | 271 } |
| OLD | NEW |