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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/presentation/presentation_dispatcher.cc
diff --git a/content/renderer/presentation/presentation_dispatcher.cc b/content/renderer/presentation/presentation_dispatcher.cc
index 39e5238b189b9fd7c3219337565554affc628c92..3b322e2aac45598883021c642d2317a573c0421e 100644
--- a/content/renderer/presentation/presentation_dispatcher.cc
+++ b/content/renderer/presentation/presentation_dispatcher.cc
@@ -132,6 +132,64 @@ void PresentationDispatcher::joinSession(
base::Owned(callback)));
}
+void PresentationDispatcher::send(
+ const blink::WebString& presentationUrl,
+ const blink::WebString& presentationId,
+ const blink::WebString& message) {
+ message_request_queue_.push(make_linked_ptr(
+ new MessageRequest(
+ presentationUrl.utf8(),
+ presentationId.utf8(),
+ message.utf8())));
+ // Start processing request if only one in the queue.
+ if (message_request_queue_.size() == 1)
+ 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.
+ presentationId.utf8(),
+ message.utf8());
+}
+
+void PresentationDispatcher::send(
+ const blink::WebString& presentationUrl,
+ const blink::WebString& presentationId,
+ const char* data,
+ size_t length) {
+ // TODO(s.singapati): Handle ArrayBuffer data.
+}
+
+void PresentationDispatcher::DoSendStringMessage(
+ const std::string& presentation_url,
+ const std::string& presentation_id,
+ const std::string& message) {
+ ConnectToPresentationServiceIfNeeded();
+ presentation_service_->SendStringMessage(
+ presentation_url,
+ presentation_id,
+ message,
+ base::Bind(&PresentationDispatcher::HandleSendMessageRequests,
+ base::Unretained(this)));
+}
+
+void PresentationDispatcher::HandleSendMessageRequests() {
+ 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.
+ // In normal cases, message_request_queue_ should not be empty at this point
+ // of time, but when FrameWillClose() is invoked before receiving the
+ // callback for previous send mojo call, queue would have been emptied.
+ if (!message_request_queue_.empty())
+ message_request_queue_.pop();
+
+ if (!message_request_queue_.empty()) {
+ const linked_ptr<MessageRequest>& request = message_request_queue_.front();
+ DoSendStringMessage(request->presentation_url,
+ request->presentation_id,
+ request->message);
+ }
+}
+
+void PresentationDispatcher::RemoveAllMessageRequests() {
+ 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
+ message_request_queue_.pop();
+}
+
void PresentationDispatcher::closeSession(
const blink::WebString& presentationUrl,
const blink::WebString& presentationId) {
@@ -150,6 +208,11 @@ void PresentationDispatcher::DidChangeDefaultPresentation() {
presentation_url.spec(), mojo::String());
}
+void PresentationDispatcher::FrameWillClose() {
+ // Remove all pending send message requests.
+ RemoveAllMessageRequests();
+}
+
void PresentationDispatcher::OnScreenAvailabilityChanged(
const std::string& presentation_url, bool available) {
if (!controller_)
@@ -228,4 +291,16 @@ void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() {
*/
}
+PresentationDispatcher::MessageRequest::MessageRequest(
+ const std::string& presentation_url,
+ const std::string& presentation_id,
+ const std::string& message)
+ : presentation_url(presentation_url),
+ presentation_id(presentation_id),
+ message(message) {
+}
+
+PresentationDispatcher::MessageRequest::~MessageRequest() {
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698