blob: d643a94580fca8a1a6c513000dbd5de397cb4956 [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]d2106bc912012-04-02 13:47:0117#include "base/basictypes.h"
[email protected]7cc6e5632011-10-25 17:56:1218#include "base/compiler_specific.h"
[email protected]8368a0a32012-06-15 07:51:4619#include "net/base/net_export.h"
20#include "net/url_request/url_fetcher.h"
initial.commit09911bf2008-07-26 23:55:2921
[email protected]83822c32012-06-13 04:21:3222namespace net {
[email protected]d2106bc912012-04-02 13:47:0123class URLFetcherCore;
24class URLFetcherDelegate;
[email protected]56ed95a2012-05-25 01:11:1525class URLFetcherFactory;
[email protected]56ed95a2012-05-25 01:11:1526
[email protected]8f2d8bdd2012-06-19 23:44:0527class NET_EXPORT_PRIVATE URLFetcherImpl : public URLFetcher {
initial.commit09911bf2008-07-26 23:55:2928 public:
initial.commit09911bf2008-07-26 23:55:2929 // |url| is the URL to send the request to.
30 // |request_type| is the type of request to make.
31 // |d| the object that will receive the callback on fetch completion.
[email protected]7b419b82011-10-27 04:23:4632 URLFetcherImpl(const GURL& url,
33 RequestType request_type,
[email protected]8368a0a32012-06-15 07:51:4634 URLFetcherDelegate* d);
[email protected]7b419b82011-10-27 04:23:4635 virtual ~URLFetcherImpl();
[email protected]b6c911a2009-04-21 21:58:4536
[email protected]8368a0a32012-06-15 07:51:4637 // URLFetcher implementation:
[email protected]7cc6e5632011-10-25 17:56:1238 virtual void SetUploadData(const std::string& upload_content_type,
39 const std::string& upload_content) OVERRIDE;
[email protected]e81652c2013-03-02 21:46:1540 virtual void SetUploadFilePath(
41 const std::string& upload_content_type,
42 const base::FilePath& file_path,
[email protected]7b0db732013-05-02 09:42:0643 uint64 range_offset,
44 uint64 range_length,
[email protected]e81652c2013-03-02 21:46:1545 scoped_refptr<base::TaskRunner> file_task_runner) OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1246 virtual void SetChunkedUpload(
47 const std::string& upload_content_type) OVERRIDE;
48 virtual void AppendChunkToUpload(const std::string& data,
49 bool is_last_chunk) OVERRIDE;
50 virtual void SetLoadFlags(int load_flags) OVERRIDE;
51 virtual int GetLoadFlags() const OVERRIDE;
52 virtual void SetReferrer(const std::string& referrer) OVERRIDE;
53 virtual void SetExtraRequestHeaders(
54 const std::string& extra_request_headers) OVERRIDE;
[email protected]78376af2012-02-07 06:56:2855 virtual void AddExtraRequestHeader(const std::string& header_line) OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1256 virtual void GetExtraRequestHeaders(
[email protected]8368a0a32012-06-15 07:51:4657 HttpRequestHeaders* headers) const OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1258 virtual void SetRequestContext(
[email protected]8368a0a32012-06-15 07:51:4659 URLRequestContextGetter* request_context_getter) OVERRIDE;
[email protected]7c3bb862012-05-22 00:14:4160 virtual void SetFirstPartyForCookies(
61 const GURL& first_party_for_cookies) OVERRIDE;
62 virtual void SetURLRequestUserData(
63 const void* key,
64 const CreateDataCallback& create_data_callback) OVERRIDE;
[email protected]df117142012-06-07 05:43:4465 virtual void SetStopOnRedirect(bool stop_on_redirect) OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1266 virtual void SetAutomaticallyRetryOn5xx(bool retry) OVERRIDE;
[email protected]7af985a2012-12-14 22:40:4267 virtual void SetMaxRetriesOn5xx(int max_retries) OVERRIDE;
68 virtual int GetMaxRetriesOn5xx() const OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1269 virtual base::TimeDelta GetBackoffDelay() const OVERRIDE;
[email protected]7af985a2012-12-14 22:40:4270 virtual void SetAutomaticallyRetryOnNetworkChanges(int max_retries) OVERRIDE;
[email protected]32c82012012-03-09 23:25:4471 virtual void SaveResponseToFileAtPath(
[email protected]6cdfd7f2013-02-08 20:40:1572 const base::FilePath& file_path,
[email protected]0ec0ef732012-09-19 13:48:0673 scoped_refptr<base::TaskRunner> file_task_runner) OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1274 virtual void SaveResponseToTemporaryFile(
[email protected]0ec0ef732012-09-19 13:48:0675 scoped_refptr<base::TaskRunner> file_task_runner) OVERRIDE;
[email protected]8368a0a32012-06-15 07:51:4676 virtual HttpResponseHeaders* GetResponseHeaders() const OVERRIDE;
77 virtual HostPortPair GetSocketAddress() const OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1278 virtual bool WasFetchedViaProxy() const OVERRIDE;
79 virtual void Start() OVERRIDE;
[email protected]5645d5b2011-10-28 00:40:4880 virtual const GURL& GetOriginalURL() const OVERRIDE;
81 virtual const GURL& GetURL() const OVERRIDE;
[email protected]8368a0a32012-06-15 07:51:4682 virtual const URLRequestStatus& GetStatus() const OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1283 virtual int GetResponseCode() const OVERRIDE;
[email protected]8368a0a32012-06-15 07:51:4684 virtual const ResponseCookies& GetCookies() const OVERRIDE;
[email protected]1dd4060e2013-03-13 13:15:1385 virtual bool FileErrorOccurred(int* out_error_code) const OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1286 virtual void ReceivedContentWasMalformed() OVERRIDE;
87 virtual bool GetResponseAsString(
88 std::string* out_response_string) const OVERRIDE;
89 virtual bool GetResponseAsFilePath(
90 bool take_ownership,
[email protected]6cdfd7f2013-02-08 20:40:1591 base::FilePath* out_response_path) const OVERRIDE;
initial.commit09911bf2008-07-26 23:55:2992
[email protected]0b1ad312010-10-22 01:01:3893 static void CancelAll();
94
[email protected]8368a0a32012-06-15 07:51:4695 static void SetEnableInterceptionForTests(bool enabled);
[email protected]73c77e42013-01-31 11:37:4096 static void SetIgnoreCertificateRequests(bool ignored);
[email protected]b6c911a2009-04-21 21:58:4597
[email protected]8368a0a32012-06-15 07:51:4698 // TODO(akalin): Make these private again once URLFetcher::Create()
99 // is in net/.
[email protected]b3aced02011-05-23 12:40:43100
[email protected]8368a0a32012-06-15 07:51:46101 static URLFetcherFactory* factory();
[email protected]91c06e5e2011-07-29 16:48:19102
103 // Sets the factory used by the static method Create to create a URLFetcher.
104 // URLFetcher does not take ownership of |factory|. A value of NULL results
105 // in a URLFetcher being created directly.
106 //
107 // NOTE: for safety, this should only be used through ScopedURLFetcherFactory!
[email protected]8368a0a32012-06-15 07:51:46108 static void set_factory(URLFetcherFactory* factory);
[email protected]91c06e5e2011-07-29 16:48:19109
[email protected]8368a0a32012-06-15 07:51:46110 protected:
111 // Returns the delegate.
112 URLFetcherDelegate* delegate() const;
113
114 private:
115 friend class URLFetcherTest;
116
117 // Only used by URLFetcherTest, returns the number of URLFetcher::Core objects
118 // actively running.
119 static int GetNumFetcherCores();
120
121 const scoped_refptr<URLFetcherCore> core_;
initial.commit09911bf2008-07-26 23:55:29122
[email protected]7b419b82011-10-27 04:23:46123 DISALLOW_COPY_AND_ASSIGN(URLFetcherImpl);
initial.commit09911bf2008-07-26 23:55:29124};
125
[email protected]8368a0a32012-06-15 07:51:46126} // namespace net
127
128#endif // NET_URL_REQUEST_URL_FETCHER_IMPL_H_