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

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

Issue 2858353002: MediaPerceptionPrivate API impl and testing. (Closed)
Patch Set: Added media_perception_proto as direct dependency of test targets. 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 "base/memory/weak_ptr.h"
9 #include "chromeos/media_perception/media_perception.pb.h"
10 #include "extensions/browser/browser_context_keyed_api_factory.h"
11 #include "extensions/common/api/media_perception_private.h"
12
13 namespace extensions {
14
15 class MediaPerceptionAPIManager : public BrowserContextKeyedAPI {
16 public:
17 enum class CallbackStatus {
18 // Request to media analytics process was successful.
19 SUCCESS,
20 // Request to media analytics process failed at D-Bus layer.
21 DBUS_ERROR,
22 // The media analytics process is not running.
23 PROCESS_IDLE_ERROR,
24 // The media analytics process is still being launched via Upstart
25 // service.
26 PROCESS_LAUNCHING_ERROR
27 };
28
29 using APIStateCallback = base::Callback<void(
30 CallbackStatus status,
31 extensions::api::media_perception_private::State state)>;
32
33 using APIGetDiagnosticsCallback = base::Callback<void(
34 CallbackStatus status,
35 extensions::api::media_perception_private::Diagnostics diagnostics)>;
36
37 explicit MediaPerceptionAPIManager(content::BrowserContext* context);
38 ~MediaPerceptionAPIManager() override;
39
40 // Convenience method to get the MediaPeceptionAPIManager for a
41 // BrowserContext.
42 static MediaPerceptionAPIManager* Get(content::BrowserContext* context);
43
44 // BrowserContextKeyedAPI implementation.
45 static BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>*
46 GetFactoryInstance();
47
48 // Public functions for MediaPerceptionPrivateAPI implementation.
49 void GetState(const APIStateCallback& callback);
50 void SetState(const extensions::api::media_perception_private::State& state,
51 const APIStateCallback& callback);
52 void GetDiagnostics(const APIGetDiagnosticsCallback& callback);
53
54 private:
55 friend class BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>;
56
57 // BrowserContextKeyedAPI:
58 static const char* service_name() { return "MediaPerceptionAPIManager"; }
59
60 enum class AnalyticsProcessState {
61 // The process is not running.
62 IDLE,
63 // The process has been launched via Upstart, but waiting for callback to
64 // confirm.
65 LAUNCHING,
66 // The process is running.
67 RUNNING
68 };
69
70 // Sets the state of the analytics process.
71 void SetStateInternal(const APIStateCallback& callback,
72 const mri::State& state);
73
74 // Event handler for MediaPerception proto messages coming over D-Bus as
75 // signal.
76 void MediaPerceptionSignalHandler(
77 const mri::MediaPerception& media_perception);
78
79 // Callback for State D-Bus method calls to the media analytics process.
80 void StateCallback(const APIStateCallback& callback,
81 bool succeeded,
82 const mri::State& state);
83
84 // Callback for GetDiagnostics D-Bus method calls to the media analytics
85 // process.
86 void GetDiagnosticsCallback(const APIGetDiagnosticsCallback& callback,
87 bool succeeded,
88 const mri::Diagnostics& diagnostics);
89
90 // Callback for Upstart command to start media analytics process.
91 void UpstartCallback(const APIStateCallback& callback,
92 const mri::State& state,
93 bool succeeded);
94
95 content::BrowserContext* const browser_context_;
96
97 // Keeps track of whether the analytics process is running so that it can be
98 // started with an Upstart D-Bus method call if necessary.
99 AnalyticsProcessState analytics_process_state_;
100
101 base::WeakPtrFactory<MediaPerceptionAPIManager> weak_ptr_factory_;
102
103 DISALLOW_COPY_AND_ASSIGN(MediaPerceptionAPIManager);
104 };
105
106 } // namespace extensions
107
108 #endif // EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_ MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698