| 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..9d24728f34f5040048db44e020a2bbe1c3d0878c
|
| --- /dev/null
|
| +++ b/extensions/browser/api/media_perception_private/media_perception_api_manager.h
|
| @@ -0,0 +1,100 @@
|
| +// 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 mpp = 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.
|
| +mpp::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 mpp::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.
|
| +mpp::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.
|
| +mpp::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, mpp::State state)>;
|
| + void GetState(const APIStateCallback& callback);
|
| + void SetState(const mpp::State& state, const APIStateCallback& callback);
|
| +
|
| + using APIGetDiagnosticsCallback =
|
| + base::Callback<void(bool succeeded, mpp::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();
|
| +
|
| + // Event handler for MediaPerception proto messages coming over D-Bus as
|
| + // signal.
|
| + void MediaPerceptionSignalHandler(const uint8_t* bytes, size_t length);
|
| +
|
| + // Callback for State D-Bus method calls to the media analytics process.
|
| + void StateCallback(bool succeeded, const uint8_t* bytes, size_t length);
|
| +
|
| + // Callback for GetDiagnostics D-Bus method calls to the media analytics
|
| + // process.
|
| + void GetDiagnosticsCallback(bool succeeded,
|
| + const uint8_t* bytes,
|
| + size_t length);
|
| +
|
| + // Callback for Upstart command to start media analytics process.
|
| + void UpstartCallback(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_;
|
| +
|
| + // Stores the desired state for when its needed in a callback.
|
| + mri::State desired_state_;
|
| +
|
| + APIStateCallback api_state_callback_;
|
| + APIGetDiagnosticsCallback api_get_diagnostics_callback_;
|
| +};
|
| +
|
| +} // namespace extensions
|
| +
|
| +#endif // EXTENSIONS_BROWSER_API_MEDIA_PERCEPTION_PRIVATE_MEDIA_PERCEPTION_API_MANAGER_H_
|
|
|