summaryrefslogtreecommitdiffstats
path: root/chromecast
diff options
context:
space:
mode:
authorwzhong <wzhong@chromium.org>2015-05-19 11:06:41 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-19 18:07:41 +0000
commitfce5824251e2493f75cecea585248e63000b6ac7 (patch)
tree2e49ed68cafa589306df0ca7e25668b64d0e274a /chromecast
parent602004df17bfd877f8ff5bb7d7a9665ab992a7c4 (diff)
downloadchromium_src-fce5824251e2493f75cecea585248e63000b6ac7.zip
chromium_src-fce5824251e2493f75cecea585248e63000b6ac7.tar.gz
chromium_src-fce5824251e2493f75cecea585248e63000b6ac7.tar.bz2
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}
Diffstat (limited to 'chromecast')
-rw-r--r--chromecast/net/connectivity_checker.cc36
-rw-r--r--chromecast/net/connectivity_checker.h10
2 files changed, 32 insertions, 14 deletions
diff --git a/chromecast/net/connectivity_checker.cc b/chromecast/net/connectivity_checker.cc
index de30812..95c4a57 100644
--- a/chromecast/net/connectivity_checker.cc
+++ b/chromecast/net/connectivity_checker.cc
@@ -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));
diff --git a/chromecast/net/connectivity_checker.h b/chromecast/net/connectivity_checker.h
index c52b8a6..f1dedcf 100644
--- a/chromecast/net/connectivity_checker.h
+++ b/chromecast/net/connectivity_checker.h
@@ -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);
};