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

Side by Side 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 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 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_ICON_HASHER_H_ 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_ICON_HASHER_H_
6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_ICON_HASHER_H_ 6 #define CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_ICON_HASHER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/time/time.h" 13 #include "base/timer/timer.h"
14 #include "net/url_request/url_fetcher_delegate.h" 14 #include "net/url_request/url_fetcher_delegate.h"
15 #include "url/gurl.h"
15 16
16 namespace net { 17 namespace net {
17 class URLFetcher; 18 class URLFetcher;
18 class URLRequestContextGetter; 19 class URLRequestContextGetter;
19 } 20 }
20 21
21 class GURL; 22 class GURL;
dominickn 2017/03/24 02:41:01 If you are #including GURL, you can remove this.
F 2017/03/27 20:37:09 Done.
22 23
23 // Downloads an icon and takes a Murmur2 hash of the downloaded image. 24 // Downloads an icon and takes a Murmur2 hash of the downloaded image.
24 class WebApkIconHasher : public net::URLFetcherDelegate { 25 class WebApkIconHasher : public net::URLFetcherDelegate {
25 public: 26 public:
26 using Murmur2HashCallback = 27 using Murmur2HashCallback =
27 base::Callback<void(const std::string& /* icon_murmur2_hash */)>; 28 base::Callback<void(const std::string& /* icon_murmur2_hash */)>;
28 29
29 WebApkIconHasher(); 30 WebApkIconHasher(
30 ~WebApkIconHasher() override;
31
32 // Downloads |icon_url|. Calls |callback| with the Murmur2 hash of the
33 // downloaded image. The hash is taken over the raw image bytes (no image
34 // encoding/decoding beforehand). |callback| is called with an empty string if
35 // the image cannot not be downloaded (e.g. 404 HTTP error code).
36 void DownloadAndComputeMurmur2Hash(
37 net::URLRequestContextGetter* request_context_getter, 31 net::URLRequestContextGetter* request_context_getter,
38 const GURL& icon_url, 32 const GURL& icon_url,
39 const Murmur2HashCallback& callback); 33 const Murmur2HashCallback& callback);
34 ~WebApkIconHasher() override;
35
36 // 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.
37 // downloaded image. The hash is taken over the raw image bytes (no image
38 // 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.
39 // the image cannot not be downloaded in time (e.g. 404 HTTP error code).
40 void DownloadAndComputeMurmur2Hash();
40 41
41 private: 42 private:
42 // net::URLFetcherDelegate: 43 // net::URLFetcherDelegate:
43 void OnURLFetchComplete(const net::URLFetcher* source) override; 44 void OnURLFetchComplete(const net::URLFetcher* source) override;
44 45
45 // Fetches the image. 46 // Called if downloading the icon takes too long.
46 std::unique_ptr<net::URLFetcher> url_fetcher_; 47 void OnDownloadTimedOut();
48
49 // For retrieving URLRequestContext.
50 net::URLRequestContextGetter* url_request_context_getter_;
51
52 // The icon URL.
53 GURL icon_url_;
47 54
48 // Called with the image hash. 55 // Called with the image hash.
49 Murmur2HashCallback callback_; 56 Murmur2HashCallback callback_;
50 57
58 // Fetches the image.
dominickn 2017/03/24 02:41:01 This comment isn't needed
F 2017/03/27 20:37:09 Done.
59 std::unique_ptr<net::URLFetcher> url_fetcher_;
60
61 // Whether the download has completed or timed out.
62 bool is_download_complete_;
63
64 // Fails WebApkIconHasher if the download takes too long.
65 base::OneShotTimer download_timeout_timer_;
66
67 // Used to get |weak_ptr_|.
68 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.
69
51 DISALLOW_COPY_AND_ASSIGN(WebApkIconHasher); 70 DISALLOW_COPY_AND_ASSIGN(WebApkIconHasher);
52 }; 71 };
53 72
54 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_ICON_HASHER_H_ 73 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_ICON_HASHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698