Chromium Code Reviews| 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..916d4b507e03504334129f2dce408319287f913b 100644 |
| --- a/content/renderer/presentation/presentation_dispatcher.cc |
| +++ b/content/renderer/presentation/presentation_dispatcher.cc |
| @@ -132,6 +132,60 @@ 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(), |
| + presentationId.utf8(), |
| + message.utf8()); |
| +} |
| + |
| +void PresentationDispatcher::send( |
| + const blink::WebString& presentationUrl, |
| + const blink::WebString& presentationId, |
| + const char* data, |
| + size_t length) { |
| + // 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.
|
| +} |
| + |
| +void PresentationDispatcher::DoSendStringMessage( |
| + const std::string& presentation_url, |
| + const std::string& presentation_id, |
| + const std::string& message) { |
| + ConnectToPresentationServiceIfNeeded(); |
| + // Send one string message over mojo channel. |
| + presentation_service_->SendStringMessage( |
| + presentation_url, |
| + presentation_id, |
| + message, |
| + base::Bind(&PresentationDispatcher::OnSendMessageCallback, |
| + 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
|
| +} |
| + |
| +void PresentationDispatcher::HandleSendMessageRequests() { |
| + DCHECK(!message_request_queue_.empty()); |
|
imcheng
2015/04/09 00:29:57
Is the following scenario possible?
1. presentati
|
| + 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
|
| + 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() { |
|
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
|
| + while (!message_request_queue_.empty()) |
| + 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
|
| +} |
| + |
| void PresentationDispatcher::closeSession( |
| const blink::WebString& presentationUrl, |
| const blink::WebString& presentationId) { |
| @@ -150,6 +204,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_) |
| @@ -210,6 +269,10 @@ void PresentationDispatcher::OnSessionStateChange( |
| GetWebPresentationSessionStateFromMojo(session_state)); |
| } |
| +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.
|
| + HandleSendMessageRequests(); |
| +} |
| + |
| void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
| if (presentation_service_.get()) |
| return; |
| @@ -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 |