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 #include "content/common/net/url_fetcher_impl.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/message_loop_proxy.h" | |
9 #include "content/common/net/url_request_user_data.h" | |
10 #include "net/url_request/url_fetcher_core.h" | |
11 #include "net/url_request/url_fetcher_factory.h" | |
12 | |
13 static net::URLFetcherFactory* g_factory = NULL; | |
14 | |
15 // static | |
16 net::URLFetcher* content::URLFetcher::Create( | |
17 const GURL& url, | |
18 net::URLFetcher::RequestType request_type, | |
19 net::URLFetcherDelegate* d) { | |
20 return new URLFetcherImpl(url, request_type, d); | |
21 } | |
22 | |
23 // static | |
24 net::URLFetcher* content::URLFetcher::Create( | |
25 int id, | |
26 const GURL& url, | |
27 net::URLFetcher::RequestType request_type, | |
28 net::URLFetcherDelegate* d) { | |
29 return g_factory ? g_factory->CreateURLFetcher(id, url, request_type, d) : | |
30 new URLFetcherImpl(url, request_type, d); | |
31 } | |
32 | |
33 // static | |
34 void content::URLFetcher::CancelAll() { | |
35 URLFetcherImpl::CancelAll(); | |
36 } | |
37 | |
38 // static | |
39 void content::URLFetcher::SetEnableInterceptionForTests(bool enabled) { | |
40 net::URLFetcherCore::SetEnableInterceptionForTests(enabled); | |
41 } | |
42 | |
43 namespace { | |
44 | |
45 base::SupportsUserData::Data* CreateURLRequestUserData( | |
46 int render_process_id, | |
47 int render_view_id) { | |
48 return new URLRequestUserData(render_process_id, render_view_id); | |
49 } | |
50 | |
51 } // namespace | |
52 | |
53 namespace content { | |
54 | |
55 void AssociateURLFetcherWithRenderView(net::URLFetcher* url_fetcher, | |
56 const GURL& first_party_for_cookies, | |
57 int render_process_id, | |
58 int render_view_id) { | |
59 url_fetcher->SetFirstPartyForCookies(first_party_for_cookies); | |
60 url_fetcher->SetURLRequestUserData( | |
61 URLRequestUserData::kUserDataKey, | |
62 base::Bind(&CreateURLRequestUserData, | |
63 render_process_id, render_view_id)); | |
64 } | |
65 | |
66 } // namespace content | |
67 | |
68 URLFetcherImpl::URLFetcherImpl(const GURL& url, | |
69 RequestType request_type, | |
70 net::URLFetcherDelegate* d) | |
71 : ALLOW_THIS_IN_INITIALIZER_LIST( | |
72 core_(new net::URLFetcherCore(this, url, request_type, d))) { | |
73 } | |
74 | |
75 URLFetcherImpl::~URLFetcherImpl() { | |
76 core_->Stop(); | |
77 } | |
78 | |
79 void URLFetcherImpl::SetUploadData(const std::string& upload_content_type, | |
80 const std::string& upload_content) { | |
81 core_->SetUploadData(upload_content_type, upload_content); | |
82 } | |
83 | |
84 void URLFetcherImpl::SetChunkedUpload(const std::string& content_type) { | |
85 core_->SetChunkedUpload(content_type); | |
86 } | |
87 | |
88 void URLFetcherImpl::AppendChunkToUpload(const std::string& data, | |
89 bool is_last_chunk) { | |
90 DCHECK(data.length()); | |
91 core_->AppendChunkToUpload(data, is_last_chunk); | |
92 } | |
93 | |
94 void URLFetcherImpl::SetReferrer(const std::string& referrer) { | |
95 core_->SetReferrer(referrer); | |
96 } | |
97 | |
98 void URLFetcherImpl::SetLoadFlags(int load_flags) { | |
99 core_->SetLoadFlags(load_flags); | |
100 } | |
101 | |
102 int URLFetcherImpl::GetLoadFlags() const { | |
103 return core_->GetLoadFlags(); | |
104 } | |
105 | |
106 void URLFetcherImpl::SetExtraRequestHeaders( | |
107 const std::string& extra_request_headers) { | |
108 core_->SetExtraRequestHeaders(extra_request_headers); | |
109 } | |
110 | |
111 void URLFetcherImpl::AddExtraRequestHeader(const std::string& header_line) { | |
112 core_->AddExtraRequestHeader(header_line); | |
113 } | |
114 | |
115 void URLFetcherImpl::GetExtraRequestHeaders( | |
116 net::HttpRequestHeaders* headers) const { | |
117 GetExtraRequestHeaders(headers); | |
118 } | |
119 | |
120 void URLFetcherImpl::SetRequestContext( | |
121 net::URLRequestContextGetter* request_context_getter) { | |
122 core_->SetRequestContext(request_context_getter); | |
123 } | |
124 | |
125 void URLFetcherImpl::SetFirstPartyForCookies( | |
126 const GURL& first_party_for_cookies) { | |
127 core_->SetFirstPartyForCookies(first_party_for_cookies); | |
128 } | |
129 | |
130 void URLFetcherImpl::SetURLRequestUserData( | |
131 const void* key, | |
132 const CreateDataCallback& create_data_callback) { | |
133 core_->SetURLRequestUserData(key, create_data_callback); | |
134 } | |
135 | |
136 void URLFetcherImpl::SetStopOnRedirect(bool stop_on_redirect) { | |
137 core_->SetStopOnRedirect(stop_on_redirect); | |
138 } | |
139 | |
140 void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) { | |
141 core_->SetAutomaticallyRetryOn5xx(retry); | |
142 } | |
143 | |
144 void URLFetcherImpl::SetMaxRetries(int max_retries) { | |
145 core_->SetMaxRetries(max_retries); | |
146 } | |
147 | |
148 int URLFetcherImpl::GetMaxRetries() const { | |
149 return core_->GetMaxRetries(); | |
150 } | |
151 | |
152 | |
153 base::TimeDelta URLFetcherImpl::GetBackoffDelay() const { | |
154 return core_->GetBackoffDelay(); | |
155 } | |
156 | |
157 void URLFetcherImpl::SaveResponseToFileAtPath( | |
158 const FilePath& file_path, | |
159 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) { | |
160 core_->SaveResponseToFileAtPath(file_path, file_message_loop_proxy); | |
161 } | |
162 | |
163 void URLFetcherImpl::SaveResponseToTemporaryFile( | |
164 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) { | |
165 core_->SaveResponseToTemporaryFile(file_message_loop_proxy); | |
166 } | |
167 | |
168 net::HttpResponseHeaders* URLFetcherImpl::GetResponseHeaders() const { | |
169 return core_->GetResponseHeaders(); | |
170 } | |
171 | |
172 net::HostPortPair URLFetcherImpl::GetSocketAddress() const { | |
173 return core_->GetSocketAddress(); | |
174 } | |
175 | |
176 bool URLFetcherImpl::WasFetchedViaProxy() const { | |
177 return core_->WasFetchedViaProxy(); | |
178 } | |
179 | |
180 void URLFetcherImpl::Start() { | |
181 core_->Start(); | |
182 } | |
183 | |
184 const GURL& URLFetcherImpl::GetOriginalURL() const { | |
185 return core_->GetOriginalURL(); | |
186 } | |
187 | |
188 const GURL& URLFetcherImpl::GetURL() const { | |
189 return core_->GetURL(); | |
190 } | |
191 | |
192 const net::URLRequestStatus& URLFetcherImpl::GetStatus() const { | |
193 return core_->GetStatus(); | |
194 } | |
195 | |
196 int URLFetcherImpl::GetResponseCode() const { | |
197 return core_->GetResponseCode(); | |
198 } | |
199 | |
200 const net::ResponseCookies& URLFetcherImpl::GetCookies() const { | |
201 return core_->GetCookies(); | |
202 } | |
203 | |
204 bool URLFetcherImpl::FileErrorOccurred( | |
205 base::PlatformFileError* out_error_code) const { | |
206 return core_->FileErrorOccurred(out_error_code); | |
207 } | |
208 | |
209 void URLFetcherImpl::ReceivedContentWasMalformed() { | |
210 core_->ReceivedContentWasMalformed(); | |
211 } | |
212 | |
213 bool URLFetcherImpl::GetResponseAsString( | |
214 std::string* out_response_string) const { | |
215 return core_->GetResponseAsString(out_response_string); | |
216 } | |
217 | |
218 bool URLFetcherImpl::GetResponseAsFilePath( | |
219 bool take_ownership, | |
220 FilePath* out_response_path) const { | |
221 return core_->GetResponseAsFilePath(take_ownership, out_response_path); | |
222 } | |
223 | |
224 // static | |
225 void URLFetcherImpl::CancelAll() { | |
226 net::URLFetcherCore::CancelAll(); | |
227 } | |
228 | |
229 // static | |
230 int URLFetcherImpl::GetNumFetcherCores() { | |
231 return net::URLFetcherCore::GetNumFetcherCores(); | |
232 } | |
233 | |
234 net::URLFetcherDelegate* URLFetcherImpl::delegate() const { | |
235 return core_->delegate(); | |
236 } | |
237 | |
238 // static | |
239 net::URLFetcherFactory* URLFetcherImpl::factory() { | |
240 return g_factory; | |
241 } | |
242 | |
243 // static | |
244 void URLFetcherImpl::set_factory(net::URLFetcherFactory* factory) { | |
245 g_factory = factory; | |
246 } | |
OLD | NEW |