1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/mojo/services/mojo_media_log.h"
7 #include "base/functional/bind.h"
8 #include "base/logging.h"
9 #include "base/task/sequenced_task_runner.h"
13 MojoMediaLog::MojoMediaLog(
14 mojo::PendingRemote<mojom::MediaLog> remote_media_log,
15 scoped_refptr<base::SequencedTaskRunner> task_runner)
16 : remote_media_log_(std::move(remote_media_log)),
17 task_runner_(std::move(task_runner)) {
21 MojoMediaLog::~MojoMediaLog() {
23 // Note that we're not invalidating the remote side. We're only invalidating
24 // anything that was cloned from us. Effectively, we're a log that just
25 // happens to operate via mojo.
29 void MojoMediaLog::AddLogRecordLocked(std::unique_ptr<MediaLogRecord> event) {
33 // Don't post unless we need to. Otherwise, we can order a log entry after
34 // our own destruction. While safe, this loses the message. This can happen,
35 // for example, when we're logging why a VideoDecoder failed to initialize.
36 // It will be destroyed synchronously when Initialize returns.
38 // Also, we post here, so this is the base case. :)
39 if (task_runner_->RunsTasksInCurrentSequence()) {
40 remote_media_log_->AddLogRecord(*event);
44 // From other threads, we have little choice.
45 task_runner_->PostTask(
47 base::BindOnce(&MojoMediaLog::AddLogRecord,
48 weak_ptr_factory_.GetWeakPtr(), std::move(event)));