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

Unified Diff: media/midi/midi_manager_winrt.h

Issue 2243183002: Web MIDI backend for Windows 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, revise thread-safety Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: media/midi/midi_manager_winrt.h
diff --git a/media/midi/midi_manager_winrt.h b/media/midi/midi_manager_winrt.h
new file mode 100644
index 0000000000000000000000000000000000000000..4f5e6a7e29c190288924ce8bc063683905053a0c
--- /dev/null
+++ b/media/midi/midi_manager_winrt.h
@@ -0,0 +1,70 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_MIDI_MIDI_MANAGER_WINRT_H_
+#define MEDIA_MIDI_MIDI_MANAGER_WINRT_H_
+
+#include <memory>
+
+#include "base/threading/thread.h"
+#include "base/threading/thread_checker.h"
+#include "media/midi/midi_manager.h"
+#include "media/midi/midi_scheduler.h"
+
+namespace media {
+namespace midi {
+
+class MIDI_EXPORT MidiManagerWinrt final : public MidiManager {
+ public:
+ MidiManagerWinrt();
+ ~MidiManagerWinrt() override;
+
+ // MidiManager overrides:
+ void StartInitialization() final;
+ void Finalize() final;
+ void DispatchSendMidiData(MidiManagerClient* client,
+ uint32_t port_index,
+ const std::vector<uint8_t>& data,
+ double timestamp) final;
+
+ // Callback from MidiPortManager::OnEnumerationComplete on the COM thread.
+ // Sets |is_initialized_| and calls CompleteInitialization() when both
Shao-Chuan Lee 2016/08/23 04:33:29 |is_initialized_| is already removed, fix comments
+ // MidiPortManagers are ready.
+ void OnPortManagerReady();
+
+ private:
+ // Callbacks on the COM thread.
+ void InitializeOnComThread();
+ void FinalizeOnComThread();
+ void SendOnComThread(uint32_t port_index, const std::vector<uint8_t>& data);
+
+ // Subclasses that access protected members of MidiManager.
+ class MidiInPortManager;
+ class MidiOutPortManager;
+
+ // COM-initialized thread for calling WinRT methods.
+ base::Thread com_thread_;
+
+ // Should be instantiated on COM thread.
+ std::unique_ptr<base::ThreadChecker> com_thread_checker_;
+
+ // All operations to MidiPortManager should be done on COM thread.
+ std::unique_ptr<MidiInPortManager> port_manager_in_;
+ std::unique_ptr<MidiOutPortManager> port_manager_out_;
+
+ // |scheduler_| is constructed/destructed on COM thread and used by
+ // DispatchSendMidiData on Chrome_IOThread, a lock is required.
+ base::Lock scheduler_lock_;
+ std::unique_ptr<MidiScheduler> scheduler_; // GUARDED_BY(scheduler_lock_)
+
+ // Incremented when a MidiPortManager is ready.
+ uint8_t port_manager_ready_count_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(MidiManagerWinrt);
+};
+
+} // namespace midi
+} // namespace media
+
+#endif // MEDIA_MIDI_MIDI_MANAGER_WINRT_H_

Powered by Google App Engine
This is Rietveld 408576698