| Index: chrome/browser/chromeos/device/input_service_proxy.cc
|
| diff --git a/chrome/browser/chromeos/device/input_service_proxy.cc b/chrome/browser/chromeos/device/input_service_proxy.cc
|
| index 601bc611a7298d6f64c7fe52bb863d707a86b500..e3fa43007c49bfb0817f6e30fe7aba14a72b7830 100644
|
| --- a/chrome/browser/chromeos/device/input_service_proxy.cc
|
| +++ b/chrome/browser/chromeos/device/input_service_proxy.cc
|
| @@ -6,7 +6,9 @@
|
|
|
| #include "base/bind_helpers.h"
|
| #include "base/macros.h"
|
| +#include "base/sequence_checker.h"
|
| #include "base/task_runner_util.h"
|
| +#include "base/task_scheduler/post_task.h"
|
| #include "content/public/browser/browser_thread.h"
|
|
|
| using content::BrowserThread;
|
| @@ -16,29 +18,48 @@ typedef device::InputServiceLinux::InputDeviceInfo InputDeviceInfo;
|
|
|
| namespace chromeos {
|
|
|
| -// static
|
| -BrowserThread::ID InputServiceProxy::thread_identifier_ = BrowserThread::FILE;
|
| +namespace {
|
| +
|
| +InputServiceProxy::TaskRunnerFactory* task_runner_factory = nullptr;
|
| +
|
| +scoped_refptr<base::TaskRunner> GetTaskRunner() {
|
| + if (task_runner_factory)
|
| + return task_runner_factory->Run();
|
| +
|
| + return base::CreateSequencedTaskRunnerWithTraits(
|
| + {base::TaskPriority::BACKGROUND});
|
| +}
|
| +
|
| +} // namespace
|
|
|
| class InputServiceProxy::ServiceObserver : public InputServiceLinux::Observer {
|
| public:
|
| - ServiceObserver() { DCHECK_CURRENTLY_ON(BrowserThread::UI); }
|
| - ~ServiceObserver() override { DCHECK(CalledOnValidThread()); }
|
| + ServiceObserver() {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| +
|
| + // Detach since this object is constructed on UI thread and forever after
|
| + // used from another sequence.
|
| + DETACH_FROM_SEQUENCE(sequence_checker_);
|
| + }
|
| + ~ServiceObserver() override {
|
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
| + }
|
|
|
| void Initialize(const base::WeakPtr<InputServiceProxy>& proxy) {
|
| - DCHECK(CalledOnValidThread());
|
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
| InputServiceLinux::GetInstance()->AddObserver(this);
|
| proxy_ = proxy;
|
| }
|
|
|
| void Shutdown() {
|
| - DCHECK(CalledOnValidThread());
|
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
| if (InputServiceLinux::HasInstance())
|
| InputServiceLinux::GetInstance()->RemoveObserver(this);
|
| delete this;
|
| }
|
|
|
| std::vector<InputDeviceInfo> GetDevices() {
|
| - DCHECK(CalledOnValidThread());
|
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
| std::vector<InputDeviceInfo> devices;
|
| if (InputServiceLinux::HasInstance())
|
| InputServiceLinux::GetInstance()->GetDevices(&devices);
|
| @@ -47,7 +68,7 @@ class InputServiceProxy::ServiceObserver : public InputServiceLinux::Observer {
|
|
|
| void GetDeviceInfo(const std::string& id,
|
| const InputServiceProxy::GetDeviceInfoCallback& callback) {
|
| - DCHECK(CalledOnValidThread());
|
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
| bool success = false;
|
| InputDeviceInfo info;
|
| info.id = id;
|
| @@ -60,7 +81,7 @@ class InputServiceProxy::ServiceObserver : public InputServiceLinux::Observer {
|
| // InputServiceLinux::Observer implementation:
|
| void OnInputDeviceAdded(
|
| const InputServiceLinux::InputDeviceInfo& info) override {
|
| - DCHECK(CalledOnValidThread());
|
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
| BrowserThread::PostTask(
|
| BrowserThread::UI,
|
| FROM_HERE,
|
| @@ -68,7 +89,7 @@ class InputServiceProxy::ServiceObserver : public InputServiceLinux::Observer {
|
| }
|
|
|
| void OnInputDeviceRemoved(const std::string& id) override {
|
| - DCHECK(CalledOnValidThread());
|
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
| BrowserThread::PostTask(
|
| BrowserThread::UI,
|
| FROM_HERE,
|
| @@ -76,18 +97,15 @@ class InputServiceProxy::ServiceObserver : public InputServiceLinux::Observer {
|
| }
|
|
|
| private:
|
| - bool CalledOnValidThread() const {
|
| - return BrowserThread::CurrentlyOn(InputServiceProxy::thread_identifier_);
|
| - }
|
| -
|
| base::WeakPtr<InputServiceProxy> proxy_;
|
| + SEQUENCE_CHECKER(sequence_checker_);
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ServiceObserver);
|
| };
|
|
|
| InputServiceProxy::InputServiceProxy()
|
| : service_observer_(new ServiceObserver()),
|
| - task_runner_(BrowserThread::GetTaskRunnerForThread(thread_identifier_)),
|
| + task_runner_(GetTaskRunner()),
|
| weak_factory_(this) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| task_runner_->PostTask(
|
| @@ -139,8 +157,9 @@ void InputServiceProxy::GetDeviceInfo(const std::string& id,
|
| }
|
|
|
| // static
|
| -void InputServiceProxy::SetThreadIdForTesting(BrowserThread::ID thread_id) {
|
| - InputServiceProxy::thread_identifier_ = thread_id;
|
| +void InputServiceProxy::SetTaskRunnerFactoryForTesting(
|
| + TaskRunnerFactory* factory) {
|
| + task_runner_factory = factory;
|
| }
|
|
|
| void InputServiceProxy::OnDeviceAdded(
|
|
|