Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: chrome/browser/android/webapk/webapk_installer.cc

Issue 2782313002: Add static method WebApkIconHasher::DownloadAndComputeMurmur2Hash (Closed)
Patch Set: Delete non-static download method` Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 task_type_ = INSTALL; 373 task_type_ = INSTALL;
374 374
375 // We need to take the hash of the bitmap at the icon URL prior to any 375 // 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 376 // transformations being applied to the bitmap (such as encoding/decoding
377 // the bitmap). The icon hash is used to determine whether the icon that 377 // 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 378 // the user sees matches the icon of a WebAPK that the WebAPK server
379 // generated for another user. (The icon can be dynamically generated.) 379 // generated for another user. (The icon can be dynamically generated.)
380 // 380 //
381 // We redownload the icon in order to take the Murmur2 hash. The redownload 381 // 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. 382 // should be fast because the icon should be in the HTTP cache.
383 DownloadAppIconAndComputeMurmur2Hash(); 383 WebApkIconHasher::DownloadAndComputeMurmur2Hash(
384 request_context_getter_, shortcut_info_.best_primary_icon_url,
385 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash,
386 weak_ptr_factory_.GetWeakPtr()));
384 } 387 }
385 388
386 void WebApkInstaller::UpdateAsync( 389 void WebApkInstaller::UpdateAsync(
387 const std::string& webapk_package, 390 const std::string& webapk_package,
388 int webapk_version, 391 int webapk_version,
389 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, 392 const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
390 bool is_manifest_stale, 393 bool is_manifest_stale,
391 const FinishCallback& finish_callback) { 394 const FinishCallback& finish_callback) {
392 webapk_package_ = webapk_package; 395 webapk_package_ = webapk_package;
393 webapk_version_ = webapk_version; 396 webapk_version_ = webapk_version;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 int version = 1; 445 int version = 1;
443 base::StringToInt(response->version(), &version); 446 base::StringToInt(response->version(), &version);
444 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version, 447 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version,
445 response->token()); 448 response->token());
446 return; 449 return;
447 } 450 }
448 451
449 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); 452 OnGotWebApkDownloadUrl(signed_download_url, response->package_name());
450 } 453 }
451 454
452 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() {
453 icon_hasher_.reset(new WebApkIconHasher(
454 request_context_getter_, shortcut_info_.best_primary_icon_url,
455 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash,
456 weak_ptr_factory_.GetWeakPtr())));
457 icon_hasher_->DownloadAndComputeMurmur2Hash();
458 }
459
460 void WebApkInstaller::OnGotIconMurmur2Hash( 455 void WebApkInstaller::OnGotIconMurmur2Hash(
461 const std::string& icon_murmur2_hash) { 456 const std::string& icon_murmur2_hash) {
462 icon_hasher_.reset();
463
464 // An empty hash indicates that |icon_hasher_| encountered an error. 457 // An empty hash indicates that |icon_hasher_| encountered an error.
465 if (icon_murmur2_hash.empty()) { 458 if (icon_murmur2_hash.empty()) {
466 OnResult(WebApkInstallResult::FAILURE); 459 OnResult(WebApkInstallResult::FAILURE);
467 return; 460 return;
468 } 461 }
469 462
470 std::map<std::string, std::string> icon_url_to_murmur2_hash; 463 std::map<std::string, std::string> icon_url_to_murmur2_hash;
471 for (const std::string& icon_url : shortcut_info_.icon_urls) { 464 for (const std::string& icon_url : shortcut_info_.icon_urls) {
472 if (icon_url != shortcut_info_.best_primary_icon_url.spec()) 465 if (icon_url != shortcut_info_.best_primary_icon_url.spec())
473 icon_url_to_murmur2_hash[icon_url] = ""; 466 icon_url_to_murmur2_hash[icon_url] = "";
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 base::android::ScopedJavaLocalRef<jstring> java_file_path = 593 base::android::ScopedJavaLocalRef<jstring> java_file_path =
601 base::android::ConvertUTF8ToJavaString(env, file_path.value()); 594 base::android::ConvertUTF8ToJavaString(env, file_path.value());
602 if (task_type_ == INSTALL) { 595 if (task_type_ == INSTALL) {
603 base::android::ScopedJavaLocalRef<jstring> java_package_name = 596 base::android::ScopedJavaLocalRef<jstring> java_package_name =
604 base::android::ConvertUTF8ToJavaString(env, webapk_package_); 597 base::android::ConvertUTF8ToJavaString(env, webapk_package_);
605 InstallDownloadedWebApk(env, java_file_path, java_package_name); 598 InstallDownloadedWebApk(env, java_file_path, java_package_name);
606 } else if (task_type_ == UPDATE) { 599 } else if (task_type_ == UPDATE) {
607 UpdateUsingDownloadedWebApk(env, java_file_path); 600 UpdateUsingDownloadedWebApk(env, java_file_path);
608 } 601 }
609 } 602 }
OLDNEW
« no previous file with comments | « chrome/browser/android/webapk/webapk_installer.h ('k') | chrome/browser/android/webapk/webapk_update_data_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698