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

Unified Diff: media/midi/midi_manager.cc

Issue 264053002: Web MIDI: introduce pending client count limit to start sessions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: renames by #8 Created 6 years, 7 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 | « media/midi/midi_manager.h ('k') | media/midi/midi_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/midi/midi_manager.cc
diff --git a/media/midi/midi_manager.cc b/media/midi/midi_manager.cc
index 6d6bda40751724a747f751d33f847c2d8fd63418..aba8441ef8f0548ef417dcd477b8e17b934cdf19 100644
--- a/media/midi/midi_manager.cc
+++ b/media/midi/midi_manager.cc
@@ -11,13 +11,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) {
@@ -26,18 +19,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(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));
+ }
}
}
@@ -49,6 +57,11 @@ void MidiManager::StartSession(MidiManagerClient* client, int client_id) {
base::MessageLoop::current()->message_loop_proxy();
StartInitialization();
}
+ if (too_many_pending_clients_exist) {
+ // 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;
« no previous file with comments | « media/midi/midi_manager.h ('k') | media/midi/midi_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698