refactor: move IOThread and NetLog ownership to g_browser_process

This commit is contained in:
deepak1556 2018-11-07 18:53:09 +05:30
parent 414dcfcd07
commit 666a106fa8
8 changed files with 45 additions and 50 deletions

View file

@ -7,10 +7,10 @@
#include <utility>
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "base/command_line.h"
#include "chrome/browser/browser_process.h"
#include "components/net_log/chrome_net_log.h"
#include "content/public/browser/storage_partition.h"
#include "native_mate/dictionary.h"
@ -27,8 +27,7 @@ NetLog::NetLog(v8::Isolate* isolate, AtomBrowserContext* browser_context)
: browser_context_(browser_context) {
Init(isolate);
net_log_writer_ =
atom::AtomBrowserMainParts::Get()->net_log()->net_export_file_writer();
net_log_writer_ = g_browser_process->net_log()->net_export_file_writer();
net_log_writer_->AddObserver(this);
}

View file

@ -45,6 +45,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "components/net_log/chrome_net_log.h"
#include "content/public/browser/browser_ppapi_host.h"
#include "content/public/browser/client_certificate_delegate.h"
@ -662,7 +663,7 @@ std::unique_ptr<base::Value> AtomBrowserClient::GetServiceManifestOverlay(
}
net::NetLog* AtomBrowserClient::GetNetLog() {
return AtomBrowserMainParts::Get()->net_log();
return g_browser_process->net_log();
}
content::BrowserMainParts* AtomBrowserClient::CreateBrowserMainParts(

View file

@ -19,7 +19,6 @@
#include "atom/browser/atom_web_ui_controller_factory.h"
#include "atom/browser/browser.h"
#include "atom/browser/browser_process_impl.h"
#include "atom/browser/io_thread.h"
#include "atom/browser/javascript_environment.h"
#include "atom/browser/media/media_capture_devices_dispatcher.h"
#include "atom/browser/node_debugger.h"
@ -36,9 +35,6 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/icon_manager.h"
#include "chrome/browser/net/chrome_net_log_helper.h"
#include "components/net_log/chrome_net_log.h"
#include "components/net_log/net_export_file_writer.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/web_ui_controller_factory.h"
@ -49,7 +45,6 @@
#include "electron/buildflags/buildflags.h"
#include "media/base/localized_strings.h"
#include "services/device/public/mojom/constants.mojom.h"
#include "services/network/public/cpp/network_switches.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/base/idle/idle.h"
#include "ui/base/l10n/l10n_util.h"
@ -382,24 +377,7 @@ int AtomBrowserMainParts::PreCreateThreads() {
ui::InitIdleMonitor();
#endif
net_log_ = std::make_unique<net_log::ChromeNetLog>();
auto& command_line = main_function_params_.command_line;
// start net log trace if --log-net-log is passed in the command line.
if (command_line.HasSwitch(network::switches::kLogNetLog)) {
base::FilePath log_file =
command_line.GetSwitchValuePath(network::switches::kLogNetLog);
if (!log_file.empty()) {
net_log_->StartWritingToFile(
log_file, GetNetCaptureModeFromCommandLine(command_line),
command_line.GetCommandLineString(), std::string());
}
}
// Initialize net log file exporter.
net_log_->net_export_file_writer()->Initialize();
fake_browser_process_->PreCreateThreads(command_line);
// Manage global state of net and other IO thread related.
io_thread_ = std::make_unique<IOThread>(net_log_.get());
fake_browser_process_->PreCreateThreads(main_function_params_.command_line);
return 0;
}
@ -409,7 +387,7 @@ void AtomBrowserMainParts::PostDestroyThreads() {
device::BluetoothAdapterFactory::Shutdown();
bluez::DBusBluezManagerWrapperLinux::Shutdown();
#endif
io_thread_.reset();
fake_browser_process_->PostDestroyThreads();
}
void AtomBrowserMainParts::ToolkitInitialized() {

View file

@ -20,10 +20,6 @@
class BrowserProcess;
class IconManager;
namespace net_log {
class ChromeNetLog;
}
#if defined(USE_AURA)
namespace wm {
class WMState;
@ -34,7 +30,6 @@ namespace atom {
class AtomBindings;
class Browser;
class IOThread;
class JavascriptEnvironment;
class NodeBindings;
class NodeDebugger;
@ -75,8 +70,6 @@ class AtomBrowserMainParts : public content::BrowserMainParts {
IconManager* GetIconManager();
Browser* browser() { return browser_.get(); }
IOThread* io_thread() const { return io_thread_.get(); }
net_log::ChromeNetLog* net_log() { return net_log_.get(); }
protected:
// content::BrowserMainParts:
@ -134,8 +127,6 @@ class AtomBrowserMainParts : public content::BrowserMainParts {
std::unique_ptr<AtomBindings> atom_bindings_;
std::unique_ptr<NodeEnvironment> node_env_;
std::unique_ptr<NodeDebugger> node_debugger_;
std::unique_ptr<IOThread> io_thread_;
std::unique_ptr<net_log::ChromeNetLog> net_log_;
std::unique_ptr<IconManager> icon_manager_;
base::RepeatingTimer gc_timer_;

View file

@ -6,8 +6,10 @@
#include <utility>
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/net/chrome_net_log_helper.h"
#include "chrome/common/chrome_switches.h"
#include "components/net_log/chrome_net_log.h"
#include "components/net_log/net_export_file_writer.h"
#include "components/prefs/in_memory_pref_store.h"
#include "components/prefs/overlay_user_pref_store.h"
#include "components/prefs/pref_registry.h"
@ -21,6 +23,7 @@
#include "net/proxy_resolution/proxy_config_service.h"
#include "net/proxy_resolution/proxy_config_with_annotation.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "services/network/public/cpp/network_switches.h"
#include "ui/base/l10n/l10n_util.h"
#if BUILDFLAG(ENABLE_PRINTING)
@ -90,6 +93,27 @@ void BrowserProcessImpl::PreCreateThreads(
// this can be created on first use.
system_network_context_manager_ =
std::make_unique<SystemNetworkContextManager>();
net_log_ = std::make_unique<net_log::ChromeNetLog>();
// start net log trace if --log-net-log is passed in the command line.
if (command_line.HasSwitch(network::switches::kLogNetLog)) {
base::FilePath log_file =
command_line.GetSwitchValuePath(network::switches::kLogNetLog);
if (!log_file.empty()) {
net_log_->StartWritingToFile(
log_file, GetNetCaptureModeFromCommandLine(command_line),
command_line.GetCommandLineString(), std::string());
}
}
// Initialize net log file exporter.
net_log_->net_export_file_writer()->Initialize();
// Manage global state of net and other IO thread related.
io_thread_ = std::make_unique<IOThread>(net_log_.get());
}
void BrowserProcessImpl::PostDestroyThreads() {
io_thread_.reset();
}
void BrowserProcessImpl::PostMainMessageLoopRun() {
@ -154,7 +178,8 @@ NotificationPlatformBridge* BrowserProcessImpl::notification_platform_bridge() {
}
IOThread* BrowserProcessImpl::io_thread() {
return nullptr;
DCHECK(io_thread_.get());
return io_thread_.get();
}
SystemNetworkContextManager*
@ -239,7 +264,8 @@ BrowserProcessImpl::optimization_guide_service() {
}
net_log::ChromeNetLog* BrowserProcessImpl::net_log() {
return nullptr;
DCHECK(net_log_.get());
return net_log_.get();
}
component_updater::ComponentUpdateService*

View file

@ -13,6 +13,7 @@
#include <memory>
#include <string>
#include "atom/browser/io_thread.h"
#include "atom/browser/net/system_network_context_manager.h"
#include "base/command_line.h"
#include "base/macros.h"
@ -22,6 +23,10 @@
#include "printing/buildflags/buildflags.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace net_log {
class ChromeNetLog;
}
namespace printing {
class PrintJobManager;
}
@ -40,6 +45,7 @@ class BrowserProcessImpl : public BrowserProcess {
void PostEarlyInitialization();
void PreCreateThreads(const base::CommandLine& command_line);
void PostDestroyThreads();
void PostMainMessageLoopRun();
void ResourceDispatcherHostCreated() override {}
@ -113,6 +119,8 @@ class BrowserProcessImpl : public BrowserProcess {
std::unique_ptr<printing::PrintJobManager> print_job_manager_;
#endif
std::unique_ptr<PrefService> local_state_;
std::unique_ptr<IOThread> io_thread_;
std::unique_ptr<net_log::ChromeNetLog> net_log_;
std::unique_ptr<SystemNetworkContextManager> system_network_context_manager_;
std::string locale_;

View file

@ -25,8 +25,6 @@
using content::BrowserThread;
namespace atom {
namespace {
network::mojom::HttpAuthStaticParamsPtr CreateHttpAuthStaticParams() {
@ -45,9 +43,9 @@ network::mojom::HttpAuthDynamicParamsPtr CreateHttpAuthDynamicParams(
network::mojom::HttpAuthDynamicParams::New();
auth_dynamic_params->server_whitelist =
command_line.GetSwitchValueASCII(switches::kAuthServerWhitelist);
command_line.GetSwitchValueASCII(atom::switches::kAuthServerWhitelist);
auth_dynamic_params->delegate_whitelist = command_line.GetSwitchValueASCII(
switches::kAuthNegotiateDelegateWhitelist);
atom::switches::kAuthNegotiateDelegateWhitelist);
return auth_dynamic_params;
}
@ -114,5 +112,3 @@ void IOThread::CleanUp() {
if (net_log_)
net_log_->ShutDownBeforeTaskScheduler();
}
} // namespace atom

View file

@ -20,8 +20,6 @@ namespace net_log {
class ChromeNetLog;
}
namespace atom {
class IOThread : public content::BrowserThreadDelegate {
public:
explicit IOThread(net_log::ChromeNetLog* net_log);
@ -46,6 +44,4 @@ class IOThread : public content::BrowserThreadDelegate {
DISALLOW_COPY_AND_ASSIGN(IOThread);
};
} // namespace atom
#endif // ATOM_BROWSER_IO_THREAD_H_