Index: media/midi/midi_manager.h |
diff --git a/media/midi/midi_manager.h b/media/midi/midi_manager.h |
index 156a2465cb424bb943a271fdd4b7f99c53a669f5..4f8e4baf05f144c805854718cfde31683ac74904 100644 |
--- a/media/midi/midi_manager.h |
+++ b/media/midi/midi_manager.h |
@@ -10,12 +10,17 @@ |
#include <vector> |
#include "base/basictypes.h" |
+#include "base/memory/ref_counted.h" |
#include "base/synchronization/lock.h" |
#include "base/time/time.h" |
#include "media/base/media_export.h" |
#include "media/midi/midi_port_info.h" |
#include "media/midi/midi_result.h" |
+namespace base { |
+class SingleThreadTaskRunner; |
+} // namespace base |
+ |
namespace media { |
// A MidiManagerClient registers with the MidiManager to receive MIDI data. |
@@ -50,6 +55,8 @@ class MEDIA_EXPORT MidiManagerClient { |
// Manages access to all MIDI hardware. |
class MEDIA_EXPORT MidiManager { |
public: |
+ // The constructor and the destructor will be called on the CrBrowserMain |
+ // thread. |
static MidiManager* Create(); |
MidiManager(); |
@@ -60,6 +67,8 @@ class MEDIA_EXPORT MidiManager { |
// and the client is registered to receive MIDI data. |
// CompleteStartSession() is called with MIDI_OK if the session is started. |
// Otherwise CompleteStartSession() is called with proper MidiResult code. |
+ // StartSession() and EndSession() can be called on the Chrome_IOThread. |
+ // CompleteStartSession() will be invoked on the same Chrome_IOThread. |
void StartSession(MidiManagerClient* client, int client_id); |
// A client calls EndSession() to stop receiving MIDI data. |
@@ -92,15 +101,17 @@ class MEDIA_EXPORT MidiManager { |
protected: |
friend class MidiManagerUsb; |
- // Initializes the platform dependent MIDI system. It will call |
- // CompleteInitialization() asynchronously when initialization is finished. |
+ // Initializes the platform dependent MIDI system. It is called on |
+ // Chrome_IOThread, but will invoke CompleteInitialization() asynchronously |
+ // on the same thread or another thread when initialization is finished. |
// |result| of CompleteInitialization() will be MIDI_OK on success. |
- // MidiManager has a default implementation that calls |
- // CompleteInitialization() with MIDI_NOT_SUPPORTED. |
+ // MidiManager has a default implementation that synchronously calls |
+ // CompleteInitialization() with MIDI_NOT_SUPPORTED on the caller thread. |
virtual void StartInitialization(); |
// Called from a platform dependent implementation of StartInitialization(). |
- // It will distribute |result| to MIDIManagerClient objects in |
+ // It invokes CompleteInitializationInternal() on the thread that calls |
+ // StartSession() and distributes |result| to MIDIManagerClient objects in |
// |pending_clients_|. |
void CompleteInitialization(MidiResult result); |
@@ -123,9 +134,6 @@ class MEDIA_EXPORT MidiManager { |
(time - base::TimeTicks()).InSecondsF()); |
} |
- bool initialized_; |
- MidiResult result_; |
- |
// Keeps track of all clients who wish to receive MIDI data. |
typedef std::set<MidiManagerClient*> ClientList; |
ClientList clients_; |
@@ -134,13 +142,26 @@ class MEDIA_EXPORT MidiManager { |
typedef std::map<int, MidiManagerClient*> PendingClientMap; |
PendingClientMap pending_clients_; |
+ private: |
+ void CompleteInitializationInternal(MidiResult result); |
+ |
+ // Keeps a SingleThreadTaskRunner of the thread that calls StartSession in |
+ // order to invoke CompleteStartSession() on the thread. |
+ scoped_refptr<base::SingleThreadTaskRunner> session_thread_runner_; |
+ |
+ // Keeps true if platform dependent initialization is already completed. |
yukawa
2014/05/04 23:16:02
It seems that |initialized_| and |result_| are asy
Takashi Toyoshima
2014/05/05 00:45:08
|clients_lock_| is used, so I should rename it to
|
+ bool initialized_; |
+ |
+ // Keeps the platform dependent initialization result if initialization is |
+ // completed. Otherwise keeps MIDI_NOT_SUPPORTED. |
+ MidiResult result_; |
+ |
// Protects access to our clients, |clients_| and |pending_clients_|. |
base::Lock clients_lock_; |
MidiPortInfoList input_ports_; |
MidiPortInfoList output_ports_; |
- private: |
DISALLOW_COPY_AND_ASSIGN(MidiManager); |
}; |