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

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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/media/midi_messages.h ('k') | content/renderer/media/midi_message_filter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4aa560aa0972b8ae6999a92be3d7387f14822812..34cee3d1c26a59f44b9b3cc17e9f03835d203a7a 100644
--- a/content/renderer/media/midi_message_filter.h
+++ b/content/renderer/media/midi_message_filter.h
@@ -5,7 +5,7 @@
#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"
@@ -29,9 +29,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 +48,14 @@ class CONTENT_EXPORT MidiMessageFilter : public IPC::MessageFilter {
~MidiMessageFilter() override;
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 +67,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,22 +84,14 @@ 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);
+ // Following methods, Handle*, run on |main_message_loop_|.
+ void HandleClientAdded(media::MidiResult result);
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);
+ void HandleAckknowledgeSentData(size_t bytes_sent);
// IPC sender for Send(); must only be accessed on |io_message_loop_|.
IPC::Sender* sender_;
@@ -103,15 +102,24 @@ class CONTENT_EXPORT MidiMessageFilter : public IPC::MessageFilter {
// Main thread's message loop.
scoped_refptr<base::MessageLoopProxy> main_message_loop_;
+ /*
+ * Notice: Following members are designed to be accessed only on
+ * |main_message_loop_|.
+ */
// 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. Can be accessed only on
+ media::MidiResult session_result_;
+
+ // Holds MidiPortInfoList for input ports and output ports.
+ media::MidiPortInfoList inputs_;
+ media::MidiPortInfoList outputs_;
size_t unacknowledged_bytes_sent_;
« no previous file with comments | « content/common/media/midi_messages.h ('k') | content/renderer/media/midi_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698