| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 // This file contains URLFetcher, a wrapper around net::URLRequest that handles | |
| 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. | |
| 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. | |
| 13 | |
| 14 #ifndef CONTENT_COMMON_NET_URL_FETCHER_H_ | |
| 15 #define CONTENT_COMMON_NET_URL_FETCHER_H_ | |
| 16 #pragma once | |
| 17 | |
| 18 #include "base/compiler_specific.h" | |
| 19 #include "base/message_loop.h" | |
| 20 #include "base/time.h" | |
| 21 #include "content/public/common/url_fetcher.h" | |
| 22 | |
| 23 namespace content { | |
| 24 class URLFetcherFactory; | |
| 25 } | |
| 26 | |
| 27 class CONTENT_EXPORT URLFetcher : public content::URLFetcher{ | |
| 28 public: | |
| 29 // |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. | |
| 32 URLFetcher(const GURL& url, | |
| 33 RequestType request_type, | |
| 34 content::URLFetcherDelegate* d); | |
| 35 virtual ~URLFetcher(); | |
| 36 | |
| 37 // content::URLFetcher implementation: | |
| 38 virtual void SetUploadData(const std::string& upload_content_type, | |
| 39 const std::string& upload_content) OVERRIDE; | |
| 40 virtual void SetChunkedUpload( | |
| 41 const std::string& upload_content_type) OVERRIDE; | |
| 42 virtual void AppendChunkToUpload(const std::string& data, | |
| 43 bool is_last_chunk) OVERRIDE; | |
| 44 virtual void SetLoadFlags(int load_flags) OVERRIDE; | |
| 45 virtual int GetLoadFlags() const OVERRIDE; | |
| 46 virtual void SetReferrer(const std::string& referrer) OVERRIDE; | |
| 47 virtual void SetExtraRequestHeaders( | |
| 48 const std::string& extra_request_headers) OVERRIDE; | |
| 49 virtual void GetExtraRequestHeaders( | |
| 50 net::HttpRequestHeaders* headers) OVERRIDE; | |
| 51 virtual void SetRequestContext( | |
| 52 net::URLRequestContextGetter* request_context_getter) OVERRIDE; | |
| 53 virtual void SetAutomaticallyRetryOn5xx(bool retry) OVERRIDE; | |
| 54 virtual void SetMaxRetries(int max_retries) OVERRIDE; | |
| 55 virtual int GetMaxRetries() const OVERRIDE; | |
| 56 virtual base::TimeDelta GetBackoffDelay() const OVERRIDE; | |
| 57 virtual void SaveResponseToTemporaryFile( | |
| 58 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) OVERRIDE; | |
| 59 virtual net::HttpResponseHeaders* GetResponseHeaders() const OVERRIDE; | |
| 60 virtual net::HostPortPair GetSocketAddress() const OVERRIDE; | |
| 61 virtual bool WasFetchedViaProxy() const OVERRIDE; | |
| 62 virtual void Start() OVERRIDE; | |
| 63 virtual void StartWithRequestContextGetter( | |
| 64 net::URLRequestContextGetter* request_context_getter) OVERRIDE; | |
| 65 virtual const GURL& GetOriginalUrl() const OVERRIDE; | |
| 66 virtual const GURL& GetUrl() const OVERRIDE; | |
| 67 virtual const net::URLRequestStatus& GetStatus() const OVERRIDE; | |
| 68 virtual int GetResponseCode() const OVERRIDE; | |
| 69 virtual const net::ResponseCookies& GetCookies() const OVERRIDE; | |
| 70 virtual bool FileErrorOccurred( | |
| 71 base::PlatformFileError* out_error_code) const OVERRIDE; | |
| 72 virtual void ReceivedContentWasMalformed() OVERRIDE; | |
| 73 virtual bool GetResponseAsString( | |
| 74 std::string* out_response_string) const OVERRIDE; | |
| 75 virtual bool GetResponseAsFilePath( | |
| 76 bool take_ownership, | |
| 77 FilePath* out_response_path) const OVERRIDE; | |
| 78 | |
| 79 static void CancelAll(); | |
| 80 | |
| 81 protected: | |
| 82 // How should the response be stored? | |
| 83 enum ResponseDestinationType { | |
| 84 STRING, // Default: In a std::string | |
| 85 TEMP_FILE // Write to a temp file | |
| 86 }; | |
| 87 | |
| 88 // Returns the delegate. | |
| 89 content::URLFetcherDelegate* delegate() const; | |
| 90 | |
| 91 // Used by tests. | |
| 92 const std::string& upload_data() const; | |
| 93 | |
| 94 // Used by tests. | |
| 95 void set_was_fetched_via_proxy(bool flag); | |
| 96 | |
| 97 // Used by tests. | |
| 98 void set_response_headers(scoped_refptr<net::HttpResponseHeaders> headers); | |
| 99 | |
| 100 private: | |
| 101 friend class ScopedURLFetcherFactory; | |
| 102 friend class TestURLFetcher; | |
| 103 friend class URLFetcherTest; | |
| 104 | |
| 105 // Only used by URLFetcherTest, returns the number of URLFetcher::Core objects | |
| 106 // actively running. | |
| 107 static int GetNumFetcherCores(); | |
| 108 | |
| 109 static content::URLFetcherFactory* factory(); | |
| 110 | |
| 111 // Sets the factory used by the static method Create to create a URLFetcher. | |
| 112 // URLFetcher does not take ownership of |factory|. A value of NULL results | |
| 113 // in a URLFetcher being created directly. | |
| 114 // | |
| 115 // NOTE: for safety, this should only be used through ScopedURLFetcherFactory! | |
| 116 static void set_factory(content::URLFetcherFactory* factory); | |
| 117 | |
| 118 class Core; | |
| 119 scoped_refptr<Core> core_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(URLFetcher); | |
| 122 }; | |
| 123 | |
| 124 #endif // CONTENT_COMMON_NET_URL_FETCHER_H_ | |
| OLD | NEW |