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"
19 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h"
30 class ResourceFetcherImpl
: public ResourceFetcher
,
31 public WebURLLoaderClientImpl
{
33 // ResourceFetcher implementation:
34 void SetMethod(const std::string
& method
) override
;
35 void SetBody(const std::string
& body
) override
;
36 void SetHeader(const std::string
& header
, const std::string
& value
) override
;
37 void SetSkipServiceWorker(bool skip_service_worker
) override
;
38 void SetLoaderOptions(const blink::WebURLLoaderOptions
& options
) override
;
39 void Start(blink::WebFrame
* frame
,
40 blink::WebURLRequest::RequestContext request_context
,
41 blink::WebURLRequest::FrameType frame_type
,
42 LoaderType loader_type
,
43 const Callback
& callback
) override
;
44 void SetTimeout(const base::TimeDelta
& timeout
) override
;
47 friend class ResourceFetcher
;
49 explicit ResourceFetcherImpl(const GURL
& url
);
51 virtual ~ResourceFetcherImpl();
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.
57 // WebURLLoaderClientImpl methods:
58 void OnLoadComplete() override
;
59 void Cancel() override
;
61 scoped_ptr
<blink::WebURLLoader
> loader_
;
63 // Options to send to the loader.
64 blink::WebURLLoaderOptions options_
;
66 // Request to send. Released once Start() is called.
67 blink::WebURLRequest request_
;
69 // Callback when we're done.
72 // Limit how long to wait for the server.
73 base::OneShotTimer
<ResourceFetcherImpl
> timeout_timer_
;
75 DISALLOW_COPY_AND_ASSIGN(ResourceFetcherImpl
);
78 } // namespace content
80 #endif // CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_H_