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

Side by Side Diff: extensions/browser/api/display_source/display_source_api.cc

Issue 1410093008: Introduce chrome.displaySource API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from Antony Created 5 years, 1 month 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "extensions/browser/api/display_source/display_source_api.h"
6 #include "extensions/browser/api/display_source/display_source_connection_delega te_factory.h"
7 #include "extensions/common/api/display_source.h"
8
9 namespace extensions {
10
11 namespace {
12
13 const char kErrorNotSupported[] = "Not supported";
14 const char kErrorInvalidArguments[] = "Invalid arguments";
15
16 } // namespace
17
18 ////////////////////////////////////////////////////////////////////////////////
19 // DisplaySourceGetAvailableSinksFunction
20
21 DisplaySourceGetAvailableSinksFunction::
22 ~DisplaySourceGetAvailableSinksFunction() {}
23
24 ExtensionFunction::ResponseAction
25 DisplaySourceGetAvailableSinksFunction::Run() {
26 DisplaySourceConnectionDelegate* delegate =
27 DisplaySourceConnectionDelegateFactory::GetForBrowserContext(
28 browser_context());
29 if (!delegate) {
30 return RespondNow(Error(kErrorNotSupported));
31 }
32
33 auto success_callback = base::Bind(
34 &DisplaySourceGetAvailableSinksFunction::OnGetSinksCompleted, this);
35 auto failure_callback = base::Bind(
36 &DisplaySourceGetAvailableSinksFunction::OnGetSinksFailed, this);
37 delegate->GetAvailableSinks(success_callback, failure_callback);
38
39 return RespondLater();
40 }
41
42 void DisplaySourceGetAvailableSinksFunction::OnGetSinksCompleted(
43 const DisplaySourceSinkInfoList& sinks) {
44 scoped_ptr<base::ListValue> result =
45 api::display_source::GetAvailableSinks::Results::Create(sinks);
46 Respond(ArgumentList(result.Pass()));
47 }
48
49 void DisplaySourceGetAvailableSinksFunction::OnGetSinksFailed(
50 const std::string& reason) {
51 Respond(Error(reason));
52 }
53
54 ////////////////////////////////////////////////////////////////////////////////
55 // DisplaySourceRequestAuthenticationFunction
56
57 DisplaySourceRequestAuthenticationFunction::
58 ~DisplaySourceRequestAuthenticationFunction() {}
59
60 ExtensionFunction::ResponseAction
61 DisplaySourceRequestAuthenticationFunction::Run() {
62 scoped_ptr<api::display_source::RequestAuthentication::Params> params(
63 api::display_source::RequestAuthentication::Params::Create(*args_));
64 if (!params) {
65 return RespondNow(Error(kErrorInvalidArguments));
66 }
67
68 DisplaySourceConnectionDelegate* delegate =
69 DisplaySourceConnectionDelegateFactory::GetForBrowserContext(
70 browser_context());
71 if (!delegate) {
72 return RespondNow(Error(kErrorNotSupported));
73 }
74
75 auto success_callback = base::Bind(
76 &DisplaySourceRequestAuthenticationFunction::OnRequestAuthCompleted,
77 this);
78 auto failure_callback = base::Bind(
79 &DisplaySourceRequestAuthenticationFunction::OnRequestAuthFailed, this);
80 delegate->RequestAuthentication(params->sink_id, success_callback,
81 failure_callback);
82 return RespondLater();
83 }
84
85 void DisplaySourceRequestAuthenticationFunction::OnRequestAuthCompleted(
86 const DisplaySourceAuthInfo& auth_info) {
87 scoped_ptr<base::ListValue> result =
88 api::display_source::RequestAuthentication::Results::Create(auth_info);
89 Respond(ArgumentList(result.Pass()));
90 }
91
92 void DisplaySourceRequestAuthenticationFunction::OnRequestAuthFailed(
93 const std::string& reason) {
94 Respond(Error(reason));
95 }
96
97 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698