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

Side by Side Diff: content/browser/media/midi_host.h

Issue 662853003: Manage MIDI related objects and sessions' lifecycles correctly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one line bug fix Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/media/midi_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_MEDIA_MIDI_HOST_H_ 5 #ifndef CONTENT_BROWSER_MEDIA_MIDI_HOST_H_
6 #define CONTENT_BROWSER_MEDIA_MIDI_HOST_H_ 6 #define CONTENT_BROWSER_MEDIA_MIDI_HOST_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/synchronization/lock.h"
14 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
15 #include "content/public/browser/browser_message_filter.h" 16 #include "content/public/browser/browser_message_filter.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "media/midi/midi_manager.h" 18 #include "media/midi/midi_manager.h"
18 19
19 namespace media { 20 namespace media {
20 class MidiManager; 21 class MidiManager;
21 class MidiMessageQueue; 22 class MidiMessageQueue;
22 } 23 }
23 24
24 namespace content { 25 namespace content {
25 26
26 class CONTENT_EXPORT MidiHost 27 class CONTENT_EXPORT MidiHost
27 : public BrowserMessageFilter, 28 : public BrowserMessageFilter,
28 public media::MidiManagerClient { 29 public media::MidiManagerClient {
29 public: 30 public:
30 // Called from UI thread from the owner of this object. 31 // Called from UI thread from the owner of this object.
31 MidiHost(int renderer_process_id, media::MidiManager* midi_manager); 32 MidiHost(int renderer_process_id, media::MidiManager* midi_manager);
32 33
33 // BrowserMessageFilter implementation. 34 // BrowserMessageFilter implementation.
34 void OnDestruct() const override; 35 void OnDestruct() const override;
35 bool OnMessageReceived(const IPC::Message& message) override; 36 bool OnMessageReceived(const IPC::Message& message) override;
36 37
37 // MidiManagerClient implementation. 38 // MidiManagerClient implementation.
38 void CompleteStartSession(int client_id, media::MidiResult result) override; 39 void CompleteStartSession(media::MidiResult result) override;
39 void ReceiveMidiData(uint32 port, 40 void ReceiveMidiData(uint32 port,
40 const uint8* data, 41 const uint8* data,
41 size_t length, 42 size_t length,
42 double timestamp) override; 43 double timestamp) override;
43 void AccumulateMidiBytesSent(size_t n) override; 44 void AccumulateMidiBytesSent(size_t n) override;
44 45
45 // Start session to access MIDI hardware. 46 // Start session to access MIDI hardware.
46 void OnStartSession(int client_id); 47 void OnStartSession();
47 48
48 // Data to be sent to a MIDI output port. 49 // Data to be sent to a MIDI output port.
49 void OnSendData(uint32 port, 50 void OnSendData(uint32 port,
50 const std::vector<uint8>& data, 51 const std::vector<uint8>& data,
51 double timestamp); 52 double timestamp);
52 53
54 void OnEndSession();
55
53 private: 56 private:
54 FRIEND_TEST_ALL_PREFIXES(MidiHostTest, IsValidWebMIDIData); 57 FRIEND_TEST_ALL_PREFIXES(MidiHostTest, IsValidWebMIDIData);
55 friend class base::DeleteHelper<MidiHost>; 58 friend class base::DeleteHelper<MidiHost>;
56 friend class BrowserThread; 59 friend class BrowserThread;
57 60
58 ~MidiHost() override; 61 ~MidiHost() override;
59 62
60 // Returns true if |data| fulfills the requirements of MidiOutput.send API 63 // Returns true if |data| fulfills the requirements of MidiOutput.send API
61 // defined in the WebMIDI spec. 64 // defined in the WebMIDI spec.
62 // - |data| must be any number of complete MIDI messages (data abbreviation 65 // - |data| must be any number of complete MIDI messages (data abbreviation
63 // called "running status" is disallowed). 66 // called "running status" is disallowed).
64 // - 1-byte MIDI realtime messages can be placed at any position of |data|. 67 // - 1-byte MIDI realtime messages can be placed at any position of |data|.
65 static bool IsValidWebMIDIData(const std::vector<uint8>& data); 68 static bool IsValidWebMIDIData(const std::vector<uint8>& data);
66 69
67 int renderer_process_id_; 70 int renderer_process_id_;
68 71
69 // Represents if the renderer has a permission to send/receive MIDI SysEX 72 // Represents if the renderer has a permission to send/receive MIDI SysEX
70 // messages. 73 // messages.
71 bool has_sys_ex_permission_; 74 bool has_sys_ex_permission_;
72 75
76 // Represents if a session is requested to start.
77 bool is_session_requested_;
78
73 // |midi_manager_| talks to the platform-specific MIDI APIs. 79 // |midi_manager_| talks to the platform-specific MIDI APIs.
74 // It can be NULL if the platform (or our current implementation) 80 // It can be NULL if the platform (or our current implementation)
75 // does not support MIDI. If not supported then a call to 81 // does not support MIDI. If not supported then a call to
76 // OnRequestAccess() will always refuse access and a call to 82 // OnRequestAccess() will always refuse access and a call to
77 // OnSendData() will do nothing. 83 // OnSendData() will do nothing.
78 media::MidiManager* const midi_manager_; 84 media::MidiManager* const midi_manager_;
79 85
80 // Buffers where data sent from each MIDI input port is stored. 86 // Buffers where data sent from each MIDI input port is stored.
81 ScopedVector<media::MidiMessageQueue> received_messages_queues_; 87 ScopedVector<media::MidiMessageQueue> received_messages_queues_;
82 88
83 // The number of bytes sent to the platform-specific MIDI sending 89 // The number of bytes sent to the platform-specific MIDI sending
84 // system, but not yet completed. 90 // system, but not yet completed.
85 size_t sent_bytes_in_flight_; 91 size_t sent_bytes_in_flight_;
86 92
87 // The number of bytes successfully sent since the last time 93 // The number of bytes successfully sent since the last time
88 // we've acknowledged back to the renderer. 94 // we've acknowledged back to the renderer.
89 size_t bytes_sent_since_last_acknowledgement_; 95 size_t bytes_sent_since_last_acknowledgement_;
90 96
91 // Protects access to |sent_bytes_in_flight_|. 97 // Protects access to |sent_bytes_in_flight_|.
92 base::Lock in_flight_lock_; 98 base::Lock in_flight_lock_;
93 99
94 DISALLOW_COPY_AND_ASSIGN(MidiHost); 100 DISALLOW_COPY_AND_ASSIGN(MidiHost);
95 }; 101 };
96 102
97 } // namespace content 103 } // namespace content
98 104
99 #endif // CONTENT_BROWSER_MEDIA_MIDI_HOST_H_ 105 #endif // CONTENT_BROWSER_MEDIA_MIDI_HOST_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/media/midi_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698