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 #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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 using FinishCallback = base::Callback<void(bool, const std::string&)>; | 46 using FinishCallback = base::Callback<void(bool, const std::string&)>; |
| 47 | 47 |
| 48 ~WebApkInstaller() override; | 48 ~WebApkInstaller() override; |
| 49 | 49 |
| 50 // Creates a self-owned WebApkInstaller instance and talks to the Chrome | 50 // 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 | 51 // 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 | 52 // install the downloaded WebAPK. Calls |callback| once the install completed |
| 53 // or failed. | 53 // or failed. |
| 54 static void InstallAsync(content::BrowserContext* context, | 54 static void InstallAsync(content::BrowserContext* context, |
| 55 const ShortcutInfo& shortcut_info, | 55 const ShortcutInfo& shortcut_info, |
| 56 const SkBitmap& shortcut_icon, | 56 const SkBitmap& primary_icon, |
| 57 const SkBitmap& badge_icon, | |
| 57 const FinishCallback& finish_callback); | 58 const FinishCallback& finish_callback); |
| 58 | 59 |
| 59 // Creates a self-owned WebApkInstaller instance and talks to the Chrome | 60 // Creates a self-owned WebApkInstaller instance and talks to the Chrome |
| 60 // WebAPK server to update a WebAPK on the server and to the Google Play | 61 // WebAPK server to update a WebAPK on the server and to the Google Play |
| 61 // server to install the downloaded WebAPK. Calls |callback| after the request | 62 // server to install the downloaded WebAPK. Calls |callback| after the request |
| 62 // to install the WebAPK is sent to the Google Play server. | 63 // to install the WebAPK is sent to the Google Play server. |
| 63 static void UpdateAsync( | 64 static void UpdateAsync( |
| 64 content::BrowserContext* context, | 65 content::BrowserContext* context, |
| 65 const ShortcutInfo& shortcut_info, | 66 const ShortcutInfo& shortcut_info, |
| 66 const SkBitmap& shortcut_icon, | 67 const SkBitmap& primary_icon, |
| 67 const std::string& webapk_package, | 68 const std::string& webapk_package, |
| 68 int webapk_version, | 69 int webapk_version, |
| 69 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 70 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 70 bool is_manifest_stale, | 71 bool is_manifest_stale, |
| 71 const FinishCallback& callback); | 72 const FinishCallback& callback); |
| 72 | 73 |
| 73 // Calls the private function |InstallAsync| for testing. | 74 // Calls the private function |InstallAsync| for testing. |
| 74 // Should be used only for testing. | 75 // Should be used only for testing. |
| 75 static void InstallAsyncForTesting(WebApkInstaller* installer, | 76 static void InstallAsyncForTesting(WebApkInstaller* installer, |
| 76 const FinishCallback& finish_callback); | 77 const FinishCallback& finish_callback); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 88 // Sets the timeout for the server requests. | 89 // Sets the timeout for the server requests. |
| 89 void SetTimeoutMs(int timeout_ms); | 90 void SetTimeoutMs(int timeout_ms); |
| 90 | 91 |
| 91 // Called once the installation is complete or failed. | 92 // Called once the installation is complete or failed. |
| 92 void OnInstallFinished(JNIEnv* env, | 93 void OnInstallFinished(JNIEnv* env, |
| 93 const base::android::JavaParamRef<jobject>& obj, | 94 const base::android::JavaParamRef<jobject>& obj, |
| 94 jboolean success); | 95 jboolean success); |
| 95 | 96 |
| 96 // Creates a WebApk install or update request. | 97 // Creates a WebApk install or update request. |
| 97 // Should be used only for testing. | 98 // Should be used only for testing. |
| 99 // TODO | |
|
dominickn
2017/02/23 02:08:52
TODO what?
F
2017/03/30 18:20:12
Oops.
| |
| 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); |
| 105 | 107 |
| 106 protected: | 108 protected: |
| 107 WebApkInstaller(content::BrowserContext* browser_context, | 109 WebApkInstaller(content::BrowserContext* browser_context, |
| 108 const ShortcutInfo& shortcut_info, | 110 const ShortcutInfo& shortcut_info, |
| 109 const SkBitmap& shortcut_icon); | 111 const SkBitmap& primary_icon, |
| 112 const SkBitmap& badge_icon); | |
| 110 | 113 |
| 111 // Starts installation of the downloaded WebAPK. Returns whether the install | 114 // Starts installation of the downloaded WebAPK. Returns whether the install |
| 112 // could be started. The installation may still fail if true is returned. | 115 // could be started. The installation may still fail if true is returned. |
| 113 // |file_path| is the file path that the WebAPK was downloaded to. | 116 // |file_path| is the file path that the WebAPK was downloaded to. |
| 114 // |package_name| is the package name that the WebAPK should be installed at. | 117 // |package_name| is the package name that the WebAPK should be installed at. |
| 115 virtual bool StartInstallingDownloadedWebApk( | 118 virtual bool StartInstallingDownloadedWebApk( |
| 116 JNIEnv* env, | 119 JNIEnv* env, |
| 117 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, | 120 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, |
| 118 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); | 121 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); |
| 119 | 122 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 void UpdateAsync( | 164 void UpdateAsync( |
| 162 const std::string& webapk_package, | 165 const std::string& webapk_package, |
| 163 int webapk_version, | 166 int webapk_version, |
| 164 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 167 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 165 bool is_manifest_stale, | 168 bool is_manifest_stale, |
| 166 const FinishCallback& callback); | 169 const FinishCallback& callback); |
| 167 | 170 |
| 168 // net::URLFetcherDelegate: | 171 // net::URLFetcherDelegate: |
| 169 void OnURLFetchComplete(const net::URLFetcher* source) override; | 172 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 170 | 173 |
| 171 // Downloads app icon in order to compute Murmur2 hash. | 174 // Downloads primary icon and computes its Murmur2 hash. |
| 172 void DownloadAppIconAndComputeMurmur2Hash(); | 175 void DownloadPrimaryIconAndComputeMurmur2Hash(); |
| 173 | 176 |
| 174 // Called with the computed Murmur2 hash for the app icon. | 177 // Called with the computed Murmur2 hash for the primary icon. |
| 175 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash); | 178 void OnGotPrimaryIconMurmur2Hash(const std::string& primary_icon_hash); |
| 179 | |
| 180 // Downloads badge icon and computes its Murmur2 hash. | |
| 181 void DownloadBadgeIconAndComputeMurmur2Hash(); | |
| 182 | |
| 183 // Called with the computed Murmur2 hash for the badge icon. | |
| 184 void OnGotBadgeIconMurmur2Hash(const std::string& badge_icon_hash); | |
| 185 | |
| 186 // Maps icon URLs to Murmur2 hashes. | |
| 187 void MapIconUrlToMurmur2Hash(); | |
| 176 | 188 |
| 177 // Sends request to WebAPK server to create WebAPK. During a successful | 189 // Sends request to WebAPK server to create WebAPK. During a successful |
| 178 // request the WebAPK server responds with the URL of the generated WebAPK. | 190 // request the WebAPK server responds with the URL of the generated WebAPK. |
| 179 // |webapk| is the proto to send to the WebAPK server. | 191 // |webapk| is the proto to send to the WebAPK server. |
| 180 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); | 192 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); |
| 181 | 193 |
| 182 // Sends request to WebAPK server to update a WebAPK. During a successful | 194 // Sends request to WebAPK server to update a WebAPK. During a successful |
| 183 // request the WebAPK server responds with the URL of the generated WebAPK. | 195 // request the WebAPK server responds with the URL of the generated WebAPK. |
| 184 // |webapk| is the proto to send to the WebAPK server. | 196 // |webapk| is the proto to send to the WebAPK server. |
| 185 void SendUpdateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); | 197 void SendUpdateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 // Fails WebApkInstaller if WebAPK server takes too long to respond or if the | 259 // Fails WebApkInstaller if WebAPK server takes too long to respond or if the |
| 248 // download takes too long. | 260 // download takes too long. |
| 249 base::OneShotTimer timer_; | 261 base::OneShotTimer timer_; |
| 250 | 262 |
| 251 // Callback to call once WebApkInstaller succeeds or fails. | 263 // Callback to call once WebApkInstaller succeeds or fails. |
| 252 FinishCallback finish_callback_; | 264 FinishCallback finish_callback_; |
| 253 | 265 |
| 254 // Web Manifest info. | 266 // Web Manifest info. |
| 255 const ShortcutInfo shortcut_info_; | 267 const ShortcutInfo shortcut_info_; |
| 256 | 268 |
| 257 // WebAPK app icon. | 269 // WebAPK primary icon & its Murmur2 hash. |
| 258 const SkBitmap shortcut_icon_; | 270 const SkBitmap primary_icon_; |
| 271 std::string primary_icon_hash_; | |
| 272 | |
| 273 // WebAPK badge icon & its Murmur2 hash. | |
| 274 const SkBitmap badge_icon_; | |
| 275 std::string badge_icon_hash_; | |
| 259 | 276 |
| 260 // WebAPK server URL. | 277 // WebAPK server URL. |
| 261 GURL server_url_; | 278 GURL server_url_; |
| 262 | 279 |
| 263 // The number of milliseconds to wait for the WebAPK download URL from the | 280 // The number of milliseconds to wait for the WebAPK download URL from the |
| 264 // WebAPK server. | 281 // WebAPK server. |
| 265 int webapk_download_url_timeout_ms_; | 282 int webapk_download_url_timeout_ms_; |
| 266 | 283 |
| 267 // The number of milliseconds to wait for the WebAPK download to complete. | 284 // The number of milliseconds to wait for the WebAPK download to complete. |
| 268 int download_timeout_ms_; | 285 int download_timeout_ms_; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 279 // Points to the Java Object. | 296 // Points to the Java Object. |
| 280 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 297 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 281 | 298 |
| 282 // Used to get |weak_ptr_|. | 299 // Used to get |weak_ptr_|. |
| 283 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; | 300 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; |
| 284 | 301 |
| 285 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); | 302 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); |
| 286 }; | 303 }; |
| 287 | 304 |
| 288 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 305 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| OLD | NEW |