| 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 CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_NETWORK_OBSERVER_H_ | 5 #ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_NETWORK_OBSERVER_H_ |
| 6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_NETWORK_OBSERVER_H_ | 6 #define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_NETWORK_OBSERVER_H_ |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "content/browser/background_sync/background_sync.pb.h" | 10 #include "content/browser/background_sync/background_sync.pb.h" |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "net/base/network_change_notifier.h" | 12 #include "net/base/network_change_notifier.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 class CONTENT_EXPORT BackgroundSyncNetworkObserver | 16 class CONTENT_EXPORT BackgroundSyncNetworkObserver |
| 17 : public net::NetworkChangeNotifier::NetworkChangeObserver { | 17 : public net::NetworkChangeNotifier::NetworkChangeObserver { |
| 18 public: | 18 public: |
| 19 // Creates a BackgroundSyncNetworkObserver. |network_changed_callback| is | 19 // Creates a BackgroundSyncNetworkObserver. |network_changed_callback| is |
| 20 // called when the network connection changes asynchronously via PostMessage. | 20 // called when the network connection changes asynchronously via PostMessage. |
| 21 BackgroundSyncNetworkObserver(const base::Closure& network_changed_callback); | 21 BackgroundSyncNetworkObserver( |
| 22 const base::RepeatingClosure& network_changed_callback); |
| 22 | 23 |
| 23 ~BackgroundSyncNetworkObserver() override; | 24 ~BackgroundSyncNetworkObserver() override; |
| 24 | 25 |
| 25 // Enable or disable notifications coming from the NetworkChangeNotifier. (For | 26 // Enable or disable notifications coming from the NetworkChangeNotifier. (For |
| 26 // preventing flakes in tests) | 27 // preventing flakes in tests) |
| 27 static void SetIgnoreNetworkChangeNotifierForTests(bool ignore); | 28 static void SetIgnoreNetworkChangeNotifierForTests(bool ignore); |
| 28 | 29 |
| 29 // Returns true if the state of the network meets the needs of | 30 // Returns true if the state of the network meets the needs of |
| 30 // |network_state|. | 31 // |network_state|. |
| 31 bool NetworkSufficient(SyncNetworkState network_state); | 32 bool NetworkSufficient(SyncNetworkState network_state); |
| 32 | 33 |
| 33 // NetworkChangeObserver overrides | 34 // NetworkChangeObserver overrides |
| 34 void OnNetworkChanged( | 35 void OnNetworkChanged( |
| 35 net::NetworkChangeNotifier::ConnectionType connection_type) override; | 36 net::NetworkChangeNotifier::ConnectionType connection_type) override; |
| 36 | 37 |
| 37 // Allow tests to call NotifyManagerIfNetworkChanged. | 38 // Allow tests to call NotifyManagerIfNetworkChanged. |
| 38 void NotifyManagerIfNetworkChangedForTesting( | 39 void NotifyManagerIfNetworkChangedForTesting( |
| 39 net::NetworkChangeNotifier::ConnectionType connection_type); | 40 net::NetworkChangeNotifier::ConnectionType connection_type); |
| 40 | 41 |
| 41 private: | 42 private: |
| 42 // Calls NotifyNetworkChanged if the connection type has changed. | 43 // Calls NotifyNetworkChanged if the connection type has changed. |
| 43 void NotifyManagerIfNetworkChanged( | 44 void NotifyManagerIfNetworkChanged( |
| 44 net::NetworkChangeNotifier::ConnectionType connection_type); | 45 net::NetworkChangeNotifier::ConnectionType connection_type); |
| 45 | 46 |
| 46 void NotifyNetworkChanged(); | 47 void NotifyNetworkChanged(); |
| 47 | 48 |
| 48 net::NetworkChangeNotifier::ConnectionType connection_type_; | 49 net::NetworkChangeNotifier::ConnectionType connection_type_; |
| 49 | 50 |
| 50 // The callback to run when the network changes. | 51 // The callback to run when the network changes. |
| 51 base::Closure network_changed_callback_; | 52 base::RepeatingClosure network_changed_callback_; |
| 52 | 53 |
| 53 // Set true to ignore notifications coming from the NetworkChangeNotifier | 54 // Set true to ignore notifications coming from the NetworkChangeNotifier |
| 54 // (to prevent flakes in tests). | 55 // (to prevent flakes in tests). |
| 55 static bool ignore_network_change_notifier_; | 56 static bool ignore_network_change_notifier_; |
| 56 | 57 |
| 57 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncNetworkObserver); | 58 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncNetworkObserver); |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 } // namespace content | 61 } // namespace content |
| 61 | 62 |
| 62 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_NETWORK_OBSERVER_H_ | 63 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_NETWORK_OBSERVER_H_ |
| OLD | NEW |