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

Side by Side Diff: content/renderer/presentation/presentation_dispatcher.cc

Issue 1235083006: CallbackPromiseAdapter types should be more compatible with WebCallbacks (2/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web-callbacks-3
Patch Set: Created 5 years, 4 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 <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 218
219 presentation_service_->CloseSession( 219 presentation_service_->CloseSession(
220 presentationUrl.utf8(), 220 presentationUrl.utf8(),
221 presentationId.utf8()); 221 presentationId.utf8());
222 } 222 }
223 223
224 void PresentationDispatcher::getAvailability( 224 void PresentationDispatcher::getAvailability(
225 const blink::WebString& presentationUrl, 225 const blink::WebString& presentationUrl,
226 blink::WebPresentationAvailabilityCallbacks* callbacks) { 226 blink::WebPresentationAvailabilityCallbacks* callbacks) {
227 if (listening_state_ == ListeningState::Active) { 227 if (listening_state_ == ListeningState::Active) {
228 callbacks->onSuccess(new bool(last_known_availability_)); 228 callbacks->onSuccess(last_known_availability_);
229 delete callbacks; 229 delete callbacks;
230 return; 230 return;
231 } 231 }
232 232
233 availability_callbacks_.Add(callbacks); 233 availability_callbacks_.Add(callbacks);
234 UpdateListeningState(); 234 UpdateListeningState();
235 } 235 }
236 236
237 void PresentationDispatcher::startListening( 237 void PresentationDispatcher::startListening(
238 blink::WebPresentationAvailabilityObserver* observer) { 238 blink::WebPresentationAvailabilityObserver* observer) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 last_known_availability_ = available; 270 last_known_availability_ = available;
271 271
272 if (listening_state_ == ListeningState::Waiting) 272 if (listening_state_ == ListeningState::Waiting)
273 listening_state_ = ListeningState::Active; 273 listening_state_ = ListeningState::Active;
274 274
275 for (auto observer : availability_observers_) 275 for (auto observer : availability_observers_)
276 observer->availabilityChanged(available); 276 observer->availabilityChanged(available);
277 277
278 for (AvailabilityCallbacksMap::iterator iter(&availability_callbacks_); 278 for (AvailabilityCallbacksMap::iterator iter(&availability_callbacks_);
279 !iter.IsAtEnd(); iter.Advance()) { 279 !iter.IsAtEnd(); iter.Advance()) {
280 iter.GetCurrentValue()->onSuccess(new bool(available)); 280 iter.GetCurrentValue()->onSuccess(available);
281 } 281 }
282 availability_callbacks_.Clear(); 282 availability_callbacks_.Clear();
283 283
284 UpdateListeningState(); 284 UpdateListeningState();
285 } 285 }
286 286
287 void PresentationDispatcher::OnScreenAvailabilityNotSupported() { 287 void PresentationDispatcher::OnScreenAvailabilityNotSupported() {
288 DCHECK(listening_state_ == ListeningState::Waiting); 288 DCHECK(listening_state_ == ListeningState::Waiting);
289 289
290 for (AvailabilityCallbacksMap::iterator iter(&availability_callbacks_); 290 for (AvailabilityCallbacksMap::iterator iter(&availability_callbacks_);
291 !iter.IsAtEnd(); iter.Advance()) { 291 !iter.IsAtEnd(); iter.Advance()) {
292 iter.GetCurrentValue()->onError(new blink::WebPresentationError( 292 iter.GetCurrentValue()->onError(blink::WebPresentationError(
293 blink::WebPresentationError::ErrorTypeAvailabilityNotSupported, 293 blink::WebPresentationError::ErrorTypeAvailabilityNotSupported,
294 blink::WebString::fromUTF8( 294 blink::WebString::fromUTF8(
295 "getAvailability() isn't supported at the moment. It can be due to" 295 "getAvailability() isn't supported at the moment. It can be due to"
296 "a permanent or temporary system limitation. It is recommended to" 296 "a permanent or temporary system limitation. It is recommended to"
297 "try to blindly start a session in that case."))); 297 "try to blindly start a session in that case.")));
298 } 298 }
299 availability_callbacks_.Clear(); 299 availability_callbacks_.Clear();
300 300
301 UpdateListeningState(); 301 UpdateListeningState();
302 } 302 }
(...skipping 15 matching lines...) Expand all
318 } 318 }
319 } 319 }
320 320
321 void PresentationDispatcher::OnSessionCreated( 321 void PresentationDispatcher::OnSessionCreated(
322 blink::WebPresentationSessionClientCallbacks* callback, 322 blink::WebPresentationSessionClientCallbacks* callback,
323 presentation::PresentationSessionInfoPtr session_info, 323 presentation::PresentationSessionInfoPtr session_info,
324 presentation::PresentationErrorPtr error) { 324 presentation::PresentationErrorPtr error) {
325 DCHECK(callback); 325 DCHECK(callback);
326 if (!error.is_null()) { 326 if (!error.is_null()) {
327 DCHECK(session_info.is_null()); 327 DCHECK(session_info.is_null());
328 callback->onError(new blink::WebPresentationError( 328 callback->onError(blink::WebPresentationError(
329 GetWebPresentationErrorTypeFromMojo(error->error_type), 329 GetWebPresentationErrorTypeFromMojo(error->error_type),
330 blink::WebString::fromUTF8(error->message))); 330 blink::WebString::fromUTF8(error->message)));
331 return; 331 return;
332 } 332 }
333 333
334 DCHECK(!session_info.is_null()); 334 DCHECK(!session_info.is_null());
335 callback->onSuccess(new PresentationSessionClient(session_info.Clone())); 335 callback->onSuccess(
336 blink::adoptWebPtr(new PresentationSessionClient(session_info.Clone())));
336 presentation_service_->ListenForSessionMessages(session_info.Pass()); 337 presentation_service_->ListenForSessionMessages(session_info.Pass());
337 } 338 }
338 339
339 void PresentationDispatcher::OnSessionStateChanged( 340 void PresentationDispatcher::OnSessionStateChanged(
340 presentation::PresentationSessionInfoPtr session_info, 341 presentation::PresentationSessionInfoPtr session_info,
341 presentation::PresentationSessionState session_state) { 342 presentation::PresentationSessionState session_state) {
342 if (!controller_) 343 if (!controller_)
343 return; 344 return;
344 345
345 DCHECK(!session_info.is_null()); 346 DCHECK(!session_info.is_null());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 460
460 presentation::SessionMessagePtr session_message = 461 presentation::SessionMessagePtr session_message =
461 presentation::SessionMessage::New(); 462 presentation::SessionMessage::New();
462 session_message->type = type; 463 session_message->type = type;
463 std::vector<uint8> tmp_data_vector(data, data + length); 464 std::vector<uint8> tmp_data_vector(data, data + length);
464 session_message->data.Swap(&tmp_data_vector); 465 session_message->data.Swap(&tmp_data_vector);
465 return new SendMessageRequest(session_info.Pass(), session_message.Pass()); 466 return new SendMessageRequest(session_info.Pass(), session_message.Pass());
466 } 467 }
467 468
468 } // namespace content 469 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698