blob: a6ac993cbf06644036c88a679c42dadf6837c149 [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;
toyoshimf4d61522017-02-10 02:03:32 -080021class MidiService;
shaochuane58f9c72016-08-30 22:27:08 -070022
23class MIDI_EXPORT MidiManagerWinrt final : public MidiManager {
24 public:
toyoshimf4d61522017-02-10 02:03:32 -080025 explicit MidiManagerWinrt(MidiService* service);
shaochuane58f9c72016-08-30 22:27:08 -070026 ~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_)
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
shaochuane58f9c72016-08-30 22:27:08 -070085
86#endif // MEDIA_MIDI_MIDI_MANAGER_WINRT_H_