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 #ifndef EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_MAN AGER_H_ | |
| 6 #define EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_MAN AGER_H_ | |
| 7 | |
| 8 #include "chromeos/media_perception/media_perception.pb.h" | |
| 9 #include "extensions/browser/browser_context_keyed_api_factory.h" | |
| 10 #include "extensions/common/api/media_perception_private.h" | |
| 11 | |
| 12 namespace media_perception = extensions::api::media_perception_private; | |
| 13 | |
| 14 namespace extensions { | |
| 15 | |
| 16 // Converts State proto messages to State objects (generated by the | |
| 17 // media_perception_private.idl) to be returned to the JavaScript frontend. | |
| 18 media_perception::State StateProtoToIdl(const mri::State& state); | |
| 19 | |
| 20 // Converts State objects (generated by the media_perception_private.idl) to | |
| 21 // State proto messages to be sent over D-Bus. | |
| 22 mri::State StateIdlToProto(const media_perception::State& state); | |
| 23 | |
| 24 // Converts incoming (over D-Bus channel) MediaPerception proto messages | |
| 25 // to MediaPerception objects (generated by the | |
| 26 // media_perception_private.idl) to be broadcasted as events to the | |
| 27 // JavaScript frontend. | |
| 28 media_perception::MediaPerception MediaPerceptionProtoToIdl( | |
| 29 const mri::MediaPerception& media_perception); | |
|
tbarzic
2017/05/09 01:28:37
if you want to make these public, maybe moove them
Luke Sorenson
2017/05/09 21:05:45
Moving to separate files.
| |
| 30 | |
| 31 // Converts Diagnostics proto messages to Diagnostics objects (generated by the | |
| 32 // media_perception_private.idl) to be returned to the JavaScript frontend as a | |
| 33 // callback. | |
| 34 media_perception::Diagnostics DiagnosticsProtoToIdl( | |
| 35 const mri::Diagnostics& diagnostics); | |
| 36 | |
| 37 class MediaPerceptionAPIManager : public BrowserContextKeyedAPI { | |
| 38 public: | |
| 39 explicit MediaPerceptionAPIManager(content::BrowserContext* context); | |
| 40 ~MediaPerceptionAPIManager() override; | |
| 41 | |
| 42 // Convenience method to get the MediaPeceptionAPIManager for a | |
| 43 // BrowserContext. | |
| 44 static MediaPerceptionAPIManager* Get(content::BrowserContext* context); | |
| 45 | |
| 46 // BrowserContextKeyedAPI implementation. | |
| 47 static BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>* | |
| 48 GetFactoryInstance(); | |
| 49 | |
| 50 // Public functions for MediaPerceptionPrivateAPI implementation. | |
| 51 // Abstracts away D-Bus communication and underlying protos. | |
| 52 using APIStateCallback = | |
| 53 base::Callback<void(bool succeeded, media_perception::State state)>; | |
| 54 void GetState(const APIStateCallback& callback); | |
| 55 void SetState(const media_perception::State& state, | |
| 56 const APIStateCallback& callback); | |
| 57 | |
| 58 using APIGetDiagnosticsCallback = | |
| 59 base::Callback<void(bool succeeded, | |
| 60 media_perception::Diagnostics diagnostics)>; | |
| 61 void GetDiagnostics(const APIGetDiagnosticsCallback& callback); | |
| 62 | |
| 63 private: | |
| 64 friend class BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>; | |
| 65 | |
| 66 // BrowserContextKeyedAPI: | |
| 67 static const char* service_name() { return "MediaPerceptionAPIManager"; } | |
| 68 | |
| 69 // Sets the state of the analytics process. | |
| 70 void SetStateInternal(const APIStateCallback& callback, | |
| 71 const mri::State& state); | |
| 72 | |
| 73 // Event handler for MediaPerception proto messages coming over D-Bus as | |
| 74 // signal. | |
| 75 void MediaPerceptionSignalHandler( | |
| 76 const mri::MediaPerception& media_perception); | |
| 77 | |
| 78 // Callback for State D-Bus method calls to the media analytics process. | |
| 79 void StateCallback(const APIStateCallback& callback, | |
| 80 bool succeeded, | |
| 81 const mri::State& state); | |
| 82 | |
| 83 // Callback for GetDiagnostics D-Bus method calls to the media analytics | |
| 84 // process. | |
| 85 void GetDiagnosticsCallback(const APIGetDiagnosticsCallback& callback, | |
| 86 bool succeeded, | |
| 87 const mri::Diagnostics& diagnostics); | |
| 88 | |
| 89 // Callback for Upstart command to start media analytics process. | |
| 90 void UpstartCallback(const APIStateCallback& callback, | |
| 91 const mri::State& state, | |
| 92 bool succeeded); | |
| 93 | |
| 94 content::BrowserContext* const browser_context_; | |
| 95 | |
| 96 // Keeps track of whether the analytics process is running so that it can be | |
| 97 // started with an Upstart D-Bus method call if necessary. | |
| 98 bool analytics_process_running_; | |
|
tbarzic
2017/05/09 01:28:37
disallow copy and assign
Luke Sorenson
2017/05/09 21:05:45
Done.
| |
| 99 }; | |
| 100 | |
| 101 } // namespace extensions | |
| 102 | |
| 103 #endif // EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_ MANAGER_H_ | |
| OLD | NEW |