OLD | NEW |
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 "net/base/request_priority.h" | 17 #include "net/base/request_priority.h" |
18 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
19 #include "net/http/http_response_info.h" | 19 #include "net/http/http_response_info.h" |
20 #include "net/http/http_status_code.h" | 20 #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" | 21 #include "net/socket/ssl_client_socket.h" |
24 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
25 #include "net/url_request/url_request_context_builder.h" | 23 #include "net/url_request/url_request_context_builder.h" |
26 | 24 |
27 namespace chromecast { | 25 namespace chromecast { |
28 | 26 |
29 namespace { | 27 namespace { |
30 | 28 |
31 // How often connectivity checks are performed in seconds while not connected. | 29 // How often connectivity checks are performed in seconds while not connected. |
32 const unsigned int kConnectivityPeriodSeconds = 1; | 30 const unsigned int kConnectivityPeriodSeconds = 1; |
(...skipping 18 matching lines...) Expand all Loading... |
51 // Histogram "Cast.Network.Down.Duration.In.Seconds" shows 40% of network | 49 // Histogram "Cast.Network.Down.Duration.In.Seconds" shows 40% of network |
52 // downtime is less than 3 seconds. | 50 // downtime is less than 3 seconds. |
53 const char kNetworkChangedDelayInSeconds = 3; | 51 const char kNetworkChangedDelayInSeconds = 3; |
54 | 52 |
55 const char kMetricNameNetworkConnectivityCheckingErrorType[] = | 53 const char kMetricNameNetworkConnectivityCheckingErrorType[] = |
56 "Network.ConnectivityChecking.ErrorType"; | 54 "Network.ConnectivityChecking.ErrorType"; |
57 | 55 |
58 } // namespace | 56 } // namespace |
59 | 57 |
60 ConnectivityCheckerImpl::ConnectivityCheckerImpl( | 58 ConnectivityCheckerImpl::ConnectivityCheckerImpl( |
61 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) | 59 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 60 std::unique_ptr<net::ProxyConfigService> proxy_config_service) |
62 : ConnectivityChecker(), | 61 : ConnectivityChecker(), |
63 task_runner_(task_runner), | 62 task_runner_(task_runner), |
64 connected_(false), | 63 connected_(false), |
65 connection_type_(net::NetworkChangeNotifier::CONNECTION_NONE), | 64 connection_type_(net::NetworkChangeNotifier::CONNECTION_NONE), |
66 check_errors_(0), | 65 check_errors_(0), |
67 network_changed_pending_(false) { | 66 network_changed_pending_(false), |
| 67 proxy_config_service_(std::move(proxy_config_service)) { |
68 DCHECK(task_runner_.get()); | 68 DCHECK(task_runner_.get()); |
69 task_runner->PostTask(FROM_HERE, | 69 task_runner->PostTask(FROM_HERE, |
70 base::Bind(&ConnectivityCheckerImpl::Initialize, this)); | 70 base::Bind(&ConnectivityCheckerImpl::Initialize, this)); |
71 } | 71 } |
72 | 72 |
73 void ConnectivityCheckerImpl::Initialize() { | 73 void ConnectivityCheckerImpl::Initialize() { |
74 DCHECK(task_runner_->BelongsToCurrentThread()); | 74 DCHECK(task_runner_->BelongsToCurrentThread()); |
75 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 75 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
76 base::CommandLine::StringType check_url_str = | 76 base::CommandLine::StringType check_url_str = |
77 command_line->GetSwitchValueNative(switches::kConnectivityCheckUrl); | 77 command_line->GetSwitchValueNative(switches::kConnectivityCheckUrl); |
78 connectivity_check_url_.reset(new GURL( | 78 connectivity_check_url_.reset(new GURL( |
79 check_url_str.empty() ? kDefaultConnectivityCheckUrl : check_url_str)); | 79 check_url_str.empty() ? kDefaultConnectivityCheckUrl : check_url_str)); |
80 | 80 |
81 net::URLRequestContextBuilder builder; | 81 net::URLRequestContextBuilder builder; |
82 builder.set_proxy_config_service( | 82 builder.set_proxy_config_service(std::move(proxy_config_service_)); |
83 base::MakeUnique<net::ProxyConfigServiceFixed>( | 83 |
84 net::ProxyConfig::CreateDirect())); | |
85 builder.DisableHttpCache(); | 84 builder.DisableHttpCache(); |
86 url_request_context_ = builder.Build(); | 85 url_request_context_ = builder.Build(); |
87 | 86 |
88 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); | 87 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
89 task_runner_->PostTask(FROM_HERE, | 88 task_runner_->PostTask(FROM_HERE, |
90 base::Bind(&ConnectivityCheckerImpl::Check, this)); | 89 base::Bind(&ConnectivityCheckerImpl::Check, this)); |
91 } | 90 } |
92 | 91 |
93 ConnectivityCheckerImpl::~ConnectivityCheckerImpl() { | 92 ConnectivityCheckerImpl::~ConnectivityCheckerImpl() { |
94 DCHECK(task_runner_.get()); | 93 DCHECK(task_runner_.get()); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 void ConnectivityCheckerImpl::Cancel() { | 250 void ConnectivityCheckerImpl::Cancel() { |
252 DCHECK(task_runner_->BelongsToCurrentThread()); | 251 DCHECK(task_runner_->BelongsToCurrentThread()); |
253 if (!url_request_.get()) | 252 if (!url_request_.get()) |
254 return; | 253 return; |
255 VLOG(2) << "Cancel connectivity check in progress"; | 254 VLOG(2) << "Cancel connectivity check in progress"; |
256 url_request_.reset(nullptr); // URLRequest::Cancel() is called in destructor. | 255 url_request_.reset(nullptr); // URLRequest::Cancel() is called in destructor. |
257 timeout_.Cancel(); | 256 timeout_.Cancel(); |
258 } | 257 } |
259 | 258 |
260 } // namespace chromecast | 259 } // namespace chromecast |
OLD | NEW |