Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(818)

Side by Side Diff: media/midi/dynamically_initialized_midi_manager_win.h

Issue 2701783003: Web MIDI: implement receiving for dynamic manager instantiation on Windows (Closed)
Patch Set: move methods into private Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 } // namespace base 19 } // namespace base
20 20
21 namespace midi { 21 namespace midi {
22 22
23 // New backend for legacy Windows that support dynamic instantiation. 23 // New backend for legacy Windows that support dynamic instantiation.
24 class DynamicallyInitializedMidiManagerWin final 24 class DynamicallyInitializedMidiManagerWin final
25 : public MidiManager, 25 : public MidiManager,
26 public base::SystemMonitor::DevicesChangedObserver { 26 public base::SystemMonitor::DevicesChangedObserver {
27 public: 27 public:
28 class PortManager;
29
28 explicit DynamicallyInitializedMidiManagerWin(MidiService* service); 30 explicit DynamicallyInitializedMidiManagerWin(MidiService* service);
29 ~DynamicallyInitializedMidiManagerWin() override; 31 ~DynamicallyInitializedMidiManagerWin() override;
30 32
31 // Posts a reply task to the I/O thread that hosts MidiManager instance, runs 33 // Returns PortManager that implements interfaces to help implementation.
32 // it safely, and ensures that the instance keeps alive while the task is 34 // This hides Windows specific structures, i.e. HMIDIIN in the header.
33 // running. 35 PortManager* port_manager() { return port_manager_.get(); }
34 void PostReplyTask(const base::Closure&);
35 36
36 // MidiManager overrides: 37 // MidiManager overrides:
37 void StartInitialization() override; 38 void StartInitialization() override;
38 void Finalize() override; 39 void Finalize() override;
39 void DispatchSendMidiData(MidiManagerClient* client, 40 void DispatchSendMidiData(MidiManagerClient* client,
40 uint32_t port_index, 41 uint32_t port_index,
41 const std::vector<uint8_t>& data, 42 const std::vector<uint8_t>& data,
42 double timestamp) override; 43 double timestamp) override;
43 44
44 // base::SystemMonitor::DevicesChangedObserver overrides: 45 // base::SystemMonitor::DevicesChangedObserver overrides:
45 void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override; 46 void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override;
46 47
47 private: 48 private:
48 class InPort; 49 class InPort;
49 class OutPort; 50 class OutPort;
50 51
52 // Handles MIDI inport event posted from a thread system provides.
53 void ReceiveMidiData(uint32_t index,
54 const std::vector<uint8_t>& data,
55 base::TimeTicks time);
56
51 // Posts a task to TaskRunner, and ensures that the instance keeps alive while 57 // Posts a task to TaskRunner, and ensures that the instance keeps alive while
52 // the task is running. 58 // the task is running.
53 void PostTask(const base::Closure&); 59 void PostTask(const base::Closure&);
54 60
61 // 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
63 // running.
64 void PostReplyTask(const base::Closure&);
65
55 // Initializes instance asynchronously on TaskRunner. 66 // Initializes instance asynchronously on TaskRunner.
56 void InitializeOnTaskRunner(); 67 void InitializeOnTaskRunner();
57 68
58 // Updates device lists on TaskRunner. 69 // Updates device lists on TaskRunner.
59 // Returns true if device lists were changed. 70 // Returns true if device lists were changed.
60 void UpdateDeviceListOnTaskRunner(); 71 void UpdateDeviceListOnTaskRunner();
61 72
62 // Reflect active port list to a device list. 73 // Reflect active port list to a device list.
63 template <typename T> 74 template <typename T>
64 void ReflectActiveDeviceList(DynamicallyInitializedMidiManagerWin* manager, 75 void ReflectActiveDeviceList(DynamicallyInitializedMidiManagerWin* manager,
65 std::vector<T>* known_ports, 76 std::vector<T>* known_ports,
66 std::vector<T>* active_ports); 77 std::vector<T>* active_ports);
67 78
68 // Holds an unique instance ID. 79 // Holds an unique instance ID.
69 const int instance_id_; 80 const int instance_id_;
70 81
71 // Keeps a TaskRunner for the I/O thread. 82 // Keeps a TaskRunner for the I/O thread.
72 scoped_refptr<base::SingleThreadTaskRunner> thread_runner_; 83 scoped_refptr<base::SingleThreadTaskRunner> thread_runner_;
73 84
74 // Following members should be accessed only on TaskRunner. 85 // Manages platform dependent implementation for port managegent. Should be
75 86 // accessed with the task lock.
76 // Holds all MIDI input or output ports connected once. 87 std::unique_ptr<PortManager> port_manager_;
77 std::vector<std::unique_ptr<InPort>> input_ports_;
78 std::vector<std::unique_ptr<OutPort>> output_ports_;
79 88
80 DISALLOW_COPY_AND_ASSIGN(DynamicallyInitializedMidiManagerWin); 89 DISALLOW_COPY_AND_ASSIGN(DynamicallyInitializedMidiManagerWin);
81 }; 90 };
82 91
83 } // namespace midi 92 } // namespace midi
84 93
85 #endif // MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_ 94 #endif // MEDIA_MIDI_DYNAMICALLY_INITIALIZED_MIDI_MANAGER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698