Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2484)

Unified Diff: device/usb/usb_service_linux.cc

Issue 2482463002: Remove DeviceMonitorLinux::WillDestroyCurrentMessageLoop(). (Closed)
Patch Set: CR achuithb #24 Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/usb/usb_service_linux.h ('k') | extensions/shell/browser/shell_browser_main_parts.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/usb/usb_service_linux.cc
diff --git a/device/usb/usb_service_linux.cc b/device/usb/usb_service_linux.cc
index 73c71a7b6c46e12f6b34fbeed48c729491dbbb1d..56ad14929c27362fb00ab788b66d33193e0b4206 100644
--- a/device/usb/usb_service_linux.cc
+++ b/device/usb/usb_service_linux.cc
@@ -6,11 +6,15 @@
#include <stdint.h>
+#include <utility>
+
#include "base/bind.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/location.h"
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "base/single_thread_task_runner.h"
@@ -70,13 +74,12 @@ class UsbServiceLinux::FileThreadHelper : public DeviceMonitorLinux::Observer {
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~FileThreadHelper() override;
- static void Start(std::unique_ptr<FileThreadHelper> self);
+ void Start();
private:
// DeviceMonitorLinux::Observer:
void OnDeviceAdded(udev_device* udev_device) override;
void OnDeviceRemoved(udev_device* device) override;
- void WillDestroyMonitorMessageLoop() override;
base::ThreadChecker thread_checker_;
ScopedObserver<DeviceMonitorLinux, DeviceMonitorLinux::Observer> observer_;
@@ -91,27 +94,25 @@ class UsbServiceLinux::FileThreadHelper : public DeviceMonitorLinux::Observer {
UsbServiceLinux::FileThreadHelper::FileThreadHelper(
base::WeakPtr<UsbServiceLinux> service,
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : observer_(this), service_(service), task_runner_(task_runner) {}
+ : observer_(this), service_(service), task_runner_(std::move(task_runner)) {
+ thread_checker_.DetachFromThread();
+}
UsbServiceLinux::FileThreadHelper::~FileThreadHelper() {
DCHECK(thread_checker_.CalledOnValidThread());
}
// static
-void UsbServiceLinux::FileThreadHelper::Start(
- std::unique_ptr<FileThreadHelper> self) {
+void UsbServiceLinux::FileThreadHelper::Start() {
base::ThreadRestrictions::AssertIOAllowed();
- self->thread_checker_.DetachFromThread();
+ DCHECK(thread_checker_.CalledOnValidThread());
DeviceMonitorLinux* monitor = DeviceMonitorLinux::GetInstance();
- self->observer_.Add(monitor);
- monitor->Enumerate(base::Bind(&FileThreadHelper::OnDeviceAdded,
- base::Unretained(self.get())));
- self->task_runner_->PostTask(
- FROM_HERE, base::Bind(&UsbServiceLinux::HelperStarted, self->service_));
-
- // |self| is now owned by the current message loop.
- ignore_result(self.release());
+ observer_.Add(monitor);
+ monitor->Enumerate(
+ base::Bind(&FileThreadHelper::OnDeviceAdded, base::Unretained(this)));
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&UsbServiceLinux::HelperStarted, service_));
}
void UsbServiceLinux::FileThreadHelper::OnDeviceAdded(
@@ -182,23 +183,27 @@ void UsbServiceLinux::FileThreadHelper::OnDeviceRemoved(udev_device* device) {
}
}
-void UsbServiceLinux::FileThreadHelper::WillDestroyMonitorMessageLoop() {
- delete this;
-}
-
UsbServiceLinux::UsbServiceLinux(
- scoped_refptr<base::SequencedTaskRunner> blocking_task_runner)
- : UsbService(base::ThreadTaskRunnerHandle::Get(), blocking_task_runner),
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_in)
+ : UsbService(base::ThreadTaskRunnerHandle::Get(),
+ std::move(blocking_task_runner_in)),
weak_factory_(this) {
- std::unique_ptr<FileThreadHelper> helper(
- new FileThreadHelper(weak_factory_.GetWeakPtr(), task_runner()));
- helper_ = helper.get();
- blocking_task_runner->PostTask(
- FROM_HERE, base::Bind(&FileThreadHelper::Start, base::Passed(&helper)));
+ helper_ = base::MakeUnique<FileThreadHelper>(weak_factory_.GetWeakPtr(),
+ task_runner());
+ blocking_task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&FileThreadHelper::Start, base::Unretained(helper_.get())));
}
UsbServiceLinux::~UsbServiceLinux() {
- blocking_task_runner()->DeleteSoon(FROM_HERE, helper_);
+ DCHECK(!helper_);
+}
+
+void UsbServiceLinux::Shutdown() {
+ const bool did_post_task =
+ blocking_task_runner()->DeleteSoon(FROM_HERE, helper_.release());
+ DCHECK(did_post_task);
+ UsbService::Shutdown();
}
void UsbServiceLinux::GetDevices(const GetDevicesCallback& callback) {
« no previous file with comments | « device/usb/usb_service_linux.h ('k') | extensions/shell/browser/shell_browser_main_parts.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698