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

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

Issue 2771793003: Move timeout timer into WebApkIconHasher (Closed)
Patch Set: Remove weakptr and use unretained 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 base::StringToInt(response->version(), &version); 443 base::StringToInt(response->version(), &version);
444 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version, 444 InstallOrUpdateWebApkFromGooglePlay(response->package_name(), version,
445 response->token()); 445 response->token());
446 return; 446 return;
447 } 447 }
448 448
449 OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); 449 OnGotWebApkDownloadUrl(signed_download_url, response->package_name());
450 } 450 }
451 451
452 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() { 452 void WebApkInstaller::DownloadAppIconAndComputeMurmur2Hash() {
453 // Safeguard. WebApkIconHasher crashes if asked to fetch an invalid URL. 453 icon_hasher_.reset(new WebApkIconHasher(
454 if (!shortcut_info_.best_primary_icon_url.is_valid()) {
455 OnResult(WebApkInstallResult::FAILURE);
456 return;
457 }
458
459 timer_.Start(
460 FROM_HERE, base::TimeDelta::FromMilliseconds(download_timeout_ms_),
461 base::Bind(&WebApkInstaller::OnResult, weak_ptr_factory_.GetWeakPtr(),
462 WebApkInstallResult::FAILURE));
463
464 icon_hasher_.reset(new WebApkIconHasher());
465 icon_hasher_->DownloadAndComputeMurmur2Hash(
466 request_context_getter_, shortcut_info_.best_primary_icon_url, 454 request_context_getter_, shortcut_info_.best_primary_icon_url,
467 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash, 455 base::Bind(&WebApkInstaller::OnGotIconMurmur2Hash,
468 weak_ptr_factory_.GetWeakPtr())); 456 weak_ptr_factory_.GetWeakPtr())));
457 icon_hasher_->DownloadAndComputeMurmur2Hash();
469 } 458 }
470 459
471 void WebApkInstaller::OnGotIconMurmur2Hash( 460 void WebApkInstaller::OnGotIconMurmur2Hash(
472 const std::string& icon_murmur2_hash) { 461 const std::string& icon_murmur2_hash) {
473 timer_.Stop();
474 icon_hasher_.reset(); 462 icon_hasher_.reset();
475 463
476 // An empty hash indicates that |icon_hasher_| encountered an error. 464 // An empty hash indicates that |icon_hasher_| encountered an error.
477 if (icon_murmur2_hash.empty()) { 465 if (icon_murmur2_hash.empty()) {
478 OnResult(WebApkInstallResult::FAILURE); 466 OnResult(WebApkInstallResult::FAILURE);
479 return; 467 return;
480 } 468 }
481 469
482 std::map<std::string, std::string> icon_url_to_murmur2_hash; 470 std::map<std::string, std::string> icon_url_to_murmur2_hash;
483 for (const std::string& icon_url : shortcut_info_.icon_urls) { 471 for (const std::string& icon_url : shortcut_info_.icon_urls) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 base::android::ScopedJavaLocalRef<jstring> java_file_path = 600 base::android::ScopedJavaLocalRef<jstring> java_file_path =
613 base::android::ConvertUTF8ToJavaString(env, file_path.value()); 601 base::android::ConvertUTF8ToJavaString(env, file_path.value());
614 if (task_type_ == INSTALL) { 602 if (task_type_ == INSTALL) {
615 base::android::ScopedJavaLocalRef<jstring> java_package_name = 603 base::android::ScopedJavaLocalRef<jstring> java_package_name =
616 base::android::ConvertUTF8ToJavaString(env, webapk_package_); 604 base::android::ConvertUTF8ToJavaString(env, webapk_package_);
617 InstallDownloadedWebApk(env, java_file_path, java_package_name); 605 InstallDownloadedWebApk(env, java_file_path, java_package_name);
618 } else if (task_type_ == UPDATE) { 606 } else if (task_type_ == UPDATE) {
619 UpdateUsingDownloadedWebApk(env, java_file_path); 607 UpdateUsingDownloadedWebApk(env, java_file_path);
620 } 608 }
621 } 609 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698