| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 DISALLOW_COPY_AND_ASSIGN(USBDeviceManagerDelegate); | 58 DISALLOW_COPY_AND_ASSIGN(USBDeviceManagerDelegate); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // A DeviceClient implementation to be constructed iff the app is not running | 61 // A DeviceClient implementation to be constructed iff the app is not running |
| 62 // in an embedder that provides a DeviceClient (i.e. running as a standalone | 62 // in an embedder that provides a DeviceClient (i.e. running as a standalone |
| 63 // Mojo app, not in Chrome). | 63 // Mojo app, not in Chrome). |
| 64 class AppDeviceClient : public DeviceClient { | 64 class AppDeviceClient : public DeviceClient { |
| 65 public: | 65 public: |
| 66 explicit AppDeviceClient( | 66 explicit AppDeviceClient( |
| 67 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) | 67 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) |
| 68 : usb_service_(UsbService::GetInstance(blocking_task_runner)) {} | 68 : blocking_task_runner_(blocking_task_runner) {} |
| 69 ~AppDeviceClient() override {} | 69 ~AppDeviceClient() override {} |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 // DeviceClient: | 72 // DeviceClient: |
| 73 UsbService* GetUsbService() override { return usb_service_; } | 73 UsbService* GetUsbService() override { |
| 74 if (!usb_service_) { |
| 75 usb_service_ = UsbService::Create(blocking_task_runner_); |
| 76 } |
| 77 return usb_service_.get(); |
| 78 } |
| 74 | 79 |
| 75 UsbService* usb_service_; | 80 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 81 scoped_ptr<UsbService> usb_service_; |
| 76 }; | 82 }; |
| 77 | 83 |
| 78 } // namespace | 84 } // namespace |
| 79 | 85 |
| 80 // This class insures that a UsbService has been initialized and is accessible | 86 // This class insures that a UsbService has been initialized and is accessible |
| 81 // via the DeviceClient interface. | 87 // via the DeviceClient interface. |
| 82 class DevicesApp::USBServiceInitializer { | 88 class DevicesApp::USBServiceInitializer { |
| 83 public: | 89 public: |
| 84 USBServiceInitializer() | 90 USBServiceInitializer() |
| 85 : blocking_thread_("USB service blocking I/O thread") { | 91 : blocking_thread_("USB service blocking I/O thread") { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // guaranteed to outlive |this|, and the callback is canceled if |this| is | 163 // guaranteed to outlive |this|, and the callback is canceled if |this| is |
| 158 // destroyed. | 164 // destroyed. |
| 159 idle_timeout_callback_.Reset(base::Bind(&mojo::ApplicationImpl::Quit, | 165 idle_timeout_callback_.Reset(base::Bind(&mojo::ApplicationImpl::Quit, |
| 160 base::Unretained(app_impl_))); | 166 base::Unretained(app_impl_))); |
| 161 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 167 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 162 FROM_HERE, idle_timeout_callback_.callback(), | 168 FROM_HERE, idle_timeout_callback_.callback(), |
| 163 base::TimeDelta::FromSeconds(kIdleTimeoutInSeconds)); | 169 base::TimeDelta::FromSeconds(kIdleTimeoutInSeconds)); |
| 164 } | 170 } |
| 165 | 171 |
| 166 } // namespace device | 172 } // namespace device |
| OLD | NEW |