File: net_log_proxy_source.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; 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 (73 lines) | stat: -rw-r--r-- 2,902 bytes parent folder | download | duplicates (6)
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
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_NET_LOG_NET_LOG_PROXY_SOURCE_H_
#define COMPONENTS_NET_LOG_NET_LOG_PROXY_SOURCE_H_

#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/log/net_log.h"
#include "services/network/public/mojom/net_log.mojom.h"

namespace base {
class SequencedTaskRunner;
}

namespace net_log {

// Implementation of NetLogProxySource mojo interface which observes local
// NetLog events and proxies them over mojo to a remote NetLogProxySink.
// Observing and proxying is only active when notified through
// UpdateCaptureModes() that capturing is active in the remote process.
class NetLogProxySource : public net::NetLog::ThreadSafeObserver,
                          public network::mojom::NetLogProxySource {
 public:
  // When notified through |proxy_source_receiver| that capturing is active,
  // registers a local NetLog observer and sends all NetLog events to
  // |proxy_sink_remote|.
  // The caller is expected to create a new NetLogProxySource if the remote
  // process is restarted.
  NetLogProxySource(
      mojo::PendingReceiver<network::mojom::NetLogProxySource>
          proxy_source_receiver,
      mojo::Remote<network::mojom::NetLogProxySink> proxy_sink_remote);
  ~NetLogProxySource() override;
  NetLogProxySource(const NetLogProxySource&) = delete;
  NetLogProxySource& operator=(const NetLogProxySource&) = delete;

  // Remove NetLog observer and close mojo pipes.
  void ShutDown();

  // NetLog::ThreadSafeObserver:
  void OnAddEntry(const net::NetLogEntry& entry) override;

  // mojom::NetLogProxySource:
  void UpdateCaptureModes(net::NetLogCaptureModeSet modes) override;

 private:
  // Proxy entry to the remote. Must only be called on |task_runner_|.
  void SendNetLogEntry(net::NetLogEventType type,
                       const net::NetLogSource& net_log_source,
                       net::NetLogEventPhase phase,
                       base::TimeTicks time,
                       base::Value::Dict params);

  mojo::Receiver<network::mojom::NetLogProxySource> proxy_source_receiver_;
  mojo::Remote<network::mojom::NetLogProxySink> proxy_sink_remote_;
  scoped_refptr<base::SequencedTaskRunner> task_runner_;

  // A WeakPtr to |this|, which is used when posting tasks from the
  // NetLog::ThreadSafeObserver to |task_runner_|. This single WeakPtr instance
  // is used for all tasks as the ThreadSafeObserver may call on any thread, so
  // the weak_factory_ cannot be accessed safely from those threads.
  base::WeakPtr<NetLogProxySource> weak_this_;

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

}  // namespace net_log

#endif  // COMPONENTS_NET_LOG_NET_LOG_PROXY_SOURCE_H_