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.
5 #ifndef DEVICE_DEVICES_DEVICES_APP_H_
6 #define DEVICE_DEVICES_DEVICES_APP_H_
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"
16 class SequencedTaskRunner
;
20 class ApplicationImpl
;
29 class DevicesApp
: public mojo::ApplicationDelegate
,
30 public mojo::InterfaceFactory
<usb::DeviceManager
> {
33 scoped_refptr
<base::SequencedTaskRunner
> service_task_runner
);
34 ~DevicesApp() override
;
37 class USBServiceInitializer
;
39 // mojo::ApplicationDelegate:
40 void Initialize(mojo::ApplicationImpl
* app
) override
;
41 bool ConfigureIncomingConnection(
42 mojo::ApplicationConnection
* connection
) override
;
45 // mojo::InterfaceFactory<usb::DeviceManager>:
46 void Create(mojo::ApplicationConnection
* connection
,
47 mojo::InterfaceRequest
<usb::DeviceManager
> request
) override
;
49 // Mojo error handler to track device manager count.
50 void OnConnectionError();
52 // Sets the app for destruction after a period of idle time. If any top-level
53 // services (e.g. usb::DeviceManager) are bound before the timeout elapses,
55 void StartIdleTimer();
57 mojo::ApplicationImpl
* app_impl_
;
58 scoped_ptr
<USBServiceInitializer
> service_initializer_
;
59 scoped_refptr
<base::SequencedTaskRunner
> service_task_runner_
;
60 size_t active_device_manager_count_
;
62 // Callback used to shut down the app after a period of inactivity.
63 base::CancelableClosure idle_timeout_callback_
;
65 DISALLOW_COPY_AND_ASSIGN(DevicesApp
);
70 #endif // DEVICE_DEVICES_DEVICES_APP_H_