Commit 81293f48 authored by shalev@chromium.org's avatar shalev@chromium.org

Removed checks that verify URLRequest has a Context

Due to a recent cl, URLRequest must get a non-NULL context in the constructor.
This means that if-statements and DCHECKs that verify the existence of context
are no longer needed.

BUG=None


Review URL: https://chromiumcodereview.appspot.com/10830124

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151326 0039d316-1c4b-4281-b951-d872f2087c98
parent cde8b3c3
......@@ -416,21 +416,19 @@ void URLRequestAutomationJob::StartAsync() {
for (size_t i = 0; i < arraysize(kFilteredHeaderStrings); ++i)
new_request_headers.RemoveHeader(kFilteredHeaderStrings[i]);
if (request_->context()) {
// Only add default Accept-Language and Accept-Charset if the request
// didn't have them specified.
if (!new_request_headers.HasHeader(
net::HttpRequestHeaders::kAcceptLanguage) &&
!request_->context()->accept_language().empty()) {
new_request_headers.SetHeader(net::HttpRequestHeaders::kAcceptLanguage,
request_->context()->accept_language());
}
if (!new_request_headers.HasHeader(
net::HttpRequestHeaders::kAcceptCharset) &&
!request_->context()->accept_charset().empty()) {
new_request_headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset,
request_->context()->accept_charset());
}
// Only add default Accept-Language and Accept-Charset if the request
// didn't have them specified.
if (!new_request_headers.HasHeader(
net::HttpRequestHeaders::kAcceptLanguage) &&
!request_->context()->accept_language().empty()) {
new_request_headers.SetHeader(net::HttpRequestHeaders::kAcceptLanguage,
request_->context()->accept_language());
}
if (!new_request_headers.HasHeader(
net::HttpRequestHeaders::kAcceptCharset) &&
!request_->context()->accept_charset().empty()) {
new_request_headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset,
request_->context()->accept_charset());
}
// Ensure that we do not send username and password fields in the referrer.
......
......@@ -611,7 +611,7 @@ void URLRequest::NotifyResponseStarted() {
// In some cases (e.g. an event was canceled), we might have sent the
// completion event and receive a NotifyResponseStarted() later.
if (!has_notified_completion_ && status_.is_success()) {
if (context_ && context_->network_delegate())
if (context_->network_delegate())
context_->network_delegate()->NotifyResponseStarted(this);
}
......@@ -695,7 +695,7 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) {
NetLog::StringCallback("location", &location.possibly_invalid_spec()));
}
if (context_ && context_->network_delegate())
if (context_->network_delegate())
context_->network_delegate()->NotifyBeforeRedirect(this, location);
if (redirect_limit_ <= 0) {
......@@ -789,7 +789,7 @@ void URLRequest::NotifyAuthRequired(AuthChallengeInfo* auth_info) {
NetworkDelegate::AuthRequiredResponse rv =
NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
auth_info_ = auth_info;
if (context_ && context_->network_delegate()) {
if (context_->network_delegate()) {
rv = context_->network_delegate()->NotifyAuthRequired(
this,
*auth_info,
......@@ -856,7 +856,7 @@ void URLRequest::NotifySSLCertificateError(const SSLInfo& ssl_info,
bool URLRequest::CanGetCookies(const CookieList& cookie_list) const {
DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES));
if (context_ && context_->network_delegate()) {
if (context_->network_delegate()) {
return context_->network_delegate()->CanGetCookies(*this,
cookie_list);
}
......@@ -866,7 +866,7 @@ bool URLRequest::CanGetCookies(const CookieList& cookie_list) const {
bool URLRequest::CanSetCookie(const std::string& cookie_line,
CookieOptions* options) const {
DCHECK(!(load_flags_ & LOAD_DO_NOT_SAVE_COOKIES));
if (context_ && context_->network_delegate()) {
if (context_->network_delegate()) {
return context_->network_delegate()->CanSetCookie(*this,
cookie_line,
options);
......@@ -899,7 +899,7 @@ void URLRequest::NotifyRequestCompleted() {
is_pending_ = false;
has_notified_completion_ = true;
if (context_ && context_->network_delegate())
if (context_->network_delegate())
context_->network_delegate()->NotifyCompleted(this, job_ != NULL);
}
......
......@@ -253,10 +253,7 @@ void URLRequestFileJob::SetExtraRequestHeaders(
// static
bool URLRequestFileJob::IsFileAccessAllowed(const URLRequest& request,
const FilePath& path) {
const URLRequestContext* context = request.context();
if (!context)
return false;
const NetworkDelegate* delegate = context->network_delegate();
const NetworkDelegate* delegate = request.context()->network_delegate();
if (delegate)
return delegate->CanAccessFile(request, path);
return false;
......
......@@ -172,8 +172,7 @@ URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request,
const std::string& scheme) {
DCHECK(scheme == "http" || scheme == "https");
if (!request->context() ||
!request->context()->http_transaction_factory()) {
if (!request->context()->http_transaction_factory()) {
NOTREACHED() << "requires a valid context";
return new URLRequestErrorJob(request, ERR_INVALID_ARGUMENT);
}
......@@ -294,7 +293,7 @@ void URLRequestHttpJob::DestroyTransaction() {
}
void URLRequestHttpJob::StartTransaction() {
if (request_->context() && request_->context()->network_delegate()) {
if (request_->context()->network_delegate()) {
int rv = request_->context()->network_delegate()->NotifyBeforeSendHeaders(
request_, notify_before_headers_sent_callback_,
&request_info_.extra_headers);
......@@ -332,7 +331,7 @@ void URLRequestHttpJob::StartTransactionInternal() {
int rv;
if (request_->context() && request_->context()->network_delegate()) {
if (request_->context()->network_delegate()) {
request_->context()->network_delegate()->NotifySendHeaders(
request_, request_info_.extra_headers);
}
......@@ -341,7 +340,6 @@ void URLRequestHttpJob::StartTransactionInternal() {
rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_);
auth_credentials_ = AuthCredentials();
} else {
DCHECK(request_->context());
DCHECK(request_->context()->http_transaction_factory());
rv = request_->context()->http_transaction_factory()->CreateTransaction(
......@@ -435,19 +433,17 @@ void URLRequestHttpJob::AddExtraHeaders() {
}
const URLRequestContext* context = request_->context();
if (context) {
// Only add default Accept-Language and Accept-Charset if the request
// didn't have them specified.
if (!context->accept_language().empty()) {
request_info_.extra_headers.SetHeaderIfMissing(
HttpRequestHeaders::kAcceptLanguage,
context->accept_language());
}
if (!context->accept_charset().empty()) {
request_info_.extra_headers.SetHeaderIfMissing(
HttpRequestHeaders::kAcceptCharset,
context->accept_charset());
}
// Only add default Accept-Language and Accept-Charset if the request
// didn't have them specified.
if (!context->accept_language().empty()) {
request_info_.extra_headers.SetHeaderIfMissing(
HttpRequestHeaders::kAcceptLanguage,
context->accept_language());
}
if (!context->accept_charset().empty()) {
request_info_.extra_headers.SetHeaderIfMissing(
HttpRequestHeaders::kAcceptCharset,
context->accept_charset());
}
}
......@@ -460,8 +456,7 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() {
if (!request_)
return;
CookieStore* cookie_store =
request_->context()->cookie_store();
CookieStore* cookie_store = request_->context()->cookie_store();
if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) {
net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
if (cookie_monster) {
......@@ -650,7 +645,7 @@ void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() {
// Only accept strict transport security headers on HTTPS connections that
// have no certificate errors.
if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) ||
!ctx || !ctx->transport_security_state()) {
!ctx->transport_security_state()) {
return;
}
......@@ -687,7 +682,7 @@ void URLRequestHttpJob::ProcessPublicKeyPinsHeader() {
// Only accept public key pins headers on HTTPS connections that have no
// certificate errors.
if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) ||
!ctx || !ctx->transport_security_state()) {
!ctx->transport_security_state()) {
return;
}
......@@ -750,7 +745,7 @@ void URLRequestHttpJob::OnStartCompleted(int result) {
if (result == OK) {
scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders();
if (context && context->network_delegate()) {
if (context->network_delegate()) {
// Note that |this| may not be deleted until
// |on_headers_received_callback_| or
// |NetworkDelegate::URLRequestDestroyed()| has been called.
......@@ -876,11 +871,9 @@ void URLRequestHttpJob::Start() {
referrer.spec());
}
if (request_->context()) {
request_info_.extra_headers.SetHeaderIfMissing(
HttpRequestHeaders::kUserAgent,
request_->context()->GetUserAgent(request_->url()));
}
request_info_.extra_headers.SetHeaderIfMissing(
HttpRequestHeaders::kUserAgent,
request_->context()->GetUserAgent(request_->url()));
AddExtraHeaders();
AddCookieHeaderAndStart();
......
......@@ -57,8 +57,7 @@ URLRequestJob* URLRequestJobManager::CreateJob(
// We do this here to avoid asking interceptors about unsupported schemes.
const URLRequestJobFactory* job_factory = NULL;
if (request->context())
job_factory = request->context()->job_factory();
job_factory = request->context()->job_factory();
const std::string& scheme = request->url().scheme(); // already lowercase
if (job_factory) {
......@@ -138,8 +137,7 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect(
}
const URLRequestJobFactory* job_factory = NULL;
if (request->context())
job_factory = request->context()->job_factory();
job_factory = request->context()->job_factory();
const std::string& scheme = request->url().scheme(); // already lowercase
if (job_factory) {
......@@ -175,8 +173,7 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptResponse(
}
const URLRequestJobFactory* job_factory = NULL;
if (request->context())
job_factory = request->context()->job_factory();
job_factory = request->context()->job_factory();
const std::string& scheme = request->url().scheme(); // already lowercase
if (job_factory) {
......
......@@ -153,7 +153,7 @@ bool URLRequestThrottlerEntry::ShouldRejectRequest(
const URLRequest& request) const {
bool reject_request = false;
if (!is_backoff_disabled_ && !ExplicitUserRequest(request.load_flags()) &&
(!request.context() || !request.context()->network_delegate() ||
(!request.context()->network_delegate() ||
request.context()->network_delegate()->CanThrottleRequest(request)) &&
GetBackoffEntry()->ShouldRejectRequest()) {
int num_failures = GetBackoffEntry()->failure_count();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment