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..1d8fc6dc3f06c6c410e19538124443a3a4fcb3cf |
| --- /dev/null |
| +++ b/chromeos/dbus/fake_media_analytics_client.cc |
| @@ -0,0 +1,72 @@ |
| +// 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. |
| +void FakeMediaAnalyticsClient::Init(dbus::Bus* bus) {} |
| + |
| +void FakeMediaAnalyticsClient::SetMediaPerceptionSignalHandler( |
| + const MediaPerceptionSignalHandler& handler) { |
| + media_perception_signal_handler_ = handler; |
| + // Also fire a fake MediaPerception detection signal. |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnMediaPerception, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void FakeMediaAnalyticsClient::UnsetMediaPerceptionSignalHandler() { |
| + media_perception_signal_handler_.Reset(); |
| +} |
| + |
| +void FakeMediaAnalyticsClient::State(const mri::State& state, |
| + const StateCallback& callback) { |
| + if (state.has_status()) { |
| + current_state_ = state; |
|
tbarzic
2017/05/05 21:10:42
can we check that the state is one of the settable
Luke Sorenson
2017/05/08 19:06:07
Do we need to do that, if there is a check in API
tbarzic
2017/05/08 23:04:55
I'd add (at least) a DCHECK here - so it catches i
Luke Sorenson
2017/05/09 17:39:45
Good point. Done.
|
| + } |
| + 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_); |
| +} |
| + |
| +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( |
| + 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 |