Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_ | |
| 6 #define MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback_forward.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/system_monitor/system_monitor.h" | |
| 14 #include "media/midi/midi_manager.h" | |
| 15 | |
| 16 namespace base { | |
| 17 class SingleThreadTaskRunner; | |
| 18 } // namespace base | |
| 19 | |
| 20 namespace midi { | |
| 21 | |
| 22 // New backend for legacy Windows that support dynamic instantiation. | |
| 23 class DynamicallyInitializedMidiManagerWin final | |
| 24 : public MidiManager, | |
| 25 public base::SystemMonitor::DevicesChangedObserver { | |
| 26 public: | |
| 27 explicit DynamicallyInitializedMidiManagerWin(MidiService* service); | |
| 28 ~DynamicallyInitializedMidiManagerWin() override; | |
| 29 | |
| 30 // Posts a reply task to the I/O thread that hosts MidiManager instance, runs | |
| 31 // it safely, and ensures that the instance keeps alive while the task is | |
| 32 // running. | |
| 33 void PostReplyTask(const base::Closure&); | |
| 34 | |
| 35 // MidiManager overrides: | |
| 36 void StartInitialization() override; | |
| 37 void Finalize() override; | |
| 38 void DispatchSendMidiData(MidiManagerClient* client, | |
| 39 uint32_t port_index, | |
| 40 const std::vector<uint8_t>& data, | |
| 41 double timestamp) override; | |
| 42 | |
| 43 // base::SystemMonitor::DevicesChangedObserver overrides: | |
| 44 void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override; | |
| 45 | |
| 46 private: | |
| 47 class InPort; | |
| 48 class OutPort; | |
| 49 | |
| 50 // Posts a task to TaskRunner, and ensures that the instance keeps alive while | |
| 51 // the task is running. | |
| 52 void PostTask(const base::Closure&); | |
| 53 | |
| 54 // Initializes instance asynchronously on TaskRunner. | |
| 55 void InitializeOnTaskRunner(); | |
| 56 | |
| 57 // Updates device lists on TaskRunner. | |
| 58 // Returns true if device lists were changed. | |
| 59 void UpdateDeviceListOnTaskRunner(); | |
| 60 | |
| 61 // Sends MIDI data on TaskRunner. | |
|
Takashi Toyoshima
2017/02/17 17:42:29
This wasn't used yet in this first cl.
| |
| 62 void SendOnTaskRunner(MidiManagerClient* client, | |
| 63 uint32_t port_index, | |
| 64 const std::vector<uint8_t>& data); | |
| 65 | |
| 66 // Holds an unique instance ID. | |
| 67 int instance_id_; | |
| 68 | |
| 69 // Keeps a TaskRunner for the I/O thread. | |
| 70 scoped_refptr<base::SingleThreadTaskRunner> thread_runner_; | |
| 71 | |
| 72 // Following members should be accessed only on TaskRunner. | |
| 73 | |
| 74 // Holds all MIDI input or output ports connected once. | |
| 75 std::vector<std::unique_ptr<InPort>> input_ports_; | |
| 76 std::vector<std::unique_ptr<OutPort>> output_ports_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(DynamicallyInitializedMidiManagerWin); | |
| 79 }; | |
| 80 | |
| 81 } // namespace midi | |
| 82 | |
| 83 #endif // MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_ | |
| OLD | NEW |