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

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: Address mmenke's comments 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
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 20 matching lines...) Expand all
31 #include "net/cookies/cookie_monster.h" 31 #include "net/cookies/cookie_monster.h"
32 #include "net/http/http_request_headers.h" 32 #include "net/http/http_request_headers.h"
33 #include "net/http/http_response_headers.h" 33 #include "net/http/http_response_headers.h"
34 #include "net/http/http_response_info.h" 34 #include "net/http/http_response_info.h"
35 #include "net/http/http_status_code.h" 35 #include "net/http/http_status_code.h"
36 #include "net/http/http_transaction.h" 36 #include "net/http/http_transaction.h"
37 #include "net/http/http_transaction_delegate.h" 37 #include "net/http/http_transaction_delegate.h"
38 #include "net/http/http_transaction_factory.h" 38 #include "net/http/http_transaction_factory.h"
39 #include "net/http/http_util.h" 39 #include "net/http/http_util.h"
40 #include "net/url_request/fraudulent_certificate_reporter.h" 40 #include "net/url_request/fraudulent_certificate_reporter.h"
41 #include "net/url_request/http_user_agent_settings.h"
41 #include "net/url_request/url_request.h" 42 #include "net/url_request/url_request.h"
42 #include "net/url_request/url_request_context.h" 43 #include "net/url_request/url_request_context.h"
43 #include "net/url_request/url_request_error_job.h" 44 #include "net/url_request/url_request_error_job.h"
44 #include "net/url_request/url_request_redirect_job.h" 45 #include "net/url_request/url_request_redirect_job.h"
45 #include "net/url_request/url_request_throttler_header_adapter.h" 46 #include "net/url_request/url_request_throttler_header_adapter.h"
46 #include "net/url_request/url_request_throttler_manager.h" 47 #include "net/url_request/url_request_throttler_manager.h"
47 48
48 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; 49 static const char kAvailDictionaryHeader[] = "Avail-Dictionary";
49 50
50 namespace net { 51 namespace net {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 204
204 if (!request->context()->http_transaction_factory()) { 205 if (!request->context()->http_transaction_factory()) {
205 NOTREACHED() << "requires a valid context"; 206 NOTREACHED() << "requires a valid context";
206 return new URLRequestErrorJob( 207 return new URLRequestErrorJob(
207 request, network_delegate, ERR_INVALID_ARGUMENT); 208 request, network_delegate, ERR_INVALID_ARGUMENT);
208 } 209 }
209 210
210 GURL redirect_url; 211 GURL redirect_url;
211 if (request->GetHSTSRedirect(&redirect_url)) 212 if (request->GetHSTSRedirect(&redirect_url))
212 return new URLRequestRedirectJob(request, network_delegate, redirect_url); 213 return new URLRequestRedirectJob(request, network_delegate, redirect_url);
213 return new URLRequestHttpJob(request, network_delegate); 214 return new URLRequestHttpJob(request,
215 network_delegate,
216 request->context()->http_user_agent_settings());
214 } 217 }
215 218
216 219
217 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request, 220 URLRequestHttpJob::URLRequestHttpJob(
218 NetworkDelegate* network_delegate) 221 URLRequest* request,
222 NetworkDelegate* network_delegate,
223 const HttpUserAgentSettings* http_user_agent_settings)
219 : URLRequestJob(request, network_delegate), 224 : URLRequestJob(request, network_delegate),
220 response_info_(NULL), 225 response_info_(NULL),
221 response_cookies_save_index_(0), 226 response_cookies_save_index_(0),
222 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), 227 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH),
223 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), 228 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH),
224 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( 229 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_(
225 base::Bind(&URLRequestHttpJob::OnStartCompleted, 230 base::Bind(&URLRequestHttpJob::OnStartCompleted,
226 base::Unretained(this)))), 231 base::Unretained(this)))),
227 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_( 232 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_(
228 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, 233 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback,
(...skipping 11 matching lines...) Expand all
240 bytes_observed_in_packets_(0), 245 bytes_observed_in_packets_(0),
241 request_time_snapshot_(), 246 request_time_snapshot_(),
242 final_packet_time_(), 247 final_packet_time_(),
243 ALLOW_THIS_IN_INITIALIZER_LIST( 248 ALLOW_THIS_IN_INITIALIZER_LIST(
244 filter_context_(new HttpFilterContext(this))), 249 filter_context_(new HttpFilterContext(this))),
245 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 250 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
246 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_( 251 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_(
247 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, 252 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback,
248 base::Unretained(this)))), 253 base::Unretained(this)))),
249 awaiting_callback_(false), 254 awaiting_callback_(false),
250 http_transaction_delegate_(new HttpTransactionDelegateImpl(request)) { 255 http_transaction_delegate_(new HttpTransactionDelegateImpl(request)),
256 http_user_agent_settings_(http_user_agent_settings) {
251 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); 257 URLRequestThrottlerManager* manager = request->context()->throttler_manager();
252 if (manager) 258 if (manager)
253 throttling_entry_ = manager->RegisterRequestUrl(request->url()); 259 throttling_entry_ = manager->RegisterRequestUrl(request->url());
254 260
255 ResetTimer(); 261 ResetTimer();
256 } 262 }
257 263
258 void URLRequestHttpJob::NotifyHeadersComplete() { 264 void URLRequestHttpJob::NotifyHeadersComplete() {
259 DCHECK(!response_info_); 265 DCHECK(!response_info_);
260 266
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 // Since we're tagging this transaction as advertising a dictionary, 469 // Since we're tagging this transaction as advertising a dictionary,
464 // we'll definitely employ an SDCH filter (or tentative sdch filter) 470 // we'll definitely employ an SDCH filter (or tentative sdch filter)
465 // when we get a response. When done, we'll record histograms via 471 // when we get a response. When done, we'll record histograms via
466 // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet 472 // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet
467 // arrival times. 473 // arrival times.
468 packet_timing_enabled_ = true; 474 packet_timing_enabled_ = true;
469 } 475 }
470 } 476 }
471 } 477 }
472 478
473 const URLRequestContext* context = request_->context(); 479 if (http_user_agent_settings_) {
474 // Only add default Accept-Language and Accept-Charset if the request 480 // Only add default Accept-Language and Accept-Charset if the request
475 // didn't have them specified. 481 // didn't have them specified.
476 if (!context->accept_language().empty()) { 482 std::string accept_language =
477 request_info_.extra_headers.SetHeaderIfMissing( 483 http_user_agent_settings_->GetAcceptLanguage();
478 HttpRequestHeaders::kAcceptLanguage, 484 if (!accept_language.empty()) {
479 context->accept_language()); 485 request_info_.extra_headers.SetHeaderIfMissing(
480 } 486 HttpRequestHeaders::kAcceptLanguage,
481 if (!context->accept_charset().empty()) { 487 accept_language);
482 request_info_.extra_headers.SetHeaderIfMissing( 488 }
483 HttpRequestHeaders::kAcceptCharset, 489 std::string accept_charset = http_user_agent_settings_->GetAcceptCharset();
484 context->accept_charset()); 490 if (!accept_charset.empty()) {
491 request_info_.extra_headers.SetHeaderIfMissing(
492 HttpRequestHeaders::kAcceptCharset,
493 accept_charset);
494 }
485 } 495 }
486 } 496 }
487 497
488 void URLRequestHttpJob::AddCookieHeaderAndStart() { 498 void URLRequestHttpJob::AddCookieHeaderAndStart() {
489 // No matter what, we want to report our status as IO pending since we will 499 // No matter what, we want to report our status as IO pending since we will
490 // be notifying our consumer asynchronously via OnStartCompleted. 500 // be notifying our consumer asynchronously via OnStartCompleted.
491 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 501 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
492 502
493 // If the request was destroyed, then there is no more work to do. 503 // If the request was destroyed, then there is no more work to do.
494 if (!request_) 504 if (!request_)
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 910
901 // Our consumer should have made sure that this is a safe referrer. See for 911 // Our consumer should have made sure that this is a safe referrer. See for
902 // instance WebCore::FrameLoader::HideReferrer. 912 // instance WebCore::FrameLoader::HideReferrer.
903 if (referrer.is_valid()) { 913 if (referrer.is_valid()) {
904 request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer, 914 request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer,
905 referrer.spec()); 915 referrer.spec());
906 } 916 }
907 917
908 request_info_.extra_headers.SetHeaderIfMissing( 918 request_info_.extra_headers.SetHeaderIfMissing(
909 HttpRequestHeaders::kUserAgent, 919 HttpRequestHeaders::kUserAgent,
910 request_->context()->GetUserAgent(request_->url())); 920 http_user_agent_settings_ ?
921 http_user_agent_settings_->GetUserAgent(request_->url()) :
922 EmptyString());
911 923
912 AddExtraHeaders(); 924 AddExtraHeaders();
913 AddCookieHeaderAndStart(); 925 AddCookieHeaderAndStart();
914 } 926 }
915 927
916 void URLRequestHttpJob::Kill() { 928 void URLRequestHttpJob::Kill() {
917 http_transaction_delegate_->OnDetachRequest(); 929 http_transaction_delegate_->OnDetachRequest();
918 930
919 if (!transaction_.get()) 931 if (!transaction_.get())
920 return; 932 return;
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 1516
1505 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1517 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1506 awaiting_callback_ = false; 1518 awaiting_callback_ = false;
1507 } 1519 }
1508 1520
1509 void URLRequestHttpJob::OnDetachRequest() { 1521 void URLRequestHttpJob::OnDetachRequest() {
1510 http_transaction_delegate_->OnDetachRequest(); 1522 http_transaction_delegate_->OnDetachRequest();
1511 } 1523 }
1512 1524
1513 } // namespace net 1525 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698