OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/usb/usb_service.h" | 5 #include "chrome/browser/usb/usb_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "chrome/browser/usb/usb_device.h" | 10 #include "chrome/browser/usb/usb_device.h" |
11 #include "third_party/libusb/libusb/libusb.h" | 11 #include "third_party/libusb/libusb.h" |
12 | 12 |
13 UsbService::UsbService() : running_(true), thread_("UsbThread") { | 13 UsbService::UsbService() : running_(true), thread_("UsbThread") { |
14 libusb_init(&context_); | 14 libusb_init(&context_); |
15 thread_.Start(); | 15 thread_.Start(); |
16 PostHandleEventTask(); | 16 PostHandleEventTask(); |
17 } | 17 } |
18 | 18 |
19 UsbService::~UsbService() {} | 19 UsbService::~UsbService() {} |
20 | 20 |
21 // TODO(gdk): There is currently no clean way to indicate to the event handler | 21 // TODO(gdk): There is currently no clean way to indicate to the event handler |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 void UsbService::PostHandleEventTask() { | 72 void UsbService::PostHandleEventTask() { |
73 thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 73 thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
74 &UsbService::HandleEvent, base::Unretained(this))); | 74 &UsbService::HandleEvent, base::Unretained(this))); |
75 } | 75 } |
76 | 76 |
77 void UsbService::HandleEvent() { | 77 void UsbService::HandleEvent() { |
78 libusb_handle_events_completed(context_, NULL); | 78 libusb_handle_events(context_); |
79 if (running_) { | 79 if (running_) { |
80 PostHandleEventTask(); | 80 PostHandleEventTask(); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void UsbService::PlatformShutdown() { | 84 void UsbService::PlatformShutdown() { |
85 libusb_exit(context_); | 85 libusb_exit(context_); |
86 } | 86 } |
OLD | NEW |