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

Unified Diff: content/renderer/media/midi_message_filter.h

Issue 662853003: Manage MIDI related objects and sessions' lifecycles correctly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unittest 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/midi_message_filter.h
diff --git a/content/renderer/media/midi_message_filter.h b/content/renderer/media/midi_message_filter.h
index 8eed8abbbbd387d4017c2845ae4ef12aea9c7b33..b7678eeceb287f5d09fe3f66e6d2fdb65558a68a 100644
--- a/content/renderer/media/midi_message_filter.h
+++ b/content/renderer/media/midi_message_filter.h
@@ -5,10 +5,11 @@
#ifndef CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_
#define CONTENT_RENDERER_MEDIA_MIDI_MESSAGE_FILTER_H_
-#include <map>
+#include <set>
#include <vector>
#include "base/memory/scoped_ptr.h"
+#include "base/synchronization/lock.h"
#include "content/common/content_export.h"
#include "ipc/message_filter.h"
#include "media/midi/midi_port_info.h"
@@ -29,9 +30,7 @@ class CONTENT_EXPORT MidiMessageFilter : public IPC::MessageFilter {
// Each client registers for MIDI access here.
// If permission is granted, then the client's
- // addInputPort() and addOutputPort() methods will be called,
- // giving the client access to receive and send data.
- void StartSession(blink::WebMIDIAccessorClient* client);
+ void AddClient(blink::WebMIDIAccessorClient* client);
void RemoveClient(blink::WebMIDIAccessorClient* client);
// A client will only be able to call this method if it has a suitable
@@ -50,6 +49,14 @@ class CONTENT_EXPORT MidiMessageFilter : public IPC::MessageFilter {
virtual ~MidiMessageFilter();
private:
+ void StartSessionOnIOThread();
+
+ void SendMidiDataOnIOThread(uint32 port,
+ const std::vector<uint8>& data,
+ double timestamp);
+
+ void EndSessionOnIOThread();
+
// Sends an IPC message using |sender_|.
void Send(IPC::Message* message);
@@ -61,8 +68,9 @@ class CONTENT_EXPORT MidiMessageFilter : public IPC::MessageFilter {
// Called when the browser process has approved (or denied) access to
// MIDI hardware.
- void OnSessionStarted(int client_id,
- media::MidiResult result,
+ // TODO(toyoshim): MidiPortInfoList objects should be notified separately
+ // port by port.
+ void OnSessionStarted(media::MidiResult result,
media::MidiPortInfoList inputs,
media::MidiPortInfoList outputs);
@@ -77,23 +85,12 @@ class CONTENT_EXPORT MidiMessageFilter : public IPC::MessageFilter {
// sending too much data before knowing how much has already been sent.
void OnAcknowledgeSentData(size_t bytes_sent);
- void HandleSessionStarted(int client_id,
- media::MidiResult result,
- media::MidiPortInfoList inputs,
- media::MidiPortInfoList outputs);
+ void HandleClientAdded(blink::WebMIDIAccessorClient* client);
void HandleDataReceived(uint32 port,
const std::vector<uint8>& data,
double timestamp);
- void StartSessionOnIOThread(int client_id);
-
- void SendMidiDataOnIOThread(uint32 port,
- const std::vector<uint8>& data,
- double timestamp);
-
- blink::WebMIDIAccessorClient* GetClientFromId(int client_id);
-
// IPC sender for Send(); must only be accessed on |io_message_loop_|.
IPC::Sender* sender_;
@@ -103,15 +100,24 @@ class CONTENT_EXPORT MidiMessageFilter : public IPC::MessageFilter {
// Main thread's message loop.
scoped_refptr<base::MessageLoopProxy> main_message_loop_;
+ // Protects access to |clients_|, |clients_waiting_session_|, and
+ // |session_results_|.
+ base::Lock lock_;
+
// Keeps track of all MIDI clients.
- // We map client to "client id" used to track permission.
- // When access has been approved, we add the input and output ports to
- // the client, allowing it to actually receive and send MIDI data.
- typedef std::map<blink::WebMIDIAccessorClient*, int> ClientsMap;
- ClientsMap clients_;
-
- // Dishes out client ids.
- int next_available_id_;
+ typedef std::set<blink::WebMIDIAccessorClient*> ClientsSet;
+ ClientsSet clients_;
+
+ // Represents clients that are waiting for a session being open.
+ typedef std::vector<blink::WebMIDIAccessorClient*> ClientsQueue;
+ ClientsQueue clients_waiting_session_queue_;
+
+ // Represents a result on starting a session.
+ media::MidiResult session_result_;
+
+ // Holds MidiPortInfoList for input ports and output ports.
+ media::MidiPortInfoList inputs_;
+ media::MidiPortInfoList outputs_;
size_t unacknowledged_bytes_sent_;

Powered by Google App Engine
This is Rietveld 408576698