| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/api/media_perception_private/media_perception_priva
te_api.h" | 5 #include "extensions/browser/api/media_perception_private/media_perception_priva
te_api.h" |
| 6 | 6 |
| 7 namespace media_perception = extensions::api::media_perception_private; | |
| 8 | |
| 9 namespace extensions { | 7 namespace extensions { |
| 10 | 8 |
| 11 using CallbackStatus = MediaPerceptionAPIManager::CallbackStatus; | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const char kErrorStringStatusDbusError[] = "Service is unreachable."; | |
| 16 const char kErrorStringStatusIdle[] = "Service is not running."; | |
| 17 const char kErrorStringStatusLaunching[] = "Service busy launching."; | |
| 18 | |
| 19 std::string CallbackStatusToErrorMessage(const CallbackStatus& status) { | |
| 20 switch (status) { | |
| 21 case CallbackStatus::DBUS_ERROR: | |
| 22 return kErrorStringStatusDbusError; | |
| 23 case CallbackStatus::PROCESS_IDLE_ERROR: | |
| 24 return kErrorStringStatusIdle; | |
| 25 case CallbackStatus::PROCESS_LAUNCHING_ERROR: | |
| 26 return kErrorStringStatusLaunching; | |
| 27 case CallbackStatus::SUCCESS: | |
| 28 return "CallbackStatus success."; | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 MediaPerceptionPrivateGetStateFunction :: | 9 MediaPerceptionPrivateGetStateFunction :: |
| 35 MediaPerceptionPrivateGetStateFunction() {} | 10 MediaPerceptionPrivateGetStateFunction() {} |
| 36 | 11 |
| 37 MediaPerceptionPrivateGetStateFunction :: | 12 MediaPerceptionPrivateGetStateFunction :: |
| 38 ~MediaPerceptionPrivateGetStateFunction() {} | 13 ~MediaPerceptionPrivateGetStateFunction() {} |
| 39 | 14 |
| 40 ExtensionFunction::ResponseAction | 15 ExtensionFunction::ResponseAction |
| 41 MediaPerceptionPrivateGetStateFunction::Run() { | 16 MediaPerceptionPrivateGetStateFunction::Run() { |
| 42 MediaPerceptionAPIManager* manager = | 17 return RespondNow(Error("Not implemented.")); |
| 43 MediaPerceptionAPIManager::Get(browser_context()); | |
| 44 manager->GetState(base::Bind( | |
| 45 &MediaPerceptionPrivateGetStateFunction::GetStateCallback, this)); | |
| 46 return RespondLater(); | |
| 47 } | |
| 48 | |
| 49 void MediaPerceptionPrivateGetStateFunction::GetStateCallback( | |
| 50 CallbackStatus status, | |
| 51 media_perception::State state) { | |
| 52 if (status != CallbackStatus::SUCCESS) { | |
| 53 Respond(Error(CallbackStatusToErrorMessage(status))); | |
| 54 return; | |
| 55 } | |
| 56 Respond(OneArgument(state.ToValue())); | |
| 57 } | 18 } |
| 58 | 19 |
| 59 MediaPerceptionPrivateSetStateFunction :: | 20 MediaPerceptionPrivateSetStateFunction :: |
| 60 MediaPerceptionPrivateSetStateFunction() {} | 21 MediaPerceptionPrivateSetStateFunction() {} |
| 61 | 22 |
| 62 MediaPerceptionPrivateSetStateFunction :: | 23 MediaPerceptionPrivateSetStateFunction :: |
| 63 ~MediaPerceptionPrivateSetStateFunction() {} | 24 ~MediaPerceptionPrivateSetStateFunction() {} |
| 64 | 25 |
| 65 ExtensionFunction::ResponseAction | 26 ExtensionFunction::ResponseAction |
| 66 MediaPerceptionPrivateSetStateFunction::Run() { | 27 MediaPerceptionPrivateSetStateFunction::Run() { |
| 67 std::unique_ptr<media_perception::SetState::Params> params = | 28 return RespondNow(Error("Not implemented.")); |
| 68 media_perception::SetState::Params::Create(*args_); | |
| 69 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
| 70 if (params->state.status != media_perception::STATUS_RUNNING && | |
| 71 params->state.status != media_perception::STATUS_SUSPENDED) { | |
| 72 return RespondNow( | |
| 73 Error("Status can only be set to RUNNING and SUSPENDED.")); | |
| 74 } | |
| 75 | |
| 76 // Check that device context is only provided with SetState RUNNING. | |
| 77 if (params->state.status != media_perception::STATUS_RUNNING && | |
| 78 params->state.device_context.get() != nullptr) { | |
| 79 return RespondNow( | |
| 80 Error("Only provide deviceContext with SetState RUNNING.")); | |
| 81 } | |
| 82 MediaPerceptionAPIManager* manager = | |
| 83 MediaPerceptionAPIManager::Get(browser_context()); | |
| 84 manager->SetState( | |
| 85 params->state, | |
| 86 base::Bind(&MediaPerceptionPrivateSetStateFunction::SetStateCallback, | |
| 87 this)); | |
| 88 return RespondLater(); | |
| 89 } | |
| 90 | |
| 91 void MediaPerceptionPrivateSetStateFunction::SetStateCallback( | |
| 92 CallbackStatus status, | |
| 93 media_perception::State state) { | |
| 94 if (status != CallbackStatus::SUCCESS) { | |
| 95 Respond(Error(CallbackStatusToErrorMessage(status))); | |
| 96 return; | |
| 97 } | |
| 98 Respond(OneArgument(state.ToValue())); | |
| 99 } | 29 } |
| 100 | 30 |
| 101 MediaPerceptionPrivateGetDiagnosticsFunction :: | 31 MediaPerceptionPrivateGetDiagnosticsFunction :: |
| 102 MediaPerceptionPrivateGetDiagnosticsFunction() {} | 32 MediaPerceptionPrivateGetDiagnosticsFunction() {} |
| 103 | 33 |
| 104 MediaPerceptionPrivateGetDiagnosticsFunction :: | 34 MediaPerceptionPrivateGetDiagnosticsFunction :: |
| 105 ~MediaPerceptionPrivateGetDiagnosticsFunction() {} | 35 ~MediaPerceptionPrivateGetDiagnosticsFunction() {} |
| 106 | 36 |
| 107 ExtensionFunction::ResponseAction | 37 ExtensionFunction::ResponseAction |
| 108 MediaPerceptionPrivateGetDiagnosticsFunction::Run() { | 38 MediaPerceptionPrivateGetDiagnosticsFunction::Run() { |
| 109 MediaPerceptionAPIManager* manager = | 39 return RespondNow(Error("Not implemented.")); |
| 110 MediaPerceptionAPIManager::Get(browser_context()); | |
| 111 manager->GetDiagnostics(base::Bind( | |
| 112 &MediaPerceptionPrivateGetDiagnosticsFunction::GetDiagnosticsCallback, | |
| 113 this)); | |
| 114 return RespondLater(); | |
| 115 } | |
| 116 | |
| 117 void MediaPerceptionPrivateGetDiagnosticsFunction::GetDiagnosticsCallback( | |
| 118 CallbackStatus status, | |
| 119 media_perception::Diagnostics diagnostics) { | |
| 120 if (status != CallbackStatus::SUCCESS) { | |
| 121 Respond(Error(CallbackStatusToErrorMessage(status))); | |
| 122 return; | |
| 123 } | |
| 124 Respond(OneArgument(diagnostics.ToValue())); | |
| 125 } | 40 } |
| 126 | 41 |
| 127 } // namespace extensions | 42 } // namespace extensions |
| OLD | NEW |