| 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 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <map> |
| 9 #include <memory> | 10 #include <memory> |
| 10 | 11 |
| 11 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 16 #include "chrome/browser/android/shortcut_info.h" | 17 #include "chrome/browser/android/shortcut_info.h" |
| 17 #include "chrome/browser/net/file_downloader.h" | 18 #include "chrome/browser/net/file_downloader.h" |
| 18 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 const FinishCallback& finish_callback); | 57 const FinishCallback& finish_callback); |
| 57 | 58 |
| 58 // Same as InstallAsync() but uses the passed in |request_context_getter|. | 59 // Same as InstallAsync() but uses the passed in |request_context_getter|. |
| 59 void InstallAsyncWithURLRequestContextGetter( | 60 void InstallAsyncWithURLRequestContextGetter( |
| 60 net::URLRequestContextGetter* request_context_getter, | 61 net::URLRequestContextGetter* request_context_getter, |
| 61 const FinishCallback& finish_callback); | 62 const FinishCallback& finish_callback); |
| 62 | 63 |
| 63 // Talks to the Chrome WebAPK server to update a WebAPK on the server and to | 64 // Talks to the Chrome WebAPK server to update a WebAPK on the server and to |
| 64 // the Google Play server to install the downloaded WebAPK. Calls |callback| | 65 // the Google Play server to install the downloaded WebAPK. Calls |callback| |
| 65 // after the request to install the WebAPK is sent to the Google Play server. | 66 // after the request to install the WebAPK is sent to the Google Play server. |
| 66 void UpdateAsync(content::BrowserContext* browser_context, | 67 void UpdateAsync( |
| 67 const FinishCallback& callback, | 68 content::BrowserContext* browser_context, |
| 68 const std::string& icon_murmur2_hash, | 69 const FinishCallback& callback, |
| 69 const std::string& webapk_package, | 70 const std::string& webapk_package, |
| 70 int webapk_version); | 71 int webapk_version, |
| 72 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 73 bool is_manifest_stale); |
| 71 | 74 |
| 72 // Same as UpdateAsync() but uses the passed in |request_context_getter|. | 75 // Same as UpdateAsync() but uses the passed in |request_context_getter|. |
| 73 void UpdateAsyncWithURLRequestContextGetter( | 76 void UpdateAsyncWithURLRequestContextGetter( |
| 74 net::URLRequestContextGetter* request_context_getter, | 77 net::URLRequestContextGetter* request_context_getter, |
| 75 const FinishCallback& callback, | 78 const FinishCallback& callback, |
| 76 const std::string& icon_murmur2_hash, | |
| 77 const std::string& webapk_package, | 79 const std::string& webapk_package, |
| 78 int webapk_version); | 80 int webapk_version, |
| 81 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 82 bool is_manifest_stale); |
| 79 | 83 |
| 80 // Sets the timeout for the server requests. | 84 // Sets the timeout for the server requests. |
| 81 void SetTimeoutMs(int timeout_ms); | 85 void SetTimeoutMs(int timeout_ms); |
| 82 | 86 |
| 83 // Called once the installation is complete or failed. | 87 // Called once the installation is complete or failed. |
| 84 void OnInstallFinished(JNIEnv* env, | 88 void OnInstallFinished(JNIEnv* env, |
| 85 const base::android::JavaParamRef<jobject>& obj, | 89 const base::android::JavaParamRef<jobject>& obj, |
| 86 jboolean success); | 90 jboolean success); |
| 87 | 91 |
| 92 // Creates a WebApk install or update request. |
| 93 // Should be used only for testing. |
| 94 void BuildWebApkProtoInBackgroundForTesting( |
| 95 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, |
| 96 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 97 bool is_manifest_stale); |
| 98 |
| 88 // Registers JNI hooks. | 99 // Registers JNI hooks. |
| 89 static bool Register(JNIEnv* env); | 100 static bool Register(JNIEnv* env); |
| 90 | 101 |
| 91 protected: | 102 protected: |
| 92 // Starts installation of the downloaded WebAPK. Returns whether the install | 103 // Starts installation of the downloaded WebAPK. Returns whether the install |
| 93 // could be started. The installation may still fail if true is returned. | 104 // could be started. The installation may still fail if true is returned. |
| 94 // |file_path| is the file path that the WebAPK was downloaded to. | 105 // |file_path| is the file path that the WebAPK was downloaded to. |
| 95 // |package_name| is the package name that the WebAPK should be installed at. | 106 // |package_name| is the package name that the WebAPK should be installed at. |
| 96 virtual bool StartInstallingDownloadedWebApk( | 107 virtual bool StartInstallingDownloadedWebApk( |
| 97 JNIEnv* env, | 108 JNIEnv* env, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 226 |
| 216 // Callback to call once WebApkInstaller succeeds or fails. | 227 // Callback to call once WebApkInstaller succeeds or fails. |
| 217 FinishCallback finish_callback_; | 228 FinishCallback finish_callback_; |
| 218 | 229 |
| 219 // Web Manifest info. | 230 // Web Manifest info. |
| 220 const ShortcutInfo shortcut_info_; | 231 const ShortcutInfo shortcut_info_; |
| 221 | 232 |
| 222 // WebAPK app icon. | 233 // WebAPK app icon. |
| 223 const SkBitmap shortcut_icon_; | 234 const SkBitmap shortcut_icon_; |
| 224 | 235 |
| 225 // Murmur2 hash of the bitmap at the app icon URL prior to any transformations | |
| 226 // being applied to the bitmap (such as encoding/decoding the icon bitmap). | |
| 227 std::string shortcut_icon_murmur2_hash_; | |
| 228 | |
| 229 // WebAPK server URL. | 236 // WebAPK server URL. |
| 230 GURL server_url_; | 237 GURL server_url_; |
| 231 | 238 |
| 232 // The number of milliseconds to wait for the WebAPK download URL from the | 239 // The number of milliseconds to wait for the WebAPK download URL from the |
| 233 // WebAPK server. | 240 // WebAPK server. |
| 234 int webapk_download_url_timeout_ms_; | 241 int webapk_download_url_timeout_ms_; |
| 235 | 242 |
| 236 // The number of milliseconds to wait for the WebAPK download to complete. | 243 // The number of milliseconds to wait for the WebAPK download to complete. |
| 237 int download_timeout_ms_; | 244 int download_timeout_ms_; |
| 238 | 245 |
| 239 // WebAPK package name. | 246 // WebAPK package name. |
| 240 std::string webapk_package_; | 247 std::string webapk_package_; |
| 241 | 248 |
| 242 // WebAPK version code. | 249 // WebAPK version code. |
| 243 int webapk_version_; | 250 int webapk_version_; |
| 244 | 251 |
| 245 // Indicates whether the installer is for installing or updating a WebAPK. | 252 // Indicates whether the installer is for installing or updating a WebAPK. |
| 246 TaskType task_type_; | 253 TaskType task_type_; |
| 247 | 254 |
| 248 // Points to the Java Object. | 255 // Points to the Java Object. |
| 249 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 256 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 250 | 257 |
| 251 // Used to get |weak_ptr_|. | 258 // Used to get |weak_ptr_|. |
| 252 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; | 259 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; |
| 253 | 260 |
| 254 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); | 261 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); |
| 255 }; | 262 }; |
| 256 | 263 |
| 257 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 264 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| OLD | NEW |