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

Side by Side Diff: content/renderer/presentation/presentation_dispatcher.cc

Issue 1037483003: [PresentationAPI] Implementing send() from WebPresentationClient to the PresentationService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 8 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 2015 The Chromium Authors. All rights reserved. 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 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 "content/renderer/presentation/presentation_dispatcher.h" 5 #include "content/renderer/presentation/presentation_dispatcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/common/presentation/presentation_service.mojom.h" 8 #include "content/common/presentation/presentation_service.mojom.h"
9 #include "content/public/common/service_registry.h" 9 #include "content/public/common/service_registry.h"
10 #include "content/public/renderer/render_frame.h" 10 #include "content/public/renderer/render_frame.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // OnSessionCreated() is called. |callback| needs to be alive and also needs 125 // OnSessionCreated() is called. |callback| needs to be alive and also needs
126 // to be destroyed so we transfer its ownership to the mojo callback. 126 // to be destroyed so we transfer its ownership to the mojo callback.
127 presentation_service_->JoinSession( 127 presentation_service_->JoinSession(
128 presentationUrl.utf8(), 128 presentationUrl.utf8(),
129 presentationId.utf8(), 129 presentationId.utf8(),
130 base::Bind(&PresentationDispatcher::OnSessionCreated, 130 base::Bind(&PresentationDispatcher::OnSessionCreated,
131 base::Unretained(this), 131 base::Unretained(this),
132 base::Owned(callback))); 132 base::Owned(callback)));
133 } 133 }
134 134
135 void PresentationDispatcher::send(
136 const blink::WebString& presentationUrl,
137 const blink::WebString& presentationId,
138 const blink::WebString& message) {
139 message_request_queue_.push(make_linked_ptr(
140 new MessageRequest(
141 presentationUrl.utf8(),
142 presentationId.utf8(),
143 message.utf8())));
144 // Start processing request if only one in the queue.
145 if (message_request_queue_.size() == 1)
146 DoSendStringMessage(presentationUrl.utf8(),
147 presentationId.utf8(),
148 message.utf8());
149 }
150
151 void PresentationDispatcher::send(
152 const blink::WebString& presentationUrl,
153 const blink::WebString& presentationId,
154 const char* data,
155 size_t length) {
156 // TODO(): Handle ArrayBuffer data.
mark a. foltz 2015/04/08 23:43:45 Include login.
USE s.singapati at gmail.com 2015/04/10 16:26:05 Done.
157 }
158
159 void PresentationDispatcher::DoSendStringMessage(
160 const std::string& presentation_url,
161 const std::string& presentation_id,
162 const std::string& message) {
163 ConnectToPresentationServiceIfNeeded();
164 // Send one string message over mojo channel.
165 presentation_service_->SendStringMessage(
166 presentation_url,
167 presentation_id,
168 message,
169 base::Bind(&PresentationDispatcher::OnSendMessageCallback,
170 base::Unretained(this)));
mark a. foltz 2015/04/08 23:43:45 The pattern for other callbacks in this file is to
USE s.singapati at gmail.com 2015/04/10 16:26:06 Done. Now callback is stored in PresentationServic
171 }
172
173 void PresentationDispatcher::HandleSendMessageRequests() {
174 DCHECK(!message_request_queue_.empty());
imcheng 2015/04/09 00:29:57 Is the following scenario possible? 1. presentati
175 message_request_queue_.pop();
mark a. foltz 2015/04/08 23:43:45 I don't quite follow the logic of the queue. It s
USE s.singapati at gmail.com 2015/04/10 16:26:05 Now, flow goes like this: 1. send() enques request
176 if (!message_request_queue_.empty()) {
177 const linked_ptr<MessageRequest>& request = message_request_queue_.front();
178 DoSendStringMessage(request->presentation_url,
179 request->presentation_id,
180 request->message);
181 }
182 }
183
184 void PresentationDispatcher::RemoveAllMessageRequests() {
imcheng 2015/04/09 00:29:57 Do we also need to invalidate all pending send mes
USE s.singapati at gmail.com 2015/04/10 16:26:05 Not sure. But, Isn't this enough to invalidate req
185 while (!message_request_queue_.empty())
186 message_request_queue_.pop();
mark a. foltz 2015/04/08 23:43:45 If there is a pending Mojo callback it needs to be
USE s.singapati at gmail.com 2015/04/10 16:26:05 Done. in PresentationServiceImpl, callback send_me
187 }
188
135 void PresentationDispatcher::closeSession( 189 void PresentationDispatcher::closeSession(
136 const blink::WebString& presentationUrl, 190 const blink::WebString& presentationUrl,
137 const blink::WebString& presentationId) { 191 const blink::WebString& presentationId) {
138 ConnectToPresentationServiceIfNeeded(); 192 ConnectToPresentationServiceIfNeeded();
139 193
140 presentation_service_->CloseSession( 194 presentation_service_->CloseSession(
141 presentationUrl.utf8(), 195 presentationUrl.utf8(),
142 presentationId.utf8()); 196 presentationId.utf8());
143 } 197 }
144 198
145 void PresentationDispatcher::DidChangeDefaultPresentation() { 199 void PresentationDispatcher::DidChangeDefaultPresentation() {
146 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); 200 GURL presentation_url(GetPresentationURLFromFrame(render_frame()));
147 201
148 ConnectToPresentationServiceIfNeeded(); 202 ConnectToPresentationServiceIfNeeded();
149 presentation_service_->SetDefaultPresentationURL( 203 presentation_service_->SetDefaultPresentationURL(
150 presentation_url.spec(), mojo::String()); 204 presentation_url.spec(), mojo::String());
151 } 205 }
152 206
207 void PresentationDispatcher::FrameWillClose() {
208 // Remove all pending send message requests.
209 RemoveAllMessageRequests();
210 }
211
153 void PresentationDispatcher::OnScreenAvailabilityChanged( 212 void PresentationDispatcher::OnScreenAvailabilityChanged(
154 const std::string& presentation_url, bool available) { 213 const std::string& presentation_url, bool available) {
155 if (!controller_) 214 if (!controller_)
156 return; 215 return;
157 216
158 // Reset the callback to get the next event. 217 // Reset the callback to get the next event.
159 DoUpdateAvailableChangeWatched(presentation_url, 218 DoUpdateAvailableChangeWatched(presentation_url,
160 controller_->isAvailableChangeWatched()); 219 controller_->isAvailableChangeWatched());
161 220
162 controller_->didChangeAvailability(available); 221 controller_->didChangeAvailability(available);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 presentation_service_->ListenForSessionStateChange(base::Bind( 262 presentation_service_->ListenForSessionStateChange(base::Bind(
204 &PresentationDispatcher::OnSessionStateChange, 263 &PresentationDispatcher::OnSessionStateChange,
205 base::Unretained(this))); 264 base::Unretained(this)));
206 265
207 DCHECK(!session_info.is_null()); 266 DCHECK(!session_info.is_null());
208 controller_->didChangeSessionState( 267 controller_->didChangeSessionState(
209 new PresentationSessionClient(session_info.Pass()), 268 new PresentationSessionClient(session_info.Pass()),
210 GetWebPresentationSessionStateFromMojo(session_state)); 269 GetWebPresentationSessionStateFromMojo(session_state));
211 } 270 }
212 271
272 void PresentationDispatcher::OnSendMessageCallback() {
imcheng 2015/04/09 00:29:57 This function looks redundant -- looks like you ca
USE s.singapati at gmail.com 2015/04/10 16:26:06 Done.
273 HandleSendMessageRequests();
274 }
275
213 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { 276 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() {
214 if (presentation_service_.get()) 277 if (presentation_service_.get())
215 return; 278 return;
216 279
217 render_frame()->GetServiceRegistry()->ConnectToRemoteService( 280 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
218 &presentation_service_); 281 &presentation_service_);
219 // TODO(imcheng): Uncomment these once they are implemented on the browser 282 // TODO(imcheng): Uncomment these once they are implemented on the browser
220 // side. (crbug.com/459006) 283 // side. (crbug.com/459006)
221 /* 284 /*
222 presentation_service_->ListenForDefaultSessionStart(base::Bind( 285 presentation_service_->ListenForDefaultSessionStart(base::Bind(
223 &PresentationDispatcher::OnDefaultSessionStarted, 286 &PresentationDispatcher::OnDefaultSessionStarted,
224 base::Unretained(this))); 287 base::Unretained(this)));
225 presentation_service_->ListenForSessionStateChange(base::Bind( 288 presentation_service_->ListenForSessionStateChange(base::Bind(
226 &PresentationDispatcher::OnSessionStateChange, 289 &PresentationDispatcher::OnSessionStateChange,
227 base::Unretained(this))); 290 base::Unretained(this)));
228 */ 291 */
229 } 292 }
230 293
294 PresentationDispatcher::MessageRequest::MessageRequest(
295 const std::string& presentation_url,
296 const std::string& presentation_id,
297 const std::string& message)
298 : presentation_url(presentation_url),
299 presentation_id(presentation_id),
300 message(message) {
301 }
302
303 PresentationDispatcher::MessageRequest::~MessageRequest() {
304 }
305
231 } // namespace content 306 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698