Enable ManagePasswordsBubbleViewTest.TwoTabsWtihBubble on linux x32.
[chromium-blink-merge.git] / media / midi / midi_manager_usb.h
blobd15a82831ba0215458861751edb748d73aa47338
1 // Copyright 2014 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.
5 #ifndef MEDIA_MIDI_MIDI_MANAGER_USB_H_
6 #define MEDIA_MIDI_MIDI_MANAGER_USB_H_
8 #include <utility>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/bind.h"
13 #include "base/callback.h"
14 #include "base/containers/hash_tables.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/time/time.h"
17 #include "media/base/media_export.h"
18 #include "media/midi/midi_manager.h"
19 #include "media/midi/usb_midi_device.h"
20 #include "media/midi/usb_midi_input_stream.h"
21 #include "media/midi/usb_midi_jack.h"
22 #include "media/midi/usb_midi_output_stream.h"
24 namespace media {
26 // MidiManager for USB-MIDI.
27 class MEDIA_EXPORT MidiManagerUsb : public MidiManager,
28 public UsbMidiDeviceDelegate,
29 public UsbMidiInputStream::Delegate {
30 public:
31 explicit MidiManagerUsb(scoped_ptr<UsbMidiDevice::Factory> device_factory);
32 ~MidiManagerUsb() override;
34 // MidiManager implementation.
35 void StartInitialization() override;
36 void DispatchSendMidiData(MidiManagerClient* client,
37 uint32 port_index,
38 const std::vector<uint8>& data,
39 double timestamp) override;
41 // UsbMidiDeviceDelegate implementation.
42 void ReceiveUsbMidiData(UsbMidiDevice* device,
43 int endpoint_number,
44 const uint8* data,
45 size_t size,
46 base::TimeTicks time) override;
48 // UsbMidiInputStream::Delegate implementation.
49 void OnReceivedData(size_t jack_index,
50 const uint8* data,
51 size_t size,
52 base::TimeTicks time) override;
54 const ScopedVector<UsbMidiOutputStream>& output_streams() const {
55 return output_streams_;
57 const UsbMidiInputStream* input_stream() const { return input_stream_.get(); }
59 // Initializes this object.
60 // When the initialization finishes, |callback| will be called with the
61 // result.
62 // When this factory is destroyed during the operation, the operation
63 // will be canceled silently (i.e. |callback| will not be called).
64 // The function is public just for unit tests. Do not call this function
65 // outside code for testing.
66 void Initialize(base::Callback<void(MidiResult result)> callback);
68 private:
69 void OnEnumerateDevicesDone(bool result, UsbMidiDevice::Devices* devices);
71 scoped_ptr<UsbMidiDevice::Factory> device_factory_;
72 ScopedVector<UsbMidiDevice> devices_;
73 ScopedVector<UsbMidiOutputStream> output_streams_;
74 scoped_ptr<UsbMidiInputStream> input_stream_;
76 base::Callback<void(MidiResult result)> initialize_callback_;
78 // A map from <endpoint_number, cable_number> to the index of input jacks.
79 base::hash_map<std::pair<int, int>, size_t> input_jack_dictionary_;
81 DISALLOW_COPY_AND_ASSIGN(MidiManagerUsb);
84 } // namespace media
86 #endif // MEDIA_MIDI_MIDI_MANAGER_USB_H_