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_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 URLRequestHttpJob* job_; | 73 URLRequestHttpJob* job_; |
74 | 74 |
75 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); | 75 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); |
76 }; | 76 }; |
77 | 77 |
78 class URLRequestHttpJob::HttpTransactionDelegateImpl | 78 class URLRequestHttpJob::HttpTransactionDelegateImpl |
79 : public HttpTransactionDelegate { | 79 : public HttpTransactionDelegate { |
80 public: | 80 public: |
81 explicit HttpTransactionDelegateImpl(URLRequest* request) | 81 explicit HttpTransactionDelegateImpl(URLRequest* request) |
82 : request_(request), | 82 : request_(request), |
83 network_delegate_(request->context()->network_delegate()) { | 83 network_delegate_(request->context()->network_delegate()), |
| 84 cache_active_(false), |
| 85 network_active_(false) { |
84 } | 86 } |
85 virtual ~HttpTransactionDelegateImpl() { | 87 virtual ~HttpTransactionDelegateImpl() { |
86 OnDetachRequest(); | 88 OnDetachRequest(); |
87 } | 89 } |
88 void OnDetachRequest() { | 90 void OnDetachRequest() { |
89 if (request_ == NULL || network_delegate_ == NULL) | 91 if (request_ == NULL || network_delegate_ == NULL) |
90 return; | 92 return; |
91 network_delegate_->NotifyCacheWaitStateChange( | 93 network_delegate_->NotifyRequestWaitStateChange( |
92 *request_, | 94 *request_, |
93 NetworkDelegate::CACHE_WAIT_STATE_RESET); | 95 NetworkDelegate::REQUEST_WAIT_STATE_RESET); |
| 96 cache_active_ = false; |
| 97 network_active_ = false; |
94 request_ = NULL; | 98 request_ = NULL; |
95 } | 99 } |
96 virtual void OnCacheActionStart() OVERRIDE { | 100 virtual void OnCacheActionStart() OVERRIDE { |
97 if (request_ == NULL || network_delegate_ == NULL) | 101 if (request_ == NULL || network_delegate_ == NULL) |
98 return; | 102 return; |
99 network_delegate_->NotifyCacheWaitStateChange( | 103 DCHECK(!cache_active_ && !network_active_); |
| 104 cache_active_ = true; |
| 105 network_delegate_->NotifyRequestWaitStateChange( |
100 *request_, | 106 *request_, |
101 NetworkDelegate::CACHE_WAIT_STATE_START); | 107 NetworkDelegate::REQUEST_WAIT_STATE_CACHE_START); |
102 } | 108 } |
103 virtual void OnCacheActionFinish() OVERRIDE { | 109 virtual void OnCacheActionFinish() OVERRIDE { |
104 if (request_ == NULL || network_delegate_ == NULL) | 110 if (request_ == NULL || network_delegate_ == NULL) |
105 return; | 111 return; |
106 network_delegate_->NotifyCacheWaitStateChange( | 112 DCHECK(cache_active_ && !network_active_); |
| 113 cache_active_ = false; |
| 114 network_delegate_->NotifyRequestWaitStateChange( |
107 *request_, | 115 *request_, |
108 NetworkDelegate::CACHE_WAIT_STATE_FINISH); | 116 NetworkDelegate::REQUEST_WAIT_STATE_CACHE_FINISH); |
| 117 } |
| 118 virtual void OnNetworkActionStart() OVERRIDE { |
| 119 if (request_ == NULL || network_delegate_ == NULL) |
| 120 return; |
| 121 DCHECK(!cache_active_ && !network_active_); |
| 122 network_active_ = true; |
| 123 network_delegate_->NotifyRequestWaitStateChange( |
| 124 *request_, |
| 125 NetworkDelegate::REQUEST_WAIT_STATE_NETWORK_START); |
| 126 } |
| 127 virtual void OnNetworkActionFinish() OVERRIDE { |
| 128 if (request_ == NULL || network_delegate_ == NULL) |
| 129 return; |
| 130 DCHECK(!cache_active_ && network_active_); |
| 131 network_active_ = false; |
| 132 network_delegate_->NotifyRequestWaitStateChange( |
| 133 *request_, |
| 134 NetworkDelegate::REQUEST_WAIT_STATE_NETWORK_FINISH); |
109 } | 135 } |
110 private: | 136 private: |
111 URLRequest* request_; | 137 URLRequest* request_; |
112 NetworkDelegate* network_delegate_; | 138 NetworkDelegate* network_delegate_; |
| 139 bool cache_active_; |
| 140 bool network_active_; |
113 }; | 141 }; |
114 | 142 |
115 URLRequestHttpJob::HttpFilterContext::HttpFilterContext(URLRequestHttpJob* job) | 143 URLRequestHttpJob::HttpFilterContext::HttpFilterContext(URLRequestHttpJob* job) |
116 : job_(job) { | 144 : job_(job) { |
117 DCHECK(job_); | 145 DCHECK(job_); |
118 } | 146 } |
119 | 147 |
120 URLRequestHttpJob::HttpFilterContext::~HttpFilterContext() { | 148 URLRequestHttpJob::HttpFilterContext::~HttpFilterContext() { |
121 } | 149 } |
122 | 150 |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 | 901 |
874 request_info_.extra_headers.SetHeaderIfMissing( | 902 request_info_.extra_headers.SetHeaderIfMissing( |
875 HttpRequestHeaders::kUserAgent, | 903 HttpRequestHeaders::kUserAgent, |
876 request_->context()->GetUserAgent(request_->url())); | 904 request_->context()->GetUserAgent(request_->url())); |
877 | 905 |
878 AddExtraHeaders(); | 906 AddExtraHeaders(); |
879 AddCookieHeaderAndStart(); | 907 AddCookieHeaderAndStart(); |
880 } | 908 } |
881 | 909 |
882 void URLRequestHttpJob::Kill() { | 910 void URLRequestHttpJob::Kill() { |
| 911 http_transaction_delegate_->OnDetachRequest(); |
| 912 |
883 if (!transaction_.get()) | 913 if (!transaction_.get()) |
884 return; | 914 return; |
885 | 915 |
886 weak_factory_.InvalidateWeakPtrs(); | 916 weak_factory_.InvalidateWeakPtrs(); |
887 DestroyTransaction(); | 917 DestroyTransaction(); |
888 URLRequestJob::Kill(); | 918 URLRequestJob::Kill(); |
889 } | 919 } |
890 | 920 |
891 LoadState URLRequestHttpJob::GetLoadState() const { | 921 LoadState URLRequestHttpJob::GetLoadState() const { |
892 return transaction_.get() ? | 922 return transaction_.get() ? |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 | 1497 |
1468 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1498 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1469 awaiting_callback_ = false; | 1499 awaiting_callback_ = false; |
1470 } | 1500 } |
1471 | 1501 |
1472 void URLRequestHttpJob::OnDetachRequest() { | 1502 void URLRequestHttpJob::OnDetachRequest() { |
1473 http_transaction_delegate_->OnDetachRequest(); | 1503 http_transaction_delegate_->OnDetachRequest(); |
1474 } | 1504 } |
1475 | 1505 |
1476 } // namespace net | 1506 } // namespace net |
OLD | NEW |