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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 using FinishCallback = WebApkInstallService::FinishCallback; | 42 using FinishCallback = WebApkInstallService::FinishCallback; |
43 | 43 |
44 ~WebApkInstaller() override; | 44 ~WebApkInstaller() override; |
45 | 45 |
46 // Creates a self-owned WebApkInstaller instance and talks to the Chrome | 46 // Creates a self-owned WebApkInstaller instance and talks to the Chrome |
47 // WebAPK server to generate a WebAPK on the server and to Google Play to | 47 // WebAPK server to generate a WebAPK on the server and to Google Play to |
48 // install the downloaded WebAPK. Calls |callback| once the install completed | 48 // install the downloaded WebAPK. Calls |callback| once the install completed |
49 // or failed. | 49 // or failed. |
50 static void InstallAsync(content::BrowserContext* context, | 50 static void InstallAsync(content::BrowserContext* context, |
51 const ShortcutInfo& shortcut_info, | 51 const ShortcutInfo& shortcut_info, |
52 const SkBitmap& shortcut_icon, | 52 const SkBitmap& primary_icon, |
| 53 const SkBitmap& badge_icon, |
53 const FinishCallback& finish_callback); | 54 const FinishCallback& finish_callback); |
54 | 55 |
| 56 // TODO(zpeng): Add badge icon to WebAPK update route. |
55 // Creates a self-owned WebApkInstaller instance and talks to the Chrome | 57 // Creates a self-owned WebApkInstaller instance and talks to the Chrome |
56 // WebAPK server to update a WebAPK on the server and to the Google Play | 58 // WebAPK server to update a WebAPK on the server and to the Google Play |
57 // server to install the downloaded WebAPK. Calls |callback| after the request | 59 // server to install the downloaded WebAPK. Calls |callback| after the request |
58 // to install the WebAPK is sent to the Google Play server. | 60 // to install the WebAPK is sent to the Google Play server. |
59 static void UpdateAsync( | 61 static void UpdateAsync( |
60 content::BrowserContext* context, | 62 content::BrowserContext* context, |
61 const ShortcutInfo& shortcut_info, | 63 const ShortcutInfo& shortcut_info, |
62 const SkBitmap& shortcut_icon, | 64 const SkBitmap& primary_icon, |
63 const std::string& webapk_package, | 65 const std::string& webapk_package, |
64 int webapk_version, | 66 int webapk_version, |
65 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 67 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
66 bool is_manifest_stale, | 68 bool is_manifest_stale, |
67 const FinishCallback& callback); | 69 const FinishCallback& callback); |
68 | 70 |
69 // Calls the private function |InstallAsync| for testing. | 71 // Calls the private function |InstallAsync| for testing. |
70 // Should be used only for testing. | 72 // Should be used only for testing. |
71 static void InstallAsyncForTesting(WebApkInstaller* installer, | 73 static void InstallAsyncForTesting(WebApkInstaller* installer, |
72 const FinishCallback& finish_callback); | 74 const FinishCallback& finish_callback); |
(...skipping 22 matching lines...) Expand all Loading... |
95 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, | 97 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, |
96 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 98 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
97 bool is_manifest_stale); | 99 bool is_manifest_stale); |
98 | 100 |
99 // Registers JNI hooks. | 101 // Registers JNI hooks. |
100 static bool Register(JNIEnv* env); | 102 static bool Register(JNIEnv* env); |
101 | 103 |
102 protected: | 104 protected: |
103 WebApkInstaller(content::BrowserContext* browser_context, | 105 WebApkInstaller(content::BrowserContext* browser_context, |
104 const ShortcutInfo& shortcut_info, | 106 const ShortcutInfo& shortcut_info, |
105 const SkBitmap& shortcut_icon); | 107 const SkBitmap& primary_icon, |
| 108 const SkBitmap& badge_icon); |
106 | 109 |
107 // Starts installion of the downloaded WebAPK. | 110 // Starts installion of the downloaded WebAPK. |
108 // |file_path| is the file path that the WebAPK was downloaded to. | 111 // |file_path| is the file path that the WebAPK was downloaded to. |
109 // |package_name| is the package name of the WebAPK. | 112 // |package_name| is the package name of the WebAPK. |
110 virtual void InstallDownloadedWebApk( | 113 virtual void InstallDownloadedWebApk( |
111 JNIEnv* env, | 114 JNIEnv* env, |
112 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, | 115 const base::android::ScopedJavaLocalRef<jstring>& java_file_path, |
113 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); | 116 const base::android::ScopedJavaLocalRef<jstring>& java_package_name); |
114 | 117 |
115 // Starts update using the downloaded WebAPK. | 118 // Starts update using the downloaded WebAPK. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 void UpdateAsync( | 155 void UpdateAsync( |
153 const std::string& webapk_package, | 156 const std::string& webapk_package, |
154 int webapk_version, | 157 int webapk_version, |
155 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 158 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
156 bool is_manifest_stale, | 159 bool is_manifest_stale, |
157 const FinishCallback& callback); | 160 const FinishCallback& callback); |
158 | 161 |
159 // net::URLFetcherDelegate: | 162 // net::URLFetcherDelegate: |
160 void OnURLFetchComplete(const net::URLFetcher* source) override; | 163 void OnURLFetchComplete(const net::URLFetcher* source) override; |
161 | 164 |
162 // Called with the computed Murmur2 hash for the app icon. | 165 // Called with the computed Murmur2 hash for the primary icon. |
163 void OnGotIconMurmur2Hash(const std::string& icon_murmur2_hash); | 166 void OnGotPrimaryIconMurmur2Hash(const std::string& primary_icon_hash); |
| 167 |
| 168 // Called with the computed Murmur2 hash for the badge icon, and |
| 169 // |did_fetch_badge_icon| to indicate whether there was an attempt to fetch |
| 170 // badge icon. |
| 171 void OnGotBadgeIconMurmur2Hash(bool did_fetch_badge_icon, |
| 172 const std::string& primary_icon_hash, |
| 173 const std::string& badge_icon_hash); |
164 | 174 |
165 // Sends request to WebAPK server to create WebAPK. During a successful | 175 // Sends request to WebAPK server to create WebAPK. During a successful |
166 // request the WebAPK server responds with the URL of the generated WebAPK. | 176 // request the WebAPK server responds with the URL of the generated WebAPK. |
167 // |webapk| is the proto to send to the WebAPK server. | 177 // |webapk| is the proto to send to the WebAPK server. |
168 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); | 178 void SendCreateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); |
169 | 179 |
170 // Sends request to WebAPK server to update a WebAPK. During a successful | 180 // Sends request to WebAPK server to update a WebAPK. During a successful |
171 // request the WebAPK server responds with the URL of the generated WebAPK. | 181 // request the WebAPK server responds with the URL of the generated WebAPK. |
172 // |webapk| is the proto to send to the WebAPK server. | 182 // |webapk| is the proto to send to the WebAPK server. |
173 void SendUpdateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); | 183 void SendUpdateWebApkRequest(std::unique_ptr<webapk::WebApk> webapk_proto); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 235 |
226 // Tracks how long it takes to install a WebAPK. | 236 // Tracks how long it takes to install a WebAPK. |
227 std::unique_ptr<base::ElapsedTimer> install_duration_timer_; | 237 std::unique_ptr<base::ElapsedTimer> install_duration_timer_; |
228 | 238 |
229 // Callback to call once WebApkInstaller succeeds or fails. | 239 // Callback to call once WebApkInstaller succeeds or fails. |
230 FinishCallback finish_callback_; | 240 FinishCallback finish_callback_; |
231 | 241 |
232 // Web Manifest info. | 242 // Web Manifest info. |
233 const ShortcutInfo shortcut_info_; | 243 const ShortcutInfo shortcut_info_; |
234 | 244 |
235 // WebAPK app icon. | 245 // WebAPK primary icon. |
236 const SkBitmap shortcut_icon_; | 246 const SkBitmap primary_icon_; |
| 247 |
| 248 // WebAPK badge icon. |
| 249 const SkBitmap badge_icon_; |
237 | 250 |
238 // WebAPK server URL. | 251 // WebAPK server URL. |
239 GURL server_url_; | 252 GURL server_url_; |
240 | 253 |
241 // The number of milliseconds to wait for the WebAPK download URL from the | 254 // The number of milliseconds to wait for the WebAPK download URL from the |
242 // WebAPK server. | 255 // WebAPK server. |
243 int webapk_download_url_timeout_ms_; | 256 int webapk_download_url_timeout_ms_; |
244 | 257 |
245 // The number of milliseconds to wait for the WebAPK download to complete. | 258 // The number of milliseconds to wait for the WebAPK download to complete. |
246 int download_timeout_ms_; | 259 int download_timeout_ms_; |
(...skipping 13 matching lines...) Expand all Loading... |
260 // Points to the Java Object. | 273 // Points to the Java Object. |
261 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 274 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
262 | 275 |
263 // Used to get |weak_ptr_|. | 276 // Used to get |weak_ptr_|. |
264 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; | 277 base::WeakPtrFactory<WebApkInstaller> weak_ptr_factory_; |
265 | 278 |
266 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); | 279 DISALLOW_COPY_AND_ASSIGN(WebApkInstaller); |
267 }; | 280 }; |
268 | 281 |
269 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ | 282 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_INSTALLER_H_ |
OLD | NEW |