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 #ifndef CHROMECAST_NET_CONNECTIVITY_CHECKER_H_ | 5 #ifndef CHROMECAST_NET_CONNECTIVITY_CHECKER_H_ |
6 #define CHROMECAST_NET_CONNECTIVITY_CHECKER_H_ | 6 #define CHROMECAST_NET_CONNECTIVITY_CHECKER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class URLRequestContext; | 21 class URLRequestContext; |
22 } | 22 } |
23 | 23 |
24 namespace chromecast { | 24 namespace chromecast { |
25 | 25 |
26 // Simple class to check network connectivity by sending a HEAD http request | 26 // Simple class to check network connectivity by sending a HEAD http request |
27 // to given url. | 27 // to given url. |
28 class ConnectivityChecker | 28 class ConnectivityChecker |
29 : public base::RefCountedThreadSafe<ConnectivityChecker>, | 29 : public base::RefCountedThreadSafe<ConnectivityChecker>, |
30 public net::URLRequest::Delegate, | 30 public net::URLRequest::Delegate, |
31 public net::NetworkChangeNotifier::ConnectionTypeObserver { | 31 public net::NetworkChangeNotifier::ConnectionTypeObserver, |
| 32 public net::NetworkChangeNotifier::IPAddressObserver { |
32 public: | 33 public: |
33 class ConnectivityObserver { | 34 class ConnectivityObserver { |
34 public: | 35 public: |
35 // Will be called when internet connectivity changes | 36 // Will be called when internet connectivity changes |
36 virtual void OnConnectivityChanged(bool connected) = 0; | 37 virtual void OnConnectivityChanged(bool connected) = 0; |
37 | 38 |
38 protected: | 39 protected: |
39 ConnectivityObserver() {} | 40 ConnectivityObserver() {} |
40 virtual ~ConnectivityObserver() {} | 41 virtual ~ConnectivityObserver() {} |
41 | 42 |
(...skipping 23 matching lines...) Expand all Loading... |
65 void OnResponseStarted(net::URLRequest* request) override; | 66 void OnResponseStarted(net::URLRequest* request) override; |
66 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | 67 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
67 | 68 |
68 // Initializes ConnectivityChecker | 69 // Initializes ConnectivityChecker |
69 void Initialize(); | 70 void Initialize(); |
70 | 71 |
71 // NetworkChangeNotifier::ConnectionTypeObserver implementation: | 72 // NetworkChangeNotifier::ConnectionTypeObserver implementation: |
72 void OnConnectionTypeChanged( | 73 void OnConnectionTypeChanged( |
73 net::NetworkChangeNotifier::ConnectionType type) override; | 74 net::NetworkChangeNotifier::ConnectionType type) override; |
74 | 75 |
| 76 // net::NetworkChangeNotifier::IPAddressObserver implementation: |
| 77 void OnIPAddressChanged() override; |
| 78 |
75 // Cancels current connectivity checking in progress. | 79 // Cancels current connectivity checking in progress. |
76 void Cancel(); | 80 void Cancel(); |
77 | 81 |
78 // Sets connectivity and alerts observers if it has changed | 82 // Sets connectivity and alerts observers if it has changed |
79 void SetConnectivity(bool connected); | 83 void SetConnectivity(bool connected); |
80 | 84 |
81 scoped_ptr<GURL> connectivity_check_url_; | 85 scoped_ptr<GURL> connectivity_check_url_; |
82 scoped_ptr<net::URLRequestContext> url_request_context_; | 86 scoped_ptr<net::URLRequestContext> url_request_context_; |
83 scoped_ptr<net::URLRequest> url_request_; | 87 scoped_ptr<net::URLRequest> url_request_; |
84 const scoped_refptr<ObserverListThreadSafe<ConnectivityObserver> > | 88 const scoped_refptr<ObserverListThreadSafe<ConnectivityObserver> > |
85 connectivity_observer_list_; | 89 connectivity_observer_list_; |
86 const scoped_refptr<base::MessageLoopProxy> loop_proxy_; | 90 const scoped_refptr<base::MessageLoopProxy> loop_proxy_; |
87 bool connected_; | 91 bool connected_; |
88 unsigned int bad_responses_; | 92 unsigned int bad_responses_; |
89 | 93 |
90 DISALLOW_COPY_AND_ASSIGN(ConnectivityChecker); | 94 DISALLOW_COPY_AND_ASSIGN(ConnectivityChecker); |
91 }; | 95 }; |
92 | 96 |
93 } // namespace chromecast | 97 } // namespace chromecast |
94 | 98 |
95 #endif // CHROMECAST_NET_CONNECTIVITY_CHECKER_H_ | 99 #endif // CHROMECAST_NET_CONNECTIVITY_CHECKER_H_ |
OLD | NEW |