blob: 29c8bd5c4dfdaec11c7fc86192b02dee3e875c63 [file] [log] [blame]
[email protected]78376af2012-02-07 06:56:281// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]71e1ac42011-03-23 00:46:534
[email protected]8368a0a32012-06-15 07:51:465// This file contains URLFetcher, a wrapper around URLRequest that handles
initial.commit09911bf2008-07-26 23:55:296// low-level details like thread safety, ref counting, and incremental buffer
7// reading. This is useful for callers who simply want to get the data from a
8// URL and don't care about all the nitty-gritty details.
[email protected]0b1ad312010-10-22 01:01:389//
10// NOTE(willchan): Only one "IO" thread is supported for URLFetcher. This is a
11// temporary situation. We will work on allowing support for multiple "io"
12// threads per process.
initial.commit09911bf2008-07-26 23:55:2913
[email protected]8368a0a32012-06-15 07:51:4614#ifndef NET_URL_REQUEST_URL_FETCHER_IMPL_H_
15#define NET_URL_REQUEST_URL_FETCHER_IMPL_H_
initial.commit09911bf2008-07-26 23:55:2916
[email protected]fe552402014-05-21 01:58:2917#include <string>
18
[email protected]d2106bc912012-04-02 13:47:0119#include "base/basictypes.h"
[email protected]7cc6e5632011-10-25 17:56:1220#include "base/compiler_specific.h"
[email protected]8368a0a32012-06-15 07:51:4621#include "net/base/net_export.h"
22#include "net/url_request/url_fetcher.h"
initial.commit09911bf2008-07-26 23:55:2923
[email protected]83822c32012-06-13 04:21:3224namespace net {
[email protected]d2106bc912012-04-02 13:47:0125class URLFetcherCore;
26class URLFetcherDelegate;
[email protected]56ed95a2012-05-25 01:11:1527class URLFetcherFactory;
[email protected]56ed95a2012-05-25 01:11:1528
[email protected]8f2d8bdd2012-06-19 23:44:0529class NET_EXPORT_PRIVATE URLFetcherImpl : public URLFetcher {
initial.commit09911bf2008-07-26 23:55:2930 public:
initial.commit09911bf2008-07-26 23:55:2931 // |url| is the URL to send the request to.
32 // |request_type| is the type of request to make.
33 // |d| the object that will receive the callback on fetch completion.
[email protected]7b419b82011-10-27 04:23:4634 URLFetcherImpl(const GURL& url,
35 RequestType request_type,
[email protected]8368a0a32012-06-15 07:51:4636 URLFetcherDelegate* d);
dchengb03027d2014-10-21 12:00:2037 ~URLFetcherImpl() override;
[email protected]b6c911a2009-04-21 21:58:4538
[email protected]8368a0a32012-06-15 07:51:4639 // URLFetcher implementation:
dchengb03027d2014-10-21 12:00:2040 void SetUploadData(const std::string& upload_content_type,
41 const std::string& upload_content) override;
42 void SetUploadFilePath(
[email protected]e81652c2013-03-02 21:46:1543 const std::string& upload_content_type,
44 const base::FilePath& file_path,
[email protected]7b0db732013-05-02 09:42:0645 uint64 range_offset,
46 uint64 range_length,
mostynbba063d6032014-10-09 11:01:1347 scoped_refptr<base::TaskRunner> file_task_runner) override;
dchengb03027d2014-10-21 12:00:2048 void SetChunkedUpload(const std::string& upload_content_type) override;
49 void AppendChunkToUpload(const std::string& data,
50 bool is_last_chunk) override;
51 void SetLoadFlags(int load_flags) override;
52 int GetLoadFlags() const override;
53 void SetReferrer(const std::string& referrer) override;
54 void SetReferrerPolicy(URLRequest::ReferrerPolicy referrer_policy) override;
55 void SetExtraRequestHeaders(
mostynbba063d6032014-10-09 11:01:1356 const std::string& extra_request_headers) override;
dchengb03027d2014-10-21 12:00:2057 void AddExtraRequestHeader(const std::string& header_line) override;
58 void SetRequestContext(
mostynbba063d6032014-10-09 11:01:1359 URLRequestContextGetter* request_context_getter) override;
dchengb03027d2014-10-21 12:00:2060 void SetFirstPartyForCookies(const GURL& first_party_for_cookies) override;
61 void SetURLRequestUserData(
[email protected]7c3bb862012-05-22 00:14:4162 const void* key,
mostynbba063d6032014-10-09 11:01:1363 const CreateDataCallback& create_data_callback) override;
dchengb03027d2014-10-21 12:00:2064 void SetStopOnRedirect(bool stop_on_redirect) override;
65 void SetAutomaticallyRetryOn5xx(bool retry) override;
66 void SetMaxRetriesOn5xx(int max_retries) override;
67 int GetMaxRetriesOn5xx() const override;
68 base::TimeDelta GetBackoffDelay() const override;
69 void SetAutomaticallyRetryOnNetworkChanges(int max_retries) override;
70 void SaveResponseToFileAtPath(
[email protected]6cdfd7f2013-02-08 20:40:1571 const base::FilePath& file_path,
mostynbba063d6032014-10-09 11:01:1372 scoped_refptr<base::SequencedTaskRunner> file_task_runner) override;
dchengb03027d2014-10-21 12:00:2073 void SaveResponseToTemporaryFile(
mostynbba063d6032014-10-09 11:01:1374 scoped_refptr<base::SequencedTaskRunner> file_task_runner) override;
dchengb03027d2014-10-21 12:00:2075 void SaveResponseWithWriter(
mostynbba063d6032014-10-09 11:01:1376 scoped_ptr<URLFetcherResponseWriter> response_writer) override;
dchengb03027d2014-10-21 12:00:2077 HttpResponseHeaders* GetResponseHeaders() const override;
78 HostPortPair GetSocketAddress() const override;
79 bool WasFetchedViaProxy() const override;
80 void Start() override;
81 const GURL& GetOriginalURL() const override;
82 const GURL& GetURL() const override;
83 const URLRequestStatus& GetStatus() const override;
84 int GetResponseCode() const override;
85 const ResponseCookies& GetCookies() const override;
86 void ReceivedContentWasMalformed() override;
87 bool GetResponseAsString(std::string* out_response_string) const override;
88 bool GetResponseAsFilePath(bool take_ownership,
89 base::FilePath* out_response_path) const override;
initial.commit09911bf2008-07-26 23:55:2990
[email protected]0b1ad312010-10-22 01:01:3891 static void CancelAll();
92
[email protected]8368a0a32012-06-15 07:51:4693 static void SetEnableInterceptionForTests(bool enabled);
[email protected]73c77e42013-01-31 11:37:4094 static void SetIgnoreCertificateRequests(bool ignored);
[email protected]b6c911a2009-04-21 21:58:4595
[email protected]8368a0a32012-06-15 07:51:4696 // TODO(akalin): Make these private again once URLFetcher::Create()
97 // is in net/.
[email protected]b3aced02011-05-23 12:40:4398
[email protected]8368a0a32012-06-15 07:51:4699 static URLFetcherFactory* factory();
[email protected]91c06e5e2011-07-29 16:48:19100
101 // Sets the factory used by the static method Create to create a URLFetcher.
102 // URLFetcher does not take ownership of |factory|. A value of NULL results
103 // in a URLFetcher being created directly.
104 //
105 // NOTE: for safety, this should only be used through ScopedURLFetcherFactory!
[email protected]8368a0a32012-06-15 07:51:46106 static void set_factory(URLFetcherFactory* factory);
[email protected]91c06e5e2011-07-29 16:48:19107
[email protected]8368a0a32012-06-15 07:51:46108 protected:
109 // Returns the delegate.
110 URLFetcherDelegate* delegate() const;
111
112 private:
113 friend class URLFetcherTest;
114
115 // Only used by URLFetcherTest, returns the number of URLFetcher::Core objects
116 // actively running.
117 static int GetNumFetcherCores();
118
119 const scoped_refptr<URLFetcherCore> core_;
initial.commit09911bf2008-07-26 23:55:29120
[email protected]7b419b82011-10-27 04:23:46121 DISALLOW_COPY_AND_ASSIGN(URLFetcherImpl);
initial.commit09911bf2008-07-26 23:55:29122};
123
[email protected]8368a0a32012-06-15 07:51:46124} // namespace net
125
126#endif // NET_URL_REQUEST_URL_FETCHER_IMPL_H_