Update parsing of dumpsys batterystats
[chromium-blink-merge.git] / remoting / base / url_request_context_getter.cc
blobb07ccf9854ee7cba8caf0aca8e85e8e34c8fc49e
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"
12 #if defined(OS_WIN)
13 #include "net/proxy/proxy_config_service_win.h"
14 #elif defined(OS_IOS)
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"
20 #endif
22 namespace remoting {
24 namespace {
26 // Config getter that always returns direct settings.
27 class ProxyConfigServiceDirect : public net::ProxyConfigService {
28 public:
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();
35 return CONFIG_VALID;
39 net::ProxyConfigService* CreateSystemProxyConfigService(
40 base::SingleThreadTaskRunner* io_thread_task_runner) {
41 #if defined(OS_WIN)
42 return new net::ProxyConfigServiceWin();
43 #elif defined(OS_IOS)
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";
49 return NULL;
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();
63 #else
64 LOG(WARNING) << "Failed to choose a system proxy settings fetcher "
65 "for this platform.";
66 return new ProxyConfigServiceDirect();
67 #endif
70 } // namespace
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