Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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_MIDI_MANAGER_WINRT_H_ | |
| 6 #define MEDIA_MIDI_MIDI_MANAGER_WINRT_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/strings/string16.h" | |
| 11 #include "base/threading/thread.h" | |
| 12 #include "media/midi/midi_manager.h" | |
| 13 | |
| 14 namespace base { | |
| 15 class ThreadChecker; | |
| 16 } | |
| 17 | |
| 18 namespace media { | |
| 19 namespace midi { | |
| 20 | |
| 21 class MidiScheduler; | |
| 22 | |
| 23 class MIDI_EXPORT MidiManagerWinrt final : public MidiManager { | |
| 24 public: | |
| 25 MidiManagerWinrt(); | |
| 26 ~MidiManagerWinrt() override; | |
| 27 | |
| 28 // MidiManager overrides: | |
| 29 void StartInitialization() final; | |
| 30 void Finalize() final; | |
| 31 void DispatchSendMidiData(MidiManagerClient* client, | |
| 32 uint32_t port_index, | |
| 33 const std::vector<uint8_t>& data, | |
| 34 double timestamp) final; | |
| 35 | |
| 36 private: | |
| 37 // Callbacks on the COM thread. | |
| 38 void InitializeOnComThread(); | |
| 39 void FinalizeOnComThread(); | |
| 40 void SendOnComThread(uint32_t port_index, const std::vector<uint8_t>& data); | |
| 41 | |
| 42 // Callback from MidiPortManager::OnEnumerationComplete on the COM thread. | |
| 43 // Calls CompleteInitialization() when both MidiPortManagers are ready. | |
| 44 void OnPortManagerReady(); | |
| 45 | |
| 46 // Subclasses that access private/protected members of MidiManager. | |
| 47 template <typename InterfaceType, | |
| 48 typename RuntimeType, | |
| 49 typename StaticsInterfaceType, | |
| 50 base::char16 const* runtime_class_id> | |
| 51 class MidiPortManager; | |
| 52 class MidiInPortManager; | |
| 53 class MidiOutPortManager; | |
| 54 | |
| 55 // COM-initialized thread for calling WinRT methods. | |
| 56 base::Thread com_thread_; | |
| 57 | |
| 58 // Lock to ensure all smart pointers initialized in InitializeOnComThread() | |
| 59 // and destroyed in FinalizeOnComThread() will not be accidentally destructed | |
| 60 // twice in the destructor. | |
| 61 base::Lock lazy_init_member_lock_; | |
| 62 | |
| 63 // Should be instantiated on COM thread. | |
| 64 std::unique_ptr<base::ThreadChecker> | |
| 65 com_thread_checker_; // GUARDED_BY(lazy_init_member_lock_) | |
|
Takashi Toyoshima
2016/08/25 06:09:45
Just a comment: GUARDED_BY() is not an enforced st
| |
| 66 | |
| 67 // All operations to MidiPortManager should be done on COM thread. | |
| 68 std::unique_ptr<MidiInPortManager> | |
| 69 port_manager_in_; // GUARDED_BY(lazy_init_member_lock_) | |
| 70 std::unique_ptr<MidiOutPortManager> | |
| 71 port_manager_out_; // GUARDED_BY(lazy_init_member_lock_) | |
| 72 | |
| 73 // |scheduler_| is used by DispatchSendMidiData on Chrome_IOThread, should | |
| 74 // acquire lock before use. | |
| 75 std::unique_ptr<MidiScheduler> | |
| 76 scheduler_; // GUARDED_BY(lazy_init_member_lock_) | |
| 77 | |
| 78 // Incremented when a MidiPortManager is ready. | |
| 79 uint8_t port_manager_ready_count_ = 0; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(MidiManagerWinrt); | |
| 82 }; | |
| 83 | |
| 84 } // namespace midi | |
| 85 } // namespace media | |
| 86 | |
| 87 #endif // MEDIA_MIDI_MIDI_MANAGER_WINRT_H_ | |
| OLD | NEW |