Chromium Code Reviews| 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_IMPL_H_ | 5 #ifndef CHROMECAST_NET_CONNECTIVITY_CHECKER_IMPL_H_ |
| 6 #define CHROMECAST_NET_CONNECTIVITY_CHECKER_IMPL_H_ | 6 #define CHROMECAST_NET_CONNECTIVITY_CHECKER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/cancelable_callback.h" | 8 #include "base/cancelable_callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "chromecast/net/connectivity_checker.h" | 10 #include "chromecast/net/connectivity_checker.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 // Simple class to check network connectivity by sending a HEAD http request | 28 // Simple class to check network connectivity by sending a HEAD http request |
| 29 // to given url. | 29 // to given url. |
| 30 class ConnectivityCheckerImpl | 30 class ConnectivityCheckerImpl |
| 31 : public ConnectivityChecker, | 31 : public ConnectivityChecker, |
| 32 public net::URLRequest::Delegate, | 32 public net::URLRequest::Delegate, |
| 33 public net::NetworkChangeNotifier::NetworkChangeObserver { | 33 public net::NetworkChangeNotifier::NetworkChangeObserver { |
| 34 public: | 34 public: |
| 35 // Connectivity checking and initialization will run on task_runner. | 35 // Connectivity checking and initialization will run on task_runner. |
| 36 explicit ConnectivityCheckerImpl( | 36 explicit ConnectivityCheckerImpl( |
| 37 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 37 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 38 net::URLRequestContextGetter* url_request_context_getter); | |
|
halliwell
2017/02/08 00:07:06
forward declare this class?
almasrymina
2017/02/08 00:48:04
Done.
| |
| 38 | 39 |
| 39 // ConnectivityChecker implementation: | 40 // ConnectivityChecker implementation: |
| 40 bool Connected() const override; | 41 bool Connected() const override; |
| 41 void Check() override; | 42 void Check() override; |
| 42 | 43 |
| 43 protected: | 44 protected: |
| 44 ~ConnectivityCheckerImpl() override; | 45 ~ConnectivityCheckerImpl() override; |
| 45 | 46 |
| 46 private: | 47 private: |
| 47 // UrlRequest::Delegate implementation: | 48 // UrlRequest::Delegate implementation: |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 74 | 75 |
| 75 // Called when URL request failed. | 76 // Called when URL request failed. |
| 76 void OnUrlRequestError(ErrorType type); | 77 void OnUrlRequestError(ErrorType type); |
| 77 | 78 |
| 78 // Called when URL request timed out. | 79 // Called when URL request timed out. |
| 79 void OnUrlRequestTimeout(); | 80 void OnUrlRequestTimeout(); |
| 80 | 81 |
| 81 void CheckInternal(); | 82 void CheckInternal(); |
| 82 | 83 |
| 83 std::unique_ptr<GURL> connectivity_check_url_; | 84 std::unique_ptr<GURL> connectivity_check_url_; |
| 84 std::unique_ptr<net::URLRequestContext> url_request_context_; | 85 net::URLRequestContext* url_request_context_; |
| 85 std::unique_ptr<net::URLRequest> url_request_; | 86 std::unique_ptr<net::URLRequest> url_request_; |
| 86 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 87 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 87 | 88 |
| 88 // connected_lock_ protects access to connected_ which is shared across | 89 // connected_lock_ protects access to connected_ which is shared across |
| 89 // threads. | 90 // threads. |
| 90 mutable base::Lock connected_lock_; | 91 mutable base::Lock connected_lock_; |
| 91 bool connected_; | 92 bool connected_; |
| 92 | 93 |
| 93 net::NetworkChangeNotifier::ConnectionType connection_type_; | 94 net::NetworkChangeNotifier::ConnectionType connection_type_; |
| 94 // Number of connectivity check errors. | 95 // Number of connectivity check errors. |
| 95 unsigned int check_errors_; | 96 unsigned int check_errors_; |
| 96 bool network_changed_pending_; | 97 bool network_changed_pending_; |
| 97 // Timeout handler for connectivity checks. | 98 // Timeout handler for connectivity checks. |
| 98 // Note: Cancelling this timeout can cause the destructor for this class to be | 99 // Note: Cancelling this timeout can cause the destructor for this class to be |
| 99 // called. | 100 // called. |
| 100 base::CancelableCallback<void()> timeout_; | 101 base::CancelableCallback<void()> timeout_; |
| 101 | 102 |
| 103 net::URLRequestContextGetter* url_request_context_getter_; | |
| 104 | |
| 102 DISALLOW_COPY_AND_ASSIGN(ConnectivityCheckerImpl); | 105 DISALLOW_COPY_AND_ASSIGN(ConnectivityCheckerImpl); |
| 103 }; | 106 }; |
| 104 | 107 |
| 105 } // namespace chromecast | 108 } // namespace chromecast |
| 106 | 109 |
| 107 #endif // CHROMECAST_NET_CONNECTIVITY_CHECKER_IMPL_H_ | 110 #endif // CHROMECAST_NET_CONNECTIVITY_CHECKER_IMPL_H_ |
| OLD | NEW |