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 // Calls NotifyNetworkChanged if the connection type has changed. | |
37 void NotifyManagerIfNetworkChanged( | |
jkarlin
2015/09/24 17:51:30
This would be private if not for tests. Make this
iclelland
2015/09/24 20:37:20
Done. I've friended the test classes (and moved Ba
| |
38 net::NetworkChangeNotifier::ConnectionType connection_type); | |
39 | |
40 private: | |
41 void NotifyNetworkChanged(); | |
42 | |
35 net::NetworkChangeNotifier::ConnectionType connection_type_; | 43 net::NetworkChangeNotifier::ConnectionType connection_type_; |
36 | 44 |
37 // The callback to run when the network changes. | 45 // The callback to run when the network changes. |
38 base::Closure network_changed_callback_; | 46 base::Closure network_changed_callback_; |
39 | 47 |
48 // Set true to ignore notifications coming from the NetworkChangeNotifier | |
49 // (to prevent flakes in tests). | |
50 static bool ignore_network_change_notifier_; | |
jkarlin
2015/09/24 17:51:30
I think you can initialize this to false here.
iclelland
2015/09/24 20:37:19
Nah.... "error: ISO C++ forbids in-class initiali
jkarlin
2015/09/24 23:33:12
Bah, that's right.
| |
51 | |
40 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncNetworkObserver); | 52 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncNetworkObserver); |
41 }; | 53 }; |
42 | 54 |
43 } // namespace content | 55 } // namespace content |
44 | 56 |
45 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_NETWORK_OBSERVER_H_ | 57 #endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_NETWORK_OBSERVER_H_ |
OLD | NEW |