| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return "mips"; | 102 return "mips"; |
| 103 #elif defined(__x86_64__) | 103 #elif defined(__x86_64__) |
| 104 return "x86_64"; | 104 return "x86_64"; |
| 105 #elif defined(__aarch64__) | 105 #elif defined(__aarch64__) |
| 106 return "arm64-v8a"; | 106 return "arm64-v8a"; |
| 107 #else | 107 #else |
| 108 #error "Unsupported target abi" | 108 #error "Unsupported target abi" |
| 109 #endif | 109 #endif |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Populates the webapk::Image::image_data field of |image| with |icon|. |
| 113 void SetImageData(webapk::Image* image, const SkBitmap& icon) { |
| 114 std::vector<unsigned char> png_bytes; |
| 115 gfx::PNGCodec::EncodeBGRASkBitmap(icon, false, &png_bytes); |
| 116 image->set_image_data(&png_bytes.front(), png_bytes.size()); |
| 117 } |
| 118 |
| 112 // Populates webapk::WebApk and returns it. | 119 // Populates webapk::WebApk and returns it. |
| 113 // Must be called on a worker thread because it encodes an SkBitmap. | 120 // Must be called on a worker thread because it encodes an SkBitmap. |
| 114 std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground( | 121 std::unique_ptr<webapk::WebApk> BuildWebApkProtoInBackground( |
| 115 const ShortcutInfo& shortcut_info, | 122 const ShortcutInfo& shortcut_info, |
| 116 const SkBitmap& shortcut_icon, | 123 const SkBitmap& primary_icon, |
| 124 const SkBitmap& badge_icon, |
| 117 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 125 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 118 bool is_manifest_stale) { | 126 bool is_manifest_stale) { |
| 119 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 127 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 120 | 128 |
| 121 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); | 129 std::unique_ptr<webapk::WebApk> webapk(new webapk::WebApk); |
| 122 webapk->set_manifest_url(shortcut_info.manifest_url.spec()); | 130 webapk->set_manifest_url(shortcut_info.manifest_url.spec()); |
| 123 webapk->set_requester_application_package( | 131 webapk->set_requester_application_package( |
| 124 base::android::BuildInfo::GetInstance()->package_name()); | 132 base::android::BuildInfo::GetInstance()->package_name()); |
| 125 webapk->set_requester_application_version(version_info::GetVersionNumber()); | 133 webapk->set_requester_application_version(version_info::GetVersionNumber()); |
| 126 webapk->set_android_abi(getCurrentAbi()); | 134 webapk->set_android_abi(getCurrentAbi()); |
| 127 webapk->set_stale_manifest(is_manifest_stale); | 135 webapk->set_stale_manifest(is_manifest_stale); |
| 128 | 136 |
| 129 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); | 137 webapk::WebAppManifest* web_app_manifest = webapk->mutable_manifest(); |
| 130 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name)); | 138 web_app_manifest->set_name(base::UTF16ToUTF8(shortcut_info.name)); |
| 131 web_app_manifest->set_short_name(base::UTF16ToUTF8(shortcut_info.short_name)); | 139 web_app_manifest->set_short_name(base::UTF16ToUTF8(shortcut_info.short_name)); |
| 132 web_app_manifest->set_start_url(shortcut_info.url.spec()); | 140 web_app_manifest->set_start_url(shortcut_info.url.spec()); |
| 133 web_app_manifest->set_orientation( | 141 web_app_manifest->set_orientation( |
| 134 content::WebScreenOrientationLockTypeToString(shortcut_info.orientation)); | 142 content::WebScreenOrientationLockTypeToString(shortcut_info.orientation)); |
| 135 web_app_manifest->set_display_mode( | 143 web_app_manifest->set_display_mode( |
| 136 content::WebDisplayModeToString(shortcut_info.display)); | 144 content::WebDisplayModeToString(shortcut_info.display)); |
| 137 web_app_manifest->set_background_color( | 145 web_app_manifest->set_background_color( |
| 138 ColorToString(shortcut_info.background_color)); | 146 ColorToString(shortcut_info.background_color)); |
| 139 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color)); | 147 web_app_manifest->set_theme_color(ColorToString(shortcut_info.theme_color)); |
| 140 | 148 |
| 141 std::string* scope = web_app_manifest->add_scopes(); | 149 std::string* scope = web_app_manifest->add_scopes(); |
| 142 scope->assign(GetScope(shortcut_info).spec()); | 150 scope->assign(GetScope(shortcut_info).spec()); |
| 143 | 151 |
| 144 webapk::Image* best_image = web_app_manifest->add_icons(); | 152 if (shortcut_info.best_primary_icon_url.is_empty()) { |
| 145 std::string best_primary_icon_url = | 153 // Update when web manifest is no longer available. |
| 146 shortcut_info.best_primary_icon_url.spec(); | 154 webapk::Image* best_primary_icon_image = web_app_manifest->add_icons(); |
| 147 best_image->set_src(best_primary_icon_url); | 155 SetImageData(best_primary_icon_image, primary_icon); |
| 148 auto it = icon_url_to_murmur2_hash.find(best_primary_icon_url); | 156 best_primary_icon_image->add_usages(webapk::Image::PRIMARY_ICON); |
| 149 if (it != icon_url_to_murmur2_hash.end()) | 157 |
| 150 best_image->set_hash(it->second); | 158 if (!badge_icon.drawsNothing()) { |
| 151 std::vector<unsigned char> png_bytes; | 159 webapk::Image* best_badge_icon_image = web_app_manifest->add_icons(); |
| 152 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_icon, false, &png_bytes); | 160 SetImageData(best_badge_icon_image, badge_icon); |
| 153 best_image->set_image_data(&png_bytes.front(), png_bytes.size()); | 161 best_badge_icon_image->add_usages(webapk::Image::BADGE_ICON); |
| 162 } |
| 163 } |
| 154 | 164 |
| 155 for (const auto& entry : icon_url_to_murmur2_hash) { | 165 for (const auto& entry : icon_url_to_murmur2_hash) { |
| 156 if (entry.first == shortcut_info.best_primary_icon_url.spec()) | |
| 157 continue; | |
| 158 webapk::Image* image = web_app_manifest->add_icons(); | 166 webapk::Image* image = web_app_manifest->add_icons(); |
| 167 if (entry.first == shortcut_info.best_primary_icon_url.spec()) { |
| 168 SetImageData(image, primary_icon); |
| 169 image->add_usages(webapk::Image::PRIMARY_ICON); |
| 170 } |
| 171 if (entry.first == shortcut_info.best_badge_icon_url.spec()) { |
| 172 if (shortcut_info.best_badge_icon_url != |
| 173 shortcut_info.best_primary_icon_url) { |
| 174 SetImageData(image, badge_icon); |
| 175 } |
| 176 image->add_usages(webapk::Image::BADGE_ICON); |
| 177 } |
| 159 image->set_src(entry.first); | 178 image->set_src(entry.first); |
| 160 image->set_hash(entry.second); | 179 image->set_hash(entry.second); |
| 161 } | 180 } |
| 162 | 181 |
| 163 return webapk; | 182 return webapk; |
| 164 } | 183 } |
| 165 | 184 |
| 166 // Calls the callback when the |webapk| request is created. | 185 // Calls the callback when the |webapk| request is created. |
| 167 void OnWebApkProtoBuilt( | 186 void OnWebApkProtoBuilt( |
| 168 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, | 187 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 232 |
| 214 WebApkInstaller::~WebApkInstaller() { | 233 WebApkInstaller::~WebApkInstaller() { |
| 215 JNIEnv* env = base::android::AttachCurrentThread(); | 234 JNIEnv* env = base::android::AttachCurrentThread(); |
| 216 Java_WebApkInstaller_destroy(env, java_ref_); | 235 Java_WebApkInstaller_destroy(env, java_ref_); |
| 217 java_ref_.Reset(); | 236 java_ref_.Reset(); |
| 218 } | 237 } |
| 219 | 238 |
| 220 // static | 239 // static |
| 221 void WebApkInstaller::InstallAsync(content::BrowserContext* context, | 240 void WebApkInstaller::InstallAsync(content::BrowserContext* context, |
| 222 const ShortcutInfo& shortcut_info, | 241 const ShortcutInfo& shortcut_info, |
| 223 const SkBitmap& shortcut_icon, | 242 const SkBitmap& primary_icon, |
| 243 const SkBitmap& badge_icon, |
| 224 const FinishCallback& finish_callback) { | 244 const FinishCallback& finish_callback) { |
| 225 // The installer will delete itself when it is done. | 245 // The installer will delete itself when it is done. |
| 226 WebApkInstaller* installer = | 246 WebApkInstaller* installer = |
| 227 new WebApkInstaller(context, shortcut_info, shortcut_icon); | 247 new WebApkInstaller(context, shortcut_info, primary_icon, badge_icon); |
| 228 installer->InstallAsync(finish_callback); | 248 installer->InstallAsync(finish_callback); |
| 229 } | 249 } |
| 230 | 250 |
| 231 // static | 251 // static |
| 232 void WebApkInstaller::UpdateAsync( | 252 void WebApkInstaller::UpdateAsync( |
| 233 content::BrowserContext* context, | 253 content::BrowserContext* context, |
| 234 const ShortcutInfo& shortcut_info, | 254 const ShortcutInfo& shortcut_info, |
| 235 const SkBitmap& shortcut_icon, | 255 const SkBitmap& primary_icon, |
| 236 const std::string& webapk_package, | 256 const std::string& webapk_package, |
| 237 int webapk_version, | 257 int webapk_version, |
| 238 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 258 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 239 bool is_manifest_stale, | 259 bool is_manifest_stale, |
| 240 const FinishCallback& finish_callback) { | 260 const FinishCallback& finish_callback) { |
| 241 // The installer will delete itself when it is done. | 261 // The installer will delete itself when it is done. |
| 242 WebApkInstaller* installer = | 262 WebApkInstaller* installer = new WebApkInstaller( |
| 243 new WebApkInstaller(context, shortcut_info, shortcut_icon); | 263 context, shortcut_info, primary_icon, SkBitmap()); |
| 244 installer->UpdateAsync(webapk_package, webapk_version, | 264 installer->UpdateAsync(webapk_package, webapk_version, |
| 245 icon_url_to_murmur2_hash, is_manifest_stale, | 265 icon_url_to_murmur2_hash, is_manifest_stale, |
| 246 finish_callback); | 266 finish_callback); |
| 247 } | 267 } |
| 248 | 268 |
| 249 // staic | 269 // staic |
| 250 void WebApkInstaller::InstallAsyncForTesting( | 270 void WebApkInstaller::InstallAsyncForTesting( |
| 251 WebApkInstaller* installer, | 271 WebApkInstaller* installer, |
| 252 const FinishCallback& finish_callback) { | 272 const FinishCallback& finish_callback) { |
| 253 installer->InstallAsync(finish_callback); | 273 installer->InstallAsync(finish_callback); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 277 jint result) { | 297 jint result) { |
| 278 OnResult(static_cast<WebApkInstallResult>(result)); | 298 OnResult(static_cast<WebApkInstallResult>(result)); |
| 279 } | 299 } |
| 280 | 300 |
| 281 void WebApkInstaller::BuildWebApkProtoInBackgroundForTesting( | 301 void WebApkInstaller::BuildWebApkProtoInBackgroundForTesting( |
| 282 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, | 302 const base::Callback<void(std::unique_ptr<webapk::WebApk>)>& callback, |
| 283 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 303 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 284 bool is_manifest_stale) { | 304 bool is_manifest_stale) { |
| 285 base::PostTaskAndReplyWithResult( | 305 base::PostTaskAndReplyWithResult( |
| 286 GetBackgroundTaskRunner().get(), FROM_HERE, | 306 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 287 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_, | 307 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, primary_icon_, |
| 288 icon_url_to_murmur2_hash, is_manifest_stale), | 308 badge_icon_, icon_url_to_murmur2_hash, is_manifest_stale), |
| 289 base::Bind(&OnWebApkProtoBuilt, callback)); | 309 base::Bind(&OnWebApkProtoBuilt, callback)); |
| 290 } | 310 } |
| 291 | 311 |
| 292 // static | 312 // static |
| 293 bool WebApkInstaller::Register(JNIEnv* env) { | 313 bool WebApkInstaller::Register(JNIEnv* env) { |
| 294 return RegisterNativesImpl(env); | 314 return RegisterNativesImpl(env); |
| 295 } | 315 } |
| 296 | 316 |
| 297 void WebApkInstaller::InstallDownloadedWebApk( | 317 void WebApkInstaller::InstallDownloadedWebApk( |
| 298 JNIEnv* env, | 318 JNIEnv* env, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 DVLOG(1) << "The WebAPK installation failed."; | 373 DVLOG(1) << "The WebAPK installation failed."; |
| 354 webapk::TrackInstallEvent(webapk::INSTALL_FAILED); | 374 webapk::TrackInstallEvent(webapk::INSTALL_FAILED); |
| 355 } | 375 } |
| 356 } | 376 } |
| 357 | 377 |
| 358 delete this; | 378 delete this; |
| 359 } | 379 } |
| 360 | 380 |
| 361 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, | 381 WebApkInstaller::WebApkInstaller(content::BrowserContext* browser_context, |
| 362 const ShortcutInfo& shortcut_info, | 382 const ShortcutInfo& shortcut_info, |
| 363 const SkBitmap& shortcut_icon) | 383 const SkBitmap& primary_icon, |
| 384 const SkBitmap& badge_icon) |
| 364 : request_context_getter_( | 385 : request_context_getter_( |
| 365 Profile::FromBrowserContext(browser_context)->GetRequestContext()), | 386 Profile::FromBrowserContext(browser_context)->GetRequestContext()), |
| 366 shortcut_info_(shortcut_info), | 387 shortcut_info_(shortcut_info), |
| 367 shortcut_icon_(shortcut_icon), | 388 primary_icon_(primary_icon), |
| 389 badge_icon_(badge_icon), |
| 368 server_url_(GetServerUrl()), | 390 server_url_(GetServerUrl()), |
| 369 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), | 391 webapk_download_url_timeout_ms_(kWebApkDownloadUrlTimeoutMs), |
| 370 download_timeout_ms_(kDownloadTimeoutMs), | 392 download_timeout_ms_(kDownloadTimeoutMs), |
| 371 relax_updates_(false), | 393 relax_updates_(false), |
| 372 webapk_version_(kDefaultWebApkVersion), | 394 webapk_version_(kDefaultWebApkVersion), |
| 373 task_type_(UNDEFINED), | 395 task_type_(UNDEFINED), |
| 374 weak_ptr_factory_(this) { | 396 weak_ptr_factory_(this) { |
| 375 CreateJavaRef(); | 397 CreateJavaRef(); |
| 376 } | 398 } |
| 377 | 399 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 390 // We need to take the hash of the bitmap at the icon URL prior to any | 412 // We need to take the hash of the bitmap at the icon URL prior to any |
| 391 // transformations being applied to the bitmap (such as encoding/decoding | 413 // transformations being applied to the bitmap (such as encoding/decoding |
| 392 // the bitmap). The icon hash is used to determine whether the icon that | 414 // the bitmap). The icon hash is used to determine whether the icon that |
| 393 // the user sees matches the icon of a WebAPK that the WebAPK server | 415 // the user sees matches the icon of a WebAPK that the WebAPK server |
| 394 // generated for another user. (The icon can be dynamically generated.) | 416 // generated for another user. (The icon can be dynamically generated.) |
| 395 // | 417 // |
| 396 // We redownload the icon in order to take the Murmur2 hash. The redownload | 418 // We redownload the icon in order to take the Murmur2 hash. The redownload |
| 397 // should be fast because the icon should be in the HTTP cache. | 419 // should be fast because the icon should be in the HTTP cache. |
| 398 WebApkIconHasher::DownloadAndComputeMurmur2Hash( | 420 WebApkIconHasher::DownloadAndComputeMurmur2Hash( |
| 399 request_context_getter_, shortcut_info_.best_primary_icon_url, | 421 request_context_getter_, shortcut_info_.best_primary_icon_url, |
| 400 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash, | 422 base::Bind(&WebApkInstaller::OnGotPrimaryIconMurmur2Hash, |
| 401 weak_ptr_factory_.GetWeakPtr())); | 423 weak_ptr_factory_.GetWeakPtr())); |
| 402 } | 424 } |
| 403 | 425 |
| 404 void WebApkInstaller::UpdateAsync( | 426 void WebApkInstaller::UpdateAsync( |
| 405 const std::string& webapk_package, | 427 const std::string& webapk_package, |
| 406 int webapk_version, | 428 int webapk_version, |
| 407 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 429 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
| 408 bool is_manifest_stale, | 430 bool is_manifest_stale, |
| 409 const FinishCallback& finish_callback) { | 431 const FinishCallback& finish_callback) { |
| 410 webapk_package_ = webapk_package; | 432 webapk_package_ = webapk_package; |
| 411 webapk_version_ = webapk_version; | 433 webapk_version_ = webapk_version; |
| 412 finish_callback_ = finish_callback; | 434 finish_callback_ = finish_callback; |
| 413 task_type_ = UPDATE; | 435 task_type_ = UPDATE; |
| 414 | 436 |
| 415 base::PostTaskAndReplyWithResult( | 437 base::PostTaskAndReplyWithResult( |
| 416 GetBackgroundTaskRunner().get(), FROM_HERE, | 438 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 417 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_, | 439 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, primary_icon_, |
| 418 icon_url_to_murmur2_hash, is_manifest_stale), | 440 badge_icon_, icon_url_to_murmur2_hash, is_manifest_stale), |
| 419 base::Bind(&WebApkInstaller::SendUpdateWebApkRequest, | 441 base::Bind(&WebApkInstaller::SendUpdateWebApkRequest, |
| 420 weak_ptr_factory_.GetWeakPtr())); | 442 weak_ptr_factory_.GetWeakPtr())); |
| 421 } | 443 } |
| 422 | 444 |
| 423 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { | 445 void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { |
| 424 timer_.Stop(); | 446 timer_.Stop(); |
| 425 | 447 |
| 426 if (!source->GetStatus().is_success() || | 448 if (!source->GetStatus().is_success() || |
| 427 source->GetResponseCode() != net::HTTP_OK) { | 449 source->GetResponseCode() != net::HTTP_OK) { |
| 428 LOG(WARNING) << base::StringPrintf( | 450 LOG(WARNING) << base::StringPrintf( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 int version = 1; | 482 int version = 1; |
| 461 base::StringToInt(response->version(), &version); | 483 base::StringToInt(response->version(), &version); |
| 462 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version, | 484 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version, |
| 463 response->token()); | 485 response->token()); |
| 464 return; | 486 return; |
| 465 } | 487 } |
| 466 | 488 |
| 467 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); | 489 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); |
| 468 } | 490 } |
| 469 | 491 |
| 470 void WebApkInstaller::OnGotIconMurmur2Hash( | 492 void WebApkInstaller::OnGotPrimaryIconMurmur2Hash( |
| 471 const std::string& icon_murmur2_hash) { | 493 const std::string& primary_icon_hash) { |
| 472 // An empty hash indicates that |icon_hasher_| encountered an error. | 494 // An empty hash indicates an error during hash calculation. |
| 473 if (icon_murmur2_hash.empty()) { | 495 if (primary_icon_hash.empty()) { |
| 474 OnResult(WebApkInstallResult::FAILURE); | 496 OnResult(WebApkInstallResult::FAILURE); |
| 475 return; | 497 return; |
| 476 } | 498 } |
| 477 | 499 |
| 500 if (!shortcut_info_.best_badge_icon_url.is_empty() && |
| 501 shortcut_info_.best_badge_icon_url != |
| 502 shortcut_info_.best_primary_icon_url) { |
| 503 WebApkIconHasher::DownloadAndComputeMurmur2Hash( |
| 504 request_context_getter_, shortcut_info_.best_badge_icon_url, |
| 505 base::Bind(&WebApkInstaller::OnGotBadgeIconMurmur2Hash, |
| 506 weak_ptr_factory_.GetWeakPtr(), true, primary_icon_hash)); |
| 507 } else { |
| 508 OnGotBadgeIconMurmur2Hash(false, primary_icon_hash, ""); |
| 509 } |
| 510 } |
| 511 |
| 512 void WebApkInstaller::OnGotBadgeIconMurmur2Hash( |
| 513 bool did_fetch_badge_icon, |
| 514 const std::string& primary_icon_hash, |
| 515 const std::string& badge_icon_hash) { |
| 516 // An empty hash indicates an error during hash calculation. |
| 517 if (did_fetch_badge_icon && badge_icon_hash.empty()) { |
| 518 OnResult(WebApkInstallResult::FAILURE); |
| 519 return; |
| 520 } |
| 521 |
| 522 // Maps icon URLs to Murmur2 hashes. |
| 478 std::map<std::string, std::string> icon_url_to_murmur2_hash; | 523 std::map<std::string, std::string> icon_url_to_murmur2_hash; |
| 479 for (const std::string& icon_url : shortcut_info_.icon_urls) { | 524 for (const std::string& icon_url : shortcut_info_.icon_urls) { |
| 480 if (icon_url != shortcut_info_.best_primary_icon_url.spec()) | 525 if (icon_url == shortcut_info_.best_primary_icon_url.spec()) |
| 526 icon_url_to_murmur2_hash[icon_url] = primary_icon_hash; |
| 527 else if (icon_url == shortcut_info_.best_badge_icon_url.spec()) |
| 528 icon_url_to_murmur2_hash[icon_url] = badge_icon_hash; |
| 529 else |
| 481 icon_url_to_murmur2_hash[icon_url] = ""; | 530 icon_url_to_murmur2_hash[icon_url] = ""; |
| 482 else | |
| 483 icon_url_to_murmur2_hash[icon_url] = icon_murmur2_hash; | |
| 484 } | 531 } |
| 485 | 532 |
| 486 base::PostTaskAndReplyWithResult( | 533 base::PostTaskAndReplyWithResult( |
| 487 GetBackgroundTaskRunner().get(), FROM_HERE, | 534 GetBackgroundTaskRunner().get(), FROM_HERE, |
| 488 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, shortcut_icon_, | 535 base::Bind(&BuildWebApkProtoInBackground, shortcut_info_, primary_icon_, |
| 489 icon_url_to_murmur2_hash, false /* is_manifest_stale */), | 536 badge_icon_, icon_url_to_murmur2_hash, |
| 537 false /* is_manifest_stale */), |
| 490 base::Bind(&WebApkInstaller::SendCreateWebApkRequest, | 538 base::Bind(&WebApkInstaller::SendCreateWebApkRequest, |
| 491 weak_ptr_factory_.GetWeakPtr())); | 539 weak_ptr_factory_.GetWeakPtr())); |
| 492 } | 540 } |
| 493 | 541 |
| 494 void WebApkInstaller::SendCreateWebApkRequest( | 542 void WebApkInstaller::SendCreateWebApkRequest( |
| 495 std::unique_ptr<webapk::WebApk> webapk) { | 543 std::unique_ptr<webapk::WebApk> webapk) { |
| 496 SendRequest(std::move(webapk), server_url_); | 544 SendRequest(std::move(webapk), server_url_); |
| 497 } | 545 } |
| 498 | 546 |
| 499 void WebApkInstaller::SendUpdateWebApkRequest( | 547 void WebApkInstaller::SendUpdateWebApkRequest( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 base::android::ScopedJavaLocalRef<jstring> java_file_path = | 656 base::android::ScopedJavaLocalRef<jstring> java_file_path = |
| 609 base::android::ConvertUTF8ToJavaString(env, file_path.value()); | 657 base::android::ConvertUTF8ToJavaString(env, file_path.value()); |
| 610 if (task_type_ == INSTALL) { | 658 if (task_type_ == INSTALL) { |
| 611 base::android::ScopedJavaLocalRef<jstring> java_package_name = | 659 base::android::ScopedJavaLocalRef<jstring> java_package_name = |
| 612 base::android::ConvertUTF8ToJavaString(env, webapk_package_); | 660 base::android::ConvertUTF8ToJavaString(env, webapk_package_); |
| 613 InstallDownloadedWebApk(env, java_file_path, java_package_name); | 661 InstallDownloadedWebApk(env, java_file_path, java_package_name); |
| 614 } else if (task_type_ == UPDATE) { | 662 } else if (task_type_ == UPDATE) { |
| 615 UpdateUsingDownloadedWebApk(env, java_file_path); | 663 UpdateUsingDownloadedWebApk(env, java_file_path); |
| 616 } | 664 } |
| 617 } | 665 } |
| OLD | NEW |