OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_ |
6 #define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "components/offline_pages/core/prefetch/prefetch_types.h" |
11 #include "net/url_request/url_fetcher_delegate.h" | 12 #include "net/url_request/url_fetcher_delegate.h" |
12 | 13 |
13 class GURL; | 14 class GURL; |
14 namespace net { | 15 namespace net { |
15 class URLRequestContextGetter; | 16 class URLRequestContextGetter; |
16 } | 17 } |
17 | 18 |
18 namespace offline_prefetch { | 19 namespace offline_pages { |
19 | 20 |
20 class PrefetchRequestFetcher : public net::URLFetcherDelegate { | 21 class PrefetchRequestFetcher : public net::URLFetcherDelegate { |
21 public: | 22 public: |
22 enum class Status { | 23 using FinishedCallback = base::Callback<void(PrefetchRequestStatus status, |
23 // Request completed successfully. | 24 const std::string& data)>; |
24 SUCCESS, | |
25 // Request failed due to to local network problem, unrelated to server load | |
26 // levels. The caller will simply reschedule the retry in the next available | |
27 // WiFi window after 15 minutes have passed. | |
28 SHOULD_RETRY_WITHOUT_BACKOFF, | |
29 // Request failed probably related to transient server problems. The caller | |
30 // will reschedule the retry with backoff included. | |
31 SHOULD_RETRY_WITH_BACKOFF, | |
32 // Request failed with error indicating that the server no longer knows how | |
33 // to service a request. The caller will prevent network requests for the | |
34 // period of 1 day. | |
35 SHOULD_SUSPEND | |
36 }; | |
37 | 25 |
38 using FinishedCallback = | 26 PrefetchRequestFetcher(const GURL& url, |
39 base::Callback<void(Status status, const std::string& data)>; | 27 const std::string& message, |
40 | 28 net::URLRequestContextGetter* request_context_getter, |
41 PrefetchRequestFetcher( | 29 const FinishedCallback& callback); |
42 const GURL& url, | |
43 const std::string& message, | |
44 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | |
45 const FinishedCallback& callback); | |
46 ~PrefetchRequestFetcher() override; | 30 ~PrefetchRequestFetcher() override; |
47 | 31 |
48 // URLFetcherDelegate implementation. | 32 // URLFetcherDelegate implementation. |
49 void OnURLFetchComplete(const net::URLFetcher* source) override; | 33 void OnURLFetchComplete(const net::URLFetcher* source) override; |
50 | 34 |
51 private: | 35 private: |
52 Status ParseResponse(const net::URLFetcher* source, std::string* data); | 36 PrefetchRequestStatus ParseResponse(const net::URLFetcher* source, |
| 37 std::string* data); |
53 | 38 |
54 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 39 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
55 std::unique_ptr<net::URLFetcher> url_fetcher_; | 40 std::unique_ptr<net::URLFetcher> url_fetcher_; |
56 FinishedCallback callback_; | 41 FinishedCallback callback_; |
57 | 42 |
58 DISALLOW_COPY_AND_ASSIGN(PrefetchRequestFetcher); | 43 DISALLOW_COPY_AND_ASSIGN(PrefetchRequestFetcher); |
59 }; | 44 }; |
60 | 45 |
61 } // namespace offline_prefetch | 46 } // namespace offline_pages |
62 | 47 |
63 #endif // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_ | 48 #endif // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_ |
OLD | NEW |