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

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: Removing enums.xml from this change. 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.
tbarzic 2017/05/12 01:00:22 can you add some tests for this? e.g. the flow whe
Luke Sorenson 2017/05/12 17:07:31 Right now the browser API tests cover half of the
tbarzic 2017/05/15 22:05:50 I'd prefer to test those cases in unit_tests - it
Luke Sorenson 2017/05/16 20:29:12 Done.
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 class MediaPerceptionAPIManager : public BrowserContextKeyedAPI {
18 public:
19 explicit MediaPerceptionAPIManager(content::BrowserContext* context);
20 ~MediaPerceptionAPIManager() override;
21
22 // Convenience method to get the MediaPeceptionAPIManager for a
23 // BrowserContext.
24 static MediaPerceptionAPIManager* Get(content::BrowserContext* context);
25
26 // BrowserContextKeyedAPI implementation.
27 static BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>*
28 GetFactoryInstance();
29
30 // Public functions for MediaPerceptionPrivateAPI implementation.
31 // Abstracts away D-Bus communication and underlying protos.
32 using APIStateCallback =
33 base::Callback<void(bool succeeded, media_perception::State state)>;
34 void GetState(const APIStateCallback& callback);
35 void SetState(const media_perception::State& state,
36 const APIStateCallback& callback);
37
38 using APIGetDiagnosticsCallback =
39 base::Callback<void(bool succeeded,
40 media_perception::Diagnostics diagnostics)>;
41 void GetDiagnostics(const APIGetDiagnosticsCallback& callback);
42
43 private:
44 friend class BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>;
45
46 // BrowserContextKeyedAPI:
47 static const char* service_name() { return "MediaPerceptionAPIManager"; }
48
49 // Sets the state of the analytics process.
50 void SetStateInternal(const APIStateCallback& callback,
51 const mri::State& state);
52
53 // Event handler for MediaPerception proto messages coming over D-Bus as
54 // signal.
55 void MediaPerceptionSignalHandler(
56 const mri::MediaPerception& media_perception);
57
58 // Callback for State D-Bus method calls to the media analytics process.
59 void StateCallback(const APIStateCallback& callback,
60 bool succeeded,
61 const mri::State& state);
62
63 // Callback for GetDiagnostics D-Bus method calls to the media analytics
64 // process.
65 void GetDiagnosticsCallback(const APIGetDiagnosticsCallback& callback,
66 bool succeeded,
67 const mri::Diagnostics& diagnostics);
68
69 // Callback for Upstart command to start media analytics process.
70 void UpstartCallback(const APIStateCallback& callback,
71 const mri::State& state,
72 bool succeeded);
73
74 content::BrowserContext* const browser_context_;
75
76 // Keeps track of whether the analytics process is running so that it can be
77 // started with an Upstart D-Bus method call if necessary.
78 bool analytics_process_running_;
79
80 base::WeakPtrFactory<MediaPerceptionAPIManager> weak_ptr_factory_;
81
82 DISALLOW_COPY_AND_ASSIGN(MediaPerceptionAPIManager);
83 };
84
85 } // namespace extensions
86
87 #endif // EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_ MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698