OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/metrics/stats_counters.h" | 9 #include "base/metrics/stats_counters.h" |
10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 // Discard headers which have meaning in POST (Content-Length, Content-Type, | 36 // Discard headers which have meaning in POST (Content-Length, Content-Type, |
37 // Origin). | 37 // Origin). |
38 void StripPostSpecificHeaders(net::HttpRequestHeaders* headers) { | 38 void StripPostSpecificHeaders(net::HttpRequestHeaders* headers) { |
39 // These are headers that may be attached to a POST. | 39 // These are headers that may be attached to a POST. |
40 headers->RemoveHeader(net::HttpRequestHeaders::kContentLength); | 40 headers->RemoveHeader(net::HttpRequestHeaders::kContentLength); |
41 headers->RemoveHeader(net::HttpRequestHeaders::kContentType); | 41 headers->RemoveHeader(net::HttpRequestHeaders::kContentType); |
42 headers->RemoveHeader(net::HttpRequestHeaders::kOrigin); | 42 headers->RemoveHeader(net::HttpRequestHeaders::kOrigin); |
43 } | 43 } |
44 | 44 |
45 // This counter keeps track of the identifiers used for URL requests so far. | 45 // This counter keeps track of the identifiers used for URL requests so far. |
46 uint64 g_next_url_request_identifier = 0; | 46 // 0 is reserved to represent an invalid ID. |
| 47 uint64 g_next_url_request_identifier = 1; |
47 | 48 |
48 // This lock protects g_next_url_request_identifier. | 49 // This lock protects g_next_url_request_identifier. |
49 base::Lock g_next_url_request_identifier_lock; | 50 base::Lock g_next_url_request_identifier_lock; |
50 | 51 |
51 // Returns an prior unused identifier for URL requests. | 52 // Returns an prior unused identifier for URL requests. |
52 uint64 GenerateURLRequestIdentifier() { | 53 uint64 GenerateURLRequestIdentifier() { |
53 base::AutoLock lock(g_next_url_request_identifier_lock); | 54 base::AutoLock lock(g_next_url_request_identifier_lock); |
54 return g_next_url_request_identifier++; | 55 return g_next_url_request_identifier++; |
55 } | 56 } |
56 | 57 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 SIMPLE_STATS_COUNTER("URLRequestCount"); | 125 SIMPLE_STATS_COUNTER("URLRequestCount"); |
125 | 126 |
126 // Sanity check out environment. | 127 // Sanity check out environment. |
127 DCHECK(MessageLoop::current()) << | 128 DCHECK(MessageLoop::current()) << |
128 "The current MessageLoop must exist"; | 129 "The current MessageLoop must exist"; |
129 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << | 130 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << |
130 "The current MessageLoop must be TYPE_IO"; | 131 "The current MessageLoop must be TYPE_IO"; |
131 } | 132 } |
132 | 133 |
133 URLRequest::~URLRequest() { | 134 URLRequest::~URLRequest() { |
| 135 if (context_ && context_->network_delegate()) |
| 136 context_->network_delegate()->NotifyURLRequestDestroyed(this); |
| 137 |
134 if (before_request_callback_) | 138 if (before_request_callback_) |
135 before_request_callback_->Cancel(); | 139 before_request_callback_->Cancel(); |
136 | 140 |
137 Cancel(); | 141 Cancel(); |
138 | 142 |
139 if (job_) | 143 if (job_) |
140 OrphanJob(); | 144 OrphanJob(); |
141 | 145 |
142 set_context(NULL); | 146 set_context(NULL); |
143 } | 147 } |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 return ret; | 360 return ret; |
357 } | 361 } |
358 | 362 |
359 void URLRequest::Start() { | 363 void URLRequest::Start() { |
360 response_info_.request_time = Time::Now(); | 364 response_info_.request_time = Time::Now(); |
361 | 365 |
362 if (context_ && context_->network_delegate()) { | 366 if (context_ && context_->network_delegate()) { |
363 before_request_callback_ = new CancelableCompletionCallback<URLRequest>( | 367 before_request_callback_ = new CancelableCompletionCallback<URLRequest>( |
364 this, &URLRequest::BeforeRequestComplete); | 368 this, &URLRequest::BeforeRequestComplete); |
365 if (context_->network_delegate()->NotifyBeforeURLRequest( | 369 if (context_->network_delegate()->NotifyBeforeURLRequest( |
366 this, before_request_callback_)) { | 370 this, before_request_callback_) == net::ERR_IO_PENDING) { |
367 before_request_callback_->AddRef(); // balanced in BeforeRequestComplete | 371 before_request_callback_->AddRef(); // balanced in BeforeRequestComplete |
368 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_EXTENSION, NULL); | 372 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_EXTENSION, NULL); |
369 return; // paused | 373 return; // paused |
370 } | 374 } |
371 } | 375 } |
372 | 376 |
373 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); | 377 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); |
374 } | 378 } |
375 | 379 |
376 /////////////////////////////////////////////////////////////////////////////// | 380 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 if (found != user_data_.end()) | 668 if (found != user_data_.end()) |
665 return found->second.get(); | 669 return found->second.get(); |
666 return NULL; | 670 return NULL; |
667 } | 671 } |
668 | 672 |
669 void URLRequest::SetUserData(const void* key, UserData* data) { | 673 void URLRequest::SetUserData(const void* key, UserData* data) { |
670 user_data_[key] = linked_ptr<UserData>(data); | 674 user_data_[key] = linked_ptr<UserData>(data); |
671 } | 675 } |
672 | 676 |
673 } // namespace net | 677 } // namespace net |
OLD | NEW |