Chromium Code Reviews| Index: media/midi/midi_manager.cc |
| diff --git a/media/midi/midi_manager.cc b/media/midi/midi_manager.cc |
| index c53eef4112c33a662bd5e850e38c497df8c52aaf..d72dbe292db5abf6f33d34c7bdbe43b6d4725137 100644 |
| --- a/media/midi/midi_manager.cc |
| +++ b/media/midi/midi_manager.cc |
| @@ -26,7 +26,7 @@ MidiManager* MidiManager::Create() { |
| } |
| #endif |
| -void MidiManager::StartSession(MidiManagerClient* client, int client_id) { |
| +void MidiManager::StartSession(MidiManagerClient* client) { |
| bool session_is_ready; |
| bool session_needs_initialization = false; |
| bool too_many_pending_clients_exist = false; |
| @@ -34,6 +34,12 @@ void MidiManager::StartSession(MidiManagerClient* client, int client_id) { |
| { |
| base::AutoLock auto_lock(lock_); |
| session_is_ready = initialized_; |
| + if (clients_.find(client) != clients_.end() || |
| + pending_clients_.find(client) != pending_clients_.end()) { |
| + // Should not happen. But just in case on renderer being hijacked. |
|
palmer
2014/10/21 21:20:12
Nit: "But just in case the renderer is compromised
Takashi Toyoshima
2014/10/22 05:57:40
Done.
|
| + NOTREACHED(); |
| + return; |
| + } |
| if (!session_is_ready) { |
| // Do not accept a new request if the pending client list contains too |
| // many clients. |
| @@ -43,7 +49,7 @@ void MidiManager::StartSession(MidiManagerClient* client, int client_id) { |
| if (!too_many_pending_clients_exist) { |
| // Call StartInitialization() only for the first request. |
| session_needs_initialization = pending_clients_.empty(); |
| - pending_clients_.insert(std::make_pair(client, client_id)); |
| + pending_clients_.insert(client); |
| } |
| } |
| } |
| @@ -58,7 +64,7 @@ void MidiManager::StartSession(MidiManagerClient* client, int client_id) { |
| } |
| if (too_many_pending_clients_exist) { |
| // Return an error immediately if there are too many requests. |
| - client->CompleteStartSession(client_id, MIDI_INITIALIZATION_ERROR); |
| + client->CompleteStartSession(MIDI_INITIALIZATION_ERROR); |
| return; |
| } |
| // CompleteInitialization() will be called asynchronously when platform |
| @@ -75,7 +81,7 @@ void MidiManager::StartSession(MidiManagerClient* client, int client_id) { |
| clients_.insert(client); |
| result = result_; |
| } |
| - client->CompleteStartSession(client_id, result); |
| + client->CompleteStartSession(result); |
| } |
| void MidiManager::EndSession(MidiManagerClient* client) { |
| @@ -121,8 +127,8 @@ void MidiManager::ReceiveMidiData( |
| double timestamp) { |
| base::AutoLock auto_lock(lock_); |
| - for (ClientList::iterator i = clients_.begin(); i != clients_.end(); ++i) |
| - (*i)->ReceiveMidiData(port_index, data, length, timestamp); |
| + for (MidiManagerClient* client : clients_) |
| + client->ReceiveMidiData(port_index, data, length, timestamp); |
| } |
| void MidiManager::CompleteInitializationInternal(MidiResult result) { |
| @@ -134,12 +140,10 @@ void MidiManager::CompleteInitializationInternal(MidiResult result) { |
| initialized_ = true; |
| result_ = result; |
| - for (PendingClientMap::iterator it = pending_clients_.begin(); |
| - it != pending_clients_.end(); |
| - ++it) { |
| + for (MidiManagerClient* client : pending_clients_) { |
| if (result_ == MIDI_OK) |
| - clients_.insert(it->first); |
| - it->first->CompleteStartSession(it->second, result_); |
| + clients_.insert(client); |
| + client->CompleteStartSession(result_); |
| } |
| pending_clients_.clear(); |
| } |