| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // Owned by its message pipe. | 145 // Owned by its message pipe. |
| 146 usb::DeviceManagerImpl* device_manager = new usb::DeviceManagerImpl( | 146 usb::DeviceManagerImpl* device_manager = new usb::DeviceManagerImpl( |
| 147 request.Pass(), delegate.Pass(), service_task_runner_); | 147 request.Pass(), delegate.Pass(), service_task_runner_); |
| 148 device_manager->set_error_handler(this); | 148 device_manager->set_error_handler(this); |
| 149 | 149 |
| 150 active_device_manager_count_++; | 150 active_device_manager_count_++; |
| 151 idle_timeout_callback_.Cancel(); | 151 idle_timeout_callback_.Cancel(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void DevicesApp::OnConnectionError() { | 154 void DevicesApp::OnConnectionError() { |
| 155 DCHECK_GE(active_device_manager_count_, 0u); | 155 DCHECK_GT(active_device_manager_count_, 0u); |
| 156 active_device_manager_count_--; | 156 active_device_manager_count_--; |
| 157 if (active_device_manager_count_ == 0) { | 157 if (active_device_manager_count_ == 0) { |
| 158 // If the last DeviceManager connection has been dropped, kick off an idle | 158 // If the last DeviceManager connection has been dropped, kick off an idle |
| 159 // timeout to shut ourselves down. | 159 // timeout to shut ourselves down. |
| 160 StartIdleTimer(); | 160 StartIdleTimer(); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 | 163 |
| 164 void DevicesApp::StartIdleTimer() { | 164 void DevicesApp::StartIdleTimer() { |
| 165 // Passing unretained |app_impl_| is safe here because |app_impl_| is | 165 // Passing unretained |app_impl_| is safe here because |app_impl_| is |
| 166 // guaranteed to outlive |this|, and the callback is canceled if |this| is | 166 // guaranteed to outlive |this|, and the callback is canceled if |this| is |
| 167 // destroyed. | 167 // destroyed. |
| 168 idle_timeout_callback_.Reset(base::Bind(&mojo::ApplicationImpl::Terminate, | 168 idle_timeout_callback_.Reset(base::Bind(&mojo::ApplicationImpl::Terminate, |
| 169 base::Unretained(app_impl_))); | 169 base::Unretained(app_impl_))); |
| 170 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 170 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 171 FROM_HERE, idle_timeout_callback_.callback(), | 171 FROM_HERE, idle_timeout_callback_.callback(), |
| 172 base::TimeDelta::FromSeconds(kIdleTimeoutInSeconds)); | 172 base::TimeDelta::FromSeconds(kIdleTimeoutInSeconds)); |
| 173 } | 173 } |
| 174 | 174 |
| 175 } // namespace device | 175 } // namespace device |
| OLD | NEW |