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_H_ | 5 #ifndef CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_ |
6 #define CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_ | 6 #define CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 class WebURLLoader; | 24 class WebURLLoader; |
25 struct WebURLError; | 25 struct WebURLError; |
26 } | 26 } |
27 | 27 |
28 namespace content { | 28 namespace content { |
29 | 29 |
30 class ResourceFetcherImpl : public ResourceFetcher, | 30 class ResourceFetcherImpl : public ResourceFetcher, |
31 public blink::WebURLLoaderClient { | 31 public blink::WebURLLoaderClient { |
32 public: | 32 public: |
33 // ResourceFetcher implementation: | 33 // ResourceFetcher implementation: |
| 34 virtual void SetMethod(const std::string& method) OVERRIDE; |
| 35 virtual void SetBody(const std::string& body) OVERRIDE; |
| 36 virtual void SetHeader(const std::string& header, |
| 37 const std::string& value) OVERRIDE; |
| 38 virtual void Start(blink::WebFrame* frame, |
| 39 blink::WebURLRequest::TargetType target_type, |
| 40 const Callback& callback) OVERRIDE; |
34 virtual void SetTimeout(const base::TimeDelta& timeout) OVERRIDE; | 41 virtual void SetTimeout(const base::TimeDelta& timeout) OVERRIDE; |
35 | 42 |
36 private: | 43 private: |
37 friend class ResourceFetcher; | 44 friend class ResourceFetcher; |
38 | 45 |
39 ResourceFetcherImpl( | 46 explicit ResourceFetcherImpl(const GURL& url); |
40 const GURL& url, blink::WebFrame* frame, | |
41 blink::WebURLRequest::TargetType target_type, | |
42 const Callback& callback); | |
43 | 47 |
44 virtual ~ResourceFetcherImpl(); | 48 virtual ~ResourceFetcherImpl(); |
45 | 49 |
46 // Start the actual download. | |
47 void Start(const GURL& url, blink::WebFrame* frame, | |
48 blink::WebURLRequest::TargetType target_type); | |
49 | |
50 void RunCallback(const blink::WebURLResponse& response, | 50 void RunCallback(const blink::WebURLResponse& response, |
51 const std::string& data); | 51 const std::string& data); |
52 | 52 |
53 // Callback for timer that limits how long we wait for the server. If this | 53 // Callback for timer that limits how long we wait for the server. If this |
54 // timer fires and the request hasn't completed, we kill the request. | 54 // timer fires and the request hasn't completed, we kill the request. |
55 void TimeoutFired(); | 55 void TimeoutFired(); |
56 | 56 |
57 // WebURLLoaderClient methods: | 57 // WebURLLoaderClient methods: |
58 virtual void willSendRequest( | 58 virtual void willSendRequest( |
59 blink::WebURLLoader* loader, blink::WebURLRequest& new_request, | 59 blink::WebURLLoader* loader, blink::WebURLRequest& new_request, |
60 const blink::WebURLResponse& redirect_response); | 60 const blink::WebURLResponse& redirect_response); |
61 virtual void didSendData( | 61 virtual void didSendData( |
62 blink::WebURLLoader* loader, unsigned long long bytes_sent, | 62 blink::WebURLLoader* loader, unsigned long long bytes_sent, |
63 unsigned long long total_bytes_to_be_sent); | 63 unsigned long long total_bytes_to_be_sent); |
64 virtual void didReceiveResponse( | 64 virtual void didReceiveResponse( |
65 blink::WebURLLoader* loader, const blink::WebURLResponse& response); | 65 blink::WebURLLoader* loader, const blink::WebURLResponse& response); |
66 virtual void didReceiveCachedMetadata( | 66 virtual void didReceiveCachedMetadata( |
67 blink::WebURLLoader* loader, const char* data, int data_length); | 67 blink::WebURLLoader* loader, const char* data, int data_length); |
68 | 68 |
69 virtual void didReceiveData( | 69 virtual void didReceiveData( |
70 blink::WebURLLoader* loader, const char* data, int data_length, | 70 blink::WebURLLoader* loader, const char* data, int data_length, |
71 int encoded_data_length); | 71 int encoded_data_length); |
72 virtual void didFinishLoading( | 72 virtual void didFinishLoading( |
73 blink::WebURLLoader* loader, double finishTime); | 73 blink::WebURLLoader* loader, double finishTime); |
74 virtual void didFail( | 74 virtual void didFail( |
75 blink::WebURLLoader* loader, const blink::WebURLError& error); | 75 blink::WebURLLoader* loader, const blink::WebURLError& error); |
76 | 76 |
77 scoped_ptr<blink::WebURLLoader> loader_; | 77 scoped_ptr<blink::WebURLLoader> loader_; |
78 | 78 |
| 79 // Request to send. Released once Start() is called. |
| 80 blink::WebURLRequest request_; |
| 81 |
79 // Set to true once the request is complete. | 82 // Set to true once the request is complete. |
80 bool completed_; | 83 bool completed_; |
81 | 84 |
82 // Buffer to hold the content from the server. | 85 // Buffer to hold the content from the server. |
83 std::string data_; | 86 std::string data_; |
84 | 87 |
85 // A copy of the original resource response. | 88 // A copy of the original resource response. |
86 blink::WebURLResponse response_; | 89 blink::WebURLResponse response_; |
87 | 90 |
88 // Callback when we're done. | 91 // Callback when we're done. |
89 Callback callback_; | 92 Callback callback_; |
90 | 93 |
91 // Buffer to hold metadata from the cache. | 94 // Buffer to hold metadata from the cache. |
92 std::string metadata_; | 95 std::string metadata_; |
93 | 96 |
94 // Limit how long to wait for the server. | 97 // Limit how long to wait for the server. |
95 base::OneShotTimer<ResourceFetcherImpl> timeout_timer_; | 98 base::OneShotTimer<ResourceFetcherImpl> timeout_timer_; |
96 | 99 |
97 DISALLOW_COPY_AND_ASSIGN(ResourceFetcherImpl); | 100 DISALLOW_COPY_AND_ASSIGN(ResourceFetcherImpl); |
98 }; | 101 }; |
99 | 102 |
100 } // namespace content | 103 } // namespace content |
101 | 104 |
102 #endif // CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_ | 105 #endif // CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_ |
OLD | NEW |