Avi Drissman | 6459548 | 2022-09-14 20:52:29 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
Tiago Vignatti | 2ea0d0b | 2024-01-18 16:05:08 | [diff] [blame] | 5 | #ifndef NET_BASE_NETWORK_CONFIG_WATCHER_APPLE_H_ |
6 | #define NET_BASE_NETWORK_CONFIG_WATCHER_APPLE_H_ | ||||
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 7 | |
Helen Li | a4dda252 | 2018-04-03 15:09:12 | [diff] [blame] | 8 | #include <SystemConfiguration/SystemConfiguration.h> |
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 9 | |
danakj | 7f767e6 | 2016-04-16 23:20:23 | [diff] [blame] | 10 | #include <memory> |
11 | |||||
Avi Drissman | a09d7dd | 2023-08-17 16:26:58 | [diff] [blame] | 12 | #include "base/apple/scoped_cftyperef.h" |
Tsuyoshi Horo | 93f8e3b6e | 2024-03-11 04:04:22 | [diff] [blame] | 13 | #include "net/base/net_export.h" |
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 14 | |
15 | namespace base { | ||||
16 | class Thread; | ||||
17 | } | ||||
18 | |||||
19 | namespace net { | ||||
20 | |||||
[email protected] | 9be87ba | 2011-09-30 01:49:25 | [diff] [blame] | 21 | // Helper class for watching the Mac OS system network settings. |
Tsuyoshi Horo | 93f8e3b6e | 2024-03-11 04:04:22 | [diff] [blame] | 22 | class NET_EXPORT_PRIVATE NetworkConfigWatcherApple { |
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 23 | public: |
[email protected] | 6688a496 | 2010-09-07 19:41:36 | [diff] [blame] | 24 | // NOTE: The lifetime of Delegate is expected to exceed the lifetime of |
Tiago Vignatti | 2ea0d0b | 2024-01-18 16:05:08 | [diff] [blame] | 25 | // NetworkConfigWatcherApple. |
[email protected] | 6688a496 | 2010-09-07 19:41:36 | [diff] [blame] | 26 | class Delegate { |
27 | public: | ||||
David Bienvenu | a03ac8c | 2020-11-06 15:55:39 | [diff] [blame] | 28 | virtual ~Delegate() = default; |
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 29 | |
[email protected] | f671d79 | 2011-09-02 18:11:47 | [diff] [blame] | 30 | // Called to let the delegate do any setup work the must be run on the |
31 | // notifier thread immediately after it starts. | ||||
32 | virtual void Init() {} | ||||
33 | |||||
[email protected] | a301055d | 2012-01-11 10:58:17 | [diff] [blame] | 34 | // Called to start receiving notifications from the SCNetworkReachability |
35 | // API. | ||||
36 | // Will be called on the notifier thread. | ||||
37 | virtual void StartReachabilityNotifications() = 0; | ||||
38 | |||||
[email protected] | 6688a496 | 2010-09-07 19:41:36 | [diff] [blame] | 39 | // Called to register the notification keys on |store|. |
40 | // Implementors are expected to call SCDynamicStoreSetNotificationKeys(). | ||||
41 | // Will be called on the notifier thread. | ||||
Tsuyoshi Horo | 93f8e3b6e | 2024-03-11 04:04:22 | [diff] [blame] | 42 | virtual void SetDynamicStoreNotificationKeys( |
43 | base::apple::ScopedCFTypeRef<SCDynamicStoreRef> store) = 0; | ||||
[email protected] | 6688a496 | 2010-09-07 19:41:36 | [diff] [blame] | 44 | |
45 | // Called when one of the notification keys has changed. | ||||
46 | // Will be called on the notifier thread. | ||||
47 | virtual void OnNetworkConfigChange(CFArrayRef changed_keys) = 0; | ||||
Tsuyoshi Horo | 93f8e3b6e | 2024-03-11 04:04:22 | [diff] [blame] | 48 | |
49 | // Called when `this` is being destructed. | ||||
50 | // Will be called on the notifier thread. | ||||
51 | virtual void CleanUpOnNotifierThread() = 0; | ||||
[email protected] | 6688a496 | 2010-09-07 19:41:36 | [diff] [blame] | 52 | }; |
53 | |||||
Tiago Vignatti | 2ea0d0b | 2024-01-18 16:05:08 | [diff] [blame] | 54 | explicit NetworkConfigWatcherApple(Delegate* delegate); |
55 | NetworkConfigWatcherApple(const NetworkConfigWatcherApple&) = delete; | ||||
56 | NetworkConfigWatcherApple& operator=(const NetworkConfigWatcherApple&) = delete; | ||||
57 | ~NetworkConfigWatcherApple(); | ||||
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 58 | |
Tsuyoshi Horo | 93f8e3b6e | 2024-03-11 04:04:22 | [diff] [blame] | 59 | base::Thread* GetNotifierThreadForTest(); |
60 | |||||
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 61 | private: |
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 62 | // The thread used to listen for notifications. This relays the notification |
63 | // to the registered observers without posting back to the thread the object | ||||
64 | // was created on. | ||||
danakj | 7f767e6 | 2016-04-16 23:20:23 | [diff] [blame] | 65 | std::unique_ptr<base::Thread> notifier_thread_; |
[email protected] | 9328443b | 2010-07-30 06:09:40 | [diff] [blame] | 66 | }; |
67 | |||||
68 | } // namespace net | ||||
69 | |||||
Tiago Vignatti | 2ea0d0b | 2024-01-18 16:05:08 | [diff] [blame] | 70 | #endif // NET_BASE_NETWORK_CONFIG_WATCHER_APPLE_H_ |