OLD | NEW |
---|---|
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 // OnSessionCreated() is called. |callback| needs to be alive and also needs | 113 // OnSessionCreated() is called. |callback| needs to be alive and also needs |
114 // to be destroyed so we transfer its ownership to the mojo callback. | 114 // to be destroyed so we transfer its ownership to the mojo callback. |
115 presentation_service_->JoinSession( | 115 presentation_service_->JoinSession( |
116 presentationUrl.utf8(), | 116 presentationUrl.utf8(), |
117 presentationId.utf8(), | 117 presentationId.utf8(), |
118 base::Bind(&PresentationDispatcher::OnSessionCreated, | 118 base::Bind(&PresentationDispatcher::OnSessionCreated, |
119 base::Unretained(this), | 119 base::Unretained(this), |
120 base::Owned(callback))); | 120 base::Owned(callback))); |
121 } | 121 } |
122 | 122 |
123 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
| |
124 const blink::WebString& presentationUrl, | |
125 const blink::WebString& presentationId, | |
126 const blink::WebString& message) { | |
127 | |
128 auto iter = post_message_requests_map_.find(presentationId.utf8()); | |
129 if (iter == post_message_requests_map_.end()) { | |
130 // No match is found for the key (presentationId). | |
131 // Create a new vector for messages and insert into hashmap. | |
132 linked_ptr<PostMessageVector> message_vector(new PostMessageVector()); | |
133 iter = post_message_requests_map_.insert( | |
134 std::make_pair(presentationId.utf8(), message_vector)).first; | |
135 } | |
136 | |
137 iter->second->push_back(make_linked_ptr( | |
138 new PostMessageRequest( | |
139 presentationUrl.utf8(), | |
140 presentationId.utf8(), | |
141 message.utf8()))); | |
142 | |
143 // Start processing request if only one in the hashmap. | |
144 if (post_message_requests_map_.size() == 1) | |
145 PostMessagesOfFirstSession(); | |
146 } | |
147 | |
148 void PresentationDispatcher::postMessage( | |
149 const blink::WebString& presentationUrl, | |
150 const blink::WebString& presentationId, | |
151 const char* data, | |
152 size_t length) { | |
153 // TODO(): Handle ArrayBuffer data. | |
154 } | |
155 | |
156 void PresentationDispatcher::PostMessagesOfFirstSession() { | |
157 PostMessageRequestMap::const_iterator iter = | |
158 post_message_requests_map_.begin(); | |
159 std::string presentation_id = iter->first; | |
160 std::string presentation_url; | |
161 std::vector<std::string> string_messages; | |
162 | |
163 linked_ptr<PostMessageVector> message_vector = iter->second; | |
164 | |
165 for (PostMessageVector::iterator it = message_vector->begin(); | |
166 it != message_vector->end(); | |
167 ++it) { | |
168 string_messages.push_back((*it)->message); | |
169 | |
170 // TODO(): url should goto key of hashmap and be removed here. | |
171 presentation_url = (*it)->presentation_url; | |
172 } | |
173 | |
174 DoPostMessages(presentation_url, presentation_id, string_messages); | |
175 } | |
176 | |
177 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
| |
178 const std::string& presentation_url, | |
179 const std::string& presentation_id, | |
180 std::vector<std::string> string_messages) { | |
181 ConnectToPresentationServiceIfNeeded(); | |
182 | |
183 // send array of messages over mojo service | |
184 /* | |
185 presentation_service_->PostMessages( | |
186 presentation_url, | |
187 presentation_id, | |
188 mojo::Array<mojo::String>(string_messages)); | |
189 */ | |
190 } | |
191 | |
192 // TODO(): Send messages for next session when the result for current | |
193 // PostMessages request is received form the mojo service. | |
194 void PresentationDispatcher::HandlePostMessageRequests() { | |
195 DCHECK(!post_message_requests_map_.empty()); | |
196 | |
197 // Remove first element in the PostMessageRequests hashmap. | |
198 RemovePostMessageRequestsOfFirstSession(); | |
199 | |
200 if (!post_message_requests_map_.empty()) | |
201 PostMessagesOfFirstSession(); | |
202 } | |
203 | |
204 void PresentationDispatcher::RemovePostMessageRequestsOfFirstSession() { | |
205 PostMessageRequestMap::iterator iter = post_message_requests_map_.begin(); | |
206 post_message_requests_map_.erase(iter); | |
207 } | |
208 | |
123 void PresentationDispatcher::closeSession( | 209 void PresentationDispatcher::closeSession( |
124 const blink::WebString& presentationUrl, | 210 const blink::WebString& presentationUrl, |
125 const blink::WebString& presentationId) { | 211 const blink::WebString& presentationId) { |
126 ConnectToPresentationServiceIfNeeded(); | 212 ConnectToPresentationServiceIfNeeded(); |
127 | 213 |
128 presentation_service_->CloseSession( | 214 presentation_service_->CloseSession( |
129 presentationUrl.utf8(), | 215 presentationUrl.utf8(), |
130 presentationId.utf8()); | 216 presentationId.utf8()); |
131 } | 217 } |
132 | 218 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 if (presentation_service_.get()) | 278 if (presentation_service_.get()) |
193 return; | 279 return; |
194 | 280 |
195 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 281 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
196 &presentation_service_); | 282 &presentation_service_); |
197 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 283 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
198 &PresentationDispatcher::OnDefaultSessionStarted, | 284 &PresentationDispatcher::OnDefaultSessionStarted, |
199 base::Unretained(this))); | 285 base::Unretained(this))); |
200 } | 286 } |
201 | 287 |
288 PresentationDispatcher::PostMessageRequest::PostMessageRequest( | |
289 const std::string& presentation_url, | |
290 const std::string& presentation_id, | |
291 const std::string& message) | |
292 : presentation_url(presentation_url), | |
293 presentation_id(presentation_id), | |
294 message(message) { | |
295 } | |
296 | |
297 PresentationDispatcher::PostMessageRequest::~PostMessageRequest() { | |
298 } | |
299 | |
202 } // namespace content | 300 } // namespace content |
OLD | NEW |