OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef DEVICE_DEVICES_DEVICES_APP_H_ |
| 6 #define DEVICE_DEVICES_DEVICES_APP_H_ |
| 7 |
| 8 #include "base/cancelable_callback.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "mojo/application/public/cpp/application_delegate.h" |
| 13 #include "mojo/application/public/cpp/interface_factory.h" |
| 14 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" |
| 15 |
| 16 namespace base { |
| 17 class SequencedTaskRunner; |
| 18 } |
| 19 |
| 20 namespace mojo { |
| 21 class ApplicationImpl; |
| 22 } |
| 23 |
| 24 namespace device { |
| 25 |
| 26 namespace usb { |
| 27 class DeviceManager; |
| 28 } |
| 29 |
| 30 extern const char kDevicesMojoAppUrl[]; |
| 31 |
| 32 class DevicesApp : public mojo::ApplicationDelegate, |
| 33 public mojo::InterfaceFactory<usb::DeviceManager>, |
| 34 public mojo::ErrorHandler { |
| 35 public: |
| 36 ~DevicesApp() override; |
| 37 |
| 38 // |service_task_runner| is the thread TaskRunner on which the UsbService |
| 39 // lives. This argument should be removed once UsbService is owned by the |
| 40 // USB device manager and no longer part of the public device API. If null, |
| 41 // the app will construct its own DeviceClient and UsbService. |
| 42 static scoped_ptr<mojo::ApplicationDelegate> CreateDelegate( |
| 43 scoped_refptr<base::SequencedTaskRunner> service_task_runner); |
| 44 |
| 45 private: |
| 46 class USBServiceInitializer; |
| 47 |
| 48 DevicesApp(scoped_refptr<base::SequencedTaskRunner> service_task_runner); |
| 49 |
| 50 // mojo::ApplicationDelegate: |
| 51 void Initialize(mojo::ApplicationImpl* app) override; |
| 52 bool ConfigureIncomingConnection( |
| 53 mojo::ApplicationConnection* connection) override; |
| 54 void Quit() override; |
| 55 |
| 56 // mojo::InterfaceFactory<usb::DeviceManager>: |
| 57 void Create(mojo::ApplicationConnection* connection, |
| 58 mojo::InterfaceRequest<usb::DeviceManager> request) override; |
| 59 |
| 60 // mojo::ErrorHandler: |
| 61 void OnConnectionError() override; |
| 62 |
| 63 // Sets the app for destruction after a period of idle time. If any top-level |
| 64 // services (e.g. usb::DeviceManager) are bound before the timeout elapses, |
| 65 // it's canceled. |
| 66 void StartIdleTimer(); |
| 67 |
| 68 mojo::ApplicationImpl* app_impl_; |
| 69 scoped_ptr<USBServiceInitializer> service_initializer_; |
| 70 scoped_refptr<base::SequencedTaskRunner> service_task_runner_; |
| 71 size_t active_device_manager_count_; |
| 72 |
| 73 // Callback used to shut down the app after a period of inactivity. |
| 74 base::CancelableClosure idle_timeout_callback_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(DevicesApp); |
| 77 }; |
| 78 |
| 79 } // naespace device |
| 80 |
| 81 #endif // DEVICE_DEVICES_DEVICES_APP_H_ |
OLD | NEW |