| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/url_request/url_request.h" | 5 #include "net/url_request/url_request.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 bool* defer) { | 202 bool* defer) { |
| 203 } | 203 } |
| 204 | 204 |
| 205 /////////////////////////////////////////////////////////////////////////////// | 205 /////////////////////////////////////////////////////////////////////////////// |
| 206 // URLRequest | 206 // URLRequest |
| 207 | 207 |
| 208 URLRequest::URLRequest(const GURL& url, | 208 URLRequest::URLRequest(const GURL& url, |
| 209 RequestPriority priority, | 209 RequestPriority priority, |
| 210 Delegate* delegate, | 210 Delegate* delegate, |
| 211 const URLRequestContext* context) | 211 const URLRequestContext* context) |
| 212 : context_(context), | 212 : identifier_(GenerateURLRequestIdentifier()) { |
| 213 network_delegate_(context->network_delegate()), | 213 Init(url, priority, delegate, context, NULL); |
| 214 net_log_(BoundNetLog::Make(context->net_log(), | 214 } |
| 215 NetLog::SOURCE_URL_REQUEST)), | |
| 216 url_chain_(1, url), | |
| 217 method_("GET"), | |
| 218 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), | |
| 219 load_flags_(LOAD_NORMAL), | |
| 220 delegate_(delegate), | |
| 221 is_pending_(false), | |
| 222 is_redirecting_(false), | |
| 223 redirect_limit_(kMaxRedirects), | |
| 224 priority_(priority), | |
| 225 identifier_(GenerateURLRequestIdentifier()), | |
| 226 calling_delegate_(false), | |
| 227 use_blocked_by_as_load_param_(false), | |
| 228 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, | |
| 229 base::Unretained(this))), | |
| 230 has_notified_completion_(false), | |
| 231 received_response_content_length_(0), | |
| 232 creation_time_(base::TimeTicks::Now()), | |
| 233 notified_before_network_start_(false) { | |
| 234 SIMPLE_STATS_COUNTER("URLRequestCount"); | |
| 235 | 215 |
| 236 // Sanity check out environment. | 216 URLRequest::URLRequest(const GURL& url, |
| 237 DCHECK(base::MessageLoop::current()) | 217 RequestPriority priority, |
| 238 << "The current base::MessageLoop must exist"; | 218 Delegate* delegate, |
| 239 | 219 const URLRequestContext* context, |
| 240 CHECK(context); | 220 CookieStore* cookie_store) |
| 241 context->url_requests()->insert(this); | 221 : identifier_(GenerateURLRequestIdentifier()) { |
| 242 | 222 Init(url, priority, delegate, context, cookie_store); |
| 243 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); | |
| 244 } | 223 } |
| 245 | 224 |
| 246 URLRequest::~URLRequest() { | 225 URLRequest::~URLRequest() { |
| 247 Cancel(); | 226 Cancel(); |
| 248 | 227 |
| 249 if (network_delegate_) { | 228 if (network_delegate_) { |
| 250 network_delegate_->NotifyURLRequestDestroyed(this); | 229 network_delegate_->NotifyURLRequestDestroyed(this); |
| 251 if (job_.get()) | 230 if (job_.get()) |
| 252 job_->NotifyURLRequestDestroyed(); | 231 job_->NotifyURLRequestDestroyed(); |
| 253 } | 232 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 277 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { | 256 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { |
| 278 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); | 257 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); |
| 279 } | 258 } |
| 280 | 259 |
| 281 // static | 260 // static |
| 282 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { | 261 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { |
| 283 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( | 262 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( |
| 284 interceptor); | 263 interceptor); |
| 285 } | 264 } |
| 286 | 265 |
| 266 void URLRequest::Init(const GURL& url, |
| 267 RequestPriority priority, |
| 268 Delegate* delegate, |
| 269 const URLRequestContext* context, |
| 270 CookieStore* cookie_store) { |
| 271 context_ = context; |
| 272 network_delegate_ = context->network_delegate(); |
| 273 net_log_ = BoundNetLog::Make(context->net_log(), NetLog::SOURCE_URL_REQUEST); |
| 274 url_chain_.push_back(url); |
| 275 method_ = "GET"; |
| 276 referrer_policy_ = CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE; |
| 277 load_flags_ = LOAD_NORMAL; |
| 278 delegate_ = delegate; |
| 279 is_pending_ = false; |
| 280 is_redirecting_ = false; |
| 281 redirect_limit_ = kMaxRedirects; |
| 282 priority_ = priority; |
| 283 calling_delegate_ = false; |
| 284 use_blocked_by_as_load_param_ =false; |
| 285 before_request_callback_ = base::Bind(&URLRequest::BeforeRequestComplete, |
| 286 base::Unretained(this)); |
| 287 has_notified_completion_ = false; |
| 288 received_response_content_length_ = 0; |
| 289 creation_time_ = base::TimeTicks::Now(); |
| 290 notified_before_network_start_ = false; |
| 291 |
| 292 SIMPLE_STATS_COUNTER("URLRequestCount"); |
| 293 |
| 294 // Sanity check out environment. |
| 295 DCHECK(base::MessageLoop::current()) |
| 296 << "The current base::MessageLoop must exist"; |
| 297 |
| 298 CHECK(context); |
| 299 context->url_requests()->insert(this); |
| 300 cookie_store_ = cookie_store; |
| 301 if (cookie_store_ == NULL) |
| 302 cookie_store_ = context->cookie_store(); |
| 303 |
| 304 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); |
| 305 } |
| 306 |
| 287 void URLRequest::EnableChunkedUpload() { | 307 void URLRequest::EnableChunkedUpload() { |
| 288 DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked()); | 308 DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked()); |
| 289 if (!upload_data_stream_) { | 309 if (!upload_data_stream_) { |
| 290 upload_data_stream_.reset( | 310 upload_data_stream_.reset( |
| 291 new UploadDataStream(UploadDataStream::CHUNKED, 0)); | 311 new UploadDataStream(UploadDataStream::CHUNKED, 0)); |
| 292 } | 312 } |
| 293 } | 313 } |
| 294 | 314 |
| 295 void URLRequest::AppendChunkToUpload(const char* bytes, | 315 void URLRequest::AppendChunkToUpload(const char* bytes, |
| 296 int bytes_len, | 316 int bytes_len, |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 new base::debug::StackTrace(NULL, 0); | 1256 new base::debug::StackTrace(NULL, 0); |
| 1237 *stack_trace_copy = stack_trace; | 1257 *stack_trace_copy = stack_trace; |
| 1238 stack_trace_.reset(stack_trace_copy); | 1258 stack_trace_.reset(stack_trace_copy); |
| 1239 } | 1259 } |
| 1240 | 1260 |
| 1241 const base::debug::StackTrace* URLRequest::stack_trace() const { | 1261 const base::debug::StackTrace* URLRequest::stack_trace() const { |
| 1242 return stack_trace_.get(); | 1262 return stack_trace_.get(); |
| 1243 } | 1263 } |
| 1244 | 1264 |
| 1245 } // namespace net | 1265 } // namespace net |
| OLD | NEW |