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

Unified Diff: chrome/browser/android/webapk/webapk_icon_hasher.cc

Issue 2771793003: Move timeout timer into WebApkIconHasher (Closed)
Patch Set: Move timeout timer into WebApkIconHasher Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/webapk/webapk_icon_hasher.cc
diff --git a/chrome/browser/android/webapk/webapk_icon_hasher.cc b/chrome/browser/android/webapk/webapk_icon_hasher.cc
index c685e08496ba5099e3fe8ac550af9eca5317ab21..1b0321e9cdd2d11a6ef09a28b15d195f7811ec87 100644
--- a/chrome/browser/android/webapk/webapk_icon_hasher.cc
+++ b/chrome/browser/android/webapk/webapk_icon_hasher.cc
@@ -32,33 +32,55 @@ std::string ComputeMurmur2Hash(const std::string& raw_image_data) {
} // anonymous namespace
-WebApkIconHasher::WebApkIconHasher() {}
+WebApkIconHasher::WebApkIconHasher(
+ net::URLRequestContextGetter* url_request_context_getter,
+ const GURL& icon_url,
+ const Murmur2HashCallback& callback)
+ : url_request_context_getter_(url_request_context_getter),
+ icon_url_(icon_url),
+ callback_(callback),
+ is_download_complete_(false),
+ weak_ptr_factory_(this) {}
WebApkIconHasher::~WebApkIconHasher() {}
-void WebApkIconHasher::DownloadAndComputeMurmur2Hash(
- net::URLRequestContextGetter* request_context_getter,
- const GURL& icon_url,
- const Murmur2HashCallback& callback) {
- if (icon_url.SchemeIs(url::kDataScheme)) {
+void WebApkIconHasher::DownloadAndComputeMurmur2Hash() {
+ if (!icon_url_.is_valid()) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::Bind(callback_, ""));
+ return;
+ }
+
+ if (icon_url_.SchemeIs(url::kDataScheme)) {
std::string mime_type, char_set, data;
std::string hash;
- if (net::DataURL::Parse(icon_url, &mime_type, &char_set, &data) &&
+ if (net::DataURL::Parse(icon_url_, &mime_type, &char_set, &data) &&
!data.empty()) {
hash = ComputeMurmur2Hash(data);
}
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback, hash));
+ base::Bind(callback_, hash));
return;
}
- callback_ = callback;
- url_fetcher_ = net::URLFetcher::Create(icon_url, net::URLFetcher::GET, this);
- url_fetcher_->SetRequestContext(request_context_getter);
+ download_timeout_timer_.Start(
+ FROM_HERE, base::TimeDelta::FromMilliseconds(60000),
dominickn 2017/03/24 02:41:00 Can you put this constant in the anonymous namespa
F 2017/03/27 20:37:08 Done.
+ base::Bind(&WebApkIconHasher::OnDownloadTimedOut,
+ weak_ptr_factory_.GetWeakPtr()));
+
+ url_fetcher_ = net::URLFetcher::Create(icon_url_, net::URLFetcher::GET, this);
+ url_fetcher_->SetRequestContext(url_request_context_getter_);
url_fetcher_->Start();
}
void WebApkIconHasher::OnURLFetchComplete(const net::URLFetcher* source) {
+ if (is_download_complete_)
+ return;
+
+ is_download_complete_ = true;
+
+ download_timeout_timer_.Stop();
dominickn 2017/03/24 02:41:00 Stop the timer first. Remove the extra newline bet
F 2017/03/27 20:37:08 Done.
+
if (!source->GetStatus().is_success() ||
source->GetResponseCode() != net::HTTP_OK) {
callback_.Run("");
@@ -73,3 +95,13 @@ void WebApkIconHasher::OnURLFetchComplete(const net::URLFetcher* source) {
source->GetResponseAsString(&raw_image_data);
callback_.Run(ComputeMurmur2Hash(raw_image_data));
}
+
+void WebApkIconHasher::OnDownloadTimedOut() {
+ if (is_download_complete_)
+ return;
+
+ is_download_complete_ = true;
+
dominickn 2017/03/24 02:41:00 Remove the extra newline
F 2017/03/27 20:37:08 Done.
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::Bind(callback_, ""));
+}

Powered by Google App Engine
This is Rietveld 408576698