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/memory/ref_counted.h" | |
|
Takashi Toyoshima
2017/02/17 17:42:29
restore the line I mistakenly removed from the ori
| |
| 14 #include "base/system_monitor/system_monitor.h" | |
| 15 #include "media/midi/midi_manager.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class SingleThreadTaskRunner; | |
| 19 } // namespace base | |
| 20 | |
| 21 namespace midi { | |
| 22 | |
| 23 // New backend for legacy Windows that support dynamic instantiation. | |
| 24 class DynamicallyInitializedMidiManagerWin final | |
| 25 : public MidiManager, | |
| 26 public base::SystemMonitor::DevicesChangedObserver { | |
| 27 public: | |
| 28 explicit DynamicallyInitializedMidiManagerWin(MidiService* service); | |
| 29 ~DynamicallyInitializedMidiManagerWin() override; | |
| 30 | |
| 31 // Posts a reply task to the I/O thread that hosts MidiManager instance, runs | |
| 32 // it safely, and ensures that the instance keeps alive while the task is | |
| 33 // running. | |
| 34 void PostReplyTask(const base::Closure&); | |
| 35 | |
| 36 // MidiManager overrides: | |
| 37 void StartInitialization() override; | |
| 38 void Finalize() override; | |
| 39 void DispatchSendMidiData(MidiManagerClient* client, | |
| 40 uint32_t port_index, | |
| 41 const std::vector<uint8_t>& data, | |
| 42 double timestamp) override; | |
| 43 | |
| 44 // base::SystemMonitor::DevicesChangedObserver overrides: | |
| 45 void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override; | |
| 46 | |
| 47 private: | |
| 48 class InPort; | |
| 49 class OutPort; | |
| 50 | |
| 51 // Posts a task to TaskRunner, and ensures that the instance keeps alive while | |
| 52 // the task is running. | |
| 53 void PostTask(const base::Closure&); | |
| 54 | |
| 55 // Initializes instance asynchronously on TaskRunner. | |
| 56 void InitializeOnTaskRunner(); | |
| 57 | |
| 58 // Updates device lists on TaskRunner. | |
| 59 // Returns true if device lists were changed. | |
| 60 void UpdateDeviceListOnTaskRunner(); | |
| 61 | |
| 62 // Reflect active port list to a device list. | |
| 63 template <typename T> | |
| 64 void ReflectActiveDeviceList(DynamicallyInitializedMidiManagerWin* manager, | |
| 65 T* known_ports, | |
|
yhirano
2017/02/20 08:02:06
std::vector<T>* is easier to understand, I think.
Takashi Toyoshima
2017/02/20 16:51:59
Done.
| |
| 66 T* active_ports); | |
|
yhirano
2017/02/20 08:02:06
const std::vector<T>& is easier to understand, I t
Takashi Toyoshima
2017/02/20 16:51:59
I may misunderstand something, but if I use "const
yhirano
2017/02/21 03:03:48
Ah, I was wrong, Sorry.
| |
| 67 | |
| 68 // Holds an unique instance ID. | |
| 69 const int instance_id_; | |
| 70 | |
| 71 // Keeps a TaskRunner for the I/O thread. | |
| 72 scoped_refptr<base::SingleThreadTaskRunner> thread_runner_; | |
| 73 | |
| 74 // Following members should be accessed only on TaskRunner. | |
| 75 | |
| 76 // Holds all MIDI input or output ports connected once. | |
| 77 std::vector<std::unique_ptr<InPort>> input_ports_; | |
| 78 std::vector<std::unique_ptr<OutPort>> output_ports_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(DynamicallyInitializedMidiManagerWin); | |
| 81 }; | |
| 82 | |
| 83 } // namespace midi | |
| 84 | |
| 85 #endif // MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_ | |
| OLD | NEW |