| OLD | NEW |
| 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 "device/devices_app/devices_app.h" | 5 #include "device/devices_app/devices_app.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "device/core/device_client.h" | 17 #include "device/core/device_client.h" |
| 17 #include "device/devices_app/usb/device_manager_impl.h" | 18 #include "device/devices_app/usb/device_manager_impl.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 99 } |
| 99 | 100 |
| 100 void DevicesApp::Create(mojo::ApplicationConnection* connection, | 101 void DevicesApp::Create(mojo::ApplicationConnection* connection, |
| 101 mojo::InterfaceRequest<usb::DeviceManager> request) { | 102 mojo::InterfaceRequest<usb::DeviceManager> request) { |
| 102 // Bind the new device manager to the connecting application's permission | 103 // Bind the new device manager to the connecting application's permission |
| 103 // provider. | 104 // provider. |
| 104 usb::PermissionProviderPtr permission_provider; | 105 usb::PermissionProviderPtr permission_provider; |
| 105 connection->ConnectToService(&permission_provider); | 106 connection->ConnectToService(&permission_provider); |
| 106 | 107 |
| 107 // Owned by its message pipe. | 108 // Owned by its message pipe. |
| 108 usb::DeviceManagerImpl* device_manager = | 109 usb::DeviceManagerImpl* device_manager = new usb::DeviceManagerImpl( |
| 109 new usb::DeviceManagerImpl(permission_provider.Pass(), request.Pass()); | 110 std::move(permission_provider), std::move(request)); |
| 110 device_manager->set_connection_error_handler( | 111 device_manager->set_connection_error_handler( |
| 111 base::Bind(&DevicesApp::OnConnectionError, base::Unretained(this))); | 112 base::Bind(&DevicesApp::OnConnectionError, base::Unretained(this))); |
| 112 | 113 |
| 113 active_device_manager_count_++; | 114 active_device_manager_count_++; |
| 114 idle_timeout_callback_.Cancel(); | 115 idle_timeout_callback_.Cancel(); |
| 115 } | 116 } |
| 116 | 117 |
| 117 void DevicesApp::OnConnectionError() { | 118 void DevicesApp::OnConnectionError() { |
| 118 DCHECK_GE(active_device_manager_count_, 0u); | 119 DCHECK_GE(active_device_manager_count_, 0u); |
| 119 active_device_manager_count_--; | 120 active_device_manager_count_--; |
| 120 if (active_device_manager_count_ == 0) { | 121 if (active_device_manager_count_ == 0) { |
| 121 // If the last DeviceManager connection has been dropped, kick off an idle | 122 // If the last DeviceManager connection has been dropped, kick off an idle |
| 122 // timeout to shut ourselves down. | 123 // timeout to shut ourselves down. |
| 123 StartIdleTimer(); | 124 StartIdleTimer(); |
| 124 } | 125 } |
| 125 } | 126 } |
| 126 | 127 |
| 127 void DevicesApp::StartIdleTimer() { | 128 void DevicesApp::StartIdleTimer() { |
| 128 // Passing unretained |app_impl_| is safe here because |app_impl_| is | 129 // Passing unretained |app_impl_| is safe here because |app_impl_| is |
| 129 // guaranteed to outlive |this|, and the callback is canceled if |this| is | 130 // guaranteed to outlive |this|, and the callback is canceled if |this| is |
| 130 // destroyed. | 131 // destroyed. |
| 131 idle_timeout_callback_.Reset(base::Bind(&mojo::ApplicationImpl::Quit, | 132 idle_timeout_callback_.Reset(base::Bind(&mojo::ApplicationImpl::Quit, |
| 132 base::Unretained(app_impl_))); | 133 base::Unretained(app_impl_))); |
| 133 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 134 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 134 FROM_HERE, idle_timeout_callback_.callback(), | 135 FROM_HERE, idle_timeout_callback_.callback(), |
| 135 base::TimeDelta::FromSeconds(kIdleTimeoutInSeconds)); | 136 base::TimeDelta::FromSeconds(kIdleTimeoutInSeconds)); |
| 136 } | 137 } |
| 137 | 138 |
| 138 } // namespace device | 139 } // namespace device |
| OLD | NEW |