| 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 28 matching lines...) Expand all Loading... |
| 39 public: | 39 public: |
| 40 using FinishCallback = WebApkInstallService::FinishCallback; | 40 using FinishCallback = WebApkInstallService::FinishCallback; |
| 41 | 41 |
| 42 ~WebApkInstaller() override; | 42 ~WebApkInstaller() override; |
| 43 | 43 |
| 44 // Creates a self-owned WebApkInstaller instance and talks to the Chrome | 44 // Creates a self-owned WebApkInstaller instance and talks to the Chrome |
| 45 // WebAPK server to generate a WebAPK on the server and locally requests the | 45 // WebAPK server to generate a WebAPK on the server and locally requests the |
| 46 // APK to be installed. Calls |callback| once the install completed or failed. | 46 // APK to be installed. Calls |callback| once the install completed or failed. |
| 47 static void InstallAsync(content::BrowserContext* context, | 47 static void InstallAsync(content::BrowserContext* context, |
| 48 const ShortcutInfo& shortcut_info, | 48 const ShortcutInfo& shortcut_info, |
| 49 const SkBitmap& shortcut_icon, | 49 const SkBitmap& primary_icon, |
| 50 const SkBitmap& badge_icon, |
| 50 const FinishCallback& finish_callback); | 51 const FinishCallback& finish_callback); |
| 51 | 52 |
| 53 // TODO(zpeng): Add badge icon to WebAPK update route. |
| 52 // Creates a self-owned WebApkInstaller instance and talks to the Chrome | 54 // Creates a self-owned WebApkInstaller instance and talks to the Chrome |
| 53 // WebAPK server to update a WebAPK on the server and locally requests the | 55 // WebAPK server to update a WebAPK on the server and locally requests the |
| 54 // APK to be installed. Calls |callback| once the install completed or failed. | 56 // APK to be installed. Calls |callback| once the install completed or failed. |
| 55 static void UpdateAsync( | 57 static void UpdateAsync( |
| 56 content::BrowserContext* context, | 58 content::BrowserContext* context, |
| 57 const ShortcutInfo& shortcut_info, | 59 const ShortcutInfo& shortcut_info, |
| 58 const SkBitmap& shortcut_icon, | 60 const SkBitmap& primary_icon, |
| 59 const std::string& webapk_package, | 61 const std::string& webapk_package, |
| 60 int webapk_version, | 62 int webapk_version, |
| 61 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 63 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 62 bool is_manifest_stale, | 64 bool is_manifest_stale, |
| 63 const FinishCallback& callback); | 65 const FinishCallback& callback); |
| 64 | 66 |
| 65 // Calls the private function |InstallAsync| for testing. | 67 // Calls the private function |InstallAsync| for testing. |
| 66 // Should be used only for testing. | 68 // Should be used only for testing. |
| 67 static void InstallAsyncForTesting(WebApkInstaller* installer, | 69 static void InstallAsyncForTesting(WebApkInstaller* installer, |
| 68 const FinishCallback& finish_callback); | 70 const FinishCallback& finish_callback); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 91 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, | 93 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, |
| 92 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 94 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 93 bool is_manifest_stale); | 95 bool is_manifest_stale); |
| 94 | 96 |
| 95 // Registers JNI hooks. | 97 // Registers JNI hooks. |
| 96 static bool Register(JNIEnv* env); | 98 static bool Register(JNIEnv* env); |
| 97 | 99 |
| 98 protected: | 100 protected: |
| 99 WebApkInstaller(content::BrowserContext* browser_context, | 101 WebApkInstaller(content::BrowserContext* browser_context, |
| 100 const ShortcutInfo& shortcut_info, | 102 const ShortcutInfo& shortcut_info, |
| 101 const SkBitmap& shortcut_icon); | 103 const SkBitmap& primary_icon, |
| 104 const SkBitmap& badge_icon); |
| 102 | 105 |
| 103 // Returns whether the device supports installing WebAPKs. | 106 // Returns whether the device supports installing WebAPKs. |
| 104 virtual bool CanInstallWebApks(); | 107 virtual bool CanInstallWebApks(); |
| 105 | 108 |
| 106 // Called when the package name of the WebAPK is available and the install | 109 // Called when the package name of the WebAPK is available and the install |
| 107 // or update request should be issued. | 110 // or update request should be issued. |
| 108 virtual void InstallOrUpdateWebApk(const std::string& package_name, | 111 virtual void InstallOrUpdateWebApk(const std::string& package_name, |
| 109 int version, | 112 int version, |
| 110 const std::string& token); | 113 const std::string& token); |
| 111 | 114 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 133 void UpdateAsync( | 136 void UpdateAsync( |
| 134 const std::string& webapk_package, | 137 const std::string& webapk_package, |
| 135 int webapk_version, | 138 int webapk_version, |
| 136 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 139 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 137 bool is_manifest_stale, | 140 bool is_manifest_stale, |
| 138 const FinishCallback& callback); | 141 const FinishCallback& callback); |
| 139 | 142 |
| 140 // net::URLFetcherDelegate: | 143 // net::URLFetcherDelegate: |
| 141 void OnURLFetchComplete(const net::URLFetcher* source) override; | 144 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 142 | 145 |
| 143 // Called with the computed Murmur2 hash for the app icon. | 146 // Called with the computed Murmur2 hash for the primary icon. |
| 144 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash); | 147 void OnGotPrimaryIconMurmur2Hash(const std::string& primary_icon_hash); |
| 148 |
| 149 // Called with the computed Murmur2 hash for the badge icon, and |
| 150 // |did_fetch_badge_icon| to indicate whether there was an attempt to fetch |
| 151 // badge icon. |
| 152 void OnGotBadgeIconMurmur2Hash(bool did_fetch_badge_icon, |
| 153 const std::string& primary_icon_hash, |
| 154 const std::string& badge_icon_hash); |
| 145 | 155 |
| 146 // Sends request to WebAPK server to create WebAPK. During a successful | 156 // Sends request to WebAPK server to create WebAPK. During a successful |
| 147 // request the WebAPK server responds with the URL of the generated WebAPK. | 157 // request the WebAPK server responds with the URL of the generated WebAPK. |
| 148 // |webapk| is the proto to send to the WebAPK server. | 158 // |webapk| is the proto to send to the WebAPK server. |
| 149 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); | 159 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); |
| 150 | 160 |
| 151 // Sends request to WebAPK server to update a WebAPK. During a successful | 161 // Sends request to WebAPK server to update a WebAPK. During a successful |
| 152 // request the WebAPK server responds with the URL of the generated WebAPK. | 162 // request the WebAPK server responds with the URL of the generated WebAPK. |
| 153 // |webapk| is the proto to send to the WebAPK server. | 163 // |webapk| is the proto to send to the WebAPK server. |
| 154 void SendUpdateWebApkRequest(int webapk_version, | 164 void SendUpdateWebApkRequest(int webapk_version, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 171 | 181 |
| 172 // Tracks how long it takes to install a WebAPK. | 182 // Tracks how long it takes to install a WebAPK. |
| 173 std::unique_ptr<base::ElapsedTimer> install_duration_timer_; | 183 std::unique_ptr<base::ElapsedTimer> install_duration_timer_; |
| 174 | 184 |
| 175 // Callback to call once WebApkInstaller succeeds or fails. | 185 // Callback to call once WebApkInstaller succeeds or fails. |
| 176 FinishCallback finish_callback_; | 186 FinishCallback finish_callback_; |
| 177 | 187 |
| 178 // Web Manifest info. | 188 // Web Manifest info. |
| 179 const ShortcutInfo shortcut_info_; | 189 const ShortcutInfo shortcut_info_; |
| 180 | 190 |
| 181 // WebAPK app icon. | 191 // WebAPK primary icon. |
| 182 const SkBitmap shortcut_icon_; | 192 const SkBitmap primary_icon_; |
| 193 |
| 194 // WebAPK badge icon. |
| 195 const SkBitmap badge_icon_; |
| 183 | 196 |
| 184 // WebAPK server URL. | 197 // WebAPK server URL. |
| 185 GURL server_url_; | 198 GURL server_url_; |
| 186 | 199 |
| 187 // The number of milliseconds to wait for the WebAPK server to respond. | 200 // The number of milliseconds to wait for the WebAPK server to respond. |
| 188 int webapk_server_timeout_ms_; | 201 int webapk_server_timeout_ms_; |
| 189 | 202 |
| 190 // WebAPK package name. | 203 // WebAPK package name. |
| 191 std::string webapk_package_; | 204 std::string webapk_package_; |
| 192 | 205 |
| 193 // Whether the server wants the WebAPK to request updates less frequently. | 206 // Whether the server wants the WebAPK to request updates less frequently. |
| 194 bool relax_updates_; | 207 bool relax_updates_; |
| 195 | 208 |
| 196 | 209 |
| 197 // Indicates whether the installer is for installing or updating a WebAPK. | 210 // Indicates whether the installer is for installing or updating a WebAPK. |
| 198 TaskType task_type_; | 211 TaskType task_type_; |
| 199 | 212 |
| 200 // Points to the Java Object. | 213 // Points to the Java Object. |
| 201 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 214 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 202 | 215 |
| 203 // Used to get |weak_ptr_|. | 216 // Used to get |weak_ptr_|. |
| 204 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; | 217 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; |
| 205 | 218 |
| 206 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); | 219 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); |
| 207 }; | 220 }; |
| 208 | 221 |
| 209 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 222 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
| OLD | NEW |