OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_IMPL_H_ |
6 #define CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_IMPL_H_ | 6 #define CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_IMPL_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/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
15 #include "content/public/renderer/resource_fetcher.h" | 15 #include "content/public/renderer/resource_fetcher.h" |
16 #include "content/renderer/fetchers/web_url_loader_client_impl.h" | |
17 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 16 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
18 #include "third_party/WebKit/public/platform/WebURLResponse.h" | |
19 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" | |
20 | 17 |
21 class GURL; | 18 class GURL; |
22 | 19 |
23 namespace blink { | 20 namespace blink { |
24 class WebFrame; | 21 class WebFrame; |
25 class WebURLLoader; | 22 class WebURLLoader; |
26 enum class WebCachePolicy; | |
27 } | 23 } |
28 | 24 |
29 namespace content { | 25 namespace content { |
30 | 26 |
31 class ResourceFetcherImpl : public ResourceFetcher, | 27 class ResourceFetcherImpl : public ResourceFetcher { |
32 public WebURLLoaderClientImpl { | |
33 public: | 28 public: |
34 // ResourceFetcher implementation: | 29 // ResourceFetcher implementation: |
35 void SetMethod(const std::string& method) override; | 30 void SetMethod(const std::string& method) override; |
36 void SetBody(const std::string& body) override; | 31 void SetBody(const std::string& body) override; |
37 void SetHeader(const std::string& header, const std::string& value) override; | 32 void SetHeader(const std::string& header, const std::string& value) override; |
38 void SetSkipServiceWorker( | |
39 blink::WebURLRequest::SkipServiceWorker skip_service_worker) override; | |
40 void SetCachePolicy(blink::WebCachePolicy policy) override; | |
41 void SetLoaderOptions(const blink::WebURLLoaderOptions& options) override; | |
42 void Start(blink::WebFrame* frame, | 33 void Start(blink::WebFrame* frame, |
43 blink::WebURLRequest::RequestContext request_context, | 34 blink::WebURLRequest::RequestContext request_context, |
44 blink::WebURLRequest::FrameType frame_type, | 35 blink::WebURLRequest::FrameType frame_type, |
45 LoaderType loader_type, | |
46 const Callback& callback) override; | 36 const Callback& callback) override; |
47 void SetTimeout(const base::TimeDelta& timeout) override; | 37 void SetTimeout(const base::TimeDelta& timeout) override; |
48 | 38 |
49 private: | 39 private: |
50 friend class ResourceFetcher; | 40 friend class ResourceFetcher; |
51 | 41 |
| 42 class ClientImpl; |
| 43 |
52 explicit ResourceFetcherImpl(const GURL& url); | 44 explicit ResourceFetcherImpl(const GURL& url); |
53 | 45 |
54 ~ResourceFetcherImpl() override; | 46 ~ResourceFetcherImpl() override; |
55 | 47 |
56 // Callback for timer that limits how long we wait for the server. If this | 48 void OnLoadComplete(); |
57 // timer fires and the request hasn't completed, we kill the request. | |
58 void TimeoutFired(); | |
59 | |
60 // WebURLLoaderClientImpl methods: | |
61 void OnLoadComplete() override; | |
62 void Cancel() override; | 49 void Cancel() override; |
63 | 50 |
64 std::unique_ptr<blink::WebURLLoader> loader_; | 51 std::unique_ptr<blink::WebURLLoader> loader_; |
65 | 52 std::unique_ptr<ClientImpl> client_; |
66 // Options to send to the loader. | |
67 blink::WebURLLoaderOptions options_; | |
68 | 53 |
69 // Request to send. | 54 // Request to send. |
70 blink::WebURLRequest request_; | 55 blink::WebURLRequest request_; |
71 | 56 |
72 // Callback when we're done. | |
73 Callback callback_; | |
74 | |
75 // Limit how long to wait for the server. | 57 // Limit how long to wait for the server. |
76 base::OneShotTimer timeout_timer_; | 58 base::OneShotTimer timeout_timer_; |
77 | 59 |
78 DISALLOW_COPY_AND_ASSIGN(ResourceFetcherImpl); | 60 DISALLOW_COPY_AND_ASSIGN(ResourceFetcherImpl); |
79 }; | 61 }; |
80 | 62 |
81 } // namespace content | 63 } // namespace content |
82 | 64 |
83 #endif // CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_IMPL_H_ | 65 #endif // CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_IMPL_H_ |
OLD | NEW |