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

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

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.h
diff --git a/chrome/browser/android/webapk/webapk_icon_hasher.h b/chrome/browser/android/webapk/webapk_icon_hasher.h
index 8fb7e2ed0db288840b85f1554dde5a41bd2dfa6a..99aa0de774a6957804caecddf1b4f8a48b552833 100644
--- a/chrome/browser/android/webapk/webapk_icon_hasher.h
+++ b/chrome/browser/android/webapk/webapk_icon_hasher.h
@@ -10,8 +10,9 @@
#include "base/callback.h"
#include "base/macros.h"
-#include "base/time/time.h"
+#include "base/timer/timer.h"
#include "net/url_request/url_fetcher_delegate.h"
+#include "url/gurl.h"
namespace net {
class URLFetcher;
@@ -26,28 +27,46 @@ class WebApkIconHasher : public net::URLFetcherDelegate {
using Murmur2HashCallback =
base::Callback<void(const std::string& /* icon_murmur2_hash */)>;
- WebApkIconHasher();
- ~WebApkIconHasher() override;
-
- // Downloads |icon_url|. Calls |callback| with the Murmur2 hash of the
- // downloaded image. The hash is taken over the raw image bytes (no image
- // encoding/decoding beforehand). |callback| is called with an empty string if
- // the image cannot not be downloaded (e.g. 404 HTTP error code).
- void DownloadAndComputeMurmur2Hash(
+ WebApkIconHasher(
net::URLRequestContextGetter* request_context_getter,
const GURL& icon_url,
const Murmur2HashCallback& callback);
+ ~WebApkIconHasher() override;
+
+ // Downloads icon_url_. Calls callback_ with the Murmur2 hash of the
dominickn 2017/03/24 02:41:01 |icon_url_|, |callback_|
F 2017/03/27 20:37:09 Done.
+ // downloaded image. The hash is taken over the raw image bytes (no image
+ // encoding/decoding beforehand). callback_ is called with an empty string if
dominickn 2017/03/24 02:41:00 |callback_|
F 2017/03/27 20:37:08 Done.
+ // the image cannot not be downloaded in time (e.g. 404 HTTP error code).
+ void DownloadAndComputeMurmur2Hash();
private:
// net::URLFetcherDelegate:
void OnURLFetchComplete(const net::URLFetcher* source) override;
- // Fetches the image.
- std::unique_ptr<net::URLFetcher> url_fetcher_;
+ // Called if downloading the icon takes too long.
+ void OnDownloadTimedOut();
+
+ // For retrieving URLRequestContext.
+ net::URLRequestContextGetter* url_request_context_getter_;
+
+ // The icon URL.
+ GURL icon_url_;
// Called with the image hash.
Murmur2HashCallback callback_;
+ // Fetches the image.
dominickn 2017/03/24 02:41:01 This comment isn't needed
F 2017/03/27 20:37:09 Done.
+ std::unique_ptr<net::URLFetcher> url_fetcher_;
+
+ // Whether the download has completed or timed out.
+ bool is_download_complete_;
+
+ // Fails WebApkIconHasher if the download takes too long.
+ base::OneShotTimer download_timeout_timer_;
+
+ // Used to get |weak_ptr_|.
+ base::WeakPtrFactory<WebApkIconHasher> weak_ptr_factory_;
dominickn 2017/03/24 02:41:01 Instead of a weak_ptr_factory_ and is_download_co
F 2017/03/27 20:37:09 Done.
+
DISALLOW_COPY_AND_ASSIGN(WebApkIconHasher);
};

Powered by Google App Engine
This is Rietveld 408576698