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 #include "chrome/browser/android/webapk/webapk_installer.h" | 5 #include "chrome/browser/android/webapk/webapk_installer.h" |
| 6 | 6 |
| 7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/path_utils.h" | 10 #include "base/android/path_utils.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 return "arm64-v8a"; | 104 return "arm64-v8a"; |
| 105 #else | 105 #else |
| 106 #error "Unsupported target abi" | 106 #error "Unsupported target abi" |
| 107 #endif | 107 #endif |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Populates webapk::WebApk and returns it. | 110 // Populates webapk::WebApk and returns it. |
| 111 // Must be called on a worker thread because it encodes an SkBitmap. | 111 // Must be called on a worker thread because it encodes an SkBitmap. |
| 112 std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground( | 112 std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground( |
| 113 const ShortcutInfo& shortcut_info, | 113 const ShortcutInfo& shortcut_info, |
| 114 const SkBitmap& shortcut_icon, | 114 const SkBitmap& primary_icon, |
| 115 const SkBitmap& badge_icon, | |
| 115 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 116 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 116 bool is_manifest_stale) { | 117 bool is_manifest_stale) { |
| 117 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 118 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 118 | 119 |
| 119 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); | 120 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); |
| 120 webapk->set_manifest_url(shortcut_info.manifest_url.spec()); | 121 webapk->set_manifest_url(shortcut_info.manifest_url.spec()); |
| 121 webapk->set_requester_application_package( | 122 webapk->set_requester_application_package( |
| 122 base::android::BuildInfo::GetInstance()->package_name()); | 123 base::android::BuildInfo::GetInstance()->package_name()); |
| 123 webapk->set_requester_application_version(version_info::GetVersionNumber()); | 124 webapk->set_requester_application_version(version_info::GetVersionNumber()); |
| 124 webapk->set_android_abi(getCurrentAbi()); | 125 webapk->set_android_abi(getCurrentAbi()); |
| 125 webapk->set_stale_manifest(is_manifest_stale); | 126 webapk->set_stale_manifest(is_manifest_stale); |
| 126 | 127 |
| 127 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); | 128 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); |
| 128 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name)); | 129 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name)); |
| 129 web_app_manifest->set_short_name(base::UTF16ToUTF8(shortcut_info.short_name)); | 130 web_app_manifest->set_short_name(base::UTF16ToUTF8(shortcut_info.short_name)); |
| 130 web_app_manifest->set_start_url(shortcut_info.url.spec()); | 131 web_app_manifest->set_start_url(shortcut_info.url.spec()); |
| 131 web_app_manifest->set_orientation( | 132 web_app_manifest->set_orientation( |
| 132 content::WebScreenOrientationLockTypeToString(shortcut_info.orientation)); | 133 content::WebScreenOrientationLockTypeToString(shortcut_info.orientation)); |
| 133 web_app_manifest->set_display_mode( | 134 web_app_manifest->set_display_mode( |
| 134 content::WebDisplayModeToString(shortcut_info.display)); | 135 content::WebDisplayModeToString(shortcut_info.display)); |
| 135 web_app_manifest->set_background_color( | 136 web_app_manifest->set_background_color( |
| 136 ColorToString(shortcut_info.background_color)); | 137 ColorToString(shortcut_info.background_color)); |
| 137 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color)); | 138 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color)); |
| 138 | 139 |
| 139 std::string* scope = web_app_manifest->add_scopes(); | 140 std::string* scope = web_app_manifest->add_scopes(); |
| 140 scope->assign(GetScope(shortcut_info).spec()); | 141 scope->assign(GetScope(shortcut_info).spec()); |
| 141 | 142 |
| 142 webapk::Image* best_image = web_app_manifest->add_icons(); | 143 webapk::Image* best_primary_icon_image = web_app_manifest->add_icons(); |
| 143 std::string best_primary_icon_url = | 144 std::string best_primary_icon_url = |
| 144 shortcut_info.best_primary_icon_url.spec(); | 145 shortcut_info.best_primary_icon_url.spec(); |
| 145 best_image->set_src(best_primary_icon_url); | 146 best_primary_icon_image->set_src(best_primary_icon_url); |
| 146 auto it = icon_url_to_murmur2_hash.find(best_primary_icon_url); | 147 auto it = icon_url_to_murmur2_hash.find(best_primary_icon_url); |
| 147 if (it != icon_url_to_murmur2_hash.end()) | 148 if (it != icon_url_to_murmur2_hash.end()) |
| 148 best_image->set_hash(it->second); | 149 best_primary_icon_image->set_hash(it->second); |
| 149 std::vector<unsigned char> png_bytes; | 150 std::vector<unsigned char> png_bytes; |
| 150 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes); | 151 gfx::PNGCodec::EncodeBGRASkBitmap(primary_icon, false, &png_bytes); |
| 151 best_image->set_image_data(&png_bytes.front(), png_bytes.size()); | 152 best_primary_icon_image->set_image_data(&png_bytes.front(), png_bytes.size()); |
| 153 best_primary_icon_image->add_usages(webapk::Image::PRIMARY_ICON); | |
| 154 | |
| 155 if (!badge_icon.drawsNothing()) { | |
| 156 std::string best_badge_icon_url = shortcut_info.best_badge_icon_url.spec(); | |
| 157 if (best_badge_icon_url == best_primary_icon_url) { | |
| 158 best_primary_icon_image->add_usages(webapk::Image::BADGE_ICON); | |
| 159 } else { | |
| 160 webapk::Image* best_badge_icon_image = web_app_manifest->add_icons(); | |
| 161 best_badge_icon_image->set_src(best_badge_icon_url); | |
| 162 auto it = icon_url_to_murmur2_hash.find(best_badge_icon_url); | |
| 163 if (it != icon_url_to_murmur2_hash.end()) | |
| 164 best_badge_icon_image->set_hash(it->second); | |
| 165 std::vector<unsigned char> png_bytes; | |
| 166 gfx::PNGCodec::EncodeBGRASkBitmap(badge_icon, false, &png_bytes); | |
| 167 best_badge_icon_image->set_image_data(&png_bytes.front(), | |
| 168 png_bytes.size()); | |
| 169 best_badge_icon_image->add_usages(webapk::Image::BADGE_ICON); | |
| 170 } | |
| 171 } | |
| 152 | 172 |
| 153 for (const auto& entry : icon_url_to_murmur2_hash) { | 173 for (const auto& entry : icon_url_to_murmur2_hash) { |
| 154 if (entry.first == shortcut_info.best_primary_icon_url.spec()) | 174 if (entry.first == shortcut_info.best_primary_icon_url.spec() || |
| 175 entry.first == shortcut_info.best_badge_icon_url.spec()) { | |
| 155 continue; | 176 continue; |
| 177 } | |
| 156 webapk::Image* image = web_app_manifest->add_icons(); | 178 webapk::Image* image = web_app_manifest->add_icons(); |
| 157 image->set_src(entry.first); | 179 image->set_src(entry.first); |
| 158 image->set_hash(entry.second); | 180 image->set_hash(entry.second); |
|
pkotwicz
2017/03/30 21:19:37
Can we simplify this logic to:
if (entry.first ==
F
2017/04/03 21:57:29
Resolved by offline. Doing everything inside the l
| |
| 159 } | 181 } |
| 160 | 182 |
| 161 return webapk; | 183 return webapk; |
| 162 } | 184 } |
| 163 | 185 |
| 164 // Calls the callback when the |webapk| request is created. | 186 // Calls the callback when the |webapk| request is created. |
| 165 void OnWebApkProtoBuilt( | 187 void OnWebApkProtoBuilt( |
| 166 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, | 188 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, |
| 167 std::unique_ptr<webapk::WebApk> webapk) { | 189 std::unique_ptr<webapk::WebApk> webapk) { |
| 168 callback.Run(std::move(webapk)); | 190 callback.Run(std::move(webapk)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 | 233 |
| 212 WebApkInstaller::~WebApkInstaller() { | 234 WebApkInstaller::~WebApkInstaller() { |
| 213 JNIEnv* env = base::android::AttachCurrentThread(); | 235 JNIEnv* env = base::android::AttachCurrentThread(); |
| 214 Java_WebApkInstaller_destroy(env, java_ref_); | 236 Java_WebApkInstaller_destroy(env, java_ref_); |
| 215 java_ref_.Reset(); | 237 java_ref_.Reset(); |
| 216 } | 238 } |
| 217 | 239 |
| 218 // static | 240 // static |
| 219 void WebApkInstaller::InstallAsync(content::BrowserContext* context, | 241 void WebApkInstaller::InstallAsync(content::BrowserContext* context, |
| 220 const ShortcutInfo& shortcut_info, | 242 const ShortcutInfo& shortcut_info, |
| 221 const SkBitmap& shortcut_icon, | 243 const SkBitmap& primary_icon, |
| 244 const SkBitmap& badge_icon, | |
| 222 const FinishCallback& finish_callback) { | 245 const FinishCallback& finish_callback) { |
| 223 // The installer will delete itself when it is done. | 246 // The installer will delete itself when it is done. |
| 224 WebApkInstaller* installer = | 247 WebApkInstaller* installer = |
| 225 new WebApkInstaller(context, shortcut_info, shortcut_icon); | 248 new WebApkInstaller(context, shortcut_info, primary_icon, badge_icon); |
| 226 installer->InstallAsync(finish_callback); | 249 installer->InstallAsync(finish_callback); |
| 227 } | 250 } |
| 228 | 251 |
| 229 // static | 252 // static |
| 230 void WebApkInstaller::UpdateAsync( | 253 void WebApkInstaller::UpdateAsync( |
| 231 content::BrowserContext* context, | 254 content::BrowserContext* context, |
| 232 const ShortcutInfo& shortcut_info, | 255 const ShortcutInfo& shortcut_info, |
| 233 const SkBitmap& shortcut_icon, | 256 const SkBitmap& primary_icon, |
| 234 const std::string& webapk_package, | 257 const std::string& webapk_package, |
| 235 int webapk_version, | 258 int webapk_version, |
| 236 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 259 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 237 bool is_manifest_stale, | 260 bool is_manifest_stale, |
| 238 const FinishCallback& finish_callback) { | 261 const FinishCallback& finish_callback) { |
| 239 // The installer will delete itself when it is done. | 262 // The installer will delete itself when it is done. |
| 240 WebApkInstaller* installer = | 263 SkBitmap empty_badge_icon; |
| 241 new WebApkInstaller(context, shortcut_info, shortcut_icon); | 264 WebApkInstaller* installer = new WebApkInstaller( |
| 265 context, shortcut_info, primary_icon, empty_badge_icon); | |
|
pkotwicz
2017/03/30 21:49:50
I assume that passing a badge icon for updates is
pkotwicz
2017/03/31 18:03:27
After some thought, we actually need to fetch the
F
2017/04/03 21:57:29
I'll do it in follow up CLs. Added TODO in header
| |
| 242 installer->UpdateAsync(webapk_package, webapk_version, | 266 installer->UpdateAsync(webapk_package, webapk_version, |
| 243 icon_url_to_murmur2_hash, is_manifest_stale, | 267 icon_url_to_murmur2_hash, is_manifest_stale, |
| 244 finish_callback); | 268 finish_callback); |
| 245 } | 269 } |
| 246 | 270 |
| 247 // staic | 271 // staic |
| 248 void WebApkInstaller::InstallAsyncForTesting( | 272 void WebApkInstaller::InstallAsyncForTesting( |
| 249 WebApkInstaller* installer, | 273 WebApkInstaller* installer, |
| 250 const FinishCallback& finish_callback) { | 274 const FinishCallback& finish_callback) { |
| 251 installer->InstallAsync(finish_callback); | 275 installer->InstallAsync(finish_callback); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 275 jint result) { | 299 jint result) { |
| 276 OnResult(static_cast<WebApkInstallResult>(result)); | 300 OnResult(static_cast<WebApkInstallResult>(result)); |
| 277 } | 301 } |
| 278 | 302 |
| 279 void WebApkInstaller::BuildWebApkProtoInBackgroundForTesting( | 303 void WebApkInstaller::BuildWebApkProtoInBackgroundForTesting( |
| 280 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, | 304 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, |
| 281 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 305 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 282 bool is_manifest_stale) { | 306 bool is_manifest_stale) { |
| 283 base::PostTaskAndReplyWithResult( | 307 base::PostTaskAndReplyWithResult( |
| 284 GetBackgroundTaskRunner().get(), FROM_HERE, | 308 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 285 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_, | 309 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, primary_icon_, |
| 286 icon_url_to_murmur2_hash, is_manifest_stale), | 310 badge_icon_, icon_url_to_murmur2_hash, is_manifest_stale), |
| 287 base::Bind(&OnWebApkProtoBuilt, callback)); | 311 base::Bind(&OnWebApkProtoBuilt, callback)); |
| 288 } | 312 } |
| 289 | 313 |
| 290 // static | 314 // static |
| 291 bool WebApkInstaller::Register(JNIEnv* env) { | 315 bool WebApkInstaller::Register(JNIEnv* env) { |
| 292 return RegisterNativesImpl(env); | 316 return RegisterNativesImpl(env); |
| 293 } | 317 } |
| 294 | 318 |
| 295 void WebApkInstaller::InstallDownloadedWebApk( | 319 void WebApkInstaller::InstallDownloadedWebApk( |
| 296 JNIEnv* env, | 320 JNIEnv* env, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 } | 364 } |
| 341 | 365 |
| 342 void WebApkInstaller::OnResult(WebApkInstallResult result) { | 366 void WebApkInstaller::OnResult(WebApkInstallResult result) { |
| 343 weak_ptr_factory_.InvalidateWeakPtrs(); | 367 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 344 finish_callback_.Run(result, relax_updates_, webapk_package_); | 368 finish_callback_.Run(result, relax_updates_, webapk_package_); |
| 345 delete this; | 369 delete this; |
| 346 } | 370 } |
| 347 | 371 |
| 348 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, | 372 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, |
| 349 const ShortcutInfo& shortcut_info, | 373 const ShortcutInfo& shortcut_info, |
| 350 const SkBitmap& shortcut_icon) | 374 const SkBitmap& primary_icon, |
| 375 const SkBitmap& badge_icon) | |
| 351 : request_context_getter_( | 376 : request_context_getter_( |
| 352 Profile::FromBrowserContext(browser_context)->GetRequestContext()), | 377 Profile::FromBrowserContext(browser_context)->GetRequestContext()), |
| 353 shortcut_info_(shortcut_info), | 378 shortcut_info_(shortcut_info), |
| 354 shortcut_icon_(shortcut_icon), | 379 primary_icon_(primary_icon), |
| 380 badge_icon_(badge_icon), | |
| 355 server_url_(GetServerUrl()), | 381 server_url_(GetServerUrl()), |
| 356 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), | 382 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), |
| 357 download_timeout_ms_(kDownloadTimeoutMs), | 383 download_timeout_ms_(kDownloadTimeoutMs), |
| 358 relax_updates_(false), | 384 relax_updates_(false), |
| 359 webapk_version_(kDefaultWebApkVersion), | 385 webapk_version_(kDefaultWebApkVersion), |
| 360 task_type_(UNDEFINED), | 386 task_type_(UNDEFINED), |
| 361 weak_ptr_factory_(this) { | 387 weak_ptr_factory_(this) { |
| 362 CreateJavaRef(); | 388 CreateJavaRef(); |
| 363 } | 389 } |
| 364 | 390 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 375 // We need to take the hash of the bitmap at the icon URL prior to any | 401 // We need to take the hash of the bitmap at the icon URL prior to any |
| 376 // transformations being applied to the bitmap (such as encoding/decoding | 402 // transformations being applied to the bitmap (such as encoding/decoding |
| 377 // the bitmap). The icon hash is used to determine whether the icon that | 403 // the bitmap). The icon hash is used to determine whether the icon that |
| 378 // the user sees matches the icon of a WebAPK that the WebAPK server | 404 // the user sees matches the icon of a WebAPK that the WebAPK server |
| 379 // generated for another user. (The icon can be dynamically generated.) | 405 // generated for another user. (The icon can be dynamically generated.) |
| 380 // | 406 // |
| 381 // We redownload the icon in order to take the Murmur2 hash. The redownload | 407 // We redownload the icon in order to take the Murmur2 hash. The redownload |
| 382 // should be fast because the icon should be in the HTTP cache. | 408 // should be fast because the icon should be in the HTTP cache. |
| 383 WebApkIconHasher::DownloadAndComputeMurmur2Hash( | 409 WebApkIconHasher::DownloadAndComputeMurmur2Hash( |
| 384 request_context_getter_, shortcut_info_.best_primary_icon_url, | 410 request_context_getter_, shortcut_info_.best_primary_icon_url, |
| 385 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash, | 411 base::Bind(&WebApkInstaller::OnGotPrimaryIconMurmur2Hash, |
| 386 weak_ptr_factory_.GetWeakPtr())); | 412 weak_ptr_factory_.GetWeakPtr())); |
| 387 } | 413 } |
| 388 | 414 |
| 389 void WebApkInstaller::UpdateAsync( | 415 void WebApkInstaller::UpdateAsync( |
| 390 const std::string& webapk_package, | 416 const std::string& webapk_package, |
| 391 int webapk_version, | 417 int webapk_version, |
| 392 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 418 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 393 bool is_manifest_stale, | 419 bool is_manifest_stale, |
| 394 const FinishCallback& finish_callback) { | 420 const FinishCallback& finish_callback) { |
| 395 webapk_package_ = webapk_package; | 421 webapk_package_ = webapk_package; |
| 396 webapk_version_ = webapk_version; | 422 webapk_version_ = webapk_version; |
| 397 finish_callback_ = finish_callback; | 423 finish_callback_ = finish_callback; |
| 398 task_type_ = UPDATE; | 424 task_type_ = UPDATE; |
| 399 | 425 |
| 400 base::PostTaskAndReplyWithResult( | 426 base::PostTaskAndReplyWithResult( |
| 401 GetBackgroundTaskRunner().get(), FROM_HERE, | 427 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 402 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_, | 428 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, primary_icon_, |
| 403 icon_url_to_murmur2_hash, is_manifest_stale), | 429 badge_icon_, icon_url_to_murmur2_hash, is_manifest_stale), |
| 404 base::Bind(&WebApkInstaller::SendUpdateWebApkRequest, | 430 base::Bind(&WebApkInstaller::SendUpdateWebApkRequest, |
| 405 weak_ptr_factory_.GetWeakPtr())); | 431 weak_ptr_factory_.GetWeakPtr())); |
| 406 } | 432 } |
| 407 | 433 |
| 408 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { | 434 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { |
| 409 timer_.Stop(); | 435 timer_.Stop(); |
| 410 | 436 |
| 411 if (!source->GetStatus().is_success() || | 437 if (!source->GetStatus().is_success() || |
| 412 source->GetResponseCode() != net::HTTP_OK) { | 438 source->GetResponseCode() != net::HTTP_OK) { |
| 413 LOG(WARNING) << base::StringPrintf( | 439 LOG(WARNING) << base::StringPrintf( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 int version = 1; | 471 int version = 1; |
| 446 base::StringToInt(response->version(), &version); | 472 base::StringToInt(response->version(), &version); |
| 447 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version, | 473 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version, |
| 448 response->token()); | 474 response->token()); |
| 449 return; | 475 return; |
| 450 } | 476 } |
| 451 | 477 |
| 452 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); | 478 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); |
| 453 } | 479 } |
| 454 | 480 |
| 455 void WebApkInstaller::OnGotIconMurmur2Hash( | 481 void WebApkInstaller::OnGotPrimaryIconMurmur2Hash( |
| 456 const std::string& icon_murmur2_hash) { | 482 const std::string& primary_icon_hash) { |
| 457 // An empty hash indicates that |icon_hasher_| encountered an error. | 483 // An empty hash indicates that |icon_hasher_| encountered an error. |
| 458 if (icon_murmur2_hash.empty()) { | 484 if (primary_icon_hash.empty()) { |
| 459 OnResult(WebApkInstallResult::FAILURE); | 485 OnResult(WebApkInstallResult::FAILURE); |
| 460 return; | 486 return; |
| 461 } | 487 } |
| 462 | 488 |
| 489 primary_icon_hash_ = primary_icon_hash; | |
| 490 | |
| 491 if (!shortcut_info_.best_badge_icon_url.is_empty() && | |
| 492 shortcut_info_.best_badge_icon_url.spec() != | |
| 493 shortcut_info_.best_primary_icon_url.spec()) { | |
| 494 WebApkIconHasher::DownloadAndComputeMurmur2Hash( | |
| 495 request_context_getter_, shortcut_info_.best_badge_icon_url, | |
| 496 base::Bind(&WebApkInstaller::OnGotBadgeIconMurmur2Hash, | |
| 497 weak_ptr_factory_.GetWeakPtr())); | |
| 498 } else { | |
| 499 MapIconUrlToMurmur2Hash(); | |
|
pkotwicz
2017/03/30 21:19:37
Can we keep the flow linear and call OnGotBadgeIco
F
2017/04/03 21:57:29
Done.
| |
| 500 } | |
| 501 } | |
| 502 | |
| 503 void WebApkInstaller::OnGotBadgeIconMurmur2Hash( | |
| 504 const std::string& badge_icon_hash) { | |
| 505 // An empty hash indicates that |icon_hasher_| encountered an error. | |
| 506 if (badge_icon_hash.empty()) { | |
| 507 OnResult(WebApkInstallResult::FAILURE); | |
| 508 return; | |
| 509 } | |
| 510 | |
| 511 badge_icon_hash_ = badge_icon_hash; | |
| 512 | |
| 513 MapIconUrlToMurmur2Hash(); | |
| 514 } | |
| 515 | |
| 516 void WebApkInstaller::MapIconUrlToMurmur2Hash() { | |
| 463 std::map<std::string, std::string> icon_url_to_murmur2_hash; | 517 std::map<std::string, std::string> icon_url_to_murmur2_hash; |
| 464 for (const std::string& icon_url : shortcut_info_.icon_urls) { | 518 for (const std::string& icon_url : shortcut_info_.icon_urls) { |
| 465 if (icon_url != shortcut_info_.best_primary_icon_url.spec()) | 519 if (icon_url == shortcut_info_.best_primary_icon_url.spec()) |
| 520 icon_url_to_murmur2_hash[icon_url] = primary_icon_hash_; | |
| 521 else if (icon_url == shortcut_info_.best_badge_icon_url.spec()) | |
| 522 icon_url_to_murmur2_hash[icon_url] = badge_icon_hash_; | |
| 523 else | |
| 466 icon_url_to_murmur2_hash[icon_url] = ""; | 524 icon_url_to_murmur2_hash[icon_url] = ""; |
| 467 else | |
| 468 icon_url_to_murmur2_hash[icon_url] = icon_murmur2_hash; | |
| 469 } | 525 } |
| 470 | 526 |
| 471 base::PostTaskAndReplyWithResult( | 527 base::PostTaskAndReplyWithResult( |
| 472 GetBackgroundTaskRunner().get(), FROM_HERE, | 528 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 473 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_, | 529 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, primary_icon_, |
| 474 icon_url_to_murmur2_hash, false /* is_manifest_stale */), | 530 badge_icon_, icon_url_to_murmur2_hash, |
| 531 false /* is_manifest_stale */), | |
| 475 base::Bind(&WebApkInstaller::SendCreateWebApkRequest, | 532 base::Bind(&WebApkInstaller::SendCreateWebApkRequest, |
| 476 weak_ptr_factory_.GetWeakPtr())); | 533 weak_ptr_factory_.GetWeakPtr())); |
| 477 } | 534 } |
| 478 | 535 |
| 479 void WebApkInstaller::SendCreateWebApkRequest( | 536 void WebApkInstaller::SendCreateWebApkRequest( |
| 480 std::unique_ptr<webapk::WebApk> webapk) { | 537 std::unique_ptr<webapk::WebApk> webapk) { |
| 481 SendRequest(std::move(webapk), server_url_); | 538 SendRequest(std::move(webapk), server_url_); |
| 482 } | 539 } |
| 483 | 540 |
| 484 void WebApkInstaller::SendUpdateWebApkRequest( | 541 void WebApkInstaller::SendUpdateWebApkRequest( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 base::android::ScopedJavaLocalRef<jstring> java_file_path = | 650 base::android::ScopedJavaLocalRef<jstring> java_file_path = |
| 594 base::android::ConvertUTF8ToJavaString(env, file_path.value()); | 651 base::android::ConvertUTF8ToJavaString(env, file_path.value()); |
| 595 if (task_type_ == INSTALL) { | 652 if (task_type_ == INSTALL) { |
| 596 base::android::ScopedJavaLocalRef<jstring> java_package_name = | 653 base::android::ScopedJavaLocalRef<jstring> java_package_name = |
| 597 base::android::ConvertUTF8ToJavaString(env, webapk_package_); | 654 base::android::ConvertUTF8ToJavaString(env, webapk_package_); |
| 598 InstallDownloadedWebApk(env, java_file_path, java_package_name); | 655 InstallDownloadedWebApk(env, java_file_path, java_package_name); |
| 599 } else if (task_type_ == UPDATE) { | 656 } else if (task_type_ == UPDATE) { |
| 600 UpdateUsingDownloadedWebApk(env, java_file_path); | 657 UpdateUsingDownloadedWebApk(env, java_file_path); |
| 601 } | 658 } |
| 602 } | 659 } |
| OLD | NEW |