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 #include "net/test/test_with_task_environment.h" 6 7 #include <memory> 8 9 #include "base/command_line.h" 10 #include "net/log/net_log.h" 11 #include "net/log/net_log_capture_mode.h" 12 #include "net/test/test_net_log_manager.h" 13 14 namespace net { 15 WithTaskEnvironment(base::test::TaskEnvironment::TimeSource time_source)16WithTaskEnvironment::WithTaskEnvironment( 17 base::test::TaskEnvironment::TimeSource time_source) 18 : task_environment_(base::test::TaskEnvironment::MainThreadType::IO, 19 time_source) { 20 MaybeStartNetLog(); 21 } 22 23 WithTaskEnvironment::~WithTaskEnvironment() = default; 24 MaybeStartNetLog()25void WithTaskEnvironment::MaybeStartNetLog() { 26 const base::CommandLine* command_line = 27 base::CommandLine::ForCurrentProcess(); 28 if (command_line->HasSwitch(TestNetLogManager::kLogNetLogSwitch)) { 29 net_log_manager_ = std::make_unique<TestNetLogManager>( 30 NetLog::Get(), NetLogCaptureMode::kEverything); 31 } 32 } 33 34 } // namespace net 35