diff options
author | reillyg <reillyg@chromium.org> | 2015-04-16 12:11:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-16 19:12:05 +0000 |
commit | b87cb277526092e101ce29f2ad0393f6247cc39e (patch) | |
tree | ffd0c2b8e4bb0519070cf000a872f78d83ae9791 /device/hid/hid_connection_unittest.cc | |
parent | e2ff83b4c95cbd9c0df8fd338c9afa39b861cb14 (diff) | |
download | chromium_src-b87cb277526092e101ce29f2ad0393f6247cc39e.zip chromium_src-b87cb277526092e101ce29f2ad0393f6247cc39e.tar.gz chromium_src-b87cb277526092e101ce29f2ad0393f6247cc39e.tar.bz2 |
Move device/usb classes from the FILE thread to UI thread.
Code that interacts with device/usb often lives on the UI thread. As
with the recent migration of device/hid (issue 422540) moving ownership
of these classes to the UI thread makes calling code substancially
simplier. Blocking operations are handled internally by posting tasks
to the FILE thread and returning a result to the UI thread
asynchronously.
This change paves the way for replacing libusb with platform-specific
implementations of these classes that may have different thread usage
requirements (as is the case in the device/hid code).
BUG=427985
Review URL: https://codereview.chromium.org/980023002
Cr-Commit-Position: refs/heads/master@{#325491}
Diffstat (limited to 'device/hid/hid_connection_unittest.cc')
-rw-r--r-- | device/hid/hid_connection_unittest.cc | 37 |
1 files changed, 8 insertions, 29 deletions
diff --git a/device/hid/hid_connection_unittest.cc b/device/hid/hid_connection_unittest.cc index e474a62..b036198 100644 --- a/device/hid/hid_connection_unittest.cc +++ b/device/hid/hid_connection_unittest.cc @@ -10,10 +10,12 @@ #include "base/memory/scoped_ptr.h" #include "base/run_loop.h" #include "base/scoped_observer.h" +#include "base/strings/utf_string_conversions.h" #include "base/test/test_io_thread.h" #include "device/hid/hid_connection.h" #include "device/hid/hid_service.h" #include "device/test/usb_test_gadget.h" +#include "device/usb/usb_device.h" #include "net/base/io_buffer.h" #include "testing/gtest/include/gtest/gtest.h" @@ -23,20 +25,6 @@ namespace { using net::IOBufferWithSize; -void ClaimTestDevice(scoped_ptr<UsbTestGadget>* gadget) { - base::MessageLoop::ScopedNestableTaskAllower allow( - base::MessageLoop::current()); - *gadget = UsbTestGadget::Claim(); - ASSERT_TRUE(*gadget); - ASSERT_TRUE((*gadget)->SetType(UsbTestGadget::HID_ECHO)); -} - -void UnclaimTestDevice(scoped_ptr<UsbTestGadget> gadget) { - base::MessageLoop::ScopedNestableTaskAllower allow( - base::MessageLoop::current()); - ASSERT_TRUE(gadget->Unclaim()); -} - // Helper class that can be used to block until a HID device with a particular // serial number is available. Example usage: // @@ -46,10 +34,8 @@ void UnclaimTestDevice(scoped_ptr<UsbTestGadget> gadget) { // class DeviceCatcher : HidService::Observer { public: - DeviceCatcher(const std::string& serial_number) - : serial_number_(serial_number), observer_(this) { - HidService* hid_service = HidService::GetInstance( - base::MessageLoop::current()->message_loop_proxy()); + DeviceCatcher(HidService* hid_service, const base::string16& serial_number) + : serial_number_(base::UTF16ToUTF8(serial_number)), observer_(this) { observer_.Add(hid_service); hid_service->GetDevices(base::Bind(&DeviceCatcher::OnEnumerationComplete, base::Unretained(this))); @@ -168,23 +154,16 @@ class HidConnectionTest : public testing::Test { service_ = HidService::GetInstance(io_thread_->task_runner()); ASSERT_TRUE(service_); - io_thread_->PostTaskAndWait(FROM_HERE, - base::Bind(&ClaimTestDevice, &test_gadget_)); + test_gadget_ = UsbTestGadget::Claim(io_thread_->task_runner()); ASSERT_TRUE(test_gadget_); + ASSERT_TRUE(test_gadget_->SetType(UsbTestGadget::HID_ECHO)); - DeviceCatcher device_catcher(test_gadget_->GetSerialNumber()); + DeviceCatcher device_catcher(service_, + test_gadget_->GetDevice()->serial_number()); device_id_ = device_catcher.WaitForDevice(); ASSERT_NE(device_id_, kInvalidHidDeviceId); } - void TearDown() override { - if (io_thread_) { - io_thread_->PostTaskAndWait( - FROM_HERE, - base::Bind(&UnclaimTestDevice, base::Passed(&test_gadget_))); - } - } - scoped_ptr<base::MessageLoopForUI> message_loop_; scoped_ptr<base::TestIOThread> io_thread_; HidService* service_; |