summaryrefslogtreecommitdiffstats
path: root/content/renderer/fetchers/resource_fetcher_impl.h
blob: e260b0981720c339a9c6c307f421e19261930e9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_IMPL_H_
#define CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_IMPL_H_

#include <string>

#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/timer/timer.h"
#include "content/public/renderer/resource_fetcher.h"
#include "content/renderer/fetchers/web_url_loader_client_impl.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h"
#include "third_party/WebKit/public/web/WebURLLoaderOptions.h"

class GURL;

namespace blink {
class WebFrame;
class WebURLLoader;
}

namespace content {

class ResourceFetcherImpl : public ResourceFetcher,
                            public WebURLLoaderClientImpl {
 public:
  // ResourceFetcher implementation:
  void SetMethod(const std::string& method) override;
  void SetBody(const std::string& body) override;
  void SetHeader(const std::string& header, const std::string& value) override;
  void SetSkipServiceWorker(bool skip_service_worker) override;
  void SetCachePolicy(blink::WebURLRequest::CachePolicy policy) override;
  void SetLoaderOptions(const blink::WebURLLoaderOptions& options) override;
  void Start(blink::WebFrame* frame,
             blink::WebURLRequest::RequestContext request_context,
             blink::WebURLRequest::FrameType frame_type,
             LoaderType loader_type,
             const Callback& callback) override;
  void SetTimeout(const base::TimeDelta& timeout) override;

 private:
  friend class ResourceFetcher;

  explicit ResourceFetcherImpl(const GURL& url);

  ~ResourceFetcherImpl() override;

  // Callback for timer that limits how long we wait for the server.  If this
  // timer fires and the request hasn't completed, we kill the request.
  void TimeoutFired();

  // WebURLLoaderClientImpl methods:
  void OnLoadComplete() override;
  void Cancel() override;

  scoped_ptr<blink::WebURLLoader> loader_;

  // Options to send to the loader.
  blink::WebURLLoaderOptions options_;

  // Request to send.  Released once Start() is called.
  blink::WebURLRequest request_;

  // Callback when we're done.
  Callback callback_;

  // Limit how long to wait for the server.
  base::OneShotTimer timeout_timer_;

  DISALLOW_COPY_AND_ASSIGN(ResourceFetcherImpl);
};

}  // namespace content

#endif  // CONTENT_RENDERER_FETCHERS_RESOURCE_FETCHER_IMPL_H_