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

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

Issue 2782313002: Add static method WebApkIconHasher::DownloadAndComputeMurmur2Hash (Closed)
Patch Set: Delete non-static download method` 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 2a1a4133f1ef3ee1ce3ccbb7bea2b35a9fb421be..51a44322d5aa32bc25c50ad83de301f598dfe48b 100644
--- a/chrome/browser/android/webapk/webapk_icon_hasher.cc
+++ b/chrome/browser/android/webapk/webapk_icon_hasher.cc
@@ -34,52 +34,57 @@ std::string ComputeMurmur2Hash(const std::string& raw_image_data) {
} // anonymous namespace
-WebApkIconHasher::WebApkIconHasher(
- net::URLRequestContextGetter* url_request_context_getter,
+// static
+void WebApkIconHasher::DownloadAndComputeMurmur2Hash(
+ net::URLRequestContextGetter* request_context_getter,
const GURL& icon_url,
- const Murmur2HashCallback& callback)
- : url_request_context_getter_(url_request_context_getter),
- icon_url_(icon_url),
- callback_(callback) {}
-
-WebApkIconHasher::~WebApkIconHasher() {}
-
-void WebApkIconHasher::DownloadAndComputeMurmur2Hash() {
- if (!icon_url_.is_valid()) {
+ const Murmur2HashCallback& callback) {
+ if (!icon_url.is_valid()) {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback_, ""));
+ base::Bind(callback, ""));
return;
}
- if (icon_url_.SchemeIs(url::kDataScheme)) {
+ 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;
}
+ // The icon hasher will delete itself when it is done.
+ new WebApkIconHasher(request_context_getter, icon_url, callback);
+}
+
+WebApkIconHasher::WebApkIconHasher(
+ net::URLRequestContextGetter* url_request_context_getter,
+ const GURL& icon_url,
+ const Murmur2HashCallback& callback)
+ : callback_(callback) {
download_timeout_timer_.Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kDownloadTimeoutInMilliseconds),
base::Bind(&WebApkIconHasher::OnDownloadTimedOut,
base::Unretained(this)));
- url_fetcher_ = net::URLFetcher::Create(icon_url_, net::URLFetcher::GET, this);
- url_fetcher_->SetRequestContext(url_request_context_getter_);
+ url_fetcher_ = net::URLFetcher::Create(icon_url, net::URLFetcher::GET, this);
+ url_fetcher_->SetRequestContext(url_request_context_getter);
url_fetcher_->Start();
}
+WebApkIconHasher::~WebApkIconHasher() {}
+
void WebApkIconHasher::OnURLFetchComplete(const net::URLFetcher* source) {
download_timeout_timer_.Stop();
if (!source->GetStatus().is_success() ||
source->GetResponseCode() != net::HTTP_OK) {
- callback_.Run("");
+ RunCallback("");
return;
}
@@ -89,12 +94,16 @@ void WebApkIconHasher::OnURLFetchComplete(const net::URLFetcher* source) {
// browser process is a security bug.
std::string raw_image_data;
source->GetResponseAsString(&raw_image_data);
- callback_.Run(ComputeMurmur2Hash(raw_image_data));
+ RunCallback(ComputeMurmur2Hash(raw_image_data));
}
void WebApkIconHasher::OnDownloadTimedOut() {
url_fetcher_.reset();
- base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback_, ""));
+ RunCallback("");
+}
+
+void WebApkIconHasher::RunCallback(const std::string& icon_murmur2_hash) {
+ callback_.Run(icon_murmur2_hash);
+ delete this;
}
« no previous file with comments | « chrome/browser/android/webapk/webapk_icon_hasher.h ('k') | chrome/browser/android/webapk/webapk_icon_hasher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698