| 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> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 class BrowserContext; | 28 class BrowserContext; |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace webapk { | 31 namespace webapk { |
| 32 class WebApk; | 32 class WebApk; |
| 33 } | 33 } |
| 34 | 34 |
| 35 enum class WebApkInstallResult; |
| 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 // Called when the creation/updating of a WebAPK is finished or failed. |
| 43 // Parameters: | 44 // Parameters: |
| 44 // - whether the process succeeds. | 45 // - the result of the installation. |
| 45 // - the package name of the WebAPK. | 46 // - the package name of the WebAPK. |
| 46 using FinishCallback = base::Callback<void(bool, const std::string&)>; | 47 using FinishCallback = |
| 48 base::Callback<void(WebApkInstallResult, const std::string&)>; |
| 47 | 49 |
| 48 ~WebApkInstaller() override; | 50 ~WebApkInstaller() override; |
| 49 | 51 |
| 50 // Creates a self-owned WebApkInstaller instance and talks to the Chrome | 52 // Creates a self-owned WebApkInstaller instance and talks to the Chrome |
| 51 // WebAPK server to generate a WebAPK on the server and to Google Play to | 53 // WebAPK server to generate a WebAPK on the server and to Google Play to |
| 52 // install the downloaded WebAPK. Calls |callback| once the install completed | 54 // install the downloaded WebAPK. Calls |callback| once the install completed |
| 53 // or failed. | 55 // or failed. |
| 54 static void InstallAsync(content::BrowserContext* context, | 56 static void InstallAsync(content::BrowserContext* context, |
| 55 const ShortcutInfo& shortcut_info, | 57 const ShortcutInfo& shortcut_info, |
| 56 const SkBitmap& shortcut_icon, | 58 const SkBitmap& shortcut_icon, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 84 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 86 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 85 bool is_manifest_stale, | 87 bool is_manifest_stale, |
| 86 const FinishCallback& callback); | 88 const FinishCallback& callback); |
| 87 | 89 |
| 88 // Sets the timeout for the server requests. | 90 // Sets the timeout for the server requests. |
| 89 void SetTimeoutMs(int timeout_ms); | 91 void SetTimeoutMs(int timeout_ms); |
| 90 | 92 |
| 91 // Called once the installation is complete or failed. | 93 // Called once the installation is complete or failed. |
| 92 void OnInstallFinished(JNIEnv* env, | 94 void OnInstallFinished(JNIEnv* env, |
| 93 const base::android::JavaParamRef<jobject>& obj, | 95 const base::android::JavaParamRef<jobject>& obj, |
| 94 jboolean success); | 96 jint result); |
| 95 | 97 |
| 96 // Creates a WebApk install or update request. | 98 // Creates a WebApk install or update request. |
| 97 // Should be used only for testing. | 99 // Should be used only for testing. |
| 98 void BuildWebApkProtoInBackgroundForTesting( | 100 void BuildWebApkProtoInBackgroundForTesting( |
| 99 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, | 101 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, |
| 100 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 102 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 101 bool is_manifest_stale); | 103 bool is_manifest_stale); |
| 102 | 104 |
| 103 // Registers JNI hooks. | 105 // Registers JNI hooks. |
| 104 static bool Register(JNIEnv* env); | 106 static bool Register(JNIEnv* env); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 130 // WebAPKs using Google Play is enabled. | 132 // WebAPKs using Google Play is enabled. |
| 131 virtual bool CanUseGooglePlayInstallService(); | 133 virtual bool CanUseGooglePlayInstallService(); |
| 132 | 134 |
| 133 // Called when the package name of the WebAPK is available and the install | 135 // Called when the package name of the WebAPK is available and the install |
| 134 // or update request is handled by Google Play. | 136 // or update request is handled by Google Play. |
| 135 virtual void InstallOrUpdateWebApkFromGooglePlay( | 137 virtual void InstallOrUpdateWebApkFromGooglePlay( |
| 136 const std::string& package_name, | 138 const std::string& package_name, |
| 137 int version, | 139 int version, |
| 138 const std::string& token); | 140 const std::string& token); |
| 139 | 141 |
| 140 // Called when the request to install the WebAPK is sent to Google Play. | 142 // Called when the install or update process has completed. |
| 141 void OnSuccess(); | 143 void OnSuccess(); |
| 142 | 144 |
| 143 private: | 145 private: |
| 144 enum TaskType { | 146 enum TaskType { |
| 145 UNDEFINED, | 147 UNDEFINED, |
| 146 INSTALL, | 148 INSTALL, |
| 147 UPDATE, | 149 UPDATE, |
| 148 }; | 150 }; |
| 149 | 151 |
| 150 // Create the Java object. | 152 // Create the Java object. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 // |file_path| is the file path that the WebAPK was downloaded to. | 222 // |file_path| is the file path that the WebAPK was downloaded to. |
| 221 // |change_permission_success| is whether the WebAPK could be made world | 223 // |change_permission_success| is whether the WebAPK could be made world |
| 222 // readable. | 224 // readable. |
| 223 void OnWebApkMadeWorldReadable(const base::FilePath& file_path, | 225 void OnWebApkMadeWorldReadable(const base::FilePath& file_path, |
| 224 bool change_permission_success); | 226 bool change_permission_success); |
| 225 | 227 |
| 226 // Called when the request to the WebAPK server times out or when the WebAPK | 228 // Called when the request to the WebAPK server times out or when the WebAPK |
| 227 // download times out. | 229 // download times out. |
| 228 void OnTimeout(); | 230 void OnTimeout(); |
| 229 | 231 |
| 230 // Called if a WebAPK could not be created. WebApkInstaller only tracks the | 232 // Called if the WebAPK could not be installed or updated. |
| 231 // WebAPK creation and the WebAPK download. It does not track the | |
| 232 // WebAPK installation. OnFailure() is not called if the WebAPK could not be | |
| 233 // installed. | |
| 234 void OnFailure(); | 233 void OnFailure(); |
| 235 | 234 |
| 235 // Called when the install or update process has completed or failed. |
| 236 void OnResult(WebApkInstallResult result); |
| 237 |
| 236 net::URLRequestContextGetter* request_context_getter_; | 238 net::URLRequestContextGetter* request_context_getter_; |
| 237 | 239 |
| 238 // Sends HTTP request to WebAPK server. | 240 // Sends HTTP request to WebAPK server. |
| 239 std::unique_ptr<net::URLFetcher> url_fetcher_; | 241 std::unique_ptr<net::URLFetcher> url_fetcher_; |
| 240 | 242 |
| 241 // Downloads app icon and computes Murmur2 hash. | 243 // Downloads app icon and computes Murmur2 hash. |
| 242 std::unique_ptr<WebApkIconHasher> icon_hasher_; | 244 std::unique_ptr<WebApkIconHasher> icon_hasher_; |
| 243 | 245 |
| 244 // Downloads WebAPK. | 246 // Downloads WebAPK. |
| 245 std::unique_ptr<FileDownloader> downloader_; | 247 std::unique_ptr<FileDownloader> downloader_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // Points to the Java Object. | 281 // Points to the Java Object. |
| 280 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 282 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 281 | 283 |
| 282 // Used to get |weak_ptr_|. | 284 // Used to get |weak_ptr_|. |
| 283 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; | 285 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; |
| 284 | 286 |
| 285 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); | 287 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); |
| 286 }; | 288 }; |
| 287 | 289 |
| 288 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 290 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| OLD | NEW |