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

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

Issue 10918279: Provide mutable members of UrlRequestContext via pure-virtual interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable test for chrome_frame_net_tests Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_test_util.cc » ('j') | 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"
(...skipping 21 matching lines...) Expand all
32 #include "net/http/http_network_session.h" 32 #include "net/http/http_network_session.h"
33 #include "net/http/http_request_headers.h" 33 #include "net/http/http_request_headers.h"
34 #include "net/http/http_response_headers.h" 34 #include "net/http/http_response_headers.h"
35 #include "net/http/http_response_info.h" 35 #include "net/http/http_response_info.h"
36 #include "net/http/http_status_code.h" 36 #include "net/http/http_status_code.h"
37 #include "net/http/http_transaction.h" 37 #include "net/http/http_transaction.h"
38 #include "net/http/http_transaction_delegate.h" 38 #include "net/http/http_transaction_delegate.h"
39 #include "net/http/http_transaction_factory.h" 39 #include "net/http/http_transaction_factory.h"
40 #include "net/http/http_util.h" 40 #include "net/http/http_util.h"
41 #include "net/url_request/fraudulent_certificate_reporter.h" 41 #include "net/url_request/fraudulent_certificate_reporter.h"
42 #include "net/url_request/http_user_agent_settings.h"
42 #include "net/url_request/url_request.h" 43 #include "net/url_request/url_request.h"
43 #include "net/url_request/url_request_context.h" 44 #include "net/url_request/url_request_context.h"
44 #include "net/url_request/url_request_error_job.h" 45 #include "net/url_request/url_request_error_job.h"
45 #include "net/url_request/url_request_redirect_job.h" 46 #include "net/url_request/url_request_redirect_job.h"
46 #include "net/url_request/url_request_throttler_header_adapter.h" 47 #include "net/url_request/url_request_throttler_header_adapter.h"
47 #include "net/url_request/url_request_throttler_manager.h" 48 #include "net/url_request/url_request_throttler_manager.h"
48 49
49 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; 50 static const char kAvailDictionaryHeader[] = "Avail-Dictionary";
50 51
51 namespace net { 52 namespace net {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 205
205 if (!request->context()->http_transaction_factory()) { 206 if (!request->context()->http_transaction_factory()) {
206 NOTREACHED() << "requires a valid context"; 207 NOTREACHED() << "requires a valid context";
207 return new URLRequestErrorJob( 208 return new URLRequestErrorJob(
208 request, network_delegate, ERR_INVALID_ARGUMENT); 209 request, network_delegate, ERR_INVALID_ARGUMENT);
209 } 210 }
210 211
211 GURL redirect_url; 212 GURL redirect_url;
212 if (request->GetHSTSRedirect(&redirect_url)) 213 if (request->GetHSTSRedirect(&redirect_url))
213 return new URLRequestRedirectJob(request, network_delegate, redirect_url); 214 return new URLRequestRedirectJob(request, network_delegate, redirect_url);
214 return new URLRequestHttpJob(request, network_delegate); 215 return new URLRequestHttpJob(request,
216 network_delegate,
217 request->context()->http_user_agent_settings());
215 } 218 }
216 219
217 220
218 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request, 221 URLRequestHttpJob::URLRequestHttpJob(
219 NetworkDelegate* network_delegate) 222 URLRequest* request,
223 NetworkDelegate* network_delegate,
224 const HttpUserAgentSettings* http_user_agent_settings)
220 : URLRequestJob(request, network_delegate), 225 : URLRequestJob(request, network_delegate),
221 response_info_(NULL), 226 response_info_(NULL),
222 response_cookies_save_index_(0), 227 response_cookies_save_index_(0),
223 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), 228 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH),
224 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), 229 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH),
225 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( 230 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_(
226 base::Bind(&URLRequestHttpJob::OnStartCompleted, 231 base::Bind(&URLRequestHttpJob::OnStartCompleted,
227 base::Unretained(this)))), 232 base::Unretained(this)))),
228 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_( 233 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_(
229 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, 234 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback,
(...skipping 11 matching lines...) Expand all
241 bytes_observed_in_packets_(0), 246 bytes_observed_in_packets_(0),
242 request_time_snapshot_(), 247 request_time_snapshot_(),
243 final_packet_time_(), 248 final_packet_time_(),
244 ALLOW_THIS_IN_INITIALIZER_LIST( 249 ALLOW_THIS_IN_INITIALIZER_LIST(
245 filter_context_(new HttpFilterContext(this))), 250 filter_context_(new HttpFilterContext(this))),
246 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 251 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
247 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_( 252 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_(
248 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, 253 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback,
249 base::Unretained(this)))), 254 base::Unretained(this)))),
250 awaiting_callback_(false), 255 awaiting_callback_(false),
251 http_transaction_delegate_(new HttpTransactionDelegateImpl(request)) { 256 http_transaction_delegate_(new HttpTransactionDelegateImpl(request)),
257 http_user_agent_settings_(http_user_agent_settings) {
252 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); 258 URLRequestThrottlerManager* manager = request->context()->throttler_manager();
253 if (manager) 259 if (manager)
254 throttling_entry_ = manager->RegisterRequestUrl(request->url()); 260 throttling_entry_ = manager->RegisterRequestUrl(request->url());
255 261
256 ResetTimer(); 262 ResetTimer();
257 } 263 }
258 264
259 void URLRequestHttpJob::NotifyHeadersComplete() { 265 void URLRequestHttpJob::NotifyHeadersComplete() {
260 DCHECK(!response_info_); 266 DCHECK(!response_info_);
261 267
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 // Since we're tagging this transaction as advertising a dictionary, 470 // Since we're tagging this transaction as advertising a dictionary,
465 // we'll definitely employ an SDCH filter (or tentative sdch filter) 471 // we'll definitely employ an SDCH filter (or tentative sdch filter)
466 // when we get a response. When done, we'll record histograms via 472 // when we get a response. When done, we'll record histograms via
467 // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet 473 // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet
468 // arrival times. 474 // arrival times.
469 packet_timing_enabled_ = true; 475 packet_timing_enabled_ = true;
470 } 476 }
471 } 477 }
472 } 478 }
473 479
474 const URLRequestContext* context = request_->context(); 480 if (http_user_agent_settings_) {
475 // Only add default Accept-Language and Accept-Charset if the request 481 // Only add default Accept-Language and Accept-Charset if the request
476 // didn't have them specified. 482 // didn't have them specified.
477 if (!context->accept_language().empty()) { 483 std::string accept_language =
478 request_info_.extra_headers.SetHeaderIfMissing( 484 http_user_agent_settings_->GetAcceptLanguage();
479 HttpRequestHeaders::kAcceptLanguage, 485 if (!accept_language.empty()) {
480 context->accept_language()); 486 request_info_.extra_headers.SetHeaderIfMissing(
481 } 487 HttpRequestHeaders::kAcceptLanguage,
482 if (!context->accept_charset().empty()) { 488 accept_language);
483 request_info_.extra_headers.SetHeaderIfMissing( 489 }
484 HttpRequestHeaders::kAcceptCharset, 490 std::string accept_charset = http_user_agent_settings_->GetAcceptCharset();
485 context->accept_charset()); 491 if (!accept_charset.empty()) {
492 request_info_.extra_headers.SetHeaderIfMissing(
493 HttpRequestHeaders::kAcceptCharset,
494 accept_charset);
495 }
486 } 496 }
487 } 497 }
488 498
489 void URLRequestHttpJob::AddCookieHeaderAndStart() { 499 void URLRequestHttpJob::AddCookieHeaderAndStart() {
490 // No matter what, we want to report our status as IO pending since we will 500 // No matter what, we want to report our status as IO pending since we will
491 // be notifying our consumer asynchronously via OnStartCompleted. 501 // be notifying our consumer asynchronously via OnStartCompleted.
492 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 502 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
493 503
494 // If the request was destroyed, then there is no more work to do. 504 // If the request was destroyed, then there is no more work to do.
495 if (!request_) 505 if (!request_)
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 924
915 // Our consumer should have made sure that this is a safe referrer. See for 925 // Our consumer should have made sure that this is a safe referrer. See for
916 // instance WebCore::FrameLoader::HideReferrer. 926 // instance WebCore::FrameLoader::HideReferrer.
917 if (referrer.is_valid()) { 927 if (referrer.is_valid()) {
918 request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer, 928 request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer,
919 referrer.spec()); 929 referrer.spec());
920 } 930 }
921 931
922 request_info_.extra_headers.SetHeaderIfMissing( 932 request_info_.extra_headers.SetHeaderIfMissing(
923 HttpRequestHeaders::kUserAgent, 933 HttpRequestHeaders::kUserAgent,
924 request_->context()->GetUserAgent(request_->url())); 934 http_user_agent_settings_ ?
935 http_user_agent_settings_->GetUserAgent(request_->url()) :
936 EmptyString());
925 937
926 AddExtraHeaders(); 938 AddExtraHeaders();
927 AddCookieHeaderAndStart(); 939 AddCookieHeaderAndStart();
928 } 940 }
929 941
930 void URLRequestHttpJob::Kill() { 942 void URLRequestHttpJob::Kill() {
931 http_transaction_delegate_->OnDetachRequest(); 943 http_transaction_delegate_->OnDetachRequest();
932 944
933 if (!transaction_.get()) 945 if (!transaction_.get())
934 return; 946 return;
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 1575
1564 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1576 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1565 awaiting_callback_ = false; 1577 awaiting_callback_ = false;
1566 } 1578 }
1567 1579
1568 void URLRequestHttpJob::OnDetachRequest() { 1580 void URLRequestHttpJob::OnDetachRequest() {
1569 http_transaction_delegate_->OnDetachRequest(); 1581 http_transaction_delegate_->OnDetachRequest();
1570 } 1582 }
1571 1583
1572 } // namespace net 1584 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698