[email protected] | 78376af | 2012-02-07 06:56:28 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | 71e1ac4 | 2011-03-23 00:46:53 | [diff] [blame] | 4 | |
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 5 | // This file contains URLFetcher, a wrapper around net::URLRequest that handles |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | // 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] | 0b1ad31 | 2010-10-22 01:01:38 | [diff] [blame] | 9 | // |
| 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.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | |
[email protected] | 7b419b8 | 2011-10-27 04:23:46 | [diff] [blame] | 14 | #ifndef CONTENT_COMMON_NET_URL_FETCHER_IMPL_H_ |
| 15 | #define CONTENT_COMMON_NET_URL_FETCHER_IMPL_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 16 | #pragma once |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 17 | |
[email protected] | d2106bc91 | 2012-04-02 13:47:01 | [diff] [blame] | 18 | #include "base/basictypes.h" |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 19 | #include "base/compiler_specific.h" |
[email protected] | d2106bc91 | 2012-04-02 13:47:01 | [diff] [blame] | 20 | #include "content/common/content_export.h" |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 21 | #include "content/public/common/url_fetcher.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | |
[email protected] | beba03b3 | 2011-10-26 23:39:59 | [diff] [blame] | 23 | namespace content { |
[email protected] | d2106bc91 | 2012-04-02 13:47:01 | [diff] [blame] | 24 | class URLFetcherCore; |
| 25 | class URLFetcherDelegate; |
[email protected] | beba03b3 | 2011-10-26 23:39:59 | [diff] [blame] | 26 | class URLFetcherFactory; |
[email protected] | d2106bc91 | 2012-04-02 13:47:01 | [diff] [blame] | 27 | } // namespace content |
[email protected] | beba03b3 | 2011-10-26 23:39:59 | [diff] [blame] | 28 | |
[email protected] | d2106bc91 | 2012-04-02 13:47:01 | [diff] [blame] | 29 | class CONTENT_EXPORT URLFetcherImpl : public content::URLFetcher { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 30 | public: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 31 | // |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] | 7b419b8 | 2011-10-27 04:23:46 | [diff] [blame] | 34 | URLFetcherImpl(const GURL& url, |
| 35 | RequestType request_type, |
| 36 | content::URLFetcherDelegate* d); |
| 37 | virtual ~URLFetcherImpl(); |
[email protected] | b6c911a | 2009-04-21 21:58:45 | [diff] [blame] | 38 | |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 39 | // content::URLFetcher implementation: |
| 40 | virtual void SetUploadData(const std::string& upload_content_type, |
| 41 | const std::string& upload_content) OVERRIDE; |
| 42 | virtual void SetChunkedUpload( |
| 43 | const std::string& upload_content_type) OVERRIDE; |
| 44 | virtual void AppendChunkToUpload(const std::string& data, |
| 45 | bool is_last_chunk) OVERRIDE; |
| 46 | virtual void SetLoadFlags(int load_flags) OVERRIDE; |
| 47 | virtual int GetLoadFlags() const OVERRIDE; |
| 48 | virtual void SetReferrer(const std::string& referrer) OVERRIDE; |
| 49 | virtual void SetExtraRequestHeaders( |
| 50 | const std::string& extra_request_headers) OVERRIDE; |
[email protected] | 78376af | 2012-02-07 06:56:28 | [diff] [blame] | 51 | virtual void AddExtraRequestHeader(const std::string& header_line) OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 52 | virtual void GetExtraRequestHeaders( |
[email protected] | d2106bc91 | 2012-04-02 13:47:01 | [diff] [blame] | 53 | net::HttpRequestHeaders* headers) const OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 54 | virtual void SetRequestContext( |
| 55 | net::URLRequestContextGetter* request_context_getter) OVERRIDE; |
[email protected] | 7c3bb86 | 2012-05-22 00:14:41 | [diff] [blame^] | 56 | virtual void SetFirstPartyForCookies( |
| 57 | const GURL& first_party_for_cookies) OVERRIDE; |
| 58 | virtual void SetURLRequestUserData( |
| 59 | const void* key, |
| 60 | const CreateDataCallback& create_data_callback) OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 61 | virtual void SetAutomaticallyRetryOn5xx(bool retry) OVERRIDE; |
| 62 | virtual void SetMaxRetries(int max_retries) OVERRIDE; |
| 63 | virtual int GetMaxRetries() const OVERRIDE; |
| 64 | virtual base::TimeDelta GetBackoffDelay() const OVERRIDE; |
[email protected] | 32c8201 | 2012-03-09 23:25:44 | [diff] [blame] | 65 | virtual void SaveResponseToFileAtPath( |
| 66 | const FilePath& file_path, |
| 67 | scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 68 | virtual void SaveResponseToTemporaryFile( |
| 69 | scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) OVERRIDE; |
| 70 | virtual net::HttpResponseHeaders* GetResponseHeaders() const OVERRIDE; |
| 71 | virtual net::HostPortPair GetSocketAddress() const OVERRIDE; |
| 72 | virtual bool WasFetchedViaProxy() const OVERRIDE; |
| 73 | virtual void Start() OVERRIDE; |
[email protected] | 5645d5b | 2011-10-28 00:40:48 | [diff] [blame] | 74 | virtual const GURL& GetOriginalURL() const OVERRIDE; |
| 75 | virtual const GURL& GetURL() const OVERRIDE; |
[email protected] | 7cc6e563 | 2011-10-25 17:56:12 | [diff] [blame] | 76 | virtual const net::URLRequestStatus& GetStatus() const OVERRIDE; |
| 77 | virtual int GetResponseCode() const OVERRIDE; |
| 78 | virtual const net::ResponseCookies& GetCookies() const OVERRIDE; |
| 79 | virtual bool FileErrorOccurred( |
| 80 | base::PlatformFileError* out_error_code) const OVERRIDE; |
| 81 | virtual void ReceivedContentWasMalformed() OVERRIDE; |
| 82 | virtual bool GetResponseAsString( |
| 83 | std::string* out_response_string) const OVERRIDE; |
| 84 | virtual bool GetResponseAsFilePath( |
| 85 | bool take_ownership, |
| 86 | FilePath* out_response_path) const OVERRIDE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 87 | |
[email protected] | 0b1ad31 | 2010-10-22 01:01:38 | [diff] [blame] | 88 | static void CancelAll(); |
| 89 | |
[email protected] | b6c911a | 2009-04-21 21:58:45 | [diff] [blame] | 90 | protected: |
| 91 | // Returns the delegate. |
[email protected] | c530c85 | 2011-10-24 18:18:34 | [diff] [blame] | 92 | content::URLFetcherDelegate* delegate() const; |
[email protected] | b6c911a | 2009-04-21 21:58:45 | [diff] [blame] | 93 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 94 | private: |
[email protected] | 91c06e5e | 2011-07-29 16:48:19 | [diff] [blame] | 95 | friend class ScopedURLFetcherFactory; |
[email protected] | b3aced0 | 2011-05-23 12:40:43 | [diff] [blame] | 96 | friend class TestURLFetcher; |
[email protected] | 91c06e5e | 2011-07-29 16:48:19 | [diff] [blame] | 97 | friend class URLFetcherTest; |
[email protected] | b3aced0 | 2011-05-23 12:40:43 | [diff] [blame] | 98 | |
[email protected] | 1790319 | 2011-03-08 22:27:10 | [diff] [blame] | 99 | // Only used by URLFetcherTest, returns the number of URLFetcher::Core objects |
| 100 | // actively running. |
| 101 | static int GetNumFetcherCores(); |
| 102 | |
[email protected] | beba03b3 | 2011-10-26 23:39:59 | [diff] [blame] | 103 | static content::URLFetcherFactory* factory(); |
[email protected] | 91c06e5e | 2011-07-29 16:48:19 | [diff] [blame] | 104 | |
| 105 | // Sets the factory used by the static method Create to create a URLFetcher. |
| 106 | // URLFetcher does not take ownership of |factory|. A value of NULL results |
| 107 | // in a URLFetcher being created directly. |
| 108 | // |
| 109 | // NOTE: for safety, this should only be used through ScopedURLFetcherFactory! |
[email protected] | beba03b3 | 2011-10-26 23:39:59 | [diff] [blame] | 110 | static void set_factory(content::URLFetcherFactory* factory); |
[email protected] | 91c06e5e | 2011-07-29 16:48:19 | [diff] [blame] | 111 | |
[email protected] | d2106bc91 | 2012-04-02 13:47:01 | [diff] [blame] | 112 | const scoped_refptr<content::URLFetcherCore> core_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 113 | |
[email protected] | 7b419b8 | 2011-10-27 04:23:46 | [diff] [blame] | 114 | DISALLOW_COPY_AND_ASSIGN(URLFetcherImpl); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 115 | }; |
| 116 | |
[email protected] | 7b419b8 | 2011-10-27 04:23:46 | [diff] [blame] | 117 | #endif // CONTENT_COMMON_NET_URL_FETCHER_IMPL_H_ |