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
3 // found in the LICENSE file.
5 #include "chrome/test/chromedriver/net/url_request_context_getter.h"
9 #include "net/proxy/proxy_config_service.h"
10 #include "net/url_request/url_request_context.h"
11 #include "net/url_request/url_request_context_builder.h"
15 // Config getter that always returns direct settings.
16 class ProxyConfigServiceDirect
: public net::ProxyConfigService
{
18 // Overridden from ProxyConfigService:
19 virtual void AddObserver(Observer
* observer
) OVERRIDE
{}
20 virtual void RemoveObserver(Observer
* observer
) OVERRIDE
{}
21 virtual ConfigAvailability
GetLatestProxyConfig(
22 net::ProxyConfig
* config
) OVERRIDE
{
23 *config
= net::ProxyConfig::CreateDirect();
30 URLRequestContextGetter::URLRequestContextGetter(
31 scoped_refptr
<base::SingleThreadTaskRunner
> network_task_runner
)
32 : network_task_runner_(network_task_runner
) {
35 net::URLRequestContext
* URLRequestContextGetter::GetURLRequestContext() {
36 CHECK(network_task_runner_
->BelongsToCurrentThread());
37 if (!url_request_context_
) {
38 net::URLRequestContextBuilder builder
;
39 // net::HttpServer fails to parse headers if user-agent header is blank.
40 builder
.set_user_agent("chromedriver");
41 builder
.DisableHttpCache();
42 #if defined(OS_LINUX) || defined(OS_ANDROID)
43 builder
.set_proxy_config_service(new ProxyConfigServiceDirect());
45 url_request_context_
.reset(builder
.Build());
47 return url_request_context_
.get();
50 scoped_refptr
<base::SingleThreadTaskRunner
>
51 URLRequestContextGetter::GetNetworkTaskRunner() const {
52 return network_task_runner_
;
55 URLRequestContextGetter::~URLRequestContextGetter() {}