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