| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/observer_list_threadsafe.h" | 12 #include "base/observer_list_threadsafe.h" |
| 13 | 13 |
| 14 class PrefProxyConfigTracker; |
| 15 |
| 14 namespace base { | 16 namespace base { |
| 15 class SingleThreadTaskRunner; | 17 class SingleThreadTaskRunner; |
| 16 } | 18 } |
| 17 | 19 |
| 20 namespace net { |
| 21 class ProxyConfigService; |
| 22 } |
| 23 |
| 18 namespace chromecast { | 24 namespace chromecast { |
| 19 | 25 |
| 20 // Checks if internet connectivity is available. | 26 // Checks if internet connectivity is available. |
| 21 class ConnectivityChecker | 27 class ConnectivityChecker |
| 22 : public base::RefCountedThreadSafe<ConnectivityChecker> { | 28 : public base::RefCountedThreadSafe<ConnectivityChecker> { |
| 23 public: | 29 public: |
| 24 class ConnectivityObserver { | 30 class ConnectivityObserver { |
| 25 public: | 31 public: |
| 26 // Will be called when internet connectivity changes. | 32 // Will be called when internet connectivity changes. |
| 27 virtual void OnConnectivityChanged(bool connected) = 0; | 33 virtual void OnConnectivityChanged(bool connected) = 0; |
| 28 | 34 |
| 29 protected: | 35 protected: |
| 30 ConnectivityObserver() {} | 36 ConnectivityObserver() {} |
| 31 virtual ~ConnectivityObserver() {} | 37 virtual ~ConnectivityObserver() {} |
| 32 | 38 |
| 33 private: | 39 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(ConnectivityObserver); | 40 DISALLOW_COPY_AND_ASSIGN(ConnectivityObserver); |
| 35 }; | 41 }; |
| 36 | 42 |
| 37 static scoped_refptr<ConnectivityChecker> Create( | 43 static scoped_refptr<ConnectivityChecker> Create( |
| 38 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 44 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 45 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker); |
| 39 | 46 |
| 40 ConnectivityChecker(); | 47 ConnectivityChecker(); |
| 41 | 48 |
| 42 void AddConnectivityObserver(ConnectivityObserver* observer); | 49 void AddConnectivityObserver(ConnectivityObserver* observer); |
| 43 void RemoveConnectivityObserver(ConnectivityObserver* observer); | 50 void RemoveConnectivityObserver(ConnectivityObserver* observer); |
| 44 | 51 |
| 52 virtual void DetachFromPrefService() = 0; |
| 53 |
| 45 // Returns if there is internet connectivity. | 54 // Returns if there is internet connectivity. |
| 46 virtual bool Connected() const = 0; | 55 virtual bool Connected() const = 0; |
| 47 | 56 |
| 48 // Checks for connectivity. | 57 // Checks for connectivity. |
| 49 virtual void Check() = 0; | 58 virtual void Check() = 0; |
| 50 | 59 |
| 51 protected: | 60 protected: |
| 52 virtual ~ConnectivityChecker(); | 61 virtual ~ConnectivityChecker(); |
| 53 | 62 |
| 54 // Notifies observes that connectivity has changed. | 63 // Notifies observes that connectivity has changed. |
| 55 void Notify(bool connected); | 64 void Notify(bool connected); |
| 56 | 65 |
| 57 private: | 66 private: |
| 58 friend class base::RefCountedThreadSafe<ConnectivityChecker>; | 67 friend class base::RefCountedThreadSafe<ConnectivityChecker>; |
| 59 | 68 |
| 60 const scoped_refptr<base::ObserverListThreadSafe<ConnectivityObserver>> | 69 const scoped_refptr<base::ObserverListThreadSafe<ConnectivityObserver>> |
| 61 connectivity_observer_list_; | 70 connectivity_observer_list_; |
| 62 | 71 |
| 63 DISALLOW_COPY_AND_ASSIGN(ConnectivityChecker); | 72 DISALLOW_COPY_AND_ASSIGN(ConnectivityChecker); |
| 64 }; | 73 }; |
| 65 | 74 |
| 66 } // namespace chromecast | 75 } // namespace chromecast |
| 67 | 76 |
| 68 #endif // CHROMECAST_NET_CONNECTIVITY_CHECKER_H_ | 77 #endif // CHROMECAST_NET_CONNECTIVITY_CHECKER_H_ |
| OLD | NEW |