Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: chromecast/net/connectivity_checker_impl.cc

Issue 2647323010: [Chromecast] Add proxy server support to chromecast (Closed)
Patch Set: Fix unittest failure Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromecast/net/connectivity_checker_impl.h" 5 #include "chromecast/net/connectivity_checker_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chromecast/base/metrics/cast_metrics_helper.h" 14 #include "chromecast/base/metrics/cast_metrics_helper.h"
15 #include "chromecast/chromecast_features.h" 15 #include "chromecast/chromecast_features.h"
16 #include "chromecast/net/net_switches.h" 16 #include "chromecast/net/net_switches.h"
17 #include "components/proxy_config/pref_proxy_config_tracker.h"
17 #include "net/base/request_priority.h" 18 #include "net/base/request_priority.h"
18 #include "net/http/http_response_headers.h" 19 #include "net/http/http_response_headers.h"
19 #include "net/http/http_response_info.h" 20 #include "net/http/http_response_info.h"
20 #include "net/http/http_status_code.h" 21 #include "net/http/http_status_code.h"
21 #include "net/proxy/proxy_config.h"
22 #include "net/proxy/proxy_config_service_fixed.h"
23 #include "net/socket/ssl_client_socket.h" 22 #include "net/socket/ssl_client_socket.h"
24 #include "net/url_request/url_request_context.h" 23 #include "net/url_request/url_request_context.h"
25 #include "net/url_request/url_request_context_builder.h" 24 #include "net/url_request/url_request_context_builder.h"
26 25
27 namespace chromecast { 26 namespace chromecast {
28 27
29 namespace { 28 namespace {
30 29
31 // How often connectivity checks are performed in seconds while not connected. 30 // How often connectivity checks are performed in seconds while not connected.
32 const unsigned int kConnectivityPeriodSeconds = 1; 31 const unsigned int kConnectivityPeriodSeconds = 1;
(...skipping 18 matching lines...) Expand all
51 // Histogram "Cast.Network.Down.Duration.In.Seconds" shows 40% of network 50 // Histogram "Cast.Network.Down.Duration.In.Seconds" shows 40% of network
52 // downtime is less than 3 seconds. 51 // downtime is less than 3 seconds.
53 const char kNetworkChangedDelayInSeconds = 3; 52 const char kNetworkChangedDelayInSeconds = 3;
54 53
55 const char kMetricNameNetworkConnectivityCheckingErrorType[] = 54 const char kMetricNameNetworkConnectivityCheckingErrorType[] =
56 "Network.ConnectivityChecking.ErrorType"; 55 "Network.ConnectivityChecking.ErrorType";
57 56
58 } // namespace 57 } // namespace
59 58
60 ConnectivityCheckerImpl::ConnectivityCheckerImpl( 59 ConnectivityCheckerImpl::ConnectivityCheckerImpl(
61 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) 60 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
61 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker)
62 : ConnectivityChecker(), 62 : ConnectivityChecker(),
63 task_runner_(task_runner), 63 task_runner_(task_runner),
64 connected_(false), 64 connected_(false),
65 connection_type_(net::NetworkChangeNotifier::CONNECTION_NONE), 65 connection_type_(net::NetworkChangeNotifier::CONNECTION_NONE),
66 check_errors_(0), 66 check_errors_(0),
67 network_changed_pending_(false) { 67 network_changed_pending_(false),
68 pref_proxy_config_tracker_(std::move(pref_proxy_config_tracker)) {
68 DCHECK(task_runner_.get()); 69 DCHECK(task_runner_.get());
70
69 task_runner->PostTask(FROM_HERE, 71 task_runner->PostTask(FROM_HERE,
70 base::Bind(&ConnectivityCheckerImpl::Initialize, this)); 72 base::Bind(&ConnectivityCheckerImpl::Initialize, this));
71 } 73 }
72 74
75 void ConnectivityCheckerImpl::DetachFromPrefService() {
76 if (pref_proxy_config_tracker_.get()) {
77 pref_proxy_config_tracker_->DetachFromPrefService();
78 }
79 }
80
73 void ConnectivityCheckerImpl::Initialize() { 81 void ConnectivityCheckerImpl::Initialize() {
74 DCHECK(task_runner_->BelongsToCurrentThread()); 82 DCHECK(task_runner_->BelongsToCurrentThread());
75 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 83 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
76 base::CommandLine::StringType check_url_str = 84 base::CommandLine::StringType check_url_str =
77 command_line->GetSwitchValueNative(switches::kConnectivityCheckUrl); 85 command_line->GetSwitchValueNative(switches::kConnectivityCheckUrl);
78 connectivity_check_url_.reset(new GURL( 86 connectivity_check_url_.reset(new GURL(
79 check_url_str.empty() ? kDefaultConnectivityCheckUrl : check_url_str)); 87 check_url_str.empty() ? kDefaultConnectivityCheckUrl : check_url_str));
80 88
81 net::URLRequestContextBuilder builder; 89 net::URLRequestContextBuilder builder;
90
82 builder.set_proxy_config_service( 91 builder.set_proxy_config_service(
83 base::MakeUnique<net::ProxyConfigServiceFixed>( 92 pref_proxy_config_tracker_->CreateTrackingProxyConfigService(nullptr));
84 net::ProxyConfig::CreateDirect())); 93
85 builder.DisableHttpCache(); 94 builder.DisableHttpCache();
86 url_request_context_ = builder.Build(); 95 url_request_context_ = builder.Build();
87 96
88 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 97 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
89 task_runner_->PostTask(FROM_HERE, 98 task_runner_->PostTask(FROM_HERE,
90 base::Bind(&ConnectivityCheckerImpl::Check, this)); 99 base::Bind(&ConnectivityCheckerImpl::Check, this));
91 } 100 }
92 101
93 ConnectivityCheckerImpl::~ConnectivityCheckerImpl() { 102 ConnectivityCheckerImpl::~ConnectivityCheckerImpl() {
94 DCHECK(task_runner_.get()); 103 DCHECK(task_runner_.get());
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 void ConnectivityCheckerImpl::Cancel() { 260 void ConnectivityCheckerImpl::Cancel() {
252 DCHECK(task_runner_->BelongsToCurrentThread()); 261 DCHECK(task_runner_->BelongsToCurrentThread());
253 if (!url_request_.get()) 262 if (!url_request_.get())
254 return; 263 return;
255 VLOG(2) << "Cancel connectivity check in progress"; 264 VLOG(2) << "Cancel connectivity check in progress";
256 url_request_.reset(nullptr); // URLRequest::Cancel() is called in destructor. 265 url_request_.reset(nullptr); // URLRequest::Cancel() is called in destructor.
257 timeout_.Cancel(); 266 timeout_.Cancel();
258 } 267 }
259 268
260 } // namespace chromecast 269 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698