Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: net/url_request/url_request_http_job.cc

Issue 423813002: Sdch view for net-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adopt logging for URLReqest-based dict fetcher + cosmetics Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« net/filter/sdch_filter.cc ('K') | « net/net.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 SdchResponseExpected() const OVERRIDE; 68 virtual bool SdchResponseExpected() 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
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 URLRequestThrottlerHeaderAdapter response_adapter(GetResponseHeaders()); 323 URLRequestThrottlerHeaderAdapter response_adapter(GetResponseHeaders());
314 throttling_entry_->UpdateWithResponse(request_info_.url.host(), 324 throttling_entry_->UpdateWithResponse(request_info_.url.host(),
315 &response_adapter); 325 &response_adapter);
316 } 326 }
317 327
318 // The ordering of these calls is not important. 328 // The ordering of these calls is not important.
319 ProcessStrictTransportSecurityHeader(); 329 ProcessStrictTransportSecurityHeader();
320 ProcessPublicKeyPinsHeader(); 330 ProcessPublicKeyPinsHeader();
321 331
322 SdchManager* sdch_manager(request()->context()->sdch_manager()); 332 SdchManager* sdch_manager(request()->context()->sdch_manager());
323 if (sdch_manager && sdch_manager->IsInSupportedDomain(request_->url())) { 333 if (sdch_manager) {
324 const std::string name = "Get-Dictionary"; 334 SdchManager::ProblemCodes rv =
325 std::string url_text; 335 sdch_manager->IsInSupportedDomain(request()->url());
326 void* iter = NULL; 336 if (rv != SdchManager::PROBLEM_CODE_OK) {
327 // TODO(jar): We need to not fetch dictionaries the first time they are 337 // If SDCH is disabled, it is not a real error.
328 // seen, but rather wait until we can justify their usefulness. 338 bool is_sdch_error = rv == SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET;
329 // For now, we will only fetch the first dictionary, which will at least 339 if (is_sdch_error)
330 // require multiple suggestions before we get additional ones for this site. 340 SdchManager::SdchErrorRecovery(rv);
331 // Eventually we should wait until a dictionary is requested several times 341 request()->net_log().AddEvent(
332 // before we even download it (so that we don't waste memory or bandwidth). 342 NetLog::TYPE_SDCH_RESOURCE_ERROR,
333 if (GetResponseHeaders()->EnumerateHeader(&iter, name, &url_text)) { 343 base::Bind(&NetLogSdchResourceProblemCallback, rv, is_sdch_error));
334 // Resolve suggested URL relative to request url. 344 } else {
335 GURL sdch_dictionary_url = request_->url().Resolve(url_text); 345 const std::string name = "Get-Dictionary";
336 if (sdch_dictionary_url.is_valid()) { 346 std::string url_text;
337 sdch_manager->FetchDictionary(request_->url(), sdch_dictionary_url); 347 void* iter = NULL;
348 // TODO(jar): We need to not fetch dictionaries the first time they are
349 // seen, but rather wait until we can justify their usefulness.
350 // For now, we will only fetch the first dictionary, which will at least
351 // require multiple suggestions before we get additional ones for this
352 // site. Eventually we should wait until a dictionary is requested
353 // several times
354 // before we even download it (so that we don't waste memory or
355 // bandwidth).
356 if (GetResponseHeaders()->EnumerateHeader(&iter, name, &url_text)) {
357 // Resolve suggested URL relative to request url.
358 GURL sdch_dictionary_url = request_->url().Resolve(url_text);
359 if (sdch_dictionary_url.is_valid()) {
360 rv = sdch_manager->FetchDictionary(request_->url(),
361 sdch_dictionary_url);
362 if (rv != SdchManager::PROBLEM_CODE_OK) {
363 SdchManager::SdchErrorRecovery(rv);
364 bool is_error = true;
365 if (rv == SdchManager::DICTIONARY_ALREADY_SCHEDULED_TO_DOWNLOAD ||
366 rv == SdchManager::DICTIONARY_ALREADY_TRIED_TO_DOWNLOAD)
367 is_error = false;
368 request_->net_log().AddEvent(
369 NetLog::TYPE_SDCH_DICTIONARY_FETCH_ERROR,
370 base::Bind(&NetLogSdchDictionaryFetchProblemCallback,
371 rv,
372 &sdch_dictionary_url,
373 is_error));
374 }
375 }
338 } 376 }
339 } 377 }
340 } 378 }
341 379
342 // The HTTP transaction may be restarted several times for the purposes 380 // The HTTP transaction may be restarted several times for the purposes
343 // of sending authorization information. Each time it restarts, we get 381 // of sending authorization information. Each time it restarts, we get
344 // notified of the headers completion so that we can update the cookie store. 382 // notified of the headers completion so that we can update the cookie store.
345 if (transaction_->IsReadyToRestartForAuth()) { 383 if (transaction_->IsReadyToRestartForAuth()) {
346 DCHECK(!response_info_->auth_challenge.get()); 384 DCHECK(!response_info_->auth_challenge.get());
347 // TODO(battre): This breaks the webrequest API for 385 // TODO(battre): This breaks the webrequest API for
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 513
476 // Supply Accept-Encoding field only if it is not already provided. 514 // Supply Accept-Encoding field only if it is not already provided.
477 // It should be provided IF the content is known to have restrictions on 515 // It should be provided IF the content is known to have restrictions on
478 // potential encoding, such as streaming multi-media. 516 // potential encoding, such as streaming multi-media.
479 // For details see bug 47381. 517 // For details see bug 47381.
480 // TODO(jar, enal): jpeg files etc. should set up a request header if 518 // TODO(jar, enal): jpeg files etc. should set up a request header if
481 // possible. Right now it is done only by buffered_resource_loader and 519 // possible. Right now it is done only by buffered_resource_loader and
482 // simple_data_source. 520 // simple_data_source.
483 if (!request_info_.extra_headers.HasHeader( 521 if (!request_info_.extra_headers.HasHeader(
484 HttpRequestHeaders::kAcceptEncoding)) { 522 HttpRequestHeaders::kAcceptEncoding)) {
485 bool advertise_sdch = sdch_manager && 523 // We don't support SDCH responses to POST as there is a possibility
486 // We don't support SDCH responses to POST as there is a possibility 524 // of having SDCH encoded responses returned (e.g. by the cache)
487 // of having SDCH encoded responses returned (e.g. by the cache) 525 // which we cannot decode, and in those situations, we will need
488 // which we cannot decode, and in those situations, we will need 526 // to retransmit the request without SDCH, which is illegal for a POST.
489 // to retransmit the request without SDCH, which is illegal for a POST. 527 bool advertise_sdch = sdch_manager != NULL && request()->method() != "POST";
490 request()->method() != "POST" && 528 if (advertise_sdch) {
491 sdch_manager->IsInSupportedDomain(request_->url()); 529 SdchManager::ProblemCodes rv =
530 sdch_manager->IsInSupportedDomain(request()->url());
531 if (rv != SdchManager::PROBLEM_CODE_OK) {
532 advertise_sdch = false;
533 // If SDCH is disabled, it is not a real error.
534 bool is_sdch_error =
535 rv == SdchManager::DOMAIN_BLACKLIST_INCLUDES_TARGET;
536 if (is_sdch_error)
537 SdchManager::SdchErrorRecovery(rv);
538 request()->net_log().AddEvent(
539 NetLog::TYPE_SDCH_RESOURCE_ERROR,
540 base::Bind(&NetLogSdchResourceProblemCallback, rv, is_sdch_error));
541 }
542 }
492 std::string avail_dictionaries; 543 std::string avail_dictionaries;
493 if (advertise_sdch) { 544 if (advertise_sdch) {
494 sdch_manager->GetAvailDictionaryList(request_->url(), 545 sdch_manager->GetAvailDictionaryList(request_->url(),
495 &avail_dictionaries); 546 &avail_dictionaries);
496 547
497 // The AllowLatencyExperiment() is only true if we've successfully done a 548 // The AllowLatencyExperiment() is only true if we've successfully done a
498 // full SDCH compression recently in this browser session for this host. 549 // full SDCH compression recently in this browser session for this host.
499 // Note that for this path, there might be no applicable dictionaries, 550 // Note that for this path, there might be no applicable dictionaries,
500 // and hence we can't participate in the experiment. 551 // and hence we can't participate in the experiment.
501 if (!avail_dictionaries.empty() && 552 if (!avail_dictionaries.empty() &&
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 return override_response_headers_.get() ? 1573 return override_response_headers_.get() ?
1523 override_response_headers_.get() : 1574 override_response_headers_.get() :
1524 transaction_->GetResponseInfo()->headers.get(); 1575 transaction_->GetResponseInfo()->headers.get();
1525 } 1576 }
1526 1577
1527 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1578 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1528 awaiting_callback_ = false; 1579 awaiting_callback_ = false;
1529 } 1580 }
1530 1581
1531 } // namespace net 1582 } // namespace net
OLDNEW
« net/filter/sdch_filter.cc ('K') | « net/net.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698