blob: 34b1266a12f27511ebb3575608af0e61d9d38975 [file] [log] [blame]
[email protected]a301055d2012-01-11 10:58:171// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]100d5fb92009-12-21 21:08:352// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_
6#define NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_
7
[email protected]88a59c82011-09-12 21:28:158#include <SystemConfiguration/SystemConfiguration.h>
[email protected]66761b952010-06-25 21:30:389
danakj7f767e62016-04-16 23:20:2310#include <memory>
11
[email protected]9be87ba2011-09-30 01:49:2512#include "base/compiler_specific.h"
[email protected]12bd2c02011-06-02 21:56:4413#include "base/mac/scoped_cftyperef.h"
Avi Drissman13fc8932015-12-20 04:40:4614#include "base/macros.h"
[email protected]f671d792011-09-02 18:11:4715#include "base/synchronization/condition_variable.h"
[email protected]d72b8a82011-06-08 20:43:2516#include "base/synchronization/lock.h"
[email protected]100d5fb92009-12-21 21:08:3517#include "net/base/network_change_notifier.h"
[email protected]9328443b2010-07-30 06:09:4018#include "net/base/network_config_watcher_mac.h"
[email protected]100d5fb92009-12-21 21:08:3519
20namespace net {
21
[email protected]6688a4962010-09-07 19:41:3622class NetworkChangeNotifierMac: public NetworkChangeNotifier {
[email protected]100d5fb92009-12-21 21:08:3523 public:
[email protected]aa92ba22010-06-21 23:17:2424 NetworkChangeNotifierMac();
dchengb03027d2014-10-21 12:00:2025 ~NetworkChangeNotifierMac() override;
[email protected]9328443b2010-07-30 06:09:4026
[email protected]8bbc7a792012-05-24 11:30:0527 // NetworkChangeNotifier implementation:
dchengb03027d2014-10-21 12:00:2028 ConnectionType GetCurrentConnectionType() const override;
[email protected]f671d792011-09-02 18:11:4729
[email protected]6688a4962010-09-07 19:41:3630 // Forwarder just exists to keep the NetworkConfigWatcherMac API out of
31 // NetworkChangeNotifierMac's public API.
32 class Forwarder : public NetworkConfigWatcherMac::Delegate {
33 public:
34 explicit Forwarder(NetworkChangeNotifierMac* net_config_watcher)
35 : net_config_watcher_(net_config_watcher) {}
36
37 // NetworkConfigWatcherMac::Delegate implementation:
dchengb03027d2014-10-21 12:00:2038 void Init() override;
39 void StartReachabilityNotifications() override;
40 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store) override;
41 void OnNetworkConfigChange(CFArrayRef changed_keys) override;
[email protected]6688a4962010-09-07 19:41:3642
43 private:
44 NetworkChangeNotifierMac* const net_config_watcher_;
45 DISALLOW_COPY_AND_ASSIGN(Forwarder);
46 };
47
[email protected]bb0e34542012-08-31 19:52:4048 private:
49 class DnsConfigServiceThread;
50
jkarlin5780bb02017-05-31 16:39:4951 // Called on the main thread on startup, afterwards on the notifier thread.
52 static ConnectionType CalculateConnectionType(SCNetworkConnectionFlags flags);
53
[email protected]a301055d2012-01-11 10:58:1754 // Methods directly called by the NetworkConfigWatcherMac::Delegate:
55 void StartReachabilityNotifications();
[email protected]6688a4962010-09-07 19:41:3656 void SetDynamicStoreNotificationKeys(SCDynamicStoreRef store);
57 void OnNetworkConfigChange(CFArrayRef changed_keys);
58
[email protected]8bbc7a792012-05-24 11:30:0559 void SetInitialConnectionType();
[email protected]f671d792011-09-02 18:11:4760
[email protected]12bd2c02011-06-02 21:56:4461 static void ReachabilityCallback(SCNetworkReachabilityRef target,
62 SCNetworkConnectionFlags flags,
63 void* notifier);
64
[email protected]03848872012-12-08 02:46:4165 static NetworkChangeCalculatorParams NetworkChangeCalculatorParamsMac();
66
[email protected]f671d792011-09-02 18:11:4767 // These must be constructed before config_watcher_ to ensure
68 // the lock is in a valid state when Forwarder::Init is called.
[email protected]8bbc7a792012-05-24 11:30:0569 ConnectionType connection_type_;
70 bool connection_type_initialized_;
71 mutable base::Lock connection_type_lock_;
72 mutable base::ConditionVariable initial_connection_type_cv_;
[email protected]3df79f42013-06-24 18:49:0573 base::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_;
74 base::ScopedCFTypeRef<CFRunLoopRef> run_loop_;
[email protected]f671d792011-09-02 18:11:4775
76 Forwarder forwarder_;
danakj7f767e62016-04-16 23:20:2377 std::unique_ptr<const NetworkConfigWatcherMac> config_watcher_;
[email protected]6688a4962010-09-07 19:41:3678
danakj7f767e62016-04-16 23:20:2379 std::unique_ptr<DnsConfigServiceThread> dns_config_service_thread_;
[email protected]05aad32d2012-05-16 18:10:5380
[email protected]100d5fb92009-12-21 21:08:3581 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac);
82};
83
84} // namespace net
85
86#endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_