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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/media_perception_private/media_perception_api_manager.h
diff --git a/extensions/browser/api/media_perception_private/media_perception_api_manager.h b/extensions/browser/api/media_perception_private/media_perception_api_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..2783e22e7c6d29cda505afb282e7cb7a8ad023d6
--- /dev/null
+++ b/extensions/browser/api/media_perception_private/media_perception_api_manager.h
@@ -0,0 +1,87 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// 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.
+
+#ifndef EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_MANAGER_H_
+#define EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_MANAGER_H_
+
+#include "base/memory/weak_ptr.h"
+#include "chromeos/media_perception/media_perception.pb.h"
+#include "extensions/browser/browser_context_keyed_api_factory.h"
+#include "extensions/common/api/media_perception_private.h"
+
+namespace media_perception = extensions::api::media_perception_private;
+
+namespace extensions {
+
+class MediaPerceptionAPIManager : public BrowserContextKeyedAPI {
+ public:
+ explicit MediaPerceptionAPIManager(content::BrowserContext* context);
+ ~MediaPerceptionAPIManager() override;
+
+ // Convenience method to get the MediaPeceptionAPIManager for a
+ // BrowserContext.
+ static MediaPerceptionAPIManager* Get(content::BrowserContext* context);
+
+ // BrowserContextKeyedAPI implementation.
+ static BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>*
+ GetFactoryInstance();
+
+ // Public functions for MediaPerceptionPrivateAPI implementation.
+ // Abstracts away D-Bus communication and underlying protos.
+ using APIStateCallback =
+ base::Callback<void(bool succeeded, media_perception::State state)>;
+ void GetState(const APIStateCallback& callback);
+ void SetState(const media_perception::State& state,
+ const APIStateCallback& callback);
+
+ using APIGetDiagnosticsCallback =
+ base::Callback<void(bool succeeded,
+ media_perception::Diagnostics diagnostics)>;
+ void GetDiagnostics(const APIGetDiagnosticsCallback& callback);
+
+ private:
+ friend class BrowserContextKeyedAPIFactory<MediaPerceptionAPIManager>;
+
+ // BrowserContextKeyedAPI:
+ static const char* service_name() { return "MediaPerceptionAPIManager"; }
+
+ // Sets the state of the analytics process.
+ void SetStateInternal(const APIStateCallback& callback,
+ const mri::State& state);
+
+ // Event handler for MediaPerception proto messages coming over D-Bus as
+ // signal.
+ void MediaPerceptionSignalHandler(
+ const mri::MediaPerception& media_perception);
+
+ // Callback for State D-Bus method calls to the media analytics process.
+ void StateCallback(const APIStateCallback& callback,
+ bool succeeded,
+ const mri::State& state);
+
+ // Callback for GetDiagnostics D-Bus method calls to the media analytics
+ // process.
+ void GetDiagnosticsCallback(const APIGetDiagnosticsCallback& callback,
+ bool succeeded,
+ const mri::Diagnostics& diagnostics);
+
+ // Callback for Upstart command to start media analytics process.
+ void UpstartCallback(const APIStateCallback& callback,
+ const mri::State& state,
+ bool succeeded);
+
+ content::BrowserContext* const browser_context_;
+
+ // Keeps track of whether the analytics process is running so that it can be
+ // started with an Upstart D-Bus method call if necessary.
+ bool analytics_process_running_;
+
+ base::WeakPtrFactory<MediaPerceptionAPIManager> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(MediaPerceptionAPIManager);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698