OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_IMPL_H_ | |
15 #define CONTENT_COMMON_NET_URL_FETCHER_IMPL_H_ | |
16 #pragma once | |
17 | |
18 #include "base/basictypes.h" | |
19 #include "base/compiler_specific.h" | |
20 #include "content/common/content_export.h" | |
21 #include "content/public/common/url_fetcher.h" | |
22 | |
23 namespace net { | |
24 class URLFetcherCore; | |
25 class URLFetcherDelegate; | |
26 class URLFetcherFactory; | |
27 } // namespace net | |
28 | |
29 class CONTENT_EXPORT URLFetcherImpl : public net::URLFetcher { | |
30 public: | |
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. | |
34 URLFetcherImpl(const GURL& url, | |
35 RequestType request_type, | |
36 net::URLFetcherDelegate* d); | |
37 virtual ~URLFetcherImpl(); | |
38 | |
39 // net::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; | |
51 virtual void AddExtraRequestHeader(const std::string& header_line) OVERRIDE; | |
52 virtual void GetExtraRequestHeaders( | |
53 net::HttpRequestHeaders* headers) const OVERRIDE; | |
54 virtual void SetRequestContext( | |
55 net::URLRequestContextGetter* request_context_getter) OVERRIDE; | |
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; | |
61 virtual void SetStopOnRedirect(bool stop_on_redirect) OVERRIDE; | |
62 virtual void SetAutomaticallyRetryOn5xx(bool retry) OVERRIDE; | |
63 virtual void SetMaxRetries(int max_retries) OVERRIDE; | |
64 virtual int GetMaxRetries() const OVERRIDE; | |
65 virtual base::TimeDelta GetBackoffDelay() const OVERRIDE; | |
66 virtual void SaveResponseToFileAtPath( | |
67 const FilePath& file_path, | |
68 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) OVERRIDE; | |
69 virtual void SaveResponseToTemporaryFile( | |
70 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) OVERRIDE; | |
71 virtual net::HttpResponseHeaders* GetResponseHeaders() const OVERRIDE; | |
72 virtual net::HostPortPair GetSocketAddress() const OVERRIDE; | |
73 virtual bool WasFetchedViaProxy() const OVERRIDE; | |
74 virtual void Start() OVERRIDE; | |
75 virtual const GURL& GetOriginalURL() const OVERRIDE; | |
76 virtual const GURL& GetURL() const OVERRIDE; | |
77 virtual const net::URLRequestStatus& GetStatus() const OVERRIDE; | |
78 virtual int GetResponseCode() const OVERRIDE; | |
79 virtual const net::ResponseCookies& GetCookies() const OVERRIDE; | |
80 virtual bool FileErrorOccurred( | |
81 base::PlatformFileError* out_error_code) const OVERRIDE; | |
82 virtual void ReceivedContentWasMalformed() OVERRIDE; | |
83 virtual bool GetResponseAsString( | |
84 std::string* out_response_string) const OVERRIDE; | |
85 virtual bool GetResponseAsFilePath( | |
86 bool take_ownership, | |
87 FilePath* out_response_path) const OVERRIDE; | |
88 | |
89 static void CancelAll(); | |
90 | |
91 protected: | |
92 // Returns the delegate. | |
93 net::URLFetcherDelegate* delegate() const; | |
94 | |
95 private: | |
96 friend class ScopedURLFetcherFactory; | |
97 friend class TestURLFetcher; | |
98 friend class URLFetcherTest; | |
99 | |
100 // Only used by URLFetcherTest, returns the number of URLFetcher::Core objects | |
101 // actively running. | |
102 static int GetNumFetcherCores(); | |
103 | |
104 static net::URLFetcherFactory* factory(); | |
105 | |
106 // Sets the factory used by the static method Create to create a URLFetcher. | |
107 // URLFetcher does not take ownership of |factory|. A value of NULL results | |
108 // in a URLFetcher being created directly. | |
109 // | |
110 // NOTE: for safety, this should only be used through ScopedURLFetcherFactory! | |
111 static void set_factory(net::URLFetcherFactory* factory); | |
112 | |
113 const scoped_refptr<net::URLFetcherCore> core_; | |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(URLFetcherImpl); | |
116 }; | |
117 | |
118 #endif // CONTENT_COMMON_NET_URL_FETCHER_IMPL_H_ | |
OLD | NEW |