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

Unified Diff: media/midi/midi_scheduler.h

Issue 2262043002: MidiScheduler binds to task runner of constructing thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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_usb.cc ('k') | media/midi/midi_scheduler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/midi/midi_scheduler.h
diff --git a/media/midi/midi_scheduler.h b/media/midi/midi_scheduler.h
index 17354a96a0d3b5d6c57b6b0ee074c82f15a838b8..2d79fc8266096405761a75aa7ccc4b03c04d4bca 100644
--- a/media/midi/midi_scheduler.h
+++ b/media/midi/midi_scheduler.h
@@ -10,6 +10,8 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
+#include "base/single_thread_task_runner.h"
+#include "base/threading/thread_checker.h"
#include "media/midi/midi_export.h"
namespace media {
@@ -21,12 +23,17 @@ class MidiManagerClient;
// TODO(crbug.com/467442): Make tasks cancelable per client.
class MIDI_EXPORT MidiScheduler final {
public:
+ // Both constructor and destructor should be run on the same thread. The
+ // instance is bound to the TaskRunner of the constructing thread, on which
+ // InvokeClosure() is run.
explicit MidiScheduler(MidiManager* manager);
~MidiScheduler();
- // Post |closure| to the current message loop safely. The |closure| will not
- // be invoked after MidiScheduler is deleted. AccumulateMidiBytesSent() of
- // |client| is called internally.
+ // Post |closure| to |task_runner_| safely. The |closure| will not be invoked
+ // after MidiScheduler is deleted. AccumulateMidiBytesSent() of |client| is
+ // called internally. May be called on any thread, but the user should ensure
+ // this method is not called on other threads during/after MidiScheduler
+ // destruction.
void PostSendDataTask(MidiManagerClient* client,
size_t length,
double timestamp,
@@ -39,6 +46,14 @@ class MIDI_EXPORT MidiScheduler final {
// MidiManager should own the MidiScheduler and be alive longer.
MidiManager* manager_;
+
+ // The TaskRunner of the thread on which the instance is constructed.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ // Ensures |weak_factory_| is destructed, and WeakPtrs are dereferenced on the
+ // same thread.
+ base::ThreadChecker thread_checker_;
+
base::WeakPtrFactory<MidiScheduler> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MidiScheduler);
« no previous file with comments | « media/midi/midi_manager_usb.cc ('k') | media/midi/midi_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698