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

Side by Side Diff: extensions/browser/api/media_perception_private/media_perception_api_manager.h

Issue 2791983004: DBus MediaAnalyticsClient and media_perception pb. (Closed)
Patch Set: Upstart process management 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 #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 mpp = 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 mpp::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 mpp::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 mpp::MediaPerception MediaPerceptionProtoToIdl(
29 const mri::MediaPerception& media_perception);
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 mpp::Diagnostics DiagnosticsProtoToIdl(const mri::Diagnostics& diagnostics);
35
36 class MediaPerceptionAPIManager : public BrowserContextKeyedAPI {
37 public:
38 explicit MediaPerceptionAPIManager(content::BrowserContext* context);
39 ~MediaPerceptionAPIManager() override;
40
41 // Convenience method to get the MediaPeceptionAPIManager for a
42 // BrowserContext.
43 static MediaPerceptionAPIManager* Get(content::BrowserContext* context);
44
45 // BrowserContextKeyedAPI implementation.
46 static BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>*
47 GetFactoryInstance();
48
49 // Public functions for MediaPerceptionPrivateAPI implementation.
50 // Abstracts away D-Bus communication and underlying protos.
51 using APIStateCallback =
52 base::Callback<void(bool succeeded, mpp::State state)>;
53 void GetState(const APIStateCallback& callback);
54 void SetState(const mpp::State& state, const APIStateCallback& callback);
55
56 using APIGetDiagnosticsCallback =
57 base::Callback<void(bool succeeded, mpp::Diagnostics diagnostics)>;
58 void GetDiagnostics(const APIGetDiagnosticsCallback& callback);
59
60 private:
61 friend class BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>;
62
63 // BrowserContextKeyedAPI:
64 static const char* service_name() { return "MediaPerceptionAPIManager"; }
65
66 // Sets the state of the analytics process.
67 void SetStateInternal();
68
69 // Event handler for MediaPerception proto messages coming over D-Bus as
70 // signal.
71 void MediaPerceptionSignalHandler(const uint8_t* bytes, size_t length);
72
73 // Callback for State D-Bus method calls to the media analytics process.
74 void StateCallback(bool succeeded, const uint8_t* bytes, size_t length);
75
76 // Callback for GetDiagnostics D-Bus method calls to the media analytics
77 // process.
78 void GetDiagnosticsCallback(bool succeeded,
79 const uint8_t* bytes,
80 size_t length);
81
82 // Callback for Upstart command to start media analytics process.
83 void UpstartCallback(bool succeeded);
84
85 content::BrowserContext* const browser_context_;
86
87 // Keeps track of whether the analytics process is running so that it can be
88 // started with an Upstart D-Bus method call if necessary.
89 bool analytics_process_running_;
90
91 // Stores the desired state for when its needed in a callback.
92 mri::State desired_state_;
93
94 APIStateCallback api_state_callback_;
95 APIGetDiagnosticsCallback api_get_diagnostics_callback_;
96 };
97
98 } // namespace extensions
99
100 #endif // EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_ MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698