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 eec933b874dba7d3ebdf510d6dc3833d3e3a74e5..1eeac4b6513cfbf55992ca69444d5fe919fc1bde 100644 |
| --- a/content/renderer/presentation/presentation_dispatcher.cc |
| +++ b/content/renderer/presentation/presentation_dispatcher.cc |
| @@ -120,6 +120,92 @@ void PresentationDispatcher::joinSession( |
| base::Owned(callback))); |
| } |
| +void PresentationDispatcher::postMessage( |
|
mark a. foltz
2015/04/02 20:46:26
I don't think we should be queuing on the browser
USE s.singapati at gmail.com
2015/04/07 17:45:16
Acknowledged. Commented already about current hash
|
| + const blink::WebString& presentationUrl, |
| + const blink::WebString& presentationId, |
| + const blink::WebString& message) { |
| + |
| + auto iter = post_message_requests_map_.find(presentationId.utf8()); |
| + if (iter == post_message_requests_map_.end()) { |
| + // No match is found for the key (presentationId). |
| + // Create a new vector for messages and insert into hashmap. |
| + linked_ptr<PostMessageVector> message_vector(new PostMessageVector()); |
| + iter = post_message_requests_map_.insert( |
| + std::make_pair(presentationId.utf8(), message_vector)).first; |
| + } |
| + |
| + iter->second->push_back(make_linked_ptr( |
| + new PostMessageRequest( |
| + presentationUrl.utf8(), |
| + presentationId.utf8(), |
| + message.utf8()))); |
| + |
| + // Start processing request if only one in the hashmap. |
| + if (post_message_requests_map_.size() == 1) |
| + PostMessagesOfFirstSession(); |
| +} |
| + |
| +void PresentationDispatcher::postMessage( |
| + const blink::WebString& presentationUrl, |
| + const blink::WebString& presentationId, |
| + const char* data, |
| + size_t length) { |
| + // TODO(): Handle ArrayBuffer data. |
| +} |
| + |
| +void PresentationDispatcher::PostMessagesOfFirstSession() { |
| + PostMessageRequestMap::const_iterator iter = |
| + post_message_requests_map_.begin(); |
| + std::string presentation_id = iter->first; |
| + std::string presentation_url; |
| + std::vector<std::string> string_messages; |
| + |
| + linked_ptr<PostMessageVector> message_vector = iter->second; |
| + |
| + for (PostMessageVector::iterator it = message_vector->begin(); |
| + it != message_vector->end(); |
| + ++it) { |
| + string_messages.push_back((*it)->message); |
| + |
| + // TODO(): url should goto key of hashmap and be removed here. |
| + presentation_url = (*it)->presentation_url; |
| + } |
| + |
| + DoPostMessages(presentation_url, presentation_id, string_messages); |
| +} |
| + |
| +void PresentationDispatcher::DoPostMessages( |
|
imcheng
2015/04/02 23:57:24
I think we need a mechanism to invalidate pending
USE s.singapati at gmail.com
2015/04/07 17:45:16
Done. Implemented FrameWillClose(). This is the on
|
| + const std::string& presentation_url, |
| + const std::string& presentation_id, |
| + std::vector<std::string> string_messages) { |
| + ConnectToPresentationServiceIfNeeded(); |
| + |
| + // send array of messages over mojo service |
| + /* |
| + presentation_service_->PostMessages( |
| + presentation_url, |
| + presentation_id, |
| + mojo::Array<mojo::String>(string_messages)); |
| + */ |
| +} |
| + |
| +// TODO(): Send messages for next session when the result for current |
| +// PostMessages request is received form the mojo service. |
| +void PresentationDispatcher::HandlePostMessageRequests() { |
| + DCHECK(!post_message_requests_map_.empty()); |
| + |
| + // Remove first element in the PostMessageRequests hashmap. |
| + RemovePostMessageRequestsOfFirstSession(); |
| + |
| + if (!post_message_requests_map_.empty()) |
| + PostMessagesOfFirstSession(); |
| +} |
| + |
| +void PresentationDispatcher::RemovePostMessageRequestsOfFirstSession() { |
| + PostMessageRequestMap::iterator iter = post_message_requests_map_.begin(); |
| + post_message_requests_map_.erase(iter); |
| +} |
| + |
| void PresentationDispatcher::closeSession( |
| const blink::WebString& presentationUrl, |
| const blink::WebString& presentationId) { |
| @@ -199,4 +285,16 @@ void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
| base::Unretained(this))); |
| } |
| +PresentationDispatcher::PostMessageRequest::PostMessageRequest( |
| + 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::PostMessageRequest::~PostMessageRequest() { |
| +} |
| + |
| } // namespace content |