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

Unified Diff: media/midi/midi_scheduler.cc

Issue 1052983002: Web MIDI: add MidiScheduler for send() with timestamp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« media/midi/midi_scheduler.h ('K') | « media/midi/midi_scheduler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/midi/midi_scheduler.cc
diff --git a/media/midi/midi_scheduler.cc b/media/midi/midi_scheduler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cc9373327fe23e41cea9e808e3c4234a180349e6
--- /dev/null
+++ b/media/midi/midi_scheduler.cc
@@ -0,0 +1,51 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/midi/midi_scheduler.h"
+
+#include "base/bind.h"
+#include "base/message_loop/message_loop.h"
+#include "base/time/time.h"
+#include "media/midi/midi_manager.h"
+
+namespace media {
+
+MidiScheduler::MidiScheduler() : weak_factory_(this) {
+}
+
+MidiScheduler::~MidiScheduler() {
+}
+
+// TODO(crbug.com/467442): Use CancelableTaskTracker once it supports
+// DelayedTask.
+void MidiScheduler::PostSendDataTask(MidiManagerClient* client,
+ size_t length,
+ double timestamp,
+ const base::Closure& closure) {
+ DCHECK(client);
+
+ const base::Closure& weak_closure = base::Bind(
yhirano 2015/04/03 01:32:15 Just curious, does using const reference have any
Takashi Toyoshima 2015/04/03 02:35:11 I did not have a strong reason here, but just foll
+ &MidiScheduler::InvokeClosure, weak_factory_.GetWeakPtr(), closure);
+
+ base::TimeDelta delay;
+ if (timestamp != 0.0) {
+ base::TimeTicks time_to_send =
+ base::TimeTicks() + base::TimeDelta::FromMicroseconds(
+ timestamp * base::Time::kMicrosecondsPerSecond);
+ delay = std::max(time_to_send - base::TimeTicks::Now(), base::TimeDelta());
+ }
+ base::MessageLoop::current()->task_runner()->PostDelayedTask(
+ FROM_HERE, weak_closure, delay);
+
+ // TODO(crbug.com/467442): AccumulateMidiBytesSent should be called in
+ // InvokeClosure. But for now, we call it here since |client| may be deleted
+ // at that time.
+ client->AccumulateMidiBytesSent(length);
+}
+
+void MidiScheduler::InvokeClosure(const base::Closure& closure) {
+ closure.Run();
+}
+
+} // namespace media
« media/midi/midi_scheduler.h ('K') | « media/midi/midi_scheduler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698