blob: 67ec52d62a6441f6726bc024ea36e87591c87cc0 [file] [log] [blame]
Avi Drissman64595482022-09-14 20:52:291// Copyright 2012 The Chromium Authors
[email protected]9328443b2010-07-30 06:09:402// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Tiago Vignatti2ea0d0b2024-01-18 16:05:085#ifndef NET_BASE_NETWORK_CONFIG_WATCHER_APPLE_H_
6#define NET_BASE_NETWORK_CONFIG_WATCHER_APPLE_H_
[email protected]9328443b2010-07-30 06:09:407
Helen Lia4dda2522018-04-03 15:09:128#include <SystemConfiguration/SystemConfiguration.h>
[email protected]9328443b2010-07-30 06:09:409
danakj7f767e62016-04-16 23:20:2310#include <memory>
11
Avi Drissmana09d7dd2023-08-17 16:26:5812#include "base/apple/scoped_cftyperef.h"
Tsuyoshi Horo93f8e3b6e2024-03-11 04:04:2213#include "net/base/net_export.h"
[email protected]9328443b2010-07-30 06:09:4014
15namespace base {
16class Thread;
17}
18
19namespace net {
20
[email protected]9be87ba2011-09-30 01:49:2521// Helper class for watching the Mac OS system network settings.
Tsuyoshi Horo93f8e3b6e2024-03-11 04:04:2222class NET_EXPORT_PRIVATE NetworkConfigWatcherApple {
[email protected]9328443b2010-07-30 06:09:4023 public:
[email protected]6688a4962010-09-07 19:41:3624 // NOTE: The lifetime of Delegate is expected to exceed the lifetime of
Tiago Vignatti2ea0d0b2024-01-18 16:05:0825 // NetworkConfigWatcherApple.
[email protected]6688a4962010-09-07 19:41:3626 class Delegate {
27 public:
David Bienvenua03ac8c2020-11-06 15:55:3928 virtual ~Delegate() = default;
[email protected]9328443b2010-07-30 06:09:4029
[email protected]f671d792011-09-02 18:11:4730 // 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]a301055d2012-01-11 10:58:1734 // 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]6688a4962010-09-07 19:41:3639 // Called to register the notification keys on |store|.
40 // Implementors are expected to call SCDynamicStoreSetNotificationKeys().
41 // Will be called on the notifier thread.
Tsuyoshi Horo93f8e3b6e2024-03-11 04:04:2242 virtual void SetDynamicStoreNotificationKeys(
43 base::apple::ScopedCFTypeRef<SCDynamicStoreRef> store) = 0;
[email protected]6688a4962010-09-07 19:41:3644
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 Horo93f8e3b6e2024-03-11 04:04:2248
49 // Called when `this` is being destructed.
50 // Will be called on the notifier thread.
51 virtual void CleanUpOnNotifierThread() = 0;
[email protected]6688a4962010-09-07 19:41:3652 };
53
Tiago Vignatti2ea0d0b2024-01-18 16:05:0854 explicit NetworkConfigWatcherApple(Delegate* delegate);
55 NetworkConfigWatcherApple(const NetworkConfigWatcherApple&) = delete;
56 NetworkConfigWatcherApple& operator=(const NetworkConfigWatcherApple&) = delete;
57 ~NetworkConfigWatcherApple();
[email protected]9328443b2010-07-30 06:09:4058
Tsuyoshi Horo93f8e3b6e2024-03-11 04:04:2259 base::Thread* GetNotifierThreadForTest();
60
[email protected]9328443b2010-07-30 06:09:4061 private:
[email protected]9328443b2010-07-30 06:09:4062 // 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.
danakj7f767e62016-04-16 23:20:2365 std::unique_ptr<base::Thread> notifier_thread_;
[email protected]9328443b2010-07-30 06:09:4066};
67
68} // namespace net
69
Tiago Vignatti2ea0d0b2024-01-18 16:05:0870#endif // NET_BASE_NETWORK_CONFIG_WATCHER_APPLE_H_