network_change_notifier_linux.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_LINUX_H_
  5. #define NET_BASE_NETWORK_CHANGE_NOTIFIER_LINUX_H_
  6. #include <memory>
  7. #include <unordered_set>
  8. #include "base/compiler_specific.h"
  9. #include "base/memory/scoped_refptr.h"
  10. #include "net/base/net_export.h"
  11. #include "net/base/network_change_notifier.h"
  12. namespace base {
  13. class SequencedTaskRunner;
  14. struct OnTaskRunnerDeleter;
  15. } // namespace base
  16. namespace net {
  17. class NET_EXPORT_PRIVATE NetworkChangeNotifierLinux
  18. : public NetworkChangeNotifier {
  19. public:
  20. // Creates NetworkChangeNotifierLinux with a list of ignored interfaces.
  21. // |ignored_interfaces| is the list of interfaces to ignore. An ignored
  22. // interface will not trigger IP address or connection type notifications.
  23. // NOTE: Only ignore interfaces not used to connect to the internet. Adding
  24. // interfaces used to connect to the internet can cause critical network
  25. // changed signals to be lost allowing incorrect stale state to persist.
  26. explicit NetworkChangeNotifierLinux(
  27. const std::unordered_set<std::string>& ignored_interfaces);
  28. NetworkChangeNotifierLinux(const NetworkChangeNotifierLinux&) = delete;
  29. NetworkChangeNotifierLinux& operator=(const NetworkChangeNotifierLinux&) =
  30. delete;
  31. ~NetworkChangeNotifierLinux() override;
  32. private:
  33. class BlockingThreadObjects;
  34. static NetworkChangeCalculatorParams NetworkChangeCalculatorParamsLinux();
  35. // NetworkChangeNotifier:
  36. ConnectionType GetCurrentConnectionType() const override;
  37. const internal::AddressTrackerLinux* GetAddressTrackerInternal()
  38. const override;
  39. // |blocking_thread_objects_| will live on this runner.
  40. scoped_refptr<base::SequencedTaskRunner> blocking_thread_runner_;
  41. // A collection of objects that must live on blocking sequences. These objects
  42. // listen for notifications and relay the notifications to the registered
  43. // observers without posting back to the thread the object was created on.
  44. // Also used for DnsConfigService which also must live on blocking sequences.
  45. std::unique_ptr<BlockingThreadObjects, base::OnTaskRunnerDeleter>
  46. blocking_thread_objects_;
  47. };
  48. } // namespace net
  49. #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_LINUX_H_