Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromeos/dbus/fake_media_analytics_client.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/threading/thread_task_runner_handle.h" | |
| 10 | |
| 11 namespace chromeos { | |
| 12 | |
| 13 FakeMediaAnalyticsClient::FakeMediaAnalyticsClient() | |
| 14 : weak_ptr_factory_(this) {} | |
| 15 | |
| 16 FakeMediaAnalyticsClient::~FakeMediaAnalyticsClient() {} | |
| 17 | |
| 18 // 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.
| |
| 19 void FakeMediaAnalyticsClient::Init(dbus::Bus* bus) {} | |
| 20 | |
| 21 void FakeMediaAnalyticsClient::SetMediaPerceptionSignalHandler( | |
| 22 const MediaPerceptionSignalHandler& handler) { | |
| 23 media_perception_signal_handler_ = handler; | |
| 24 } | |
| 25 | |
| 26 void FakeMediaAnalyticsClient::ClearMediaPerceptionSignalHandler() { | |
| 27 media_perception_signal_handler_.Reset(); | |
| 28 } | |
| 29 | |
| 30 void FakeMediaAnalyticsClient::GetState(const StateCallback& callback) { | |
| 31 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 32 FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnState, | |
| 33 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 34 } | |
| 35 | |
| 36 void FakeMediaAnalyticsClient::SetState(const mri::State& state, | |
| 37 const StateCallback& callback) { | |
| 38 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.
| |
| 39 DCHECK(state.status() == mri::State::SUSPENDED || | |
| 40 state.status() == mri::State::RUNNING) | |
| 41 << "Trying set state to something other than RUNNING or SUSPENDED."; | |
| 42 current_state_ = state; | |
| 43 } | |
| 44 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 45 FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnState, | |
| 46 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 47 } | |
| 48 | |
| 49 void FakeMediaAnalyticsClient::OnState(const StateCallback& callback) { | |
| 50 callback.Run(true, current_state_); | |
| 51 // Also fire a fake MediaPerception detection signal. | |
| 52 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 53 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.
| |
| 54 weak_ptr_factory_.GetWeakPtr())); | |
| 55 } | |
| 56 | |
| 57 void FakeMediaAnalyticsClient::GetDiagnostics( | |
| 58 const DiagnosticsCallback& callback) { | |
| 59 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 60 FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnGetDiagnostics, | |
| 61 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 62 } | |
| 63 | |
| 64 void FakeMediaAnalyticsClient::OnGetDiagnostics( | |
| 65 const DiagnosticsCallback& callback) { | |
| 66 mri::Diagnostics diagnostics; | |
| 67 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.
| |
| 68 1); | |
| 69 callback.Run(true, diagnostics); | |
| 70 } | |
| 71 | |
| 72 void FakeMediaAnalyticsClient::OnMediaPerception() { | |
| 73 if (media_perception_signal_handler_.is_null()) { | |
| 74 return; | |
| 75 } | |
| 76 mri::MediaPerception media_perception; | |
| 77 media_perception.set_timestamp(1); | |
| 78 media_perception_signal_handler_.Run(media_perception); | |
| 79 } | |
| 80 | |
| 81 } // namespace chromeos | |
| OLD | NEW |