Commit fce58242 authored by wzhong's avatar wzhong Committed by Commit bot

Override OnSSLCertificateError() in connectivity_checker.

By default, OnSSLCertificateError() just cancels current request.
For connectivity_checker, it needs to cancel the current request
and starts next check. In particular, this handles the case that
SSL cert fails when device system time is changing (syncing to
NTP server).

BUG=internal b/20775908

Review URL: https://codereview.chromium.org/1145723004

Cr-Commit-Position: refs/heads/master@{#330557}
parent 602004df
......@@ -21,12 +21,12 @@ namespace chromecast {
namespace {
// How often connectivity checks are performed in seconds
// How often connectivity checks are performed in seconds.
const unsigned int kConnectivityPeriodSeconds = 1;
// Number of consecutive bad responses received before connectivity status is
// changed to offline
const unsigned int kNumBadResponses = 3;
// Number of consecutive connectivity check errors before status is changed
// to offline.
const unsigned int kNumErrorsToNotifyOffline = 3;
// Default url for connectivity checking.
const char kDefaultConnectivityCheckUrl[] =
......@@ -40,7 +40,7 @@ ConnectivityChecker::ConnectivityChecker(
new ObserverListThreadSafe<ConnectivityObserver>()),
loop_proxy_(loop_proxy),
connected_(false),
bad_responses_(0) {
check_errors_(0) {
DCHECK(loop_proxy_.get());
loop_proxy->PostTask(FROM_HERE,
base::Bind(&ConnectivityChecker::Initialize, this));
......@@ -105,7 +105,7 @@ void ConnectivityChecker::Check() {
}
DCHECK(url_request_context_.get());
// Don't check connectivity if network is offline, because internet could be
// Don't check connectivity if network is offline, because Internet could be
// accessible via netifs ignored.
if (net::NetworkChangeNotifier::IsOffline())
return;
......@@ -151,19 +151,29 @@ void ConnectivityChecker::OnResponseStarted(net::URLRequest* request) {
if (http_response_code < 400) {
VLOG(1) << "Connectivity check succeeded";
bad_responses_ = 0;
check_errors_ = 0;
SetConnectivity(true);
return;
}
VLOG(1) << "Connectivity check failed: " << http_response_code;
++bad_responses_;
if (bad_responses_ > kNumBadResponses) {
bad_responses_ = kNumBadResponses;
OnUrlRequestError();
}
void ConnectivityChecker::OnSSLCertificateError(net::URLRequest* request,
const net::SSLInfo& ssl_info,
bool fatal) {
LOG(ERROR) << "OnSSLCertificateError";
OnUrlRequestError();
}
void ConnectivityChecker::OnUrlRequestError() {
++check_errors_;
if (check_errors_ > kNumErrorsToNotifyOffline) {
check_errors_ = kNumErrorsToNotifyOffline;
SetConnectivity(false);
}
// Check again
url_request_.reset(NULL);
// Check again.
loop_proxy_->PostDelayedTask(
FROM_HERE, base::Bind(&ConnectivityChecker::Check, this),
base::TimeDelta::FromSeconds(kConnectivityPeriodSeconds));
......
......@@ -18,6 +18,7 @@ class MessageLoopProxy;
}
namespace net {
class SSLInfo;
class URLRequestContext;
}
......@@ -65,6 +66,9 @@ class ConnectivityChecker
// UrlRequest::Delegate implementation:
void OnResponseStarted(net::URLRequest* request) override;
void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
void OnSSLCertificateError(net::URLRequest* request,
const net::SSLInfo& ssl_info,
bool fatal) override;
// Initializes ConnectivityChecker
void Initialize();
......@@ -82,6 +86,9 @@ class ConnectivityChecker
// Sets connectivity and alerts observers if it has changed
void SetConnectivity(bool connected);
// Called when URL request failed.
void OnUrlRequestError();
scoped_ptr<GURL> connectivity_check_url_;
scoped_ptr<net::URLRequestContext> url_request_context_;
scoped_ptr<net::URLRequest> url_request_;
......@@ -89,7 +96,8 @@ class ConnectivityChecker
connectivity_observer_list_;
const scoped_refptr<base::MessageLoopProxy> loop_proxy_;
bool connected_;
unsigned int bad_responses_;
// Number of connectivity check errors.
unsigned int check_errors_;
DISALLOW_COPY_AND_ASSIGN(ConnectivityChecker);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment