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

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

Issue 68353002: Use MIDIMessageQueue/IsValidWebMIDIData for MIDI byte stream validation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unnecessary notation from a header comment, to address scherkus' comment. Created 7 years 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/renderer_host/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_RENDERER_HOST_MEDIA_MIDI_HOST_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MIDI_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MIDI_HOST_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MIDI_HOST_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/gtest_prod_util.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
12 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
13 #include "content/public/browser/browser_message_filter.h" 15 #include "content/public/browser/browser_message_filter.h"
14 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
15 #include "media/midi/midi_manager.h" 17 #include "media/midi/midi_manager.h"
16 18
17 namespace media { 19 namespace media {
18 class MIDIManager; 20 class MIDIManager;
21 class MIDIMessageQueue;
19 } 22 }
20 23
21 namespace content { 24 namespace content {
22 25
23 class CONTENT_EXPORT MIDIHost 26 class CONTENT_EXPORT MIDIHost
24 : public BrowserMessageFilter, 27 : public BrowserMessageFilter,
25 public media::MIDIManagerClient { 28 public media::MIDIManagerClient {
26 public: 29 public:
27 // Called from UI thread from the owner of this object. 30 // Called from UI thread from the owner of this object.
28 MIDIHost(int renderer_process_id, media::MIDIManager* midi_manager); 31 MIDIHost(int renderer_process_id, media::MIDIManager* midi_manager);
29 32
30 // BrowserMessageFilter implementation. 33 // BrowserMessageFilter implementation.
31 virtual void OnDestruct() const OVERRIDE; 34 virtual void OnDestruct() const OVERRIDE;
32 virtual bool OnMessageReceived(const IPC::Message& message, 35 virtual bool OnMessageReceived(const IPC::Message& message,
33 bool* message_was_ok) OVERRIDE; 36 bool* message_was_ok) OVERRIDE;
34 37
35 // MIDIManagerClient implementation. 38 // MIDIManagerClient implementation.
36 virtual void ReceiveMIDIData( 39 virtual void ReceiveMIDIData(uint32 port,
37 uint32 port, 40 const uint8* data,
38 const uint8* data, 41 size_t length,
39 size_t length, 42 double timestamp) OVERRIDE;
40 double timestamp) OVERRIDE;
41 virtual void AccumulateMIDIBytesSent(size_t n) OVERRIDE; 43 virtual void AccumulateMIDIBytesSent(size_t n) OVERRIDE;
42 44
43 // Start session to access MIDI hardware. 45 // Start session to access MIDI hardware.
44 void OnStartSession(int client_id); 46 void OnStartSession(int client_id);
45 47
46 // Data to be sent to a MIDI output port. 48 // Data to be sent to a MIDI output port.
47 void OnSendData(uint32 port, 49 void OnSendData(uint32 port,
48 const std::vector<uint8>& data, 50 const std::vector<uint8>& data,
49 double timestamp); 51 double timestamp);
50 52
51 private: 53 private:
54 FRIEND_TEST_ALL_PREFIXES(MIDIHostTest, IsValidWebMIDIData);
52 friend class base::DeleteHelper<MIDIHost>; 55 friend class base::DeleteHelper<MIDIHost>;
53 friend class BrowserThread; 56 friend class BrowserThread;
54 57
55 virtual ~MIDIHost(); 58 virtual ~MIDIHost();
56 59
60 // Returns true if |data| fulfills the requirements of MIDIOutput.send API
61 // defined in the WebMIDI spec.
62 // - |data| must be any number of complete MIDI messages (data abbreviation
63 // called "running status" is disallowed).
64 // - 1-byte MIDI realtime messages can be placed at any position of |data|.
65 static bool IsValidWebMIDIData(const std::vector<uint8>& data);
66
57 int renderer_process_id_; 67 int renderer_process_id_;
58 68
69 // Represents if the renderer has a permission to send/receive MIDI SysEX
70 // messages.
71 bool has_sys_ex_permission_;
72
59 // |midi_manager_| talks to the platform-specific MIDI APIs. 73 // |midi_manager_| talks to the platform-specific MIDI APIs.
60 // It can be NULL if the platform (or our current implementation) 74 // It can be NULL if the platform (or our current implementation)
61 // does not support MIDI. If not supported then a call to 75 // does not support MIDI. If not supported then a call to
62 // OnRequestAccess() will always refuse access and a call to 76 // OnRequestAccess() will always refuse access and a call to
63 // OnSendData() will do nothing. 77 // OnSendData() will do nothing.
64 media::MIDIManager* const midi_manager_; 78 media::MIDIManager* const midi_manager_;
65 79
80 // Buffers where data sent from each MIDI input port is stored.
81 ScopedVector<media::MIDIMessageQueue> received_messages_queues_;
82
66 // The number of bytes sent to the platform-specific MIDI sending 83 // The number of bytes sent to the platform-specific MIDI sending
67 // system, but not yet completed. 84 // system, but not yet completed.
68 size_t sent_bytes_in_flight_; 85 size_t sent_bytes_in_flight_;
69 86
70 // The number of bytes successfully sent since the last time 87 // The number of bytes successfully sent since the last time
71 // we've acknowledged back to the renderer. 88 // we've acknowledged back to the renderer.
72 size_t bytes_sent_since_last_acknowledgement_; 89 size_t bytes_sent_since_last_acknowledgement_;
73 90
74 // Protects access to |sent_bytes_in_flight_|. 91 // Protects access to |sent_bytes_in_flight_|.
75 base::Lock in_flight_lock_; 92 base::Lock in_flight_lock_;
76 93
77 DISALLOW_COPY_AND_ASSIGN(MIDIHost); 94 DISALLOW_COPY_AND_ASSIGN(MIDIHost);
78 }; 95 };
79 96
80 } // namespace content 97 } // namespace content
81 98
82 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MIDI_HOST_H_ 99 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MIDI_HOST_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/media/midi_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698