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