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

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 if (!args_->empty()) {
asargent_no_longer_on_chrome 2015/11/17 00:51:55 I don't know that it's really worth worrying about
Mikhail 2015/11/17 14:07:42 Agree, fixed.
27 return RespondNow(Error(kErrorInvalidArguments));
28 }
29
30 DisplaySourceConnectionDelegate* delegate =
31 DisplaySourceConnectionDelegateFactory::GetForBrowserContext(
32 browser_context());
33 if (!delegate) {
34 return RespondNow(Error(kErrorNotSupported));
35 }
36
37 auto success_callback = base::Bind(
38 &DisplaySourceGetAvailableSinksFunction::OnGetSinksCompleted, this);
39 auto failure_callback = base::Bind(
40 &DisplaySourceGetAvailableSinksFunction::OnGetSinksFailed, this);
41 delegate->GetAvailableSinks(success_callback, failure_callback);
42
43 return RespondLater();
44 }
45
46 void DisplaySourceGetAvailableSinksFunction::OnGetSinksCompleted(
47 const DisplaySourceSinkInfoList& sinks) {
48 scoped_ptr<base::ListValue> result =
49 api::display_source::GetAvailableSinks::Results::Create(sinks);
50 Respond(ArgumentList(result.Pass()));
51 }
52
53 void DisplaySourceGetAvailableSinksFunction::OnGetSinksFailed(
54 const std::string& reason) {
55 Respond(Error(reason));
56 }
57
58 ////////////////////////////////////////////////////////////////////////////////
59 // DisplaySourceRequestAuthenticationFunction
60
61 DisplaySourceRequestAuthenticationFunction::
62 ~DisplaySourceRequestAuthenticationFunction() {}
63
64 ExtensionFunction::ResponseAction
65 DisplaySourceRequestAuthenticationFunction::Run() {
66 scoped_ptr<api::display_source::RequestAuthentication::Params> params(
67 api::display_source::RequestAuthentication::Params::Create(*args_));
68 if (!params) {
69 return RespondNow(Error(kErrorInvalidArguments));
70 }
71
72 DisplaySourceConnectionDelegate* delegate =
73 DisplaySourceConnectionDelegateFactory::GetForBrowserContext(
74 browser_context());
75 if (!delegate) {
76 return RespondNow(Error(kErrorNotSupported));
77 }
78
79 auto success_callback = base::Bind(
80 &DisplaySourceRequestAuthenticationFunction::OnRequestAuthCompleted,
81 this);
82 auto failure_callback = base::Bind(
83 &DisplaySourceRequestAuthenticationFunction::OnRequestAuthFailed, this);
84 delegate->RequestAuthentication(params->sink_id, success_callback,
85 failure_callback);
86 return RespondLater();
87 }
88
89 void DisplaySourceRequestAuthenticationFunction::OnRequestAuthCompleted(
90 const DisplaySourceAuthInfo& auth_info) {
91 scoped_ptr<base::ListValue> result =
92 api::display_source::RequestAuthentication::Results::Create(auth_info);
93 Respond(ArgumentList(result.Pass()));
94 }
95
96 void DisplaySourceRequestAuthenticationFunction::OnRequestAuthFailed(
97 const std::string& reason) {
98 Respond(Error(reason));
99 }
100
101 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698