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

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: Implemented CallbackStatus enum, AnalyticsProcessState enum, and addressed 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 media_perception = extensions::api::media_perception_private;
14
15 namespace extensions {
16
17 enum CallbackStatus {
tbarzic 2017/05/12 18:59:20 use enum class extension::CallbackStatus is very
Luke Sorenson 2017/05/12 21:56:21 Done.
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,
tbarzic 2017/05/12 18:59:20 nit: I'd add ERROR as name prefix or suffix - to m
Luke Sorenson 2017/05/12 21:56:21 Done.
24 // The media analytics process has been launched via Upstart, but waiting for
25 // callback to confirm.
26 PROCESS_LAUNCHING
27 };
28
29 namespace {
30
31 enum AnalyticsProcessState {
tbarzic 2017/05/12 18:59:20 enum class also, make this private member of Medi
Luke Sorenson 2017/05/12 21:56:21 Done.
32 // The process is not running.
33 IDLE,
34 // The process has been launched via Upstart, but waiting for callback to
35 // confirm.
36 LAUNCHING,
37 // The process is running.
38 RUNNING
39 };
40 }
41
42 class MediaPerceptionAPIManager : public BrowserContextKeyedAPI {
43 public:
44 explicit MediaPerceptionAPIManager(content::BrowserContext* context);
45 ~MediaPerceptionAPIManager() override;
46
47 // Convenience method to get the MediaPeceptionAPIManager for a
48 // BrowserContext.
49 static MediaPerceptionAPIManager* Get(content::BrowserContext* context);
50
51 // BrowserContextKeyedAPI implementation.
52 static BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>*
53 GetFactoryInstance();
54
55 // Public functions for MediaPerceptionPrivateAPI implementation.
56 // Abstracts away D-Bus communication and underlying protos.
57 using APIStateCallback = base::Callback<void(CallbackStatus status,
58 media_perception::State state)>;
59 void GetState(const APIStateCallback& callback);
60 void SetState(const media_perception::State& state,
61 const APIStateCallback& callback);
62
63 using APIGetDiagnosticsCallback =
64 base::Callback<void(CallbackStatus status,
65 media_perception::Diagnostics diagnostics)>;
66 void GetDiagnostics(const APIGetDiagnosticsCallback& callback);
67
68 private:
69 friend class BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>;
70
71 // BrowserContextKeyedAPI:
72 static const char* service_name() { return "MediaPerceptionAPIManager"; }
73
74 // Sets the state of the analytics process.
75 void SetStateInternal(const APIStateCallback& callback,
76 const mri::State& state);
77
78 // Event handler for MediaPerception proto messages coming over D-Bus as
79 // signal.
80 void MediaPerceptionSignalHandler(
81 const mri::MediaPerception& media_perception);
82
83 // Callback for State D-Bus method calls to the media analytics process.
84 void StateCallback(const APIStateCallback& callback,
85 bool succeeded,
86 const mri::State& state);
87
88 // Callback for GetDiagnostics D-Bus method calls to the media analytics
89 // process.
90 void GetDiagnosticsCallback(const APIGetDiagnosticsCallback& callback,
91 bool succeeded,
92 const mri::Diagnostics& diagnostics);
93
94 // Callback for Upstart command to start media analytics process.
95 void UpstartCallback(const APIStateCallback& callback,
96 const mri::State& state,
97 bool succeeded);
98
99 content::BrowserContext* const browser_context_;
100
101 // Keeps track of whether the analytics process is running so that it can be
102 // started with an Upstart D-Bus method call if necessary.
103 AnalyticsProcessState analytics_process_state_;
104
105 base::WeakPtrFactory<MediaPerceptionAPIManager> weak_ptr_factory_;
106
107 DISALLOW_COPY_AND_ASSIGN(MediaPerceptionAPIManager);
108 };
109
110 } // namespace extensions
111
112 #endif // EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_ MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698