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

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: Updated callback handling, message invalidation and and sending generic message struct. 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::sendString(
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
145 // Start processing request if only one in the queue.
146 if (message_request_queue_.size() == 1) {
147 const linked_ptr<MessageRequest>& request = message_request_queue_.front();
148 DoSendMessage(*request);
149 }
150 }
151
152 void PresentationDispatcher::sendArrayBuffer(
153 const blink::WebString& presentationUrl,
154 const blink::WebString& presentationId,
155 const uint8* data,
156 size_t length) {
157 DCHECK(data);
158 const std::vector<uint8> vector(data, data + length);
mark a. foltz 2015/04/22 19:34:23 Are you sure this is efficient (as good as or bett
USE s.singapati at gmail.com 2015/04/27 19:28:56 well, std::copy might be faster, since the vector
159 message_request_queue_.push(make_linked_ptr(
160 new MessageRequest(
161 presentationUrl.utf8(),
162 presentationId.utf8(),
163 vector)));
164
165 // Start processing request if only one in the queue.
166 if (message_request_queue_.size() == 1) {
167 const linked_ptr<MessageRequest>& request = message_request_queue_.front();
168 DoSendMessage(*request);
169 }
170 }
171
172 void PresentationDispatcher::DoSendMessage(
173 const MessageRequest& request) {
174 ConnectToPresentationServiceIfNeeded();
175
176 presentation::MessageRequestPtr message_request(
177 presentation::MessageRequest::New());
178 message_request->presentation_url = request.presentation_url;
179 message_request->presentation_id = request.presentation_id;
180 message_request->type =
181 static_cast<presentation::PresentationMessageType>(request.type);
182 message_request->message = request.message;
183 message_request->data = mojo::Array<uint8>::From(request.data);
184
185 presentation_service_->SendMessage(
186 message_request.Pass(),
187 base::Bind(&PresentationDispatcher::HandleSendMessageRequests,
188 base::Unretained(this)));
189 }
190
191 void PresentationDispatcher::HandleSendMessageRequests() {
192 // In normal cases, message_request_queue_ should not be empty at this point
193 // of time, but when FrameWillClose() is invoked before receiving the
194 // callback for previous send mojo call, queue would have been emptied.
195 if (message_request_queue_.empty())
196 return;
197
198 message_request_queue_.pop();
199 if (!message_request_queue_.empty()) {
200 const linked_ptr<MessageRequest>& request = message_request_queue_.front();
201 DoSendMessage(*request);
202 }
203 }
204
135 void PresentationDispatcher::closeSession( 205 void PresentationDispatcher::closeSession(
136 const blink::WebString& presentationUrl, 206 const blink::WebString& presentationUrl,
137 const blink::WebString& presentationId) { 207 const blink::WebString& presentationId) {
138 ConnectToPresentationServiceIfNeeded(); 208 ConnectToPresentationServiceIfNeeded();
139 209
140 presentation_service_->CloseSession( 210 presentation_service_->CloseSession(
141 presentationUrl.utf8(), 211 presentationUrl.utf8(),
142 presentationId.utf8()); 212 presentationId.utf8());
143 } 213 }
144 214
145 void PresentationDispatcher::DidChangeDefaultPresentation() { 215 void PresentationDispatcher::DidChangeDefaultPresentation() {
146 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); 216 GURL presentation_url(GetPresentationURLFromFrame(render_frame()));
147 217
148 ConnectToPresentationServiceIfNeeded(); 218 ConnectToPresentationServiceIfNeeded();
149 presentation_service_->SetDefaultPresentationURL( 219 presentation_service_->SetDefaultPresentationURL(
150 presentation_url.spec(), mojo::String()); 220 presentation_url.spec(), mojo::String());
151 } 221 }
152 222
223 void PresentationDispatcher::DidCommitProvisionalLoad(
224 bool is_new_navigation,
225 bool is_same_page_navigation) {
226 blink::WebFrame* frame = render_frame()->GetWebFrame();
227 // If not top-level navigation.
228 if (frame->parent() || is_same_page_navigation)
229 return;
230
231 // Remove all pending send message requests.
232 MessageRequestQueue empty;
233 std::swap(message_request_queue_, empty);
234 }
235
236 void PresentationDispatcher::FrameWillClose() {
237 // Remove all pending send message requests.
238 MessageRequestQueue empty;
239 std::swap(message_request_queue_, empty);
240 }
241
153 void PresentationDispatcher::OnScreenAvailabilityChanged( 242 void PresentationDispatcher::OnScreenAvailabilityChanged(
154 const std::string& presentation_url, bool available) { 243 const std::string& presentation_url, bool available) {
155 if (!controller_) 244 if (!controller_)
156 return; 245 return;
157 246
158 // Reset the callback to get the next event. 247 // Reset the callback to get the next event.
159 DoUpdateAvailableChangeWatched(presentation_url, 248 DoUpdateAvailableChangeWatched(presentation_url,
160 controller_->isAvailableChangeWatched()); 249 controller_->isAvailableChangeWatched());
161 250
162 controller_->didChangeAvailability(available); 251 controller_->didChangeAvailability(available);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 presentation_service_->ListenForDefaultSessionStart(base::Bind( 311 presentation_service_->ListenForDefaultSessionStart(base::Bind(
223 &PresentationDispatcher::OnDefaultSessionStarted, 312 &PresentationDispatcher::OnDefaultSessionStarted,
224 base::Unretained(this))); 313 base::Unretained(this)));
225 presentation_service_->ListenForSessionStateChange(base::Bind( 314 presentation_service_->ListenForSessionStateChange(base::Bind(
226 &PresentationDispatcher::OnSessionStateChange, 315 &PresentationDispatcher::OnSessionStateChange,
227 base::Unretained(this))); 316 base::Unretained(this)));
228 */ 317 */
229 } 318 }
230 319
231 } // namespace content 320 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698