File: empty_network_manager.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (78 lines) | stat: -rw-r--r-- 3,334 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_P2P_EMPTY_NETWORK_MANAGER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_P2P_EMPTY_NETWORK_MANAGER_H_

#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/webrtc/rtc_base/network.h"
#include "third_party/webrtc/rtc_base/ip_address.h"
#include "third_party/webrtc/rtc_base/third_party/sigslot/sigslot.h"

namespace blink {

class FilteringNetworkManagerTest;
class IpcNetworkManager;

// A NetworkManager implementation which handles the case where local address
// enumeration is not requested and just returns empty network lists. This class
// is not thread safe and should only be used by WebRTC's network thread.
class EmptyNetworkManager : public webrtc::NetworkManagerBase,
                            public sigslot::has_slots<> {
 public:
  // This class is created on the main thread but used by WebRTC's worker thread
  // |task_runner|.
  PLATFORM_EXPORT explicit EmptyNetworkManager(
      IpcNetworkManager* network_manager);
  EmptyNetworkManager(const EmptyNetworkManager&) = delete;
  EmptyNetworkManager& operator=(const EmptyNetworkManager&) = delete;
  PLATFORM_EXPORT ~EmptyNetworkManager() override;

  // webrtc::NetworkManager:
  void StartUpdating() override;
  void StopUpdating() override;
  std::vector<const webrtc::Network*> GetNetworks() const override;
  bool GetDefaultLocalAddress(int family,
                              webrtc::IPAddress* ipaddress) const override;

 private:
  friend class FilteringNetworkManagerTest;
  // We can't dereference the wrapped network manager from the construction
  // thread, as that would cause it to bind to the wrong sequence. We also can't
  // obtain a `WeakPtr` from an arbitrary `webrtc::NetworkManager`, so we take 2
  // pointers pointing to the same instance, one is a raw pointer for use on the
  // constructing thread and the other is a weak pointer for use on the worker
  // thread.
  // TODO(crbug.com/1191914): Simplify this, to avoid the subtleties of having
  // to pass two pointers to the same object.
  PLATFORM_EXPORT EmptyNetworkManager(webrtc::NetworkManager* network_manager,
                                      base::WeakPtr<webrtc::NetworkManager>
                                          network_manager_for_signaling_thread);

  // Receive callback from the wrapped NetworkManager when the underneath
  // network list is changed.
  //
  // We wait for this so that we don't signal networks changed before we have
  // default IP addresses.
  void OnNetworksChanged();

  THREAD_CHECKER(thread_checker_);

  // SignalNetworksChanged will only be fired if there is any outstanding
  // StartUpdating.
  int start_count_ = 0;

  // `network_manager_for_signaling_thread_` is owned by the
  // PeerConnectionDependencyFactory, that may be destroyed when the frame is
  // detached.
  base::WeakPtr<webrtc::NetworkManager> network_manager_for_signaling_thread_;

  base::WeakPtrFactory<EmptyNetworkManager> weak_ptr_factory_{this};
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_P2P_EMPTY_NETWORK_MANAGER_H_