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..799d6d034157bb66574ae2f17233aa08848b3837 |
--- /dev/null |
+++ b/extensions/browser/api/media_perception_private/media_perception_private_api.cc |
@@ -0,0 +1,61 @@ |
+// 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" |
+ |
+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; |
+ } |
+ mpp::State result; |
+ result.status = manager->status_; |
+ SetResult(result.ToValue()); |
+ SendResponse(true); |
+ return 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()); |
+ const auto& status = params->state.status; |
+ // Test triggering an onMediaPerception event. |
+ MediaPerceptionAPIManager* manager = |
+ MediaPerceptionAPIManager::Get(browser_context()); |
+ if (!manager) { |
+ SetError("Can't get manager"); |
+ return false; |
+ } |
+ manager->TriggerOnMediaPerceptionEvent(); |
+ manager->status_ = status; |
+ // Echo the status right back. |
+ mpp::State result; |
+ result.status = manager->status_; |
+ SetResult(result.ToValue()); |
+ SendResponse(true); |
+ return true; |
+} |
+ |
+} // namespace extensions |