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

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: make map non-global/statically initialized object 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
33 // Returns PortManager that implements interfaces to help implementation.
34 // This hides Windows specific structures, i.e. HMIDIIN in the header.
35 PortManager* port_manager() { return port_manager_.get(); }
36
37 // Handles MIDI inport event posted from a thread system provides.
38 void ReceiveMidiData(uint32_t index,
39 const std::vector<uint8_t>& data,
40 base::TimeTicks time);
41
42 // Posts a task to TaskRunner, and ensures that the instance keeps alive while
Takashi Toyoshima 2017/02/24 08:53:34 Move from private to public so to use this from Po
yhirano 2017/02/24 12:22:58 PortManager is an inner class so it can access to
Takashi Toyoshima 2017/02/27 06:44:49 Oh, thanks. My understanding around access specifi
43 // the task is running.
44 void PostTask(const base::Closure&);
45
31 // Posts a reply task to the I/O thread that hosts MidiManager instance, runs 46 // 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 47 // it safely, and ensures that the instance keeps alive while the task is
33 // running. 48 // running.
34 void PostReplyTask(const base::Closure&); 49 void PostReplyTask(const base::Closure&);
35 50
36 // MidiManager overrides: 51 // MidiManager overrides:
37 void StartInitialization() override; 52 void StartInitialization() override;
38 void Finalize() override; 53 void Finalize() override;
39 void DispatchSendMidiData(MidiManagerClient* client, 54 void DispatchSendMidiData(MidiManagerClient* client,
40 uint32_t port_index, 55 uint32_t port_index,
41 const std::vector<uint8_t>& data, 56 const std::vector<uint8_t>& data,
42 double timestamp) override; 57 double timestamp) override;
43 58
44 // base::SystemMonitor::DevicesChangedObserver overrides: 59 // base::SystemMonitor::DevicesChangedObserver overrides:
45 void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override; 60 void OnDevicesChanged(base::SystemMonitor::DeviceType device_type) override;
46 61
47 private: 62 private:
48 class InPort; 63 class InPort;
49 class OutPort; 64 class OutPort;
50 65
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. 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