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

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

Issue 2858353002: MediaPerceptionPrivate API impl and testing. (Closed)
Patch Set: Addressing comments on API implementation. Created 3 years, 7 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 #include "extensions/browser/api/media_perception_private/media_perception_api_m anager.h"
7 #include "extensions/browser/extension_function.h" 8 #include "extensions/browser/extension_function.h"
8 9
9 namespace media_perception = extensions::api::media_perception_private; 10 namespace media_perception = extensions::api::media_perception_private;
10 11
11 namespace extensions { 12 namespace extensions {
12 13
13 MediaPerceptionPrivateGetStateFunction :: 14 MediaPerceptionPrivateGetStateFunction ::
14 MediaPerceptionPrivateGetStateFunction() {} 15 MediaPerceptionPrivateGetStateFunction() {}
15 16
16 MediaPerceptionPrivateGetStateFunction :: 17 MediaPerceptionPrivateGetStateFunction ::
17 ~MediaPerceptionPrivateGetStateFunction() {} 18 ~MediaPerceptionPrivateGetStateFunction() {}
18 19
19 ExtensionFunction::ResponseAction 20 ExtensionFunction::ResponseAction
20 MediaPerceptionPrivateGetStateFunction::Run() { 21 MediaPerceptionPrivateGetStateFunction::Run() {
21 return RespondNow(Error("Not implemented.")); 22 MediaPerceptionAPIManager* manager =
23 MediaPerceptionAPIManager::Get(browser_context());
24 if (!manager) {
tbarzic 2017/05/09 01:28:37 Should this ever happen? Wound DCHECK be more appr
Luke Sorenson 2017/05/09 21:05:45 Don't think so. Replaced.
25 return RespondNow(Error("Can't get manager."));
26 }
27 manager->GetState(base::Bind(
28 &MediaPerceptionPrivateGetStateFunction::GetStateCallback, this));
29 return RespondLater();
30 }
31
32 void MediaPerceptionPrivateGetStateFunction::GetStateCallback(
33 bool succeeded,
34 media_perception::State state) {
35 if (!succeeded) {
36 Respond(Error("Failed to getState."));
tbarzic 2017/05/09 01:28:37 return;
Luke Sorenson 2017/05/09 21:05:45 Done.
37 }
38 Respond(OneArgument(state.ToValue()));
22 } 39 }
23 40
24 MediaPerceptionPrivateSetStateFunction :: 41 MediaPerceptionPrivateSetStateFunction ::
25 MediaPerceptionPrivateSetStateFunction() {} 42 MediaPerceptionPrivateSetStateFunction() {}
26 43
27 MediaPerceptionPrivateSetStateFunction :: 44 MediaPerceptionPrivateSetStateFunction ::
28 ~MediaPerceptionPrivateSetStateFunction() {} 45 ~MediaPerceptionPrivateSetStateFunction() {}
29 46
30 ExtensionFunction::ResponseAction 47 ExtensionFunction::ResponseAction
31 MediaPerceptionPrivateSetStateFunction::Run() { 48 MediaPerceptionPrivateSetStateFunction::Run() {
32 return RespondNow(Error("Not implemented.")); 49 std::unique_ptr<media_perception::SetState::Params> params =
50 media_perception::SetState::Params::Create(*args_);
51 EXTENSION_FUNCTION_VALIDATE(params.get());
52 // Check that the desired status is settable.
53 if (params->state.status != media_perception::STATUS_RUNNING &&
54 params->state.status != media_perception::STATUS_SUSPENDED) {
55 return RespondNow(Error("Settable statuses are RUNNING and SUSPENDED."));
tbarzic 2017/05/09 01:28:37 Status can be set only to RUNNING or SUSPEND. Also
Luke Sorenson 2017/05/09 21:05:45 Done.
56 }
57 MediaPerceptionAPIManager* manager =
58 MediaPerceptionAPIManager::Get(browser_context());
59 if (!manager) {
60 return RespondNow(Error("Can't get manager."));
61 }
62 manager->SetState(
63 params->state,
64 base::Bind(&MediaPerceptionPrivateSetStateFunction::SetStateCallback,
65 this));
66 return RespondLater();
67 }
68
69 void MediaPerceptionPrivateSetStateFunction::SetStateCallback(
70 bool succeeded,
71 media_perception::State state) {
72 if (!succeeded) {
73 Respond(Error("Failed to setState."));
tbarzic 2017/05/09 01:28:37 return;
Luke Sorenson 2017/05/09 21:05:45 Done.
74 }
75 Respond(OneArgument(state.ToValue()));
33 } 76 }
34 77
35 MediaPerceptionPrivateGetDiagnosticsFunction :: 78 MediaPerceptionPrivateGetDiagnosticsFunction ::
36 MediaPerceptionPrivateGetDiagnosticsFunction() {} 79 MediaPerceptionPrivateGetDiagnosticsFunction() {}
37 80
38 MediaPerceptionPrivateGetDiagnosticsFunction :: 81 MediaPerceptionPrivateGetDiagnosticsFunction ::
39 ~MediaPerceptionPrivateGetDiagnosticsFunction() {} 82 ~MediaPerceptionPrivateGetDiagnosticsFunction() {}
40 83
41 ExtensionFunction::ResponseAction 84 ExtensionFunction::ResponseAction
42 MediaPerceptionPrivateGetDiagnosticsFunction::Run() { 85 MediaPerceptionPrivateGetDiagnosticsFunction::Run() {
43 return RespondNow(Error("Not implemented.")); 86 MediaPerceptionAPIManager* manager =
87 MediaPerceptionAPIManager::Get(browser_context());
88 if (!manager) {
89 return RespondNow(Error("Can't get manager."));
90 }
91 manager->GetDiagnostics(base::Bind(
92 &MediaPerceptionPrivateGetDiagnosticsFunction::GetDiagnosticsCallback,
93 this));
94 return RespondLater();
95 }
96
97 void MediaPerceptionPrivateGetDiagnosticsFunction::GetDiagnosticsCallback(
98 bool succeeded,
99 media_perception::Diagnostics diagnostics) {
100 if (!succeeded) {
101 Respond(Error("Failed to getDiagnostics."));
tbarzic 2017/05/09 01:28:37 return
Luke Sorenson 2017/05/09 21:05:45 Done.
102 }
103 Respond(OneArgument(diagnostics.ToValue()));
44 } 104 }
45 105
46 } // namespace extensions 106 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698