Commit 051a4b39 authored by thestig@chromium.org's avatar thestig@chromium.org

Cleanup: Remove legacy accessors from URLRequestContext.

Review URL: https://codereview.chromium.org/83433008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243750 0039d316-1c4b-4281-b951-d872f2087c98
parent 1b901f99
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "net/http/http_stream_factory.h" #include "net/http/http_stream_factory.h"
#include "net/http/http_transaction_factory.h" #include "net/http/http_transaction_factory.h"
#include "net/ssl/ssl_config_service.h" #include "net/ssl/ssl_config_service.h"
#include "net/url_request/http_user_agent_settings.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
...@@ -57,11 +58,14 @@ void PreconnectOnIOThread( ...@@ -57,11 +58,14 @@ void PreconnectOnIOThread(
net::HttpTransactionFactory* factory = context->http_transaction_factory(); net::HttpTransactionFactory* factory = context->http_transaction_factory();
net::HttpNetworkSession* session = factory->GetSession(); net::HttpNetworkSession* session = factory->GetSession();
std::string user_agent;
if (context->http_user_agent_settings())
user_agent = context->http_user_agent_settings()->GetUserAgent(url);
net::HttpRequestInfo request_info; net::HttpRequestInfo request_info;
request_info.url = url; request_info.url = url;
request_info.method = "GET"; request_info.method = "GET";
request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent,
context->GetUserAgent(url)); user_agent);
net::NetworkDelegate* delegate = context->network_delegate(); net::NetworkDelegate* delegate = context->network_delegate();
if (delegate->CanEnablePrivacyMode(url, first_party_for_cookies)) if (delegate->CanEnablePrivacyMode(url, first_party_for_cookies))
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "google_apis/google_api_keys.h" #include "google_apis/google_api_keys.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/url_request/http_user_agent_settings.h"
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
...@@ -174,9 +175,12 @@ void GoogleOneShotRemoteEngine::StartRecognition() { ...@@ -174,9 +175,12 @@ void GoogleOneShotRemoteEngine::StartRecognition() {
// TODO(pauljensen): GoogleOneShotRemoteEngine should be constructed with // TODO(pauljensen): GoogleOneShotRemoteEngine should be constructed with
// a reference to the HttpUserAgentSettings rather than accessing the // a reference to the HttpUserAgentSettings rather than accessing the
// accept language through the URLRequestContext. // accept language through the URLRequestContext.
std::string accepted_language_list = request_context->GetAcceptLanguage(); if (request_context->http_user_agent_settings()) {
size_t separator = accepted_language_list.find_first_of(",;"); std::string accepted_language_list =
lang_param = accepted_language_list.substr(0, separator); request_context->http_user_agent_settings()->GetAcceptLanguage();
size_t separator = accepted_language_list.find_first_of(",;");
lang_param = accepted_language_list.substr(0, separator);
}
} }
if (lang_param.empty()) if (lang_param.empty())
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "google_apis/google_api_keys.h" #include "google_apis/google_api_keys.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/url_request/http_user_agent_settings.h"
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
...@@ -563,10 +564,13 @@ std::string GoogleStreamingRemoteEngine::GetAcceptedLanguages() const { ...@@ -563,10 +564,13 @@ std::string GoogleStreamingRemoteEngine::GetAcceptedLanguages() const {
// TODO(pauljensen): GoogleStreamingRemoteEngine should be constructed with // TODO(pauljensen): GoogleStreamingRemoteEngine should be constructed with
// a reference to the HttpUserAgentSettings rather than accessing the // a reference to the HttpUserAgentSettings rather than accessing the
// accept language through the URLRequestContext. // accept language through the URLRequestContext.
std::string accepted_language_list = request_context->GetAcceptLanguage(); if (request_context->http_user_agent_settings()) {
size_t separator = accepted_language_list.find_first_of(",;"); std::string accepted_language_list =
if (separator != std::string::npos) request_context->http_user_agent_settings()->GetAcceptLanguage();
langs = accepted_language_list.substr(0, separator); size_t separator = accepted_language_list.find_first_of(",;");
if (separator != std::string::npos)
langs = accepted_language_list.substr(0, separator);
}
} }
if (langs.empty()) if (langs.empty())
langs = "en-US"; langs = "en-US";
......
...@@ -81,16 +81,6 @@ void URLRequestContext::set_cookie_store(CookieStore* cookie_store) { ...@@ -81,16 +81,6 @@ void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
cookie_store_ = cookie_store; cookie_store_ = cookie_store;
} }
std::string URLRequestContext::GetAcceptLanguage() const {
return http_user_agent_settings_ ?
http_user_agent_settings_->GetAcceptLanguage() : std::string();
}
std::string URLRequestContext::GetUserAgent(const GURL& url) const {
return http_user_agent_settings_ ?
http_user_agent_settings_->GetUserAgent(url) : std::string();
}
void URLRequestContext::AssertNoURLRequests() const { void URLRequestContext::AssertNoURLRequests() const {
int num_requests = url_requests_->size(); int num_requests = url_requests_->size();
if (num_requests != 0) { if (num_requests != 0) {
......
...@@ -167,17 +167,6 @@ class NET_EXPORT URLRequestContext ...@@ -167,17 +167,6 @@ class NET_EXPORT URLRequestContext
cert_transparency_verifier_ = verifier; cert_transparency_verifier_ = verifier;
} }
// ---------------------------------------------------------------------------
// Legacy accessors that delegate to http_user_agent_settings_.
// TODO(pauljensen): Remove after all clients are updated to directly access
// http_user_agent_settings_.
// Gets the value of 'Accept-Language' header field.
std::string GetAcceptLanguage() const;
// Gets the UA string to use for the given URL. Pass an invalid URL (such as
// GURL()) to get the default UA string.
std::string GetUserAgent(const GURL& url) const;
// ---------------------------------------------------------------------------
const URLRequestJobFactory* job_factory() const { return job_factory_; } const URLRequestJobFactory* job_factory() const { return job_factory_; }
void set_job_factory(const URLRequestJobFactory* job_factory) { void set_job_factory(const URLRequestJobFactory* job_factory) {
job_factory_ = job_factory; job_factory_ = job_factory;
......
...@@ -5943,7 +5943,8 @@ TEST_F(URLRequestTestHTTP, DefaultUserAgent) { ...@@ -5943,7 +5943,8 @@ TEST_F(URLRequestTestHTTP, DefaultUserAgent) {
&default_context_); &default_context_);
req.Start(); req.Start();
base::RunLoop().Run(); base::RunLoop().Run();
EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); EXPECT_EQ(req.context()->http_user_agent_settings()->GetUserAgent(req.url()),
d.data_received());
} }
// Check that if request overrides the User-Agent header, // Check that if request overrides the User-Agent header,
......
...@@ -151,8 +151,13 @@ HttpBridge::RequestContext::RequestContext( ...@@ -151,8 +151,13 @@ HttpBridge::RequestContext::RequestContext(
// should be tied to whatever the sync servers expect (if anything). These // should be tied to whatever the sync servers expect (if anything). These
// fields should probably just be settable by sync backend; though we should // fields should probably just be settable by sync backend; though we should
// figure out if we need to give the user explicit control over policies etc. // figure out if we need to give the user explicit control over policies etc.
std::string accepted_language_list;
if (baseline_context->http_user_agent_settings()) {
accepted_language_list =
baseline_context->http_user_agent_settings()->GetAcceptLanguage();
}
http_user_agent_settings_.reset(new net::StaticHttpUserAgentSettings( http_user_agent_settings_.reset(new net::StaticHttpUserAgentSettings(
baseline_context->GetAcceptLanguage(), accepted_language_list,
user_agent)); user_agent));
set_http_user_agent_settings(http_user_agent_settings_.get()); set_http_user_agent_settings(http_user_agent_settings_.get());
......
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