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" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/file_version_info.h" | 12 #include "base/file_version_info.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
20 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
21 #include "net/base/mime_util.h" | 21 #include "net/base/mime_util.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
24 #include "net/base/network_delegate.h" | 24 #include "net/base/network_delegate.h" |
25 #include "net/base/sdch_manager.h" | 25 #include "net/base/sdch_manager.h" |
| 26 #include "net/base/sdch_net_log_params.h" |
26 #include "net/cert/cert_status_flags.h" | 27 #include "net/cert/cert_status_flags.h" |
27 #include "net/cookies/cookie_store.h" | 28 #include "net/cookies/cookie_store.h" |
28 #include "net/http/http_content_disposition.h" | 29 #include "net/http/http_content_disposition.h" |
29 #include "net/http/http_network_session.h" | 30 #include "net/http/http_network_session.h" |
30 #include "net/http/http_request_headers.h" | 31 #include "net/http/http_request_headers.h" |
31 #include "net/http/http_response_headers.h" | 32 #include "net/http/http_response_headers.h" |
32 #include "net/http/http_response_info.h" | 33 #include "net/http/http_response_info.h" |
33 #include "net/http/http_status_code.h" | 34 #include "net/http/http_status_code.h" |
34 #include "net/http/http_transaction.h" | 35 #include "net/http/http_transaction.h" |
35 #include "net/http/http_transaction_factory.h" | 36 #include "net/http/http_transaction_factory.h" |
(...skipping 26 matching lines...) Expand all Loading... |
62 virtual bool GetURL(GURL* gurl) const OVERRIDE; | 63 virtual bool GetURL(GURL* gurl) const OVERRIDE; |
63 virtual bool GetContentDisposition(std::string* disposition) const OVERRIDE; | 64 virtual bool GetContentDisposition(std::string* disposition) const OVERRIDE; |
64 virtual base::Time GetRequestTime() const OVERRIDE; | 65 virtual base::Time GetRequestTime() const OVERRIDE; |
65 virtual bool IsCachedContent() const OVERRIDE; | 66 virtual bool IsCachedContent() const OVERRIDE; |
66 virtual bool IsDownload() const OVERRIDE; | 67 virtual bool IsDownload() const OVERRIDE; |
67 virtual bool IsSdchResponse() const OVERRIDE; | 68 virtual bool IsSdchResponse() const OVERRIDE; |
68 virtual int64 GetByteReadCount() const OVERRIDE; | 69 virtual int64 GetByteReadCount() const OVERRIDE; |
69 virtual int GetResponseCode() const OVERRIDE; | 70 virtual int GetResponseCode() const OVERRIDE; |
70 virtual const URLRequestContext* GetURLRequestContext() const OVERRIDE; | 71 virtual const URLRequestContext* GetURLRequestContext() const OVERRIDE; |
71 virtual void RecordPacketStats(StatisticSelector statistic) const OVERRIDE; | 72 virtual void RecordPacketStats(StatisticSelector statistic) const OVERRIDE; |
| 73 virtual const BoundNetLog& GetNetLog() const OVERRIDE; |
72 | 74 |
73 // Method to allow us to reset filter context for a response that should have | 75 // Method to allow us to reset filter context for a response that should have |
74 // been SDCH encoded when there is an update due to an explicit HTTP header. | 76 // been SDCH encoded when there is an update due to an explicit HTTP header. |
75 void ResetSdchResponseToFalse(); | 77 void ResetSdchResponseToFalse(); |
76 | 78 |
77 private: | 79 private: |
78 URLRequestHttpJob* job_; | 80 URLRequestHttpJob* job_; |
79 | 81 |
| 82 // URLRequestHttpJob may be detached from URLRequest, but we still need to |
| 83 // return something. |
| 84 BoundNetLog dummy_log_; |
| 85 |
80 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); | 86 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); |
81 }; | 87 }; |
82 | 88 |
83 URLRequestHttpJob::HttpFilterContext::HttpFilterContext(URLRequestHttpJob* job) | 89 URLRequestHttpJob::HttpFilterContext::HttpFilterContext(URLRequestHttpJob* job) |
84 : job_(job) { | 90 : job_(job) { |
85 DCHECK(job_); | 91 DCHECK(job_); |
86 } | 92 } |
87 | 93 |
88 URLRequestHttpJob::HttpFilterContext::~HttpFilterContext() { | 94 URLRequestHttpJob::HttpFilterContext::~HttpFilterContext() { |
89 } | 95 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 const URLRequestContext* | 145 const URLRequestContext* |
140 URLRequestHttpJob::HttpFilterContext::GetURLRequestContext() const { | 146 URLRequestHttpJob::HttpFilterContext::GetURLRequestContext() const { |
141 return job_->request() ? job_->request()->context() : NULL; | 147 return job_->request() ? job_->request()->context() : NULL; |
142 } | 148 } |
143 | 149 |
144 void URLRequestHttpJob::HttpFilterContext::RecordPacketStats( | 150 void URLRequestHttpJob::HttpFilterContext::RecordPacketStats( |
145 StatisticSelector statistic) const { | 151 StatisticSelector statistic) const { |
146 job_->RecordPacketStats(statistic); | 152 job_->RecordPacketStats(statistic); |
147 } | 153 } |
148 | 154 |
| 155 const BoundNetLog& URLRequestHttpJob::HttpFilterContext::GetNetLog() const { |
| 156 return job_->request() ? job_->request()->net_log() : dummy_log_; |
| 157 } |
| 158 |
149 // TODO(darin): make sure the port blocking code is not lost | 159 // TODO(darin): make sure the port blocking code is not lost |
150 // static | 160 // static |
151 URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, | 161 URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, |
152 NetworkDelegate* network_delegate, | 162 NetworkDelegate* network_delegate, |
153 const std::string& scheme) { | 163 const std::string& scheme) { |
154 DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || | 164 DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || |
155 scheme == "wss"); | 165 scheme == "wss"); |
156 | 166 |
157 if (!request->context()->http_transaction_factory()) { | 167 if (!request->context()->http_transaction_factory()) { |
158 NOTREACHED() << "requires a valid context"; | 168 NOTREACHED() << "requires a valid context"; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // TODO(jar): We need to not fetch dictionaries the first time they are | 337 // TODO(jar): We need to not fetch dictionaries the first time they are |
328 // seen, but rather wait until we can justify their usefulness. | 338 // seen, but rather wait until we can justify their usefulness. |
329 // For now, we will only fetch the first dictionary, which will at least | 339 // For now, we will only fetch the first dictionary, which will at least |
330 // require multiple suggestions before we get additional ones for this site. | 340 // require multiple suggestions before we get additional ones for this site. |
331 // Eventually we should wait until a dictionary is requested several times | 341 // Eventually we should wait until a dictionary is requested several times |
332 // before we even download it (so that we don't waste memory or bandwidth). | 342 // before we even download it (so that we don't waste memory or bandwidth). |
333 if (GetResponseHeaders()->EnumerateHeader(&iter, name, &url_text)) { | 343 if (GetResponseHeaders()->EnumerateHeader(&iter, name, &url_text)) { |
334 // Resolve suggested URL relative to request url. | 344 // Resolve suggested URL relative to request url. |
335 GURL sdch_dictionary_url = request_->url().Resolve(url_text); | 345 GURL sdch_dictionary_url = request_->url().Resolve(url_text); |
336 if (sdch_dictionary_url.is_valid()) { | 346 if (sdch_dictionary_url.is_valid()) { |
337 sdch_manager->FetchDictionary(request_->url(), sdch_dictionary_url); | 347 SdchManager::ProblemCodes rv = |
| 348 sdch_manager->FetchDictionary(request_->url(), sdch_dictionary_url); |
| 349 if (rv != SdchManager::PROBLEM_CODE_OK) { |
| 350 SdchManager::SdchErrorRecovery(rv); |
| 351 request_->net_log().AddEvent( |
| 352 NetLog::TYPE_SDCH_DICTIONARY_FETCH_ERROR, |
| 353 base::Bind(&NetLogSdchDictionaryFetchProblemCallback, |
| 354 rv, |
| 355 &sdch_dictionary_url)); |
| 356 } |
338 } | 357 } |
339 } | 358 } |
340 } | 359 } |
341 | 360 |
342 // The HTTP transaction may be restarted several times for the purposes | 361 // The HTTP transaction may be restarted several times for the purposes |
343 // of sending authorization information. Each time it restarts, we get | 362 // of sending authorization information. Each time it restarts, we get |
344 // notified of the headers completion so that we can update the cookie store. | 363 // notified of the headers completion so that we can update the cookie store. |
345 if (transaction_->IsReadyToRestartForAuth()) { | 364 if (transaction_->IsReadyToRestartForAuth()) { |
346 DCHECK(!response_info_->auth_challenge.get()); | 365 DCHECK(!response_info_->auth_challenge.get()); |
347 // TODO(battre): This breaks the webrequest API for | 366 // TODO(battre): This breaks the webrequest API for |
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 return override_response_headers_.get() ? | 1540 return override_response_headers_.get() ? |
1522 override_response_headers_.get() : | 1541 override_response_headers_.get() : |
1523 transaction_->GetResponseInfo()->headers.get(); | 1542 transaction_->GetResponseInfo()->headers.get(); |
1524 } | 1543 } |
1525 | 1544 |
1526 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1545 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1527 awaiting_callback_ = false; | 1546 awaiting_callback_ = false; |
1528 } | 1547 } |
1529 | 1548 |
1530 } // namespace net | 1549 } // namespace net |
OLD | NEW |