Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / public / renderer / resource_fetcher.h
blob4cb568977687dc97df63242150b103b1714e9310
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_
6 #define CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "content/common/content_export.h"
12 #include "third_party/WebKit/public/platform/WebURLRequest.h"
14 class GURL;
16 namespace base {
17 class TimeDelta;
20 namespace blink {
21 class WebFrame;
22 class WebURLResponse;
25 namespace content {
27 // Interface to download resources asynchronously.
28 class CONTENT_EXPORT ResourceFetcher {
29 public:
30 virtual ~ResourceFetcher() {}
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
34 // empty. |response| and |data| are both valid until the URLFetcher instance
35 // is destroyed.
36 typedef base::Callback<void(const blink::WebURLResponse& response,
37 const std::string& data)> Callback;
39 // Creates a ResourceFetcher for the specified resource. Caller takes
40 // ownership of the returned object. Deleting the ResourceFetcher will cancel
41 // the request, and the callback will never be run.
42 static ResourceFetcher* Create(const GURL& url);
44 // Set the corresponding parameters of the request. Must be called before
45 // Start. By default, requests are GETs with no body.
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;
51 // Starts the request using the specified frame. Calls |callback| when
52 // done.
53 virtual void Start(blink::WebFrame* frame,
54 blink::WebURLRequest::RequestContext request_context,
55 blink::WebURLRequest::FrameType frame_type,
56 const Callback& callback) = 0;
58 // Sets how long to wait for the server to reply. By default, there is no
59 // timeout. Must be called after a request is started.
60 virtual void SetTimeout(const base::TimeDelta& timeout) = 0;
63 } // namespace content
65 #endif // CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_