Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: chromeos/dbus/fake_media_analytics_client.cc

Issue 2791983004: DBus MediaAnalyticsClient and media_perception pb. (Closed)
Patch Set: Fixing compile error. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
21 void FakeMediaAnalyticsClient::SetMediaPerceptionSignalHandler(
22 const MediaPerceptionSignalHandler& handler) {
23 media_perception_signal_handler_ = handler;
24 // Also fire a fake MediaPerception detection signal.
25 base::ThreadTaskRunnerHandle::Get()->PostTask(
26 FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnMediaPerception,
27 weak_ptr_factory_.GetWeakPtr()));
28 }
29
30 void FakeMediaAnalyticsClient::UnsetMediaPerceptionSignalHandler() {
31 media_perception_signal_handler_.Reset();
32 }
33
34 void FakeMediaAnalyticsClient::State(const mri::State& state,
35 const StateCallback& callback) {
36 if (state.has_status()) {
37 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.
38 }
39 base::ThreadTaskRunnerHandle::Get()->PostTask(
40 FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnState,
41 weak_ptr_factory_.GetWeakPtr(), callback));
42 }
43
44 void FakeMediaAnalyticsClient::OnState(const StateCallback& callback) {
45 callback.Run(true, current_state_);
46 }
47
48 void FakeMediaAnalyticsClient::GetDiagnostics(
49 const DiagnosticsCallback& callback) {
50 base::ThreadTaskRunnerHandle::Get()->PostTask(
51 FROM_HERE, base::Bind(&FakeMediaAnalyticsClient::OnGetDiagnostics,
52 weak_ptr_factory_.GetWeakPtr(), callback));
53 }
54
55 void FakeMediaAnalyticsClient::OnGetDiagnostics(
56 const DiagnosticsCallback& callback) {
57 mri::Diagnostics diagnostics;
58 diagnostics.add_perception_sample()->mutable_frame_perception()->set_frame_id(
59 1);
60 callback.Run(true, diagnostics);
61 }
62
63 void FakeMediaAnalyticsClient::OnMediaPerception() {
64 if (media_perception_signal_handler_.is_null()) {
65 return;
66 }
67 mri::MediaPerception media_perception;
68 media_perception.set_timestamp(1);
69 media_perception_signal_handler_.Run(media_perception);
70 }
71
72 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698