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

Side by Side Diff: media/midi/midi_scheduler.cc

Issue 1060553003: Web MIDI: call AccumulateMidiBytesSent() after operation finished (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « media/midi/midi_scheduler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/midi/midi_scheduler.h" 5 #include "media/midi/midi_scheduler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "media/midi/midi_manager.h" 10 #include "media/midi/midi_manager.h"
11 11
12 namespace media { 12 namespace media {
13 13
14 MidiScheduler::MidiScheduler() : weak_factory_(this) { 14 MidiScheduler::MidiScheduler(MidiManager* manager)
15 : manager_(manager),
16 weak_factory_(this) {
15 } 17 }
16 18
17 MidiScheduler::~MidiScheduler() { 19 MidiScheduler::~MidiScheduler() {
18 } 20 }
19 21
20 // TODO(crbug.com/467442): Use CancelableTaskTracker once it supports 22 // TODO(crbug.com/467442): Use CancelableTaskTracker once it supports
21 // DelayedTask. 23 // DelayedTask.
22 void MidiScheduler::PostSendDataTask(MidiManagerClient* client, 24 void MidiScheduler::PostSendDataTask(MidiManagerClient* client,
23 size_t length, 25 size_t length,
24 double timestamp, 26 double timestamp,
25 const base::Closure& closure) { 27 const base::Closure& closure) {
26 DCHECK(client); 28 DCHECK(client);
27 29
28 const base::Closure& weak_closure = base::Bind( 30 const base::Closure& weak_closure = base::Bind(
29 &MidiScheduler::InvokeClosure, weak_factory_.GetWeakPtr(), closure); 31 &MidiScheduler::InvokeClosure,
32 weak_factory_.GetWeakPtr(),
33 client,
34 length,
35 closure);
30 36
31 base::TimeDelta delay; 37 base::TimeDelta delay;
32 if (timestamp != 0.0) { 38 if (timestamp != 0.0) {
33 base::TimeTicks time_to_send = 39 base::TimeTicks time_to_send =
34 base::TimeTicks() + base::TimeDelta::FromMicroseconds( 40 base::TimeTicks() + base::TimeDelta::FromMicroseconds(
35 timestamp * base::Time::kMicrosecondsPerSecond); 41 timestamp * base::Time::kMicrosecondsPerSecond);
36 delay = std::max(time_to_send - base::TimeTicks::Now(), base::TimeDelta()); 42 delay = std::max(time_to_send - base::TimeTicks::Now(), base::TimeDelta());
37 } 43 }
38 base::MessageLoop::current()->task_runner()->PostDelayedTask( 44 base::MessageLoop::current()->task_runner()->PostDelayedTask(
39 FROM_HERE, weak_closure, delay); 45 FROM_HERE, weak_closure, delay);
40
41 // TODO(crbug.com/467442): AccumulateMidiBytesSent should be called in
42 // InvokeClosure. But for now, we call it here since |client| may be deleted
43 // at that time.
44 client->AccumulateMidiBytesSent(length);
45 } 46 }
46 47
47 void MidiScheduler::InvokeClosure(const base::Closure& closure) { 48 void MidiScheduler::InvokeClosure(MidiManagerClient* client,
49 size_t length,
50 const base::Closure& closure) {
48 closure.Run(); 51 closure.Run();
52 manager_->AccumulateMidiBytesSent(client, length);
49 } 53 }
50 54
51 } // namespace media 55 } // namespace media
OLDNEW
« no previous file with comments | « media/midi/midi_scheduler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698