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

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: callback handling for send requests, other fixes. 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(),
whywhat 2015/04/13 13:31:21 use {} for multiline if branches.
USE s.singapati at gmail.com 2015/04/14 17:51:51 Done.
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(s.singapati): Handle ArrayBuffer data.
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 presentation_service_->SendStringMessage(
165 presentation_url,
166 presentation_id,
167 message,
168 base::Bind(&PresentationDispatcher::HandleSendMessageRequests,
169 base::Unretained(this)));
170 }
171
172 void PresentationDispatcher::HandleSendMessageRequests() {
173 DCHECK(!message_request_queue_.empty());
mark a. foltz 2015/04/10 19:03:18 It seems like the realistic situation described be
USE s.singapati at gmail.com 2015/04/14 17:51:51 Done.
174 // In normal cases, message_request_queue_ should not be empty at this point
175 // of time, but when FrameWillClose() is invoked before receiving the
176 // callback for previous send mojo call, queue would have been emptied.
177 if (!message_request_queue_.empty())
178 message_request_queue_.pop();
179
180 if (!message_request_queue_.empty()) {
181 const linked_ptr<MessageRequest>& request = message_request_queue_.front();
182 DoSendStringMessage(request->presentation_url,
183 request->presentation_id,
184 request->message);
185 }
186 }
187
188 void PresentationDispatcher::RemoveAllMessageRequests() {
189 while (!message_request_queue_.empty())
whywhat 2015/04/13 13:31:21 I think you just can do message_request_queue_.swa
USE s.singapati at gmail.com 2015/04/14 17:51:51 Done. Had to use std::swap(). message_request_queu
190 message_request_queue_.pop();
191 }
192
135 void PresentationDispatcher::closeSession( 193 void PresentationDispatcher::closeSession(
136 const blink::WebString& presentationUrl, 194 const blink::WebString& presentationUrl,
137 const blink::WebString& presentationId) { 195 const blink::WebString& presentationId) {
138 ConnectToPresentationServiceIfNeeded(); 196 ConnectToPresentationServiceIfNeeded();
139 197
140 presentation_service_->CloseSession( 198 presentation_service_->CloseSession(
141 presentationUrl.utf8(), 199 presentationUrl.utf8(),
142 presentationId.utf8()); 200 presentationId.utf8());
143 } 201 }
144 202
145 void PresentationDispatcher::DidChangeDefaultPresentation() { 203 void PresentationDispatcher::DidChangeDefaultPresentation() {
146 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); 204 GURL presentation_url(GetPresentationURLFromFrame(render_frame()));
147 205
148 ConnectToPresentationServiceIfNeeded(); 206 ConnectToPresentationServiceIfNeeded();
149 presentation_service_->SetDefaultPresentationURL( 207 presentation_service_->SetDefaultPresentationURL(
150 presentation_url.spec(), mojo::String()); 208 presentation_url.spec(), mojo::String());
151 } 209 }
152 210
211 void PresentationDispatcher::FrameWillClose() {
212 // Remove all pending send message requests.
213 RemoveAllMessageRequests();
214 }
215
153 void PresentationDispatcher::OnScreenAvailabilityChanged( 216 void PresentationDispatcher::OnScreenAvailabilityChanged(
154 const std::string& presentation_url, bool available) { 217 const std::string& presentation_url, bool available) {
155 if (!controller_) 218 if (!controller_)
156 return; 219 return;
157 220
158 // Reset the callback to get the next event. 221 // Reset the callback to get the next event.
159 DoUpdateAvailableChangeWatched(presentation_url, 222 DoUpdateAvailableChangeWatched(presentation_url,
160 controller_->isAvailableChangeWatched()); 223 controller_->isAvailableChangeWatched());
161 224
162 controller_->didChangeAvailability(available); 225 controller_->didChangeAvailability(available);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
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