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

Side by Side Diff: chrome/browser/media/router/media_router_mojo_impl.cc

Issue 1527183003: Change mojo enums to be scoped enums in the generated C++ bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-binding-equals
Patch Set: rebase Created 4 years, 11 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 "chrome/browser/media/router/media_router_mojo_impl.h" 5 #include "chrome/browser/media/router/media_router_mojo_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 23 matching lines...) Expand all
34 34
35 using SinkAvailability = interfaces::MediaRouter::SinkAvailability; 35 using SinkAvailability = interfaces::MediaRouter::SinkAvailability;
36 36
37 namespace { 37 namespace {
38 38
39 scoped_ptr<content::PresentationSessionMessage> 39 scoped_ptr<content::PresentationSessionMessage>
40 ConvertToPresentationSessionMessage(interfaces::RouteMessagePtr input) { 40 ConvertToPresentationSessionMessage(interfaces::RouteMessagePtr input) {
41 DCHECK(!input.is_null()); 41 DCHECK(!input.is_null());
42 scoped_ptr<content::PresentationSessionMessage> output; 42 scoped_ptr<content::PresentationSessionMessage> output;
43 switch (input->type) { 43 switch (input->type) {
44 case interfaces::RouteMessage::Type::TYPE_TEXT: { 44 case interfaces::RouteMessage::Type::TEXT: {
45 DCHECK(!input->message.is_null()); 45 DCHECK(!input->message.is_null());
46 DCHECK(input->data.is_null()); 46 DCHECK(input->data.is_null());
47 output.reset(new content::PresentationSessionMessage( 47 output.reset(new content::PresentationSessionMessage(
48 content::PresentationMessageType::TEXT)); 48 content::PresentationMessageType::TEXT));
49 input->message.Swap(&output->message); 49 input->message.Swap(&output->message);
50 return output; 50 return output;
51 } 51 }
52 case interfaces::RouteMessage::Type::TYPE_BINARY: { 52 case interfaces::RouteMessage::Type::BINARY: {
53 DCHECK(!input->data.is_null()); 53 DCHECK(!input->data.is_null());
54 DCHECK(input->message.is_null()); 54 DCHECK(input->message.is_null());
55 output.reset(new content::PresentationSessionMessage( 55 output.reset(new content::PresentationSessionMessage(
56 content::PresentationMessageType::ARRAY_BUFFER)); 56 content::PresentationMessageType::ARRAY_BUFFER));
57 output->data.reset(new std::vector<uint8_t>); 57 output->data.reset(new std::vector<uint8_t>);
58 input->data.Swap(output->data.get()); 58 input->data.Swap(output->data.get());
59 return output; 59 return output;
60 } 60 }
61 } 61 }
62 62
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // |has_local_display_route| is false. Note that ObserverList supports 98 // |has_local_display_route| is false. Note that ObserverList supports
99 // removing an observer while iterating through it. 99 // removing an observer while iterating through it.
100 router_->UpdateHasLocalDisplayRoute(has_local_display_route); 100 router_->UpdateHasLocalDisplayRoute(has_local_display_route);
101 } 101 }
102 102
103 MediaRouterMojoImpl::MediaRouterMojoImpl( 103 MediaRouterMojoImpl::MediaRouterMojoImpl(
104 extensions::EventPageTracker* event_page_tracker) 104 extensions::EventPageTracker* event_page_tracker)
105 : event_page_tracker_(event_page_tracker), 105 : event_page_tracker_(event_page_tracker),
106 instance_id_(base::GenerateGUID()), 106 instance_id_(base::GenerateGUID()),
107 has_local_display_route_(false), 107 has_local_display_route_(false),
108 availability_(interfaces::MediaRouter::SINK_AVAILABILITY_UNAVAILABLE), 108 availability_(interfaces::MediaRouter::SinkAvailability::UNAVAILABLE),
109 wakeup_attempt_count_(0), 109 wakeup_attempt_count_(0),
110 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT), 110 current_wake_reason_(MediaRouteProviderWakeReason::TOTAL_COUNT),
111 weak_factory_(this) { 111 weak_factory_(this) {
112 DCHECK(event_page_tracker_); 112 DCHECK(event_page_tracker_);
113 } 113 }
114 114
115 MediaRouterMojoImpl::~MediaRouterMojoImpl() { 115 MediaRouterMojoImpl::~MediaRouterMojoImpl() {
116 DCHECK(thread_checker_.CalledOnValidThread()); 116 DCHECK(thread_checker_.CalledOnValidThread());
117 117
118 // Make sure |routes_observer_| is destroyed first, because it triggers 118 // Make sure |routes_observer_| is destroyed first, because it triggers
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 new_query = true; 423 new_query = true;
424 sinks_query = new MediaSinksQuery; 424 sinks_query = new MediaSinksQuery;
425 sinks_queries_.add(source_id, make_scoped_ptr(sinks_query)); 425 sinks_queries_.add(source_id, make_scoped_ptr(sinks_query));
426 } else { 426 } else {
427 DCHECK(!sinks_query->observers.HasObserver(observer)); 427 DCHECK(!sinks_query->observers.HasObserver(observer));
428 } 428 }
429 429
430 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. 430 // If sink availability is UNAVAILABLE, then there is no need to call MRPM.
431 // |observer| can be immediately notified with an empty list. 431 // |observer| can be immediately notified with an empty list.
432 sinks_query->observers.AddObserver(observer); 432 sinks_query->observers.AddObserver(observer);
433 if (availability_ == interfaces::MediaRouter::SINK_AVAILABILITY_UNAVAILABLE) { 433 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) {
434 observer->OnSinksReceived(std::vector<MediaSink>()); 434 observer->OnSinksReceived(std::vector<MediaSink>());
435 } else { 435 } else {
436 // Need to call MRPM to start observing sinks if the query is new. 436 // Need to call MRPM to start observing sinks if the query is new.
437 if (new_query) { 437 if (new_query) {
438 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); 438 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS);
439 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, 439 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks,
440 base::Unretained(this), source_id)); 440 base::Unretained(this), source_id));
441 } else if (sinks_query->has_cached_result) { 441 } else if (sinks_query->has_cached_result) {
442 observer->OnSinksReceived(sinks_query->cached_sink_list); 442 observer->OnSinksReceived(sinks_query->cached_sink_list);
443 } 443 }
(...skipping 14 matching lines...) Expand all
458 // If we are removing the final observer for the source, then stop 458 // If we are removing the final observer for the source, then stop
459 // observing sinks for it. 459 // observing sinks for it.
460 // might_have_observers() is reliable here on the assumption that this call 460 // might_have_observers() is reliable here on the assumption that this call
461 // is not inside the ObserverList iteration. 461 // is not inside the ObserverList iteration.
462 sinks_query->observers.RemoveObserver(observer); 462 sinks_query->observers.RemoveObserver(observer);
463 if (!sinks_query->observers.might_have_observers()) { 463 if (!sinks_query->observers.might_have_observers()) {
464 // Only ask MRPM to stop observing media sinks if the availability is not 464 // Only ask MRPM to stop observing media sinks if the availability is not
465 // UNAVAILABLE. 465 // UNAVAILABLE.
466 // Otherwise, the MRPM would have discarded the queries already. 466 // Otherwise, the MRPM would have discarded the queries already.
467 if (availability_ != 467 if (availability_ !=
468 interfaces::MediaRouter::SINK_AVAILABILITY_UNAVAILABLE) { 468 interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) {
469 SetWakeReason(MediaRouteProviderWakeReason::STOP_OBSERVING_MEDIA_SINKS); 469 SetWakeReason(MediaRouteProviderWakeReason::STOP_OBSERVING_MEDIA_SINKS);
470 // The |sinks_queries_| entry will be removed in the immediate or deferred 470 // The |sinks_queries_| entry will be removed in the immediate or deferred
471 // |DoStopObservingMediaSinks| call. 471 // |DoStopObservingMediaSinks| call.
472 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopObservingMediaSinks, 472 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopObservingMediaSinks,
473 base::Unretained(this), source_id)); 473 base::Unretained(this), source_id));
474 } else { 474 } else {
475 sinks_queries_.erase(source_id); 475 sinks_queries_.erase(source_id);
476 } 476 }
477 } 477 }
478 } 478 }
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 SinkAvailability availability) { 732 SinkAvailability availability) {
733 if (!interfaces::MediaRouter::SinkAvailability_IsValidValue(availability)) { 733 if (!interfaces::MediaRouter::SinkAvailability_IsValidValue(availability)) {
734 DLOG(WARNING) << "Unknown SinkAvailability value " << availability; 734 DLOG(WARNING) << "Unknown SinkAvailability value " << availability;
735 return; 735 return;
736 } 736 }
737 737
738 if (availability_ == availability) 738 if (availability_ == availability)
739 return; 739 return;
740 740
741 availability_ = availability; 741 availability_ = availability;
742 if (availability_ == interfaces::MediaRouter::SINK_AVAILABILITY_UNAVAILABLE) { 742 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE) {
743 // Sinks are no longer available. MRPM has already removed all sink queries. 743 // Sinks are no longer available. MRPM has already removed all sink queries.
744 for (auto& source_and_query : sinks_queries_) { 744 for (auto& source_and_query : sinks_queries_) {
745 auto* query = source_and_query.second; 745 auto* query = source_and_query.second;
746 query->is_active = false; 746 query->is_active = false;
747 query->has_cached_result = false; 747 query->has_cached_result = false;
748 query->cached_sink_list.clear(); 748 query->cached_sink_list.clear();
749 } 749 }
750 } else { 750 } else {
751 // Sinks are now available. Tell MRPM to start all sink queries again. 751 // Sinks are now available. Tell MRPM to start all sink queries again.
752 for (const auto& source_and_query : sinks_queries_) { 752 for (const auto& source_and_query : sinks_queries_) {
(...skipping 17 matching lines...) Expand all
770 } 770 }
771 771
772 bool MediaRouterMojoImpl::HasLocalDisplayRoute() const { 772 bool MediaRouterMojoImpl::HasLocalDisplayRoute() const {
773 return has_local_display_route_; 773 return has_local_display_route_;
774 } 774 }
775 775
776 void MediaRouterMojoImpl::DoStartObservingMediaSinks( 776 void MediaRouterMojoImpl::DoStartObservingMediaSinks(
777 const MediaSource::Id& source_id) { 777 const MediaSource::Id& source_id) {
778 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id; 778 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id;
779 // No need to call MRPM if there are no sinks available. 779 // No need to call MRPM if there are no sinks available.
780 if (availability_ == interfaces::MediaRouter::SINK_AVAILABILITY_UNAVAILABLE) 780 if (availability_ == interfaces::MediaRouter::SinkAvailability::UNAVAILABLE)
781 return; 781 return;
782 782
783 // No need to call MRPM if all observers have been removed in the meantime. 783 // No need to call MRPM if all observers have been removed in the meantime.
784 auto* sinks_query = sinks_queries_.get(source_id); 784 auto* sinks_query = sinks_queries_.get(source_id);
785 if (!sinks_query || !sinks_query->observers.might_have_observers()) 785 if (!sinks_query || !sinks_query->observers.might_have_observers())
786 return; 786 return;
787 787
788 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id; 788 DVLOG_WITH_INSTANCE(1) << "MRPM.StartObservingMediaSinks: " << source_id;
789 media_route_provider_->StartObservingMediaSinks(source_id); 789 media_route_provider_->StartObservingMediaSinks(source_id);
790 sinks_query->is_active = true; 790 sinks_query->is_active = true;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT) 933 if (current_wake_reason_ == MediaRouteProviderWakeReason::TOTAL_COUNT)
934 current_wake_reason_ = reason; 934 current_wake_reason_ = reason;
935 } 935 }
936 936
937 void MediaRouterMojoImpl::ClearWakeReason() { 937 void MediaRouterMojoImpl::ClearWakeReason() {
938 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT); 938 DCHECK(current_wake_reason_ != MediaRouteProviderWakeReason::TOTAL_COUNT);
939 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT; 939 current_wake_reason_ = MediaRouteProviderWakeReason::TOTAL_COUNT;
940 } 940 }
941 941
942 } // namespace media_router 942 } // namespace media_router
OLDNEW
« no previous file with comments | « blimp/engine/browser/blimp_permission_manager.cc ('k') | chrome/browser/media/router/media_router_mojo_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698