OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_ | 5 #ifndef MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_ |
6 #define MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_ | 6 #define MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/system_monitor/system_monitor.h" | 14 #include "base/system_monitor/system_monitor.h" |
15 #include "media/midi/midi_manager.h" | 15 #include "media/midi/midi_manager.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class SingleThreadTaskRunner; | 18 class SingleThreadTaskRunner; |
| 19 class TimeDelta; |
19 } // namespace base | 20 } // namespace base |
20 | 21 |
21 namespace midi { | 22 namespace midi { |
22 | 23 |
23 // New backend for legacy Windows that support dynamic instantiation. | 24 // New backend for legacy Windows that support dynamic instantiation. |
24 class DynamicallyInitializedMidiManagerWin final | 25 class DynamicallyInitializedMidiManagerWin final |
25 : public MidiManager, | 26 : public MidiManager, |
26 public base::SystemMonitor::DevicesChangedObserver { | 27 public base::SystemMonitor::DevicesChangedObserver { |
27 public: | 28 public: |
28 class PortManager; | 29 class PortManager; |
(...skipping 21 matching lines...) Expand all Loading... |
50 class OutPort; | 51 class OutPort; |
51 | 52 |
52 // Handles MIDI inport event posted from a thread system provides. | 53 // Handles MIDI inport event posted from a thread system provides. |
53 void ReceiveMidiData(uint32_t index, | 54 void ReceiveMidiData(uint32_t index, |
54 const std::vector<uint8_t>& data, | 55 const std::vector<uint8_t>& data, |
55 base::TimeTicks time); | 56 base::TimeTicks time); |
56 | 57 |
57 // Posts a task to TaskRunner, and ensures that the instance keeps alive while | 58 // Posts a task to TaskRunner, and ensures that the instance keeps alive while |
58 // the task is running. | 59 // the task is running. |
59 void PostTask(const base::Closure&); | 60 void PostTask(const base::Closure&); |
| 61 void PostDelayedTask(const base::Closure&, base::TimeDelta delay); |
60 | 62 |
61 // Posts a reply task to the I/O thread that hosts MidiManager instance, runs | 63 // Posts a reply task to the I/O thread that hosts MidiManager instance, runs |
62 // it safely, and ensures that the instance keeps alive while the task is | 64 // it safely, and ensures that the instance keeps alive while the task is |
63 // running. | 65 // running. |
64 void PostReplyTask(const base::Closure&); | 66 void PostReplyTask(const base::Closure&); |
65 | 67 |
66 // Initializes instance asynchronously on TaskRunner. | 68 // Initializes instance asynchronously on TaskRunner. |
67 void InitializeOnTaskRunner(); | 69 void InitializeOnTaskRunner(); |
68 | 70 |
69 // Updates device lists on TaskRunner. | 71 // Updates device lists on TaskRunner. |
70 // Returns true if device lists were changed. | 72 // Returns true if device lists were changed. |
71 void UpdateDeviceListOnTaskRunner(); | 73 void UpdateDeviceListOnTaskRunner(); |
72 | 74 |
73 // Reflect active port list to a device list. | 75 // Reflect active port list to a device list. |
74 template <typename T> | 76 template <typename T> |
75 void ReflectActiveDeviceList(DynamicallyInitializedMidiManagerWin* manager, | 77 void ReflectActiveDeviceList(DynamicallyInitializedMidiManagerWin* manager, |
76 std::vector<T>* known_ports, | 78 std::vector<T>* known_ports, |
77 std::vector<T>* active_ports); | 79 std::vector<T>* active_ports); |
78 | 80 |
| 81 // Sends MIDI data on TaskRunner. |
| 82 void SendOnTaskRunner(MidiManagerClient* client, |
| 83 uint32_t port_index, |
| 84 const std::vector<uint8_t>& data); |
| 85 |
79 // Holds an unique instance ID. | 86 // Holds an unique instance ID. |
80 const int instance_id_; | 87 const int instance_id_; |
81 | 88 |
82 // Keeps a TaskRunner for the I/O thread. | 89 // Keeps a TaskRunner for the I/O thread. |
83 scoped_refptr<base::SingleThreadTaskRunner> thread_runner_; | 90 scoped_refptr<base::SingleThreadTaskRunner> thread_runner_; |
84 | 91 |
85 // Manages platform dependent implementation for port managegent. Should be | 92 // Manages platform dependent implementation for port managegent. Should be |
86 // accessed with the task lock. | 93 // accessed with the task lock. |
87 std::unique_ptr<PortManager> port_manager_; | 94 std::unique_ptr<PortManager> port_manager_; |
88 | 95 |
89 DISALLOW_COPY_AND_ASSIGN(DynamicallyInitializedMidiManagerWin); | 96 DISALLOW_COPY_AND_ASSIGN(DynamicallyInitializedMidiManagerWin); |
90 }; | 97 }; |
91 | 98 |
92 } // namespace midi | 99 } // namespace midi |
93 | 100 |
94 #endif // MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_ | 101 #endif // MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_ |
OLD | NEW |