| 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 : identifier_(GenerateURLRequestIdentifier()) { | 212 : context_(context), |
| 213 Init(url, priority, delegate, context, NULL); | 213 network_delegate_(context->network_delegate()), |
| 214 } | 214 net_log_(BoundNetLog::Make(context->net_log(), |
| 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"); |
| 215 | 235 |
| 216 URLRequest::URLRequest(const GURL& url, | 236 // Sanity check out environment. |
| 217 RequestPriority priority, | 237 DCHECK(base::MessageLoop::current()) |
| 218 Delegate* delegate, | 238 << "The current base::MessageLoop must exist"; |
| 219 const URLRequestContext* context, | 239 |
| 220 CookieStore* cookie_store) | 240 CHECK(context); |
| 221 : identifier_(GenerateURLRequestIdentifier()) { | 241 context->url_requests()->insert(this); |
| 222 Init(url, priority, delegate, context, cookie_store); | 242 |
| 243 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); |
| 223 } | 244 } |
| 224 | 245 |
| 225 URLRequest::~URLRequest() { | 246 URLRequest::~URLRequest() { |
| 226 Cancel(); | 247 Cancel(); |
| 227 | 248 |
| 228 if (network_delegate_) { | 249 if (network_delegate_) { |
| 229 network_delegate_->NotifyURLRequestDestroyed(this); | 250 network_delegate_->NotifyURLRequestDestroyed(this); |
| 230 if (job_.get()) | 251 if (job_.get()) |
| 231 job_->NotifyURLRequestDestroyed(); | 252 job_->NotifyURLRequestDestroyed(); |
| 232 } | 253 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 256 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { | 277 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { |
| 257 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); | 278 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); |
| 258 } | 279 } |
| 259 | 280 |
| 260 // static | 281 // static |
| 261 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { | 282 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { |
| 262 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( | 283 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( |
| 263 interceptor); | 284 interceptor); |
| 264 } | 285 } |
| 265 | 286 |
| 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 | |
| 307 void URLRequest::EnableChunkedUpload() { | 287 void URLRequest::EnableChunkedUpload() { |
| 308 DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked()); | 288 DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked()); |
| 309 if (!upload_data_stream_) { | 289 if (!upload_data_stream_) { |
| 310 upload_data_stream_.reset( | 290 upload_data_stream_.reset( |
| 311 new UploadDataStream(UploadDataStream::CHUNKED, 0)); | 291 new UploadDataStream(UploadDataStream::CHUNKED, 0)); |
| 312 } | 292 } |
| 313 } | 293 } |
| 314 | 294 |
| 315 void URLRequest::AppendChunkToUpload(const char* bytes, | 295 void URLRequest::AppendChunkToUpload(const char* bytes, |
| 316 int bytes_len, | 296 int bytes_len, |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 new base::debug::StackTrace(NULL, 0); | 1236 new base::debug::StackTrace(NULL, 0); |
| 1257 *stack_trace_copy = stack_trace; | 1237 *stack_trace_copy = stack_trace; |
| 1258 stack_trace_.reset(stack_trace_copy); | 1238 stack_trace_.reset(stack_trace_copy); |
| 1259 } | 1239 } |
| 1260 | 1240 |
| 1261 const base::debug::StackTrace* URLRequest::stack_trace() const { | 1241 const base::debug::StackTrace* URLRequest::stack_trace() const { |
| 1262 return stack_trace_.get(); | 1242 return stack_trace_.get(); |
| 1263 } | 1243 } |
| 1264 | 1244 |
| 1265 } // namespace net | 1245 } // namespace net |
| OLD | NEW |