diff options
author | reillyg <reillyg@chromium.org> | 2015-08-28 16:08:10 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-28 23:08:46 +0000 |
commit | badbc5415c4cd4d4870b2ca2122b1b9988e341d7 (patch) | |
tree | 154dd8ff7ab4edd48de2921b43f1316849311f4c /device/test | |
parent | e7bcbf464b505face0ed490930f9ba4bbb24ed6c (diff) | |
download | chromium_src-badbc5415c4cd4d4870b2ca2122b1b9988e341d7.zip chromium_src-badbc5415c4cd4d4870b2ca2122b1b9988e341d7.tar.gz chromium_src-badbc5415c4cd4d4870b2ca2122b1b9988e341d7.tar.bz2 |
Manage UsbService lifetime in DeviceClient implementations.
To make it easier to reason about when the UsbService is destroyed this
patch makes its lifetime managed by the DeviceClient implementation that
created it. This means that in Chrome the UsbService is (indirectly)
owned by BrowserProcessImpl.
BUG=None
TBR=dgozman@chromium.org
Review URL: https://codereview.chromium.org/1314273002
Cr-Commit-Position: refs/heads/master@{#346264}
Diffstat (limited to 'device/test')
-rw-r--r-- | device/test/test_device_client.cc | 35 | ||||
-rw-r--r-- | device/test/test_device_client.h | 31 | ||||
-rw-r--r-- | device/test/usb_test_gadget_impl.cc | 3 |
3 files changed, 68 insertions, 1 deletions
diff --git a/device/test/test_device_client.cc b/device/test/test_device_client.cc new file mode 100644 index 0000000..fcfbf92 --- /dev/null +++ b/device/test/test_device_client.cc @@ -0,0 +1,35 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "device/test/test_device_client.h" + +#include "device/hid/hid_service.h" +#include "device/usb/usb_service.h" + +namespace device { + +TestDeviceClient::TestDeviceClient( + scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) + : blocking_task_runner_(blocking_task_runner) {} + +TestDeviceClient::~TestDeviceClient() {} + +HidService* TestDeviceClient::GetHidService() { +#if !defined(OS_LINUX) || defined(USE_UDEV) + return HidService::GetInstance(blocking_task_runner_); +#else + return nullptr; +#endif +} + +UsbService* TestDeviceClient::GetUsbService() { +#if !defined(OS_ANDROID) && !defined(OS_IOS) + if (!usb_service_) { + usb_service_ = UsbService::Create(blocking_task_runner_); + } +#endif + return usb_service_.get(); +} + +} // namespace device diff --git a/device/test/test_device_client.h b/device/test/test_device_client.h new file mode 100644 index 0000000..ce70f38 --- /dev/null +++ b/device/test/test_device_client.h @@ -0,0 +1,31 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "device/core/device_client.h" + +namespace base { +class SingleThreadTaskRunner; +} + +namespace device { + +class HidService; +class UsbService; + +class TestDeviceClient : public DeviceClient { + public: + TestDeviceClient(scoped_refptr<base::SingleThreadTaskRunner> task_runner); + ~TestDeviceClient() override; + + private: + HidService* GetHidService() override; + UsbService* GetUsbService() override; + + scoped_ptr<UsbService> usb_service_; + scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner_; +}; + +} // namespace device diff --git a/device/test/usb_test_gadget_impl.cc b/device/test/usb_test_gadget_impl.cc index a94cb76..0222ab3 100644 --- a/device/test/usb_test_gadget_impl.cc +++ b/device/test/usb_test_gadget_impl.cc @@ -23,6 +23,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/thread_task_runner_handle.h" #include "base/time/time.h" +#include "device/core/device_client.h" #include "device/usb/usb_device.h" #include "device/usb/usb_device_handle.h" #include "device/usb/usb_service.h" @@ -192,7 +193,7 @@ class UsbGadgetFactory : public UsbService::Observer, public: UsbGadgetFactory(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) : observer_(this), weak_factory_(this) { - usb_service_ = UsbService::GetInstance(io_task_runner); + usb_service_ = DeviceClient::Get()->GetUsbService(); request_context_getter_ = new URLRequestContextGetter(io_task_runner); static uint32 next_session_id; |