Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: extensions/browser/api/media_perception_private/media_perception_private_api.cc

Issue 2901983003: Reland of MediaPerceptionPrivate API impl and testing. (Closed)
Patch Set: Fixing compile error, missing return value. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
7 namespace extensions { 9 namespace extensions {
8 10
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 NOTREACHED() << "Reached CallbackStatus not in switch.";
31 return "CallbackStatus string not found.";
32 }
33
34 } // namespace
35
9 MediaPerceptionPrivateGetStateFunction :: 36 MediaPerceptionPrivateGetStateFunction ::
10 MediaPerceptionPrivateGetStateFunction() {} 37 MediaPerceptionPrivateGetStateFunction() {}
11 38
12 MediaPerceptionPrivateGetStateFunction :: 39 MediaPerceptionPrivateGetStateFunction ::
13 ~MediaPerceptionPrivateGetStateFunction() {} 40 ~MediaPerceptionPrivateGetStateFunction() {}
14 41
15 ExtensionFunction::ResponseAction 42 ExtensionFunction::ResponseAction
16 MediaPerceptionPrivateGetStateFunction::Run() { 43 MediaPerceptionPrivateGetStateFunction::Run() {
17 return RespondNow(Error("Not implemented.")); 44 MediaPerceptionAPIManager* manager =
45 MediaPerceptionAPIManager::Get(browser_context());
46 manager->GetState(base::Bind(
47 &MediaPerceptionPrivateGetStateFunction::GetStateCallback, this));
48 return RespondLater();
49 }
50
51 void MediaPerceptionPrivateGetStateFunction::GetStateCallback(
52 CallbackStatus status,
53 media_perception::State state) {
54 if (status != CallbackStatus::SUCCESS) {
55 Respond(Error(CallbackStatusToErrorMessage(status)));
56 return;
57 }
58 Respond(OneArgument(state.ToValue()));
18 } 59 }
19 60
20 MediaPerceptionPrivateSetStateFunction :: 61 MediaPerceptionPrivateSetStateFunction ::
21 MediaPerceptionPrivateSetStateFunction() {} 62 MediaPerceptionPrivateSetStateFunction() {}
22 63
23 MediaPerceptionPrivateSetStateFunction :: 64 MediaPerceptionPrivateSetStateFunction ::
24 ~MediaPerceptionPrivateSetStateFunction() {} 65 ~MediaPerceptionPrivateSetStateFunction() {}
25 66
26 ExtensionFunction::ResponseAction 67 ExtensionFunction::ResponseAction
27 MediaPerceptionPrivateSetStateFunction::Run() { 68 MediaPerceptionPrivateSetStateFunction::Run() {
28 return RespondNow(Error("Not implemented.")); 69 std::unique_ptr<media_perception::SetState::Params> params =
70 media_perception::SetState::Params::Create(*args_);
71 EXTENSION_FUNCTION_VALIDATE(params.get());
72 if (params->state.status != media_perception::STATUS_RUNNING &&
73 params->state.status != media_perception::STATUS_SUSPENDED) {
74 return RespondNow(
75 Error("Status can only be set to RUNNING and SUSPENDED."));
76 }
77
78 // Check that device context is only provided with SetState RUNNING.
79 if (params->state.status != media_perception::STATUS_RUNNING &&
80 params->state.device_context.get() != nullptr) {
81 return RespondNow(
82 Error("Only provide deviceContext with SetState RUNNING."));
83 }
84 MediaPerceptionAPIManager* manager =
85 MediaPerceptionAPIManager::Get(browser_context());
86 manager->SetState(
87 params->state,
88 base::Bind(&MediaPerceptionPrivateSetStateFunction::SetStateCallback,
89 this));
90 return RespondLater();
91 }
92
93 void MediaPerceptionPrivateSetStateFunction::SetStateCallback(
94 CallbackStatus status,
95 media_perception::State state) {
96 if (status != CallbackStatus::SUCCESS) {
97 Respond(Error(CallbackStatusToErrorMessage(status)));
98 return;
99 }
100 Respond(OneArgument(state.ToValue()));
29 } 101 }
30 102
31 MediaPerceptionPrivateGetDiagnosticsFunction :: 103 MediaPerceptionPrivateGetDiagnosticsFunction ::
32 MediaPerceptionPrivateGetDiagnosticsFunction() {} 104 MediaPerceptionPrivateGetDiagnosticsFunction() {}
33 105
34 MediaPerceptionPrivateGetDiagnosticsFunction :: 106 MediaPerceptionPrivateGetDiagnosticsFunction ::
35 ~MediaPerceptionPrivateGetDiagnosticsFunction() {} 107 ~MediaPerceptionPrivateGetDiagnosticsFunction() {}
36 108
37 ExtensionFunction::ResponseAction 109 ExtensionFunction::ResponseAction
38 MediaPerceptionPrivateGetDiagnosticsFunction::Run() { 110 MediaPerceptionPrivateGetDiagnosticsFunction::Run() {
39 return RespondNow(Error("Not implemented.")); 111 MediaPerceptionAPIManager* manager =
112 MediaPerceptionAPIManager::Get(browser_context());
113 manager->GetDiagnostics(base::Bind(
114 &MediaPerceptionPrivateGetDiagnosticsFunction::GetDiagnosticsCallback,
115 this));
116 return RespondLater();
117 }
118
119 void MediaPerceptionPrivateGetDiagnosticsFunction::GetDiagnosticsCallback(
120 CallbackStatus status,
121 media_perception::Diagnostics diagnostics) {
122 if (status != CallbackStatus::SUCCESS) {
123 Respond(Error(CallbackStatusToErrorMessage(status)));
124 return;
125 }
126 Respond(OneArgument(diagnostics.ToValue()));
40 } 127 }
41 128
42 } // namespace extensions 129 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698