| 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..7ddef85e509334b8e3e3633aeacf6e486f78a0b6
|
| --- /dev/null
|
| +++ b/extensions/browser/api/media_perception_private/media_perception_api_manager.h
|
| @@ -0,0 +1,103 @@
|
| +// 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.
|
| +
|
| +#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 "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 {
|
| +
|
| +// Converts State proto messages to State objects (generated by the
|
| +// media_perception_private.idl) to be returned to the JavaScript frontend.
|
| +media_perception::State StateProtoToIdl(const mri::State& state);
|
| +
|
| +// Converts State objects (generated by the media_perception_private.idl) to
|
| +// State proto messages to be sent over D-Bus.
|
| +mri::State StateIdlToProto(const media_perception::State& state);
|
| +
|
| +// Converts incoming (over D-Bus channel) MediaPerception proto messages
|
| +// to MediaPerception objects (generated by the
|
| +// media_perception_private.idl) to be broadcasted as events to the
|
| +// JavaScript frontend.
|
| +media_perception::MediaPerception MediaPerceptionProtoToIdl(
|
| + const mri::MediaPerception& media_perception);
|
| +
|
| +// Converts Diagnostics proto messages to Diagnostics objects (generated by the
|
| +// media_perception_private.idl) to be returned to the JavaScript frontend as a
|
| +// callback.
|
| +media_perception::Diagnostics DiagnosticsProtoToIdl(
|
| + const mri::Diagnostics& diagnostics);
|
| +
|
| +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_;
|
| +};
|
| +
|
| +} // namespace extensions
|
| +
|
| +#endif // EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_MANAGER_H_
|
|
|