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" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/metrics/stats_counters.h" | 14 #include "base/metrics/stats_counters.h" |
15 #include "base/stl_util.h" | |
15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
16 #include "net/base/auth.h" | 17 #include "net/base/auth.h" |
17 #include "net/base/host_port_pair.h" | 18 #include "net/base/host_port_pair.h" |
18 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
20 #include "net/base/net_log.h" | 21 #include "net/base/net_log.h" |
21 #include "net/base/network_delegate.h" | 22 #include "net/base/network_delegate.h" |
22 #include "net/base/ssl_cert_request_info.h" | 23 #include "net/base/ssl_cert_request_info.h" |
23 #include "net/base/upload_data.h" | 24 #include "net/base/upload_data.h" |
24 #include "net/http/http_response_headers.h" | 25 #include "net/http/http_response_headers.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
41 const int kMaxRedirects = 20; | 42 const int kMaxRedirects = 20; |
42 | 43 |
43 // Discard headers which have meaning in POST (Content-Length, Content-Type, | 44 // Discard headers which have meaning in POST (Content-Length, Content-Type, |
44 // Origin). | 45 // Origin). |
45 void StripPostSpecificHeaders(HttpRequestHeaders* headers) { | 46 void StripPostSpecificHeaders(HttpRequestHeaders* headers) { |
46 // These are headers that may be attached to a POST. | 47 // These are headers that may be attached to a POST. |
47 headers->RemoveHeader(HttpRequestHeaders::kContentLength); | 48 headers->RemoveHeader(HttpRequestHeaders::kContentLength); |
48 headers->RemoveHeader(HttpRequestHeaders::kContentType); | 49 headers->RemoveHeader(HttpRequestHeaders::kContentType); |
49 headers->RemoveHeader(HttpRequestHeaders::kOrigin); | 50 headers->RemoveHeader(HttpRequestHeaders::kOrigin); |
50 } | 51 } |
51 | 52 |
wtc
2012/04/05 21:37:16
Nit: undo this blank line.
| |
53 | |
52 // TODO(battre): Delete this, see http://crbug.com/89321: | 54 // TODO(battre): Delete this, see http://crbug.com/89321: |
53 // This counter keeps track of the identifiers used for URL requests so far. | 55 // This counter keeps track of the identifiers used for URL requests so far. |
54 // 0 is reserved to represent an invalid ID. | 56 // 0 is reserved to represent an invalid ID. |
55 uint64 g_next_url_request_identifier = 1; | 57 uint64 g_next_url_request_identifier = 1; |
56 | 58 |
57 // This lock protects g_next_url_request_identifier. | 59 // This lock protects g_next_url_request_identifier. |
58 base::LazyInstance<base::Lock>::Leaky | 60 base::LazyInstance<base::Lock>::Leaky |
59 g_next_url_request_identifier_lock = LAZY_INSTANCE_INITIALIZER; | 61 g_next_url_request_identifier_lock = LAZY_INSTANCE_INITIALIZER; |
60 | 62 |
61 // Returns an prior unused identifier for URL requests. | 63 // Returns an prior unused identifier for URL requests. |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
707 PrepareToRestart(); | 709 PrepareToRestart(); |
708 Start(); | 710 Start(); |
709 return OK; | 711 return OK; |
710 } | 712 } |
711 | 713 |
712 const URLRequestContext* URLRequest::context() const { | 714 const URLRequestContext* URLRequest::context() const { |
713 return context_.get(); | 715 return context_.get(); |
714 } | 716 } |
715 | 717 |
716 void URLRequest::set_context(const URLRequestContext* context) { | 718 void URLRequest::set_context(const URLRequestContext* context) { |
719 // Update the URLRequest lists in the URLRequestContext. | |
720 if (context_) { | |
721 std::set<const URLRequest*>* url_requests = context_->url_requests(); | |
722 CHECK(ContainsKey(*url_requests, this)); | |
723 url_requests->erase(this); | |
724 } | |
725 | |
726 if (context) { | |
727 std::set<const URLRequest*>* url_requests = context->url_requests(); | |
728 CHECK(!ContainsKey(*url_requests, this)); | |
729 url_requests->insert(this); | |
730 } | |
731 | |
717 scoped_refptr<const URLRequestContext> prev_context = context_; | 732 scoped_refptr<const URLRequestContext> prev_context = context_; |
718 | 733 |
719 context_ = context; | 734 context_ = context; |
720 | 735 |
721 // If the context this request belongs to has changed, update the tracker. | 736 // If the context this request belongs to has changed, update the tracker. |
722 if (prev_context != context) { | 737 if (prev_context != context) { |
723 int net_error = OK; | 738 int net_error = OK; |
724 // Log error only on failure, not cancellation, as even successful requests | 739 // Log error only on failure, not cancellation, as even successful requests |
725 // are "cancelled" on destruction. | 740 // are "cancelled" on destruction. |
726 if (status_.status() == URLRequestStatus::FAILED) | 741 if (status_.status() == URLRequestStatus::FAILED) |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
864 | 879 |
865 void URLRequest::SetUnblockedOnDelegate() { | 880 void URLRequest::SetUnblockedOnDelegate() { |
866 if (!blocked_on_delegate_) | 881 if (!blocked_on_delegate_) |
867 return; | 882 return; |
868 blocked_on_delegate_ = false; | 883 blocked_on_delegate_ = false; |
869 load_state_param_.clear(); | 884 load_state_param_.clear(); |
870 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 885 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
871 } | 886 } |
872 | 887 |
873 } // namespace net | 888 } // namespace net |
OLD | NEW |