File: socket_dispatcher_host.h

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (93 lines) | stat: -rw-r--r-- 3,430 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_DISPATCHER_HOST_H_
#define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_DISPATCHER_HOST_H_

#include <stdint.h>

#include <memory>
#include <set>
#include <vector>

#include "base/memory/weak_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "content/public/browser/render_process_host.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/remote_set.h"
#include "net/base/network_anonymization_key.h"
#include "services/network/public/mojom/p2p.mojom.h"
#include "services/network/public/mojom/p2p_trusted.mojom.h"

namespace content {

// Responsible for P2P sockets. Lives on the UI thread.
class P2PSocketDispatcherHost
    : public network::mojom::P2PTrustedSocketManagerClient {
 public:
  explicit P2PSocketDispatcherHost(int render_process_id);

  P2PSocketDispatcherHost(const P2PSocketDispatcherHost&) = delete;
  P2PSocketDispatcherHost& operator=(const P2PSocketDispatcherHost&) = delete;

  ~P2PSocketDispatcherHost() override;

  // Starts the RTP packet header dumping.
  void StartRtpDump(bool incoming,
                    bool outgoing,
                    RenderProcessHost::WebRtcRtpPacketCallback packet_callback);

  // Stops the RTP packet header dumping.
  void StopRtpDump(bool incoming, bool outgoing);

  void BindReceiver(
      RenderProcessHostImpl& process,
      mojo::PendingReceiver<network::mojom::P2PSocketManager> receiver,
      net::NetworkAnonymizationKey anonymization_key,
      const GlobalRenderFrameHostId& render_frame_host_id);

  base::WeakPtr<P2PSocketDispatcherHost> GetWeakPtr();
  void PauseSocketManagerForRenderFrameHost(
      const GlobalRenderFrameHostId& frame_id);
  void ResumeSocketManagerForRenderFrameHost(
      const GlobalRenderFrameHostId& frame_id);

 private:
  // network::mojom::P2PTrustedSocketManagerClient overrides:
  void InvalidSocketPortRangeRequested() override;
  void DumpPacket(const std::vector<uint8_t>& packet_header,
                  uint64_t packet_length,
                  bool incoming) override;

  int render_process_id_;

  bool dump_incoming_rtp_packet_ = false;
  bool dump_outgoing_rtp_packet_ = false;
  RenderProcessHost::WebRtcRtpPacketCallback packet_callback_;

  // TODO(crbug.com/1178670): We use sets of interfaces for now (instead of
  // creating a host-per-frame) since RTP dumps are started/stopped at the
  // process level (for now).
  // There are, however, plans to:
  // 1. Make WebRtcLoggingAgent per-frame (and RTP dumps along with it)
  // 2. (Maybe) deprecate RTP dumps.
  // Once either of these happens, this can be cleaned up.
  mojo::ReceiverSet<network::mojom::P2PTrustedSocketManagerClient> receivers_;
  mojo::RemoteSet<network::mojom::P2PTrustedSocketManager>
      trusted_socket_managers_;

  base::flat_map<GlobalRenderFrameHostId, mojo::RemoteSetElementId>
      frame_host_to_socket_manager_id_;

  mojo::Remote<network::mojom::P2PNetworkNotificationClient>
      network_notification_client_;

  base::WeakPtrFactory<P2PSocketDispatcherHost> weak_factory_{this};
};

}  // namespace content

#endif  // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_DISPATCHER_HOST_H_