OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_PUBLIC_RENDERER_RESOURCE_FETCHER_H_ | 5 #ifndef CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_ |
6 #define CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_ | 6 #define CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 public: | 29 public: |
30 virtual ~ResourceFetcher() {} | 30 virtual ~ResourceFetcher() {} |
31 | 31 |
32 // This will be called asynchronously after the URL has been fetched, | 32 // This will be called asynchronously after the URL has been fetched, |
33 // successfully or not. If there is a failure, response and data will both be | 33 // successfully or not. If there is a failure, response and data will both be |
34 // empty. |response| and |data| are both valid until the URLFetcher instance | 34 // empty. |response| and |data| are both valid until the URLFetcher instance |
35 // is destroyed. | 35 // is destroyed. |
36 typedef base::Callback<void(const blink::WebURLResponse& response, | 36 typedef base::Callback<void(const blink::WebURLResponse& response, |
37 const std::string& data)> Callback; | 37 const std::string& data)> Callback; |
38 | 38 |
39 // Creates a ResourceFetcher and starts fetching the specified resource. | 39 // Creates a ResourceFetcher for the specified resource. Caller takes |
40 // Caller takes ownership of the returned object. Deleting the | 40 // ownership of the returned object. Deleting the ResourceFetcher will cancel |
41 // ResourceFetcher will cancel the request, and the callback will never be | 41 // the request, and the callback will never be run. |
42 // run. | 42 static ResourceFetcher* Create(const GURL& url); |
43 static ResourceFetcher* Create(const GURL& url, | 43 |
44 blink::WebFrame* frame, | 44 // Set the corresponding parameters of the request. Must be called before |
45 blink::WebURLRequest::TargetType target_type, | 45 // Start. By default, requests are GETs with no body. |
46 const Callback& callback); | 46 virtual void SetMethod(const std::string& method) = 0; |
| 47 virtual void SetBody(const std::string& body) = 0; |
| 48 virtual void SetHeader(const std::string& header, |
| 49 const std::string& value) = 0; |
| 50 |
| 51 // Starts the request using the specified frame. Calls |callback| when |
| 52 // done. |
| 53 virtual void Start(blink::WebFrame* frame, |
| 54 blink::WebURLRequest::TargetType target_type, |
| 55 const Callback& callback) = 0; |
47 | 56 |
48 // Sets how long to wait for the server to reply. By default, there is no | 57 // Sets how long to wait for the server to reply. By default, there is no |
49 // timeout. | 58 // timeout. Must be called after a request is started. |
50 virtual void SetTimeout(const base::TimeDelta& timeout) = 0; | 59 virtual void SetTimeout(const base::TimeDelta& timeout) = 0; |
51 }; | 60 }; |
52 | 61 |
53 } // namespace content | 62 } // namespace content |
54 | 63 |
55 #endif // CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_ | 64 #endif // CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_ |
OLD | NEW |