Commit 7a9ea7ca authored by fdoray's avatar fdoray Committed by Commit bot

Leak DeviceMonitorLinux on shutdown.

In preparation for the migration of many Chrome threads to
TaskScheduler, we want to get rid of MessageLoop destruction
observers.

This CL removes the code that deletes DeviceMonitorLinux from
a destruction observer and uses a LazyInstance::Leaky to manage
the lifetime of DeviceMonitorLinux.

This CL also helps reducing the amount of work done during
shutdown
https://groups.google.com/a/chromium.org/d/msg/chromium-dev/AMB2Y7Sqj48/QltA07wUCQAJ

BUG=650318

Review-Url: https://chromiumcodereview.appspot.com/2433933004
Cr-Commit-Position: refs/heads/master@{#426518}
parent dbd3adb5
......@@ -22,8 +22,8 @@ const char kUdevActionAdd[] = "add";
const char kUdevActionRemove[] = "remove";
// The instance will be reset when message loop destroys.
base::LazyInstance<std::unique_ptr<DeviceMonitorLinux>>::Leaky
g_device_monitor_linux_ptr = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<DeviceMonitorLinux>::Leaky g_device_monitor_linux =
LAZY_INSTANCE_INITIALIZER;
} // namespace
......@@ -62,9 +62,7 @@ DeviceMonitorLinux::DeviceMonitorLinux() : monitor_fd_(-1) {
// static
DeviceMonitorLinux* DeviceMonitorLinux::GetInstance() {
if (!g_device_monitor_linux_ptr.Get().get())
g_device_monitor_linux_ptr.Get().reset(new DeviceMonitorLinux());
return g_device_monitor_linux_ptr.Get().get();
return g_device_monitor_linux.Pointer();
}
void DeviceMonitorLinux::AddObserver(Observer* observer) {
......@@ -106,13 +104,11 @@ void DeviceMonitorLinux::WillDestroyCurrentMessageLoop() {
DCHECK(thread_checker_.CalledOnValidThread());
for (auto& observer : observers_)
observer.WillDestroyMonitorMessageLoop();
g_device_monitor_linux_ptr.Get().reset(nullptr);
}
DeviceMonitorLinux::~DeviceMonitorLinux() {
DCHECK(thread_checker_.CalledOnValidThread());
base::MessageLoop::current()->RemoveDestructionObserver(this);
close(monitor_fd_);
// A leaky LazyInstance is never destroyed.
NOTREACHED();
}
void DeviceMonitorLinux::OnMonitorCanReadWithoutBlocking() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment