OLD | NEW |
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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 // Creates a self-owned WebApkIconHasher instance. The instance downloads | 28 // Creates a self-owned WebApkIconHasher instance. The instance downloads |
29 // |icon_url| and calls |callback| with the Murmur2 hash of the downloaded | 29 // |icon_url| and calls |callback| with the Murmur2 hash of the downloaded |
30 // image. The hash is taken over the raw image bytes (no image | 30 // image. The hash is taken over the raw image bytes (no image |
31 // encoding/decoding beforehand). |callback| is called with an empty string if | 31 // encoding/decoding beforehand). |callback| is called with an empty string if |
32 // the image cannot not be downloaded in time (e.g. 404 HTTP error code). | 32 // the image cannot not be downloaded in time (e.g. 404 HTTP error code). |
33 static void DownloadAndComputeMurmur2Hash( | 33 static void DownloadAndComputeMurmur2Hash( |
34 net::URLRequestContextGetter* request_context_getter, | 34 net::URLRequestContextGetter* request_context_getter, |
35 const GURL& icon_url, | 35 const GURL& icon_url, |
36 const Murmur2HashCallback& callback); | 36 const Murmur2HashCallback& callback); |
37 | 37 |
38 private: | 38 static void DownloadAndComputeMurmur2HashWithTimeout( |
39 WebApkIconHasher( | |
40 net::URLRequestContextGetter* request_context_getter, | 39 net::URLRequestContextGetter* request_context_getter, |
41 const GURL& icon_url, | 40 const GURL& icon_url, |
| 41 int timeout_ms, |
42 const Murmur2HashCallback& callback); | 42 const Murmur2HashCallback& callback); |
| 43 |
| 44 private: |
| 45 WebApkIconHasher(net::URLRequestContextGetter* request_context_getter, |
| 46 const GURL& icon_url, |
| 47 int timeout_ms, |
| 48 const Murmur2HashCallback& callback); |
43 ~WebApkIconHasher() override; | 49 ~WebApkIconHasher() override; |
44 | 50 |
45 // net::URLFetcherDelegate: | 51 // net::URLFetcherDelegate: |
46 void OnURLFetchComplete(const net::URLFetcher* source) override; | 52 void OnURLFetchComplete(const net::URLFetcher* source) override; |
47 | 53 |
48 // Called if downloading the icon takes too long. | 54 // Called if downloading the icon takes too long. |
49 void OnDownloadTimedOut(); | 55 void OnDownloadTimedOut(); |
50 | 56 |
51 // Calls |callback_| with |icon_murmur2_hash|. Also deletes the instance. | 57 // Calls |callback_| with |icon_murmur2_hash|. Also deletes the instance. |
52 void RunCallback(const std::string& icon_murmur2_hash); | 58 void RunCallback(const std::string& icon_murmur2_hash); |
53 | 59 |
54 // Called with the image hash. | 60 // Called with the image hash. |
55 Murmur2HashCallback callback_; | 61 Murmur2HashCallback callback_; |
56 | 62 |
57 std::unique_ptr<net::URLFetcher> url_fetcher_; | 63 std::unique_ptr<net::URLFetcher> url_fetcher_; |
58 | 64 |
59 // Fails WebApkIconHasher if the download takes too long. | 65 // Fails WebApkIconHasher if the download takes too long. |
60 base::OneShotTimer download_timeout_timer_; | 66 base::OneShotTimer download_timeout_timer_; |
61 | 67 |
62 DISALLOW_COPY_AND_ASSIGN(WebApkIconHasher); | 68 DISALLOW_COPY_AND_ASSIGN(WebApkIconHasher); |
63 }; | 69 }; |
64 | 70 |
65 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_ICON_HASHER_H_ | 71 #endif // CHROME_BROWSER_ANDROID_WEBAPK_WEBAPK_ICON_HASHER_H_ |
OLD | NEW |