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

Side by Side Diff: content/renderer/usb/web_usb_client_impl.cc

Issue 1331383005: Implement WebUSBClient::setObserver in WebUSBClientImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manager_full_remove
Patch Set: Less whitespace. Created 5 years, 3 months 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 unified diff | Download patch
« no previous file with comments | « content/renderer/usb/web_usb_client_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/renderer/usb/web_usb_client_impl.h" 5 #include "content/renderer/usb/web_usb_client_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/move.h" 10 #include "base/move.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 92
93 void WebUSBClientImpl::requestDevice( 93 void WebUSBClientImpl::requestDevice(
94 const blink::WebUSBDeviceRequestOptions& options, 94 const blink::WebUSBDeviceRequestOptions& options,
95 blink::WebUSBClientRequestDeviceCallbacks* callbacks) { 95 blink::WebUSBClientRequestDeviceCallbacks* callbacks) {
96 callbacks->onError(blink::WebUSBError(blink::WebUSBError::Error::Service, 96 callbacks->onError(blink::WebUSBError(blink::WebUSBError::Error::Service,
97 base::UTF8ToUTF16("Not implemented."))); 97 base::UTF8ToUTF16("Not implemented.")));
98 delete callbacks; 98 delete callbacks;
99 } 99 }
100 100
101 void WebUSBClientImpl::setObserver(Observer* observer) {
102 if (!observer_) {
103 // Set up two sequential calls to GetDeviceChanges to avoid latency.
104 device_manager_->GetDeviceChanges(base::Bind(
105 &WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this)));
106 device_manager_->GetDeviceChanges(base::Bind(
107 &WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this)));
108 }
109
110 observer_ = observer;
111 }
112
113 void WebUSBClientImpl::OnDeviceChangeNotification(
114 device::usb::DeviceChangeNotificationPtr notification) {
115 if (!observer_)
116 return;
117
118 device_manager_->GetDeviceChanges(base::Bind(
119 &WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this)));
120 for (size_t i = 0; i < notification->devices_added.size(); ++i) {
121 device::usb::DeviceManagerPtr device_manager;
122 mojo::ConnectToService(device_services_.get(), &device_manager);
123 observer_->onDeviceConnected(blink::adoptWebPtr(new WebUSBDeviceImpl(
124 device_manager.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(
125 notification->devices_added[i]))));
126 }
127 for (size_t i = 0; i < notification->devices_removed.size(); ++i) {
128 device::usb::DeviceManagerPtr device_manager;
129 mojo::ConnectToService(device_services_.get(), &device_manager);
130 observer_->onDeviceDisconnected(blink::adoptWebPtr(new WebUSBDeviceImpl(
131 device_manager.Pass(), mojo::ConvertTo<blink::WebUSBDeviceInfo>(
132 notification->devices_removed[i]))));
133 }
134 }
135
101 } // namespace content 136 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/usb/web_usb_client_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698