| Index: extensions/browser/api/media_perception_private/media_perception_private_api.cc
|
| diff --git a/extensions/browser/api/media_perception_private/media_perception_private_api.cc b/extensions/browser/api/media_perception_private/media_perception_private_api.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b1a182892377bf00c07bd78517e915c59adc8b0b
|
| --- /dev/null
|
| +++ b/extensions/browser/api/media_perception_private/media_perception_private_api.cc
|
| @@ -0,0 +1,108 @@
|
| +// 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.
|
| +
|
| +#include "extensions/browser/api/media_perception_private/media_perception_private_api.h"
|
| +
|
| +#include "extensions/browser/api/media_perception_private/media_perception_api_manager.h"
|
| +#include "extensions/browser/extension_function.h"
|
| +
|
| +namespace mpp = extensions::api::media_perception_private;
|
| +
|
| +namespace extensions {
|
| +
|
| +MediaPerceptionPrivateGetStateFunction ::
|
| + MediaPerceptionPrivateGetStateFunction() {}
|
| +
|
| +MediaPerceptionPrivateGetStateFunction ::
|
| + ~MediaPerceptionPrivateGetStateFunction() {}
|
| +
|
| +bool MediaPerceptionPrivateGetStateFunction::RunAsync() {
|
| + MediaPerceptionAPIManager* manager =
|
| + MediaPerceptionAPIManager::Get(browser_context());
|
| + if (!manager) {
|
| + SetError("Can't get manager.");
|
| + return false;
|
| + }
|
| + manager->GetState(base::Bind(
|
| + &MediaPerceptionPrivateGetStateFunction::GetStateCallback, this));
|
| + return true;
|
| +}
|
| +
|
| +void MediaPerceptionPrivateGetStateFunction::GetStateCallback(
|
| + bool succeeded,
|
| + mpp::State state) {
|
| + if (!succeeded) {
|
| + SendResponse(false);
|
| + return;
|
| + }
|
| + SetResult(state.ToValue());
|
| + SendResponse(true);
|
| +}
|
| +
|
| +MediaPerceptionPrivateSetStateFunction ::
|
| + MediaPerceptionPrivateSetStateFunction() {}
|
| +
|
| +MediaPerceptionPrivateSetStateFunction ::
|
| + ~MediaPerceptionPrivateSetStateFunction() {}
|
| +
|
| +bool MediaPerceptionPrivateSetStateFunction::RunAsync() {
|
| + std::unique_ptr<mpp::SetState::Params> params =
|
| + mpp::SetState::Params::Create(*args_);
|
| + EXTENSION_FUNCTION_VALIDATE(params.get());
|
| + // Test triggering an onMediaPerception event.
|
| + MediaPerceptionAPIManager* manager =
|
| + MediaPerceptionAPIManager::Get(browser_context());
|
| + if (!manager) {
|
| + SetError("Can't get manager.");
|
| + return false;
|
| + }
|
| + manager->SetState(
|
| + params->state,
|
| + base::Bind(&MediaPerceptionPrivateSetStateFunction::SetStateCallback,
|
| + this));
|
| + return true;
|
| +}
|
| +
|
| +void MediaPerceptionPrivateSetStateFunction::SetStateCallback(
|
| + bool succeeded,
|
| + mpp::State state) {
|
| + if (!succeeded) {
|
| + SendResponse(false);
|
| + return;
|
| + }
|
| + SetResult(state.ToValue());
|
| + SendResponse(true);
|
| +}
|
| +
|
| +MediaPerceptionPrivateGetDiagnosticsFunction ::
|
| + MediaPerceptionPrivateGetDiagnosticsFunction() {}
|
| +
|
| +MediaPerceptionPrivateGetDiagnosticsFunction ::
|
| + ~MediaPerceptionPrivateGetDiagnosticsFunction() {}
|
| +
|
| +bool MediaPerceptionPrivateGetDiagnosticsFunction::RunAsync() {
|
| + MediaPerceptionAPIManager* manager =
|
| + MediaPerceptionAPIManager::Get(browser_context());
|
| + if (!manager) {
|
| + SetError("Can't get manager.");
|
| + return false;
|
| + }
|
| + manager->GetDiagnostics(base::Bind(
|
| + &MediaPerceptionPrivateGetDiagnosticsFunction::GetDiagnosticsCallback,
|
| + this));
|
| + return true;
|
| +}
|
| +
|
| +void MediaPerceptionPrivateGetDiagnosticsFunction::GetDiagnosticsCallback(
|
| + bool succeeded,
|
| + mpp::Diagnostics diagnostics) {
|
| + if (!succeeded) {
|
| + SendResponse(false);
|
| + return;
|
| + }
|
| + SetResult(diagnostics.ToValue());
|
| + SendResponse(true);
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|