| 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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // Histogram "Cast.Network.Down.Duration.In.Seconds" shows 40% of network | 51 // Histogram "Cast.Network.Down.Duration.In.Seconds" shows 40% of network |
| 52 // downtime is less than 3 seconds. | 52 // downtime is less than 3 seconds. |
| 53 const char kNetworkChangedDelayInSeconds = 3; | 53 const char kNetworkChangedDelayInSeconds = 3; |
| 54 | 54 |
| 55 const char kMetricNameNetworkConnectivityCheckingErrorType[] = | 55 const char kMetricNameNetworkConnectivityCheckingErrorType[] = |
| 56 "Network.ConnectivityChecking.ErrorType"; | 56 "Network.ConnectivityChecking.ErrorType"; |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 ConnectivityCheckerImpl::ConnectivityCheckerImpl( | 60 ConnectivityCheckerImpl::ConnectivityCheckerImpl( |
| 61 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) | 61 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 62 net::ProxyConfig& proxy_config) |
| 62 : ConnectivityChecker(), | 63 : ConnectivityChecker(), |
| 63 task_runner_(task_runner), | 64 task_runner_(task_runner), |
| 64 connected_(false), | 65 connected_(false), |
| 65 connection_type_(net::NetworkChangeNotifier::CONNECTION_NONE), | 66 connection_type_(net::NetworkChangeNotifier::CONNECTION_NONE), |
| 66 check_errors_(0), | 67 check_errors_(0), |
| 67 network_changed_pending_(false) { | 68 network_changed_pending_(false), |
| 69 proxy_config_(proxy_config) { |
| 68 DCHECK(task_runner_.get()); | 70 DCHECK(task_runner_.get()); |
| 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 |
| 73 void ConnectivityCheckerImpl::Initialize() { | 75 void ConnectivityCheckerImpl::Initialize() { |
| 74 DCHECK(task_runner_->BelongsToCurrentThread()); | 76 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 75 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 77 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 76 base::CommandLine::StringType check_url_str = | 78 base::CommandLine::StringType check_url_str = |
| 77 command_line->GetSwitchValueNative(switches::kConnectivityCheckUrl); | 79 command_line->GetSwitchValueNative(switches::kConnectivityCheckUrl); |
| 78 connectivity_check_url_.reset(new GURL( | 80 connectivity_check_url_.reset(new GURL( |
| 79 check_url_str.empty() ? kDefaultConnectivityCheckUrl : check_url_str)); | 81 check_url_str.empty() ? kDefaultConnectivityCheckUrl : check_url_str)); |
| 80 | 82 |
| 81 net::URLRequestContextBuilder builder; | 83 net::URLRequestContextBuilder builder; |
| 82 builder.set_proxy_config_service( | 84 builder.set_proxy_config_service( |
| 83 base::MakeUnique<net::ProxyConfigServiceFixed>( | 85 base::MakeUnique<net::ProxyConfigServiceFixed>(proxy_config_)); |
| 84 net::ProxyConfig::CreateDirect())); | |
| 85 builder.DisableHttpCache(); | 86 builder.DisableHttpCache(); |
| 86 url_request_context_ = builder.Build(); | 87 url_request_context_ = builder.Build(); |
| 87 | 88 |
| 88 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); | 89 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| 89 task_runner_->PostTask(FROM_HERE, | 90 task_runner_->PostTask(FROM_HERE, |
| 90 base::Bind(&ConnectivityCheckerImpl::Check, this)); | 91 base::Bind(&ConnectivityCheckerImpl::Check, this)); |
| 91 } | 92 } |
| 92 | 93 |
| 93 ConnectivityCheckerImpl::~ConnectivityCheckerImpl() { | 94 ConnectivityCheckerImpl::~ConnectivityCheckerImpl() { |
| 94 DCHECK(task_runner_.get()); | 95 DCHECK(task_runner_.get()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 void ConnectivityCheckerImpl::Cancel() { | 252 void ConnectivityCheckerImpl::Cancel() { |
| 252 DCHECK(task_runner_->BelongsToCurrentThread()); | 253 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 253 if (!url_request_.get()) | 254 if (!url_request_.get()) |
| 254 return; | 255 return; |
| 255 VLOG(2) << "Cancel connectivity check in progress"; | 256 VLOG(2) << "Cancel connectivity check in progress"; |
| 256 url_request_.reset(nullptr); // URLRequest::Cancel() is called in destructor. | 257 url_request_.reset(nullptr); // URLRequest::Cancel() is called in destructor. |
| 257 timeout_.Cancel(); | 258 timeout_.Cancel(); |
| 258 } | 259 } |
| 259 | 260 |
| 260 } // namespace chromecast | 261 } // namespace chromecast |
| OLD | NEW |