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

Side by Side Diff: chrome/browser/media/router/incognito_presentation_service_delegate.cc

Issue 1314413005: [Presentation API] 1-UA presentation support + presenter APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
(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 "chrome/browser/media/router/incognito_presentation_service_delegate.h"
6
7 #include "chrome/browser/media/router/one_ua_presentation_router.h"
8 #include "chrome/browser/media/router/one_ua_presentation_router_factory.h"
9 #include "chrome/browser/profiles/profile.h"
10
11 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
12 media_router::IncognitoPresentationServiceDelegate);
13
14 using content::PresentationServiceDelegate;
15 using content::RenderFrameHost;
16
17 namespace media_router {
18
19 // static
20 IncognitoPresentationServiceDelegate*
21 IncognitoPresentationServiceDelegate::GetOrCreateForWebContents(
22 content::WebContents* web_contents) {
23 DCHECK(web_contents);
24 // CreateForWebContents does nothing if the delegate instance already exists.
25 IncognitoPresentationServiceDelegate::CreateForWebContents(web_contents);
26 return IncognitoPresentationServiceDelegate::FromWebContents(web_contents);
27 }
28
29 IncognitoPresentationServiceDelegate::~IncognitoPresentationServiceDelegate() {
30 for (auto& observer_pair : observers_)
31 observer_pair.second->OnDelegateDestroyed();
32 }
33
34 void IncognitoPresentationServiceDelegate::AddObserver(
35 int render_process_id,
36 int render_frame_id,
37 content::PresentationServiceDelegate::Observer* observer) {
38 DCHECK(observer);
39
40 RenderFrameHostId rfh_id(render_process_id, render_frame_id);
41 DCHECK(!ContainsKey(observers_, rfh_id));
42 observers_[rfh_id] = observer;
43 }
44
45 void IncognitoPresentationServiceDelegate::RemoveObserver(int render_process_id,
46 int render_frame_id) {
47 observers_.erase(RenderFrameHostId(render_process_id, render_frame_id));
48 }
49
50 bool IncognitoPresentationServiceDelegate::AddScreenAvailabilityListener(
51 int render_process_id,
52 int render_frame_id,
53 content::PresentationScreenAvailabilityListener* listener) {
54 NOTIMPLEMENTED();
55 return false;
56 }
57
58 void IncognitoPresentationServiceDelegate::RemoveScreenAvailabilityListener(
59 int render_process_id,
60 int render_frame_id,
61 content::PresentationScreenAvailabilityListener* listener) {
62 NOTIMPLEMENTED();
63 }
64
65 void IncognitoPresentationServiceDelegate::Reset(int render_process_id,
66 int render_frame_id) {
67 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
68 one_ua_presentation_router_->Reset(
69 RenderFrameHostId(render_process_id, render_frame_id));
70 }
71
72 void IncognitoPresentationServiceDelegate::SetDefaultPresentationUrl(
73 int render_process_id,
74 int render_frame_id,
75 const std::string& default_presentation_url) {
76 NOTIMPLEMENTED();
77 }
78
79 void IncognitoPresentationServiceDelegate::StartSession(
80 int render_process_id,
81 int render_frame_id,
82 const std::string& presentation_url,
83 const PresentationSessionSuccessCallback& success_cb,
84 const PresentationSessionErrorCallback& error_cb) {
85 NOTIMPLEMENTED();
86 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
87 "Not implemented"));
88 }
89
90 void IncognitoPresentationServiceDelegate::JoinSession(
91 int render_process_id,
92 int render_frame_id,
93 const std::string& presentation_url,
94 const std::string& presentation_id,
95 const PresentationSessionSuccessCallback& success_cb,
96 const PresentationSessionErrorCallback& error_cb) {
97 NOTIMPLEMENTED();
98 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN,
99 "Not implemented"));
100 }
101
102 void IncognitoPresentationServiceDelegate::CloseSession(
103 int render_process_id,
104 int render_frame_id,
105 const std::string& presentation_id) {
106 NOTIMPLEMENTED();
107 }
108
109 void IncognitoPresentationServiceDelegate::ListenForSessionMessages(
110 int render_process_id,
111 int render_frame_id,
112 const content::PresentationSessionInfo& session,
113 const content::PresentationSessionMessageCallback& message_cb) {
114 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
115 DCHECK(one_ua_presentation_router_->IsPresenter(
116 RenderFrameHostId(render_process_id, render_frame_id)));
117 DCHECK(session.presentation_url.empty());
118
119 one_ua_presentation_router_->ListenForMessages(session, message_cb);
120 }
121
122 void IncognitoPresentationServiceDelegate::SendMessage(
123 int render_process_id,
124 int render_frame_id,
125 const content::PresentationSessionInfo& session,
126 scoped_ptr<content::PresentationSessionMessage> message,
127 const content::SendMessageCallback& send_message_cb) {
128 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
129 DCHECK(one_ua_presentation_router_->IsPresenter(
130 RenderFrameHostId(render_process_id, render_frame_id)));
131 DCHECK(session.presentation_url.empty());
132
133 one_ua_presentation_router_->SendMessage(session, message.Pass(),
134 send_message_cb);
135 }
136
137 void IncognitoPresentationServiceDelegate::ListenForSessionStateChange(
138 int render_process_id,
139 int render_frame_id,
140 const content::SessionStateChangedCallback& state_changed_cb) {
141 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
142 NOTIMPLEMENTED();
143 // TODO(imcheng): Implement when ListenForSessionStateChange takes a
144 // PresentationSessionInfo as input.
145 }
146
147 void IncognitoPresentationServiceDelegate::GetPresenterSession(
148 int render_process_id,
149 int render_frame_id,
150 const content::PresenterSessionAvailableCallback& success_callback,
151 const base::Callback<void(const std::string&)>& error_callback) {
152 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
153
154 RenderFrameHostId rfh_id(render_process_id, render_frame_id);
155 if (!one_ua_presentation_router_->IsPresenter(rfh_id)) {
156 DVLOG(1) << "Not a presenter: " << render_process_id << ", "
157 << render_frame_id;
158 error_callback.Run("Not a presenter frame");
159 return;
160 }
161
162 one_ua_presentation_router_->GetSinglePresenterSession(rfh_id,
163 success_callback);
164 }
165
166 std::vector<content::PresentationSessionInfo>
167 IncognitoPresentationServiceDelegate::GetPresenterSessions(
168 int render_process_id,
169 int render_frame_id) {
170 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id;
171
172 RenderFrameHostId rfh_id(render_process_id, render_frame_id);
173 if (!one_ua_presentation_router_->IsPresenter(rfh_id)) {
174 DVLOG(1) << "Not a presenter: " << render_process_id << ", "
175 << render_frame_id;
176 return std::vector<content::PresentationSessionInfo>();
177 }
178
179 return one_ua_presentation_router_->GetPresenterSessions(rfh_id);
180 }
181
182 IncognitoPresentationServiceDelegate::IncognitoPresentationServiceDelegate(
183 content::WebContents* web_contents)
184 : web_contents_(web_contents),
185 // Get the OneUAPresentationRouter keyed off the controller profile, since
186 // it is where the 1-UA presentation is registered.
187 // Per OffscreenPresentationsOwner, the controller profile is the
188 // presenter
189 // tab's original profile.
190 one_ua_presentation_router_(
191 OneUAPresentationRouterFactory::GetOrCreateForBrowserContext(
192 Profile::FromBrowserContext(web_contents_->GetBrowserContext())
193 ->GetOriginalProfile())) {
194 DCHECK(web_contents_);
195 DCHECK(one_ua_presentation_router_);
196 }
197
198 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698