OLD | NEW |
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 #ifndef MEDIA_MIDI_MIDI_SCHEDULER_H_ | 5 #ifndef MEDIA_MIDI_MIDI_SCHEDULER_H_ |
6 #define MEDIA_MIDI_MIDI_SCHEDULER_H_ | 6 #define MEDIA_MIDI_MIDI_SCHEDULER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 | 10 |
11 namespace media { | 11 namespace media { |
12 | 12 |
| 13 class MidiManager; |
13 class MidiManagerClient; | 14 class MidiManagerClient; |
14 | 15 |
15 // TODO(crbug.com/467442): Make tasks cancelable per client. | 16 // TODO(crbug.com/467442): Make tasks cancelable per client. |
16 class MidiScheduler final { | 17 class MidiScheduler final { |
17 public: | 18 public: |
18 MidiScheduler(); | 19 MidiScheduler(MidiManager* manager); |
19 ~MidiScheduler(); | 20 ~MidiScheduler(); |
20 | 21 |
21 // Post |closure| to the current message loop safely. The |closure| will not | 22 // Post |closure| to the current message loop safely. The |closure| will not |
22 // be invoked after MidiScheduler is deleted. AccumulateMidiBytesSent() of | 23 // be invoked after MidiScheduler is deleted. AccumulateMidiBytesSent() of |
23 // |client| is called internally. | 24 // |client| is called internally. |
24 void PostSendDataTask(MidiManagerClient* client, | 25 void PostSendDataTask(MidiManagerClient* client, |
25 size_t length, | 26 size_t length, |
26 double timestamp, | 27 double timestamp, |
27 const base::Closure& closure); | 28 const base::Closure& closure); |
28 | 29 |
29 private: | 30 private: |
30 void InvokeClosure(const base::Closure& closure); | 31 void InvokeClosure(MidiManagerClient* client, |
| 32 size_t length, |
| 33 const base::Closure& closure); |
31 | 34 |
| 35 // MidiManager should own the MidiScheduler and be alive longer. |
| 36 MidiManager* manager_; |
32 base::WeakPtrFactory<MidiScheduler> weak_factory_; | 37 base::WeakPtrFactory<MidiScheduler> weak_factory_; |
33 | 38 |
34 DISALLOW_COPY_AND_ASSIGN(MidiScheduler); | 39 DISALLOW_COPY_AND_ASSIGN(MidiScheduler); |
35 }; | 40 }; |
36 | 41 |
37 } // namespace media | 42 } // namespace media |
38 | 43 |
39 #endif // MEDIA_MIDI_MIDI_SCHEDULER_H_ | 44 #endif // MEDIA_MIDI_MIDI_SCHEDULER_H_ |
OLD | NEW |