Chromium Code Reviews| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 13 #include "media/midi/midi_export.h" | 15 #include "media/midi/midi_export.h" |
| 14 | 16 |
| 15 namespace media { | 17 namespace media { |
| 16 namespace midi { | 18 namespace midi { |
| 17 | 19 |
| 18 class MidiManager; | 20 class MidiManager; |
| 19 class MidiManagerClient; | 21 class MidiManagerClient; |
| 20 | 22 |
| 21 // TODO(crbug.com/467442): Make tasks cancelable per client. | 23 // TODO(crbug.com/467442): Make tasks cancelable per client. |
| 22 class MIDI_EXPORT MidiScheduler final { | 24 class MIDI_EXPORT MidiScheduler final { |
| 23 public: | 25 public: |
| 24 explicit MidiScheduler(MidiManager* manager); | 26 explicit MidiScheduler(MidiManager* manager); |
| 25 ~MidiScheduler(); | 27 ~MidiScheduler(); |
| 26 | 28 |
| 27 // Post |closure| to the current message loop safely. The |closure| will not | 29 // Post |closure| to |task_runner| safely. The |closure| will not be invoked |
|
Takashi Toyoshima
2016/08/23 05:30:41
Now that this method does not take |task_runner|,
Shao-Chuan Lee
2016/08/23 09:36:07
Should be |task_runner_|. Added comments.
| |
| 28 // be invoked after MidiScheduler is deleted. AccumulateMidiBytesSent() of | 30 // after MidiScheduler is deleted. AccumulateMidiBytesSent() of |client| is |
| 29 // |client| is called internally. | 31 // called internally. |
| 30 void PostSendDataTask(MidiManagerClient* client, | 32 void PostSendDataTask(MidiManagerClient* client, |
| 31 size_t length, | 33 size_t length, |
| 32 double timestamp, | 34 double timestamp, |
| 33 const base::Closure& closure); | 35 const base::Closure& closure); |
| 34 | 36 |
| 35 private: | 37 private: |
| 36 void InvokeClosure(MidiManagerClient* client, | 38 void InvokeClosure(MidiManagerClient* client, |
| 37 size_t length, | 39 size_t length, |
| 38 const base::Closure& closure); | 40 const base::Closure& closure); |
| 39 | 41 |
| 40 // MidiManager should own the MidiScheduler and be alive longer. | 42 // MidiManager should own the MidiScheduler and be alive longer. |
| 41 MidiManager* manager_; | 43 MidiManager* manager_; |
| 44 | |
| 45 // The TaskRunner of the thread on which the instance is constructed. | |
|
Takashi Toyoshima
2016/08/23 05:30:41
Can we add some comments why it's fine that we can
Shao-Chuan Lee
2016/08/23 09:36:07
Added comments at PostSendDataTask().
| |
| 46 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 47 | |
| 48 // Ensures |weak_factory_| is destructed, and WeakPtrs are dereferenced on the | |
| 49 // same thread. | |
| 50 base::ThreadChecker thread_checker_; | |
| 51 | |
| 42 base::WeakPtrFactory<MidiScheduler> weak_factory_; | 52 base::WeakPtrFactory<MidiScheduler> weak_factory_; |
| 43 | 53 |
| 44 DISALLOW_COPY_AND_ASSIGN(MidiScheduler); | 54 DISALLOW_COPY_AND_ASSIGN(MidiScheduler); |
| 45 }; | 55 }; |
| 46 | 56 |
| 47 } // namespace midi | 57 } // namespace midi |
| 48 } // namespace media | 58 } // namespace media |
| 49 | 59 |
| 50 #endif // MEDIA_MIDI_MIDI_SCHEDULER_H_ | 60 #endif // MEDIA_MIDI_MIDI_SCHEDULER_H_ |
| OLD | NEW |