Chromium Code Reviews| Index: chromeos/dbus/fake_media_analytics_client.cc |
| diff --git a/chromeos/dbus/fake_media_analytics_client.cc b/chromeos/dbus/fake_media_analytics_client.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fbab5684353e91f1160105a750627d3a511e4b16 |
| --- /dev/null |
| +++ b/chromeos/dbus/fake_media_analytics_client.cc |
| @@ -0,0 +1,81 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chromeos/dbus/fake_media_analytics_client.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/logging.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| + |
| +namespace chromeos { |
| + |
| +FakeMediaAnalyticsClient::FakeMediaAnalyticsClient() |
| + : weak_ptr_factory_(this) {} |
| + |
| +FakeMediaAnalyticsClient::~FakeMediaAnalyticsClient() {} |
| + |
| +// Override these initializations to do nothing. |
|
tbarzic
2017/05/09 20:28:40
nit: no comment needed
Luke Sorenson
2017/05/09 22:21:24
Done.
|
| +void FakeMediaAnalyticsClient::Init(dbus::Bus* bus) {} |
| + |
| +void FakeMediaAnalyticsClient::SetMediaPerceptionSignalHandler( |
| + const MediaPerceptionSignalHandler& handler) { |
| + media_perception_signal_handler_ = handler; |
| +} |
| + |
| +void FakeMediaAnalyticsClient::ClearMediaPerceptionSignalHandler() { |
| + media_perception_signal_handler_.Reset(); |
| +} |
| + |
| +void FakeMediaAnalyticsClient::GetState(const StateCallback& callback) { |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnState, |
| + weak_ptr_factory_.GetWeakPtr(), callback)); |
| +} |
| + |
| +void FakeMediaAnalyticsClient::SetState(const mri::State& state, |
| + const StateCallback& callback) { |
| + if (state.has_status()) { |
|
tbarzic
2017/05/09 20:28:40
Status should be set here, right?
Luke Sorenson
2017/05/09 22:21:25
Done.
tbarzic
2017/05/10 03:26:24
sorry for not being precise enough...
I think you
Luke Sorenson
2017/05/10 16:38:22
Done.
|
| + DCHECK(state.status() == mri::State::SUSPENDED || |
| + state.status() == mri::State::RUNNING) |
| + << "Trying set state to something other than RUNNING or SUSPENDED."; |
| + current_state_ = state; |
| + } |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnState, |
| + weak_ptr_factory_.GetWeakPtr(), callback)); |
| +} |
| + |
| +void FakeMediaAnalyticsClient::OnState(const StateCallback& callback) { |
| + callback.Run(true, current_state_); |
| + // Also fire a fake MediaPerception detection signal. |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnMediaPerception, |
|
tbarzic
2017/05/09 20:28:40
This seems unintuitive.. if you need the fired in
Luke Sorenson
2017/05/09 22:21:24
Done.
|
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void FakeMediaAnalyticsClient::GetDiagnostics( |
| + const DiagnosticsCallback& callback) { |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnGetDiagnostics, |
| + weak_ptr_factory_.GetWeakPtr(), callback)); |
| +} |
| + |
| +void FakeMediaAnalyticsClient::OnGetDiagnostics( |
| + const DiagnosticsCallback& callback) { |
| + mri::Diagnostics diagnostics; |
| + diagnostics.add_perception_sample()->mutable_frame_perception()->set_frame_id( |
|
tbarzic
2017/05/09 20:28:41
should frames returned here ahve unique ids?
Luke Sorenson
2017/05/09 22:21:24
Only returning one fake PerceptionSample here, so
tbarzic
2017/05/10 03:26:24
OK, though, my point was that this will always ret
Luke Sorenson
2017/05/10 16:38:22
Done.
|
| + 1); |
| + callback.Run(true, diagnostics); |
| +} |
| + |
| +void FakeMediaAnalyticsClient::OnMediaPerception() { |
| + if (media_perception_signal_handler_.is_null()) { |
| + return; |
| + } |
| + mri::MediaPerception media_perception; |
| + media_perception.set_timestamp(1); |
| + media_perception_signal_handler_.Run(media_perception); |
| +} |
| + |
| +} // namespace chromeos |