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. |
| 19 void FakeMediaAnalyticsClient::Init(dbus::Bus* bus) {} |
| 20 void FakeMediaAnalyticsClient::StartMediaAnalytics( |
| 21 const UpstartCallback& callback) { |
| 22 callback.Run(true); |
| 23 } |
| 24 |
| 25 void FakeMediaAnalyticsClient::RestartMediaAnalytics( |
| 26 const UpstartCallback& callback) { |
| 27 callback.Run(true); |
| 28 } |
| 29 |
| 30 void FakeMediaAnalyticsClient::SetMediaPerceptionSignalHandler( |
| 31 const MediaPerceptionSignalHandler& handler) { |
| 32 media_perception_signal_handler_ = handler; |
| 33 // Also fire a fake MediaPerception detection signal. |
| 34 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 35 FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnMediaPerception, |
| 36 weak_ptr_factory_.GetWeakPtr())); |
| 37 } |
| 38 |
| 39 void FakeMediaAnalyticsClient::State(const uint8_t* bytes, |
| 40 size_t length, |
| 41 const StateCallback& callback) { |
| 42 if (bytes != nullptr && length != 0) { |
| 43 if (!state_.ParseFromArray(bytes, length)) { |
| 44 LOG(ERROR) << "Failed to parse State message."; |
| 45 return; |
| 46 } |
| 47 } |
| 48 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 49 FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnState, |
| 50 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 51 } |
| 52 |
| 53 void FakeMediaAnalyticsClient::OnState(const StateCallback& callback) { |
| 54 int size = state_.ByteSize(); |
| 55 uint8_t buffer[size]; |
| 56 state_.SerializeToArray(&buffer, size); |
| 57 callback.Run(true, buffer, size); |
| 58 } |
| 59 |
| 60 void FakeMediaAnalyticsClient::GetDiagnostics( |
| 61 const DiagnoticsCallback& callback) { |
| 62 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 63 FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnGetDiagnostics, |
| 64 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 65 } |
| 66 |
| 67 void FakeMediaAnalyticsClient::OnGetDiagnostics( |
| 68 const DiagnoticsCallback& callback) { |
| 69 mri::Diagnostics diagnostics; |
| 70 diagnostics.add_perception_sample()->mutable_frame_perception()->set_frame_id( |
| 71 1); |
| 72 int size = diagnostics.ByteSize(); |
| 73 uint8_t buffer[size]; |
| 74 diagnostics.SerializeToArray(&buffer, size); |
| 75 callback.Run(true, buffer, size); |
| 76 } |
| 77 |
| 78 void FakeMediaAnalyticsClient::OnMediaPerception() { |
| 79 if (media_perception_signal_handler_.is_null()) { |
| 80 return; |
| 81 } |
| 82 mri::MediaPerception media_perception; |
| 83 media_perception.set_timestamp(1); |
| 84 int size = media_perception.ByteSize(); |
| 85 uint8_t buffer[size]; |
| 86 media_perception.SerializeToArray(&buffer, size); |
| 87 media_perception_signal_handler_.Run(buffer, size); |
| 88 } |
| 89 |
| 90 } // namespace chromeos |
OLD | NEW |