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