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 #ifndef CHROMEOS_DBUS_FAKE_MEDIA_ANALYTICS_CLIENT_H_ |
| 6 #define CHROMEOS_DBUS_FAKE_MEDIA_ANALYTICS_CLIENT_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "chromeos/chromeos_export.h" |
| 12 #include "chromeos/dbus/media_analytics_client.h" |
| 13 #include "chromeos/media_perception/media_perception.pb.h" |
| 14 |
| 15 namespace chromeos { |
| 16 |
| 17 // MediaAnalyticsClient is used to communicate with a media analytics process |
| 18 // running outside of Chrome. |
| 19 class CHROMEOS_EXPORT FakeMediaAnalyticsClient : public MediaAnalyticsClient { |
| 20 public: |
| 21 FakeMediaAnalyticsClient(); |
| 22 ~FakeMediaAnalyticsClient() override; |
| 23 |
| 24 // Inherited from MediaAnalyticsClient. |
| 25 void GetState(const StateCallback& callback) override; |
| 26 void SetState(const mri::State& state, |
| 27 const StateCallback& callback) override; |
| 28 void SetMediaPerceptionSignalHandler( |
| 29 const MediaPerceptionSignalHandler& handler) override; |
| 30 void ClearMediaPerceptionSignalHandler() override; |
| 31 void GetDiagnostics(const DiagnosticsCallback& callback) override; |
| 32 |
| 33 // Inherited from DBusClient. |
| 34 void Init(dbus::Bus* bus) override; |
| 35 |
| 36 // Fires a fake media perception event. |
| 37 bool FireMediaPerceptionEvent(const mri::MediaPerception& media_perception); |
| 38 |
| 39 // Sets the object to be returned from GetDiagnostics. |
| 40 void SetDiagnostics(const mri::Diagnostics& diagnostics); |
| 41 |
| 42 void set_process_running(bool running) { process_running_ = running; } |
| 43 |
| 44 bool process_running() const { return process_running_; } |
| 45 |
| 46 private: |
| 47 // Echoes back the previously set state. |
| 48 void OnState(const StateCallback& callback); |
| 49 |
| 50 // Runs callback with the Diagnostics proto provided in SetDiagnostics. |
| 51 void OnGetDiagnostics(const DiagnosticsCallback& callback); |
| 52 |
| 53 // Runs callback with a MediaPerception proto provided in |
| 54 // FireMediaPerceptionEvent. |
| 55 void OnMediaPerception(const mri::MediaPerception& media_perception); |
| 56 |
| 57 // A handler for receiving MediaPerception proto messages. |
| 58 MediaPerceptionSignalHandler media_perception_signal_handler_; |
| 59 |
| 60 // A fake current state for the media analytics process. |
| 61 mri::State current_state_; |
| 62 |
| 63 // A fake diagnostics object to be returned by the GetDiagnostics. |
| 64 mri::Diagnostics diagnostics_; |
| 65 |
| 66 // Whether the fake media analytics was started (for example by the fake |
| 67 // upstart client) - If not set, all requests to this client will fail. |
| 68 bool process_running_; |
| 69 |
| 70 base::WeakPtrFactory<FakeMediaAnalyticsClient> weak_ptr_factory_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(FakeMediaAnalyticsClient); |
| 73 }; |
| 74 |
| 75 } // namespace chromeos |
| 76 |
| 77 #endif // CHROMEOS_DBUS_FAKE_MEDIA_ANALYTICS_CLIENT_H_ |
OLD | NEW |