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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_
6 #define CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/timer/timer.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"
18 #include "third_party/WebKit/public/platform/WebURLResponse.h"
30 class ResourceFetcherImpl
: public ResourceFetcher
,
31 public WebURLLoaderClientImpl
{
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::RequestContext request_context
,
40 blink::WebURLRequest::FrameType frame_type
,
41 LoaderType loader_type
,
42 const Callback
& callback
) OVERRIDE
;
43 virtual void SetTimeout(const base::TimeDelta
& timeout
) OVERRIDE
;
46 friend class ResourceFetcher
;
48 explicit ResourceFetcherImpl(const GURL
& url
);
50 virtual ~ResourceFetcherImpl();
52 // Callback for timer that limits how long we wait for the server. If this
53 // timer fires and the request hasn't completed, we kill the request.
56 // WebURLLoaderClientImpl methods:
57 virtual void OnLoadComplete() OVERRIDE
;
58 virtual void Cancel() OVERRIDE
;
60 scoped_ptr
<blink::WebURLLoader
> loader_
;
62 // Request to send. Released once Start() is called.
63 blink::WebURLRequest request_
;
65 // Callback when we're done.
68 // Limit how long to wait for the server.
69 base::OneShotTimer
<ResourceFetcherImpl
> timeout_timer_
;
71 DISALLOW_COPY_AND_ASSIGN(ResourceFetcherImpl
);
74 } // namespace content
76 #endif // CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_