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_IMPL_H_
6 #define CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_IMPL_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 SetCachePolicy(blink::WebURLRequest::CachePolicy policy
) override
;
39 void SetLoaderOptions(const blink::WebURLLoaderOptions
& options
) override
;
40 void Start(blink::WebFrame
* frame
,
41 blink::WebURLRequest::RequestContext request_context
,
42 blink::WebURLRequest::FrameType frame_type
,
43 LoaderType loader_type
,
44 const Callback
& callback
) override
;
45 void SetTimeout(const base::TimeDelta
& timeout
) override
;
48 friend class ResourceFetcher
;
50 explicit ResourceFetcherImpl(const GURL
& url
);
52 virtual ~ResourceFetcherImpl();
54 // Callback for timer that limits how long we wait for the server. If this
55 // timer fires and the request hasn't completed, we kill the request.
58 // WebURLLoaderClientImpl methods:
59 void OnLoadComplete() override
;
60 void Cancel() override
;
62 scoped_ptr
<blink::WebURLLoader
> loader_
;
64 // Options to send to the loader.
65 blink::WebURLLoaderOptions options_
;
67 // Request to send. Released once Start() is called.
68 blink::WebURLRequest request_
;
70 // Callback when we're done.
73 // Limit how long to wait for the server.
74 base::OneShotTimer
<ResourceFetcherImpl
> timeout_timer_
;
76 DISALLOW_COPY_AND_ASSIGN(ResourceFetcherImpl
);
79 } // namespace content
81 #endif // CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_IMPL_H_