| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 341 |
| 342 void PresentationDispatcher::OnScreenAvailabilityUpdated(bool available) { | 342 void PresentationDispatcher::OnScreenAvailabilityUpdated(bool available) { |
| 343 last_known_availability_ = available; | 343 last_known_availability_ = available; |
| 344 | 344 |
| 345 if (listening_state_ == ListeningState::Waiting) | 345 if (listening_state_ == ListeningState::Waiting) |
| 346 listening_state_ = ListeningState::Active; | 346 listening_state_ = ListeningState::Active; |
| 347 | 347 |
| 348 for (auto observer : availability_observers_) | 348 for (auto observer : availability_observers_) |
| 349 observer->availabilityChanged(available); | 349 observer->availabilityChanged(available); |
| 350 | 350 |
| 351 for (auto observer : availability_observers_) |
| 352 observer->availabilityChanged(available); |
| 353 |
| 351 for (AvailabilityCallbacksMap::iterator iter(&availability_callbacks_); | 354 for (AvailabilityCallbacksMap::iterator iter(&availability_callbacks_); |
| 352 !iter.IsAtEnd(); iter.Advance()) { | 355 !iter.IsAtEnd(); iter.Advance()) { |
| 353 iter.GetCurrentValue()->onSuccess(new bool(available)); | 356 iter.GetCurrentValue()->onSuccess(new bool(available)); |
| 354 } | 357 } |
| 355 availability_callbacks_.Clear(); | 358 availability_callbacks_.Clear(); |
| 356 | 359 |
| 357 UpdateListeningState(); | 360 UpdateListeningState(); |
| 358 } | 361 } |
| 359 | 362 |
| 363 void PresentationDispatcher::OnScreenAvailabilityNotSupported() { |
| 364 DCHECK(listening_state_ == ListeningState::Waiting); |
| 365 |
| 366 for (AvailabilityCallbacksMap::iterator iter(&availability_callbacks_); |
| 367 !iter.IsAtEnd(); iter.Advance()) { |
| 368 iter.GetCurrentValue()->onError(new blink::WebPresentationError( |
| 369 blink::WebPresentationError::ErrorTypeAvailabilityNotSupported, |
| 370 blink::WebString::fromUTF8( |
| 371 "getAvailability() isn't supported at the moment. It can be due to" |
| 372 "a permanent or temporary system limitation. It is recommended to" |
| 373 "try to blindly start a session in that case."))); |
| 374 } |
| 375 availability_callbacks_.Clear(); |
| 376 |
| 377 UpdateListeningState(); |
| 378 } |
| 379 |
| 360 void PresentationDispatcher::OnDefaultSessionStarted( | 380 void PresentationDispatcher::OnDefaultSessionStarted( |
| 361 presentation::PresentationSessionInfoPtr session_info) { | 381 presentation::PresentationSessionInfoPtr session_info) { |
| 362 if (!controller_) | 382 if (!controller_) |
| 363 return; | 383 return; |
| 364 | 384 |
| 365 // Reset the callback to get the next event. | 385 // Reset the callback to get the next event. |
| 366 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 386 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
| 367 &PresentationDispatcher::OnDefaultSessionStarted, | 387 &PresentationDispatcher::OnDefaultSessionStarted, |
| 368 base::Unretained(this))); | 388 base::Unretained(this))); |
| 369 | 389 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 if (should_listen) { | 476 if (should_listen) { |
| 457 listening_state_ = ListeningState::Waiting; | 477 listening_state_ = ListeningState::Waiting; |
| 458 presentation_service_->ListenForScreenAvailability(); | 478 presentation_service_->ListenForScreenAvailability(); |
| 459 } else { | 479 } else { |
| 460 listening_state_ = ListeningState::Inactive; | 480 listening_state_ = ListeningState::Inactive; |
| 461 presentation_service_->StopListeningForScreenAvailability(); | 481 presentation_service_->StopListeningForScreenAvailability(); |
| 462 } | 482 } |
| 463 } | 483 } |
| 464 | 484 |
| 465 } // namespace content | 485 } // namespace content |
| OLD | NEW |