• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The Chromium Authors
2 // 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_TEST_TEST_NET_LOG_MANAGER_H_
6 #define NET_TEST_TEST_NET_LOG_MANAGER_H_
7 
8 #include <memory>
9 #include <string_view>
10 
11 #include "net/log/net_log_capture_mode.h"
12 
13 namespace net {
14 
15 class NetLog;
16 class FileNetLogObserver;
17 
18 // Manages NetLogObserver for unit tests. When `--log-net-log` is specified
19 // without a file path, it dumps NetLog events to VLOG. When `--log-net-log`
20 // is specified with a file path, it dumps NetLog events to the file using
21 // FileNetLogObserver.
22 class TestNetLogManager {
23  public:
24   // TODO(crbug.com/336167322): Move network::switches::kLogNetLog so that we
25   // can use the switch here.
26   static constexpr const std::string_view kLogNetLogSwitch = "log-net-log";
27 
28   TestNetLogManager(NetLog* net_log, NetLogCaptureMode capture_mode);
29 
30   TestNetLogManager(const TestNetLogManager&) = delete;
31   TestNetLogManager& operator=(const TestNetLogManager&) = delete;
32 
33   ~TestNetLogManager();
34 
35  private:
36   class VlogNetLogObserver;
37 
38   std::unique_ptr<FileNetLogObserver> file_net_log_observer_;
39   std::unique_ptr<VlogNetLogObserver> vlog_net_log_observer_;
40 };
41 
42 }  // namespace net
43 
44 #endif  // NET_TEST_TEST_NET_LOG_MANAGER_H_
45