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

Unified Diff: content/renderer/usb/web_usb_client_impl.cc

Issue 1404043002: Connect to DeviceManager lazily in WebUSBClientImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/usb/web_usb_client_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/usb/web_usb_client_impl.cc
diff --git a/content/renderer/usb/web_usb_client_impl.cc b/content/renderer/usb/web_usb_client_impl.cc
index 43e7b629ca964a7316f83ba5e6e8cfd1d881bc9c..fc87597e8c53ee16d0e4e1341f047032ed07c6de 100644
--- a/content/renderer/usb/web_usb_client_impl.cc
+++ b/content/renderer/usb/web_usb_client_impl.cc
@@ -66,16 +66,15 @@ void OnGetDevicesComplete(
} // namespace
-WebUSBClientImpl::WebUSBClientImpl(content::ServiceRegistry* service_registry) {
- service_registry->ConnectToRemoteService(mojo::GetProxy(&device_manager_));
-}
+WebUSBClientImpl::WebUSBClientImpl(content::ServiceRegistry* service_registry)
+ : service_registry_(service_registry) {}
WebUSBClientImpl::~WebUSBClientImpl() {}
void WebUSBClientImpl::getDevices(
blink::WebUSBClientGetDevicesCallbacks* callbacks) {
auto scoped_callbacks = MakeScopedUSBCallbacks(callbacks);
- device_manager_->GetDevices(
+ GetDeviceManager()->GetDevices(
nullptr,
base::Bind(&OnGetDevicesComplete, base::Passed(&scoped_callbacks),
base::Unretained(device_manager_.get())));
@@ -92,15 +91,22 @@ void WebUSBClientImpl::requestDevice(
void WebUSBClientImpl::setObserver(Observer* observer) {
if (!observer_) {
// Set up two sequential calls to GetDeviceChanges to avoid latency.
- device_manager_->GetDeviceChanges(base::Bind(
+ device::usb::DeviceManager* device_manager = GetDeviceManager();
+ device_manager->GetDeviceChanges(base::Bind(
&WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this)));
- device_manager_->GetDeviceChanges(base::Bind(
+ device_manager->GetDeviceChanges(base::Bind(
&WebUSBClientImpl::OnDeviceChangeNotification, base::Unretained(this)));
}
observer_ = observer;
}
+device::usb::DeviceManager* WebUSBClientImpl::GetDeviceManager() {
+ if (!device_manager_)
+ service_registry_->ConnectToRemoteService(mojo::GetProxy(&device_manager_));
+ return device_manager_.get();
+}
+
void WebUSBClientImpl::OnDeviceChangeNotification(
device::usb::DeviceChangeNotificationPtr notification) {
if (!observer_)
« 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