| 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 <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 17 #include "chrome/browser/android/shortcut_info.h" | 17 #include "chrome/browser/android/shortcut_info.h" |
| 18 #include "chrome/browser/android/webapk/webapk_install_service.h" |
| 18 #include "chrome/browser/net/file_downloader.h" | 19 #include "chrome/browser/net/file_downloader.h" |
| 19 #include "net/url_request/url_fetcher.h" | 20 #include "net/url_request/url_fetcher.h" |
| 20 #include "net/url_request/url_fetcher_delegate.h" | 21 #include "net/url_request/url_fetcher_delegate.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 | 23 |
| 23 namespace base { | 24 namespace base { |
| 24 class FilePath; | 25 class FilePath; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace content { | 28 namespace content { |
| 28 class BrowserContext; | 29 class BrowserContext; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace webapk { | 32 namespace webapk { |
| 32 class WebApk; | 33 class WebApk; |
| 33 } | 34 } |
| 34 | 35 |
| 35 class WebApkIconHasher; | 36 class WebApkIconHasher; |
| 36 | 37 |
| 37 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the | 38 // Talks to Chrome WebAPK server and Google Play to generate a WebAPK on the |
| 38 // server, download it, and install it. The native WebApkInstaller owns the | 39 // server, download it, and install it. The native WebApkInstaller owns the |
| 39 // Java WebApkInstaller counterpart. | 40 // Java WebApkInstaller counterpart. |
| 40 class WebApkInstaller : public net::URLFetcherDelegate { | 41 class WebApkInstaller : public net::URLFetcherDelegate { |
| 41 public: | 42 public: |
| 42 // Called when the creation/updating of a WebAPK is finished or failed. | 43 using FinishCallback = WebApkInstallService::FinishCallback; |
| 43 // Parameters: | |
| 44 // - whether the process succeeds. | |
| 45 // - the package name of the WebAPK. | |
| 46 // - true if Chrome received a "request updates less frequently" directive | |
| 47 // from the WebAPK server. | |
| 48 using FinishCallback = base::Callback<void(bool, bool, const std::string&)>; | |
| 49 | 44 |
| 50 ~WebApkInstaller() override; | 45 ~WebApkInstaller() override; |
| 51 | 46 |
| 52 // Creates a self-owned WebApkInstaller instance and talks to the Chrome | 47 // Creates a self-owned WebApkInstaller instance and talks to the Chrome |
| 53 // WebAPK server to generate a WebAPK on the server and to Google Play to | 48 // WebAPK server to generate a WebAPK on the server and to Google Play to |
| 54 // install the downloaded WebAPK. Calls |callback| once the install completed | 49 // install the downloaded WebAPK. Calls |callback| once the install completed |
| 55 // or failed. | 50 // or failed. |
| 56 static void InstallAsync(content::BrowserContext* context, | 51 static void InstallAsync(content::BrowserContext* context, |
| 57 const ShortcutInfo& shortcut_info, | 52 const ShortcutInfo& shortcut_info, |
| 58 const SkBitmap& shortcut_icon, | 53 const SkBitmap& shortcut_icon, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 86 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 81 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 87 bool is_manifest_stale, | 82 bool is_manifest_stale, |
| 88 const FinishCallback& callback); | 83 const FinishCallback& callback); |
| 89 | 84 |
| 90 // Sets the timeout for the server requests. | 85 // Sets the timeout for the server requests. |
| 91 void SetTimeoutMs(int timeout_ms); | 86 void SetTimeoutMs(int timeout_ms); |
| 92 | 87 |
| 93 // Called once the installation is complete or failed. | 88 // Called once the installation is complete or failed. |
| 94 void OnInstallFinished(JNIEnv* env, | 89 void OnInstallFinished(JNIEnv* env, |
| 95 const base::android::JavaParamRef<jobject>& obj, | 90 const base::android::JavaParamRef<jobject>& obj, |
| 96 jboolean success); | 91 jint webApkInstallResult); |
| 97 | 92 |
| 98 // Creates a WebApk install or update request. | 93 // Creates a WebApk install or update request. |
| 99 // Should be used only for testing. | 94 // Should be used only for testing. |
| 100 void BuildWebApkProtoInBackgroundForTesting( | 95 void BuildWebApkProtoInBackgroundForTesting( |
| 101 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, | 96 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, |
| 102 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 97 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 103 bool is_manifest_stale); | 98 bool is_manifest_stale); |
| 104 | 99 |
| 105 // Registers JNI hooks. | 100 // Registers JNI hooks. |
| 106 static bool Register(JNIEnv* env); | 101 static bool Register(JNIEnv* env); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 121 // Returns whether Google Play supports installing WebAPKs. | 116 // Returns whether Google Play supports installing WebAPKs. |
| 122 virtual bool CanUseGooglePlayInstallService(); | 117 virtual bool CanUseGooglePlayInstallService(); |
| 123 | 118 |
| 124 // Called when the package name of the WebAPK is available and the install | 119 // Called when the package name of the WebAPK is available and the install |
| 125 // or update request is handled by Google Play. | 120 // or update request is handled by Google Play. |
| 126 virtual void InstallOrUpdateWebApkFromGooglePlay( | 121 virtual void InstallOrUpdateWebApkFromGooglePlay( |
| 127 const std::string& package_name, | 122 const std::string& package_name, |
| 128 int version, | 123 int version, |
| 129 const std::string& token); | 124 const std::string& token); |
| 130 | 125 |
| 131 // Called when the request to install the WebAPK is sent to Google Play. | 126 // Called when the install or update process has completed or failed. |
| 132 void OnSuccess(); | 127 void OnResult(WebApkInstallResult result); |
| 133 | 128 |
| 134 private: | 129 private: |
| 135 enum TaskType { | 130 enum TaskType { |
| 136 UNDEFINED, | 131 UNDEFINED, |
| 137 INSTALL, | 132 INSTALL, |
| 138 UPDATE, | 133 UPDATE, |
| 139 }; | 134 }; |
| 140 | 135 |
| 141 // Create the Java object. | 136 // Create the Java object. |
| 142 void CreateJavaRef(); | 137 void CreateJavaRef(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 FileDownloader::Result result); | 202 FileDownloader::Result result); |
| 208 | 203 |
| 209 // Called once the downloaded WebAPK has been made world readable. Installs | 204 // Called once the downloaded WebAPK has been made world readable. Installs |
| 210 // the WebAPK. | 205 // the WebAPK. |
| 211 // |file_path| is the file path that the WebAPK was downloaded to. | 206 // |file_path| is the file path that the WebAPK was downloaded to. |
| 212 // |change_permission_success| is whether the WebAPK could be made world | 207 // |change_permission_success| is whether the WebAPK could be made world |
| 213 // readable. | 208 // readable. |
| 214 void OnWebApkMadeWorldReadable(const base::FilePath& file_path, | 209 void OnWebApkMadeWorldReadable(const base::FilePath& file_path, |
| 215 bool change_permission_success); | 210 bool change_permission_success); |
| 216 | 211 |
| 217 // Called when the request to the WebAPK server times out or when the WebAPK | |
| 218 // download times out. | |
| 219 void OnTimeout(); | |
| 220 | |
| 221 // Called if a WebAPK could not be created. WebApkInstaller only tracks the | |
| 222 // WebAPK creation and the WebAPK download. It does not track the | |
| 223 // WebAPK installation. OnFailure() is not called if the WebAPK could not be | |
| 224 // installed. | |
| 225 void OnFailure(); | |
| 226 | |
| 227 net::URLRequestContextGetter* request_context_getter_; | 212 net::URLRequestContextGetter* request_context_getter_; |
| 228 | 213 |
| 229 // Sends HTTP request to WebAPK server. | 214 // Sends HTTP request to WebAPK server. |
| 230 std::unique_ptr<net::URLFetcher> url_fetcher_; | 215 std::unique_ptr<net::URLFetcher> url_fetcher_; |
| 231 | 216 |
| 232 // Downloads app icon and computes Murmur2 hash. | 217 // Downloads app icon and computes Murmur2 hash. |
| 233 std::unique_ptr<WebApkIconHasher> icon_hasher_; | 218 std::unique_ptr<WebApkIconHasher> icon_hasher_; |
| 234 | 219 |
| 235 // Downloads WebAPK. | 220 // Downloads WebAPK. |
| 236 std::unique_ptr<FileDownloader> downloader_; | 221 std::unique_ptr<FileDownloader> downloader_; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 // Points to the Java Object. | 258 // Points to the Java Object. |
| 274 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 259 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 275 | 260 |
| 276 // Used to get |weak_ptr_|. | 261 // Used to get |weak_ptr_|. |
| 277 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; | 262 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; |
| 278 | 263 |
| 279 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); | 264 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); |
| 280 }; | 265 }; |
| 281 | 266 |
| 282 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 267 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| OLD | NEW |