Chromium Code Reviews| Index: media/midi/midi_manager.cc |
| diff --git a/media/midi/midi_manager.cc b/media/midi/midi_manager.cc |
| index 67845cef08d5b2c49add1954b5041d96045e5676..91eb5f5daab252fbb118aaac995da53bc0d8a779 100644 |
| --- a/media/midi/midi_manager.cc |
| +++ b/media/midi/midi_manager.cc |
| @@ -8,13 +8,6 @@ |
| namespace media { |
| -#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(USE_ALSA) && \ |
| - !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| -MidiManager* MidiManager::Create() { |
| - return new MidiManager; |
| -} |
| -#endif |
| - |
| MidiManager::MidiManager() |
| : initialized_(false), |
| result_(MIDI_NOT_SUPPORTED) { |
| @@ -23,18 +16,33 @@ MidiManager::MidiManager() |
| MidiManager::~MidiManager() { |
| } |
| +#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(USE_ALSA) && \ |
| + !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| +MidiManager* MidiManager::Create() { |
| + return new MidiManager; |
| +} |
| +#endif |
| + |
| void MidiManager::StartSession(MidiManagerClient* client, int client_id) { |
| bool session_is_ready; |
| bool session_needs_initialization = false; |
| + bool too_many_pending_clients_exist = false; |
| { |
| base::AutoLock auto_lock(clients_lock_); |
| session_is_ready = initialized_; |
| if (!session_is_ready) { |
| - // Call StartInitialization() only for the first request. |
| - session_needs_initialization = pending_clients_.empty(); |
| - pending_clients_.insert( |
| - std::pair<int, MidiManagerClient*>(client_id, client)); |
| + // Do not accept a new request if the pending client list contains too |
| + // many clients. |
| + too_many_pending_clients_exist = |
| + pending_clients_.size() >= kMaxPendingClientCount; |
| + |
| + if (!too_many_pending_clients_exist) { |
| + // Call StartInitialization() only for the first request. |
| + session_needs_initialization = pending_clients_.empty(); |
| + pending_clients_.insert( |
| + std::pair<int, MidiManagerClient*>(client_id, client)); |
| + } |
| } |
| } |
| @@ -44,6 +52,11 @@ void MidiManager::StartSession(MidiManagerClient* client, int client_id) { |
| TRACE_EVENT0("midi", "MidiManager::StartInitialization"); |
| StartInitialization(); |
| } |
| + if (too_many_pending_clients_exist) { |
|
yukawa
2014/05/04 22:44:54
|too_many_pending_clients_exist| isn't guarded by
Takashi Toyoshima
2014/05/04 23:28:44
We do not want to hold |clients_lock_| to invoke v
yukawa
2014/05/04 23:45:55
Got it. Thanks.
|
| + // Return an error immediately if there are too many requests. |
| + client->CompleteStartSession(client_id, MIDI_INITIALIZATION_ERROR); |
| + return; |
| + } |
| // CompleteInitialization() will be called asynchronously when platform |
| // dependent initialization is finished. |
| return; |