1 // Copyright 2014 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 "remoting/base/url_request_context_getter.h"
7 #include "base/message_loop/message_loop_proxy.h"
8 #include "net/proxy/proxy_config_service.h"
9 #include "net/url_request/url_request_context_builder.h"
10 #include "remoting/base/vlog_net_log.h"
13 #include "net/proxy/proxy_config_service_win.h"
15 #include "net/proxy/proxy_config_service_ios.h"
16 #elif defined(OS_MACOSX)
17 #include "net/proxy/proxy_config_service_mac.h"
18 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
19 #include "net/proxy/proxy_config_service_linux.h"
26 // Config getter that always returns direct settings.
27 class ProxyConfigServiceDirect
: public net::ProxyConfigService
{
29 // ProxyConfigService implementation:
30 virtual void AddObserver(Observer
* observer
) OVERRIDE
{}
31 virtual void RemoveObserver(Observer
* observer
) OVERRIDE
{}
32 virtual ConfigAvailability
GetLatestProxyConfig(
33 net::ProxyConfig
* config
) OVERRIDE
{
34 *config
= net::ProxyConfig::CreateDirect();
39 net::ProxyConfigService
* CreateSystemProxyConfigService(
40 base::SingleThreadTaskRunner
* io_thread_task_runner
) {
42 return new net::ProxyConfigServiceWin();
44 return new net::ProxyConfigServiceIOS();
45 #elif defined(OS_MACOSX)
46 return new net::ProxyConfigServiceMac(io_thread_task_runner
);
47 #elif defined(OS_CHROMEOS)
48 NOTREACHED() << "ChromeOS is not a supported target for Chromoting host";
50 #elif defined(OS_LINUX)
51 // TODO(sergeyu): Currently ProxyConfigServiceLinux depends on
52 // base::OneShotTimer that doesn't work properly on main NPAPI
53 // thread. Fix that and uncomment the code below.
55 // net::ProxyConfigServiceLinux* linux_config_service =
56 // new net::ProxyConfigServiceLinux();
57 // linux_config_service->SetupAndFetchInitialConfig(
58 // ui_message_loop_, io_message_loop->message_loop_proxy(),
59 // file_message_loop);
61 // return linux_config_service;
62 return new ProxyConfigServiceDirect();
64 LOG(WARNING
) << "Failed to choose a system proxy settings fetcher "
66 return new ProxyConfigServiceDirect();
72 URLRequestContextGetter::URLRequestContextGetter(
73 scoped_refptr
<base::SingleThreadTaskRunner
> network_task_runner
)
74 : network_task_runner_(network_task_runner
) {
75 proxy_config_service_
.reset(CreateSystemProxyConfigService(
76 network_task_runner_
.get()));
79 net::URLRequestContext
* URLRequestContextGetter::GetURLRequestContext() {
80 if (!url_request_context_
.get()) {
81 net::URLRequestContextBuilder builder
;
82 builder
.set_net_log(new VlogNetLog());
83 builder
.DisableHttpCache();
84 builder
.set_proxy_config_service(proxy_config_service_
.release());
85 url_request_context_
.reset(builder
.Build());
87 return url_request_context_
.get();
90 scoped_refptr
<base::SingleThreadTaskRunner
>
91 URLRequestContextGetter::GetNetworkTaskRunner() const {
92 return network_task_runner_
;
95 URLRequestContextGetter::~URLRequestContextGetter() {
98 } // namespace remoting