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 "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 explicit MediaPerceptionAPIManager(content::BrowserContext* context); | |
18 ~MediaPerceptionAPIManager() override; | |
19 | |
20 enum class CallbackStatus { | |
tbarzic
2017/05/19 03:16:16
nit: move this before ctor/dtor
Luke Sorenson
2017/05/19 13:41:57
Done.
| |
21 // Request to media analytics process was successful. | |
22 SUCCESS, | |
23 // Request to media analytics process failed at D-Bus layer. | |
24 DBUS_ERROR, | |
25 // The media analytics process is not running. | |
26 PROCESS_IDLE_ERROR, | |
27 // The media analytics process has been launched via Upstart, but waiting | |
tbarzic
2017/05/19 03:16:16
nit: The media analytics process is still being la
Luke Sorenson
2017/05/19 13:41:57
Done.
| |
28 // for callback to confirm. | |
29 PROCESS_LAUNCHING_ERROR | |
30 }; | |
31 | |
32 // Convenience method to get the MediaPeceptionAPIManager for a | |
33 // BrowserContext. | |
34 static MediaPerceptionAPIManager* Get(content::BrowserContext* context); | |
35 | |
36 // BrowserContextKeyedAPI implementation. | |
37 static BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>* | |
38 GetFactoryInstance(); | |
39 | |
40 // Public functions for MediaPerceptionPrivateAPI implementation. | |
41 using APIStateCallback = base::Callback<void( | |
tbarzic
2017/05/19 03:16:16
nit: callback typedefs up, after enums
Luke Sorenson
2017/05/19 13:41:57
Done.
| |
42 CallbackStatus status, | |
43 extensions::api::media_perception_private::State state)>; | |
44 void GetState(const APIStateCallback& callback); | |
45 void SetState(const extensions::api::media_perception_private::State& state, | |
46 const APIStateCallback& callback); | |
47 | |
48 using APIGetDiagnosticsCallback = base::Callback<void( | |
49 CallbackStatus status, | |
50 extensions::api::media_perception_private::Diagnostics diagnostics)>; | |
51 void GetDiagnostics(const APIGetDiagnosticsCallback& callback); | |
52 | |
53 private: | |
54 friend class BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>; | |
55 | |
56 // BrowserContextKeyedAPI: | |
57 static const char* service_name() { return "MediaPerceptionAPIManager"; } | |
58 | |
59 enum class AnalyticsProcessState { | |
60 // The process is not running. | |
61 IDLE, | |
62 // The process has been launched via Upstart, but waiting for callback to | |
63 // confirm. | |
64 LAUNCHING, | |
65 // The process is running. | |
66 RUNNING | |
67 }; | |
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 AnalyticsProcessState analytics_process_state_; | |
99 | |
100 base::WeakPtrFactory<MediaPerceptionAPIManager> weak_ptr_factory_; | |
101 | |
102 DISALLOW_COPY_AND_ASSIGN(MediaPerceptionAPIManager); | |
103 }; | |
104 | |
105 } // namespace extensions | |
106 | |
107 #endif // EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_ MANAGER_H_ | |
OLD | NEW |