| 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 "media/cast/logging/log_event_dispatcher.h" | 5 #include "media/cast/logging/log_event_dispatcher.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "media/cast/cast_environment.h" | 14 #include "media/cast/cast_environment.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 namespace cast { | 17 namespace cast { |
| 18 | 18 |
| 19 LogEventDispatcher::LogEventDispatcher(CastEnvironment* env) | 19 LogEventDispatcher::LogEventDispatcher(CastEnvironment* env) |
| 20 : env_(env), impl_(new Impl()) { | 20 : env_(env), impl_(new Impl()) { |
| 21 DCHECK(env_); | 21 DCHECK(env_); |
| 22 } | 22 } |
| 23 | 23 |
| 24 LogEventDispatcher::~LogEventDispatcher() {} | 24 LogEventDispatcher::~LogEventDispatcher() {} |
| 25 | 25 |
| 26 void LogEventDispatcher::DispatchFrameEvent( | 26 void LogEventDispatcher::DispatchFrameEvent( |
| 27 scoped_ptr<FrameEvent> event) const { | 27 std::unique_ptr<FrameEvent> event) const { |
| 28 if (env_->CurrentlyOn(CastEnvironment::MAIN)) { | 28 if (env_->CurrentlyOn(CastEnvironment::MAIN)) { |
| 29 impl_->DispatchFrameEvent(std::move(event)); | 29 impl_->DispatchFrameEvent(std::move(event)); |
| 30 } else { | 30 } else { |
| 31 env_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 31 env_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
| 32 base::Bind(&LogEventDispatcher::Impl::DispatchFrameEvent, | 32 base::Bind(&LogEventDispatcher::Impl::DispatchFrameEvent, |
| 33 impl_, base::Passed(&event))); | 33 impl_, base::Passed(&event))); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 void LogEventDispatcher::DispatchPacketEvent( | 37 void LogEventDispatcher::DispatchPacketEvent( |
| 38 scoped_ptr<PacketEvent> event) const { | 38 std::unique_ptr<PacketEvent> event) const { |
| 39 if (env_->CurrentlyOn(CastEnvironment::MAIN)) { | 39 if (env_->CurrentlyOn(CastEnvironment::MAIN)) { |
| 40 impl_->DispatchPacketEvent(std::move(event)); | 40 impl_->DispatchPacketEvent(std::move(event)); |
| 41 } else { | 41 } else { |
| 42 env_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 42 env_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
| 43 base::Bind(&LogEventDispatcher::Impl::DispatchPacketEvent, | 43 base::Bind(&LogEventDispatcher::Impl::DispatchPacketEvent, |
| 44 impl_, base::Passed(&event))); | 44 impl_, base::Passed(&event))); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 void LogEventDispatcher::DispatchBatchOfEvents( | 48 void LogEventDispatcher::DispatchBatchOfEvents( |
| 49 scoped_ptr<std::vector<FrameEvent>> frame_events, | 49 std::unique_ptr<std::vector<FrameEvent>> frame_events, |
| 50 scoped_ptr<std::vector<PacketEvent>> packet_events) const { | 50 std::unique_ptr<std::vector<PacketEvent>> packet_events) const { |
| 51 if (env_->CurrentlyOn(CastEnvironment::MAIN)) { | 51 if (env_->CurrentlyOn(CastEnvironment::MAIN)) { |
| 52 impl_->DispatchBatchOfEvents(std::move(frame_events), | 52 impl_->DispatchBatchOfEvents(std::move(frame_events), |
| 53 std::move(packet_events)); | 53 std::move(packet_events)); |
| 54 } else { | 54 } else { |
| 55 env_->PostTask( | 55 env_->PostTask( |
| 56 CastEnvironment::MAIN, FROM_HERE, | 56 CastEnvironment::MAIN, FROM_HERE, |
| 57 base::Bind(&LogEventDispatcher::Impl::DispatchBatchOfEvents, impl_, | 57 base::Bind(&LogEventDispatcher::Impl::DispatchBatchOfEvents, impl_, |
| 58 base::Passed(&frame_events), base::Passed(&packet_events))); | 58 base::Passed(&frame_events), base::Passed(&packet_events))); |
| 59 } | 59 } |
| 60 } | 60 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 LogEventDispatcher::Impl::Impl() {} | 96 LogEventDispatcher::Impl::Impl() {} |
| 97 | 97 |
| 98 LogEventDispatcher::Impl::~Impl() { | 98 LogEventDispatcher::Impl::~Impl() { |
| 99 DCHECK(subscribers_.empty()); | 99 DCHECK(subscribers_.empty()); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void LogEventDispatcher::Impl::DispatchFrameEvent( | 102 void LogEventDispatcher::Impl::DispatchFrameEvent( |
| 103 scoped_ptr<FrameEvent> event) const { | 103 std::unique_ptr<FrameEvent> event) const { |
| 104 for (RawEventSubscriber* s : subscribers_) | 104 for (RawEventSubscriber* s : subscribers_) |
| 105 s->OnReceiveFrameEvent(*event); | 105 s->OnReceiveFrameEvent(*event); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void LogEventDispatcher::Impl::DispatchPacketEvent( | 108 void LogEventDispatcher::Impl::DispatchPacketEvent( |
| 109 scoped_ptr<PacketEvent> event) const { | 109 std::unique_ptr<PacketEvent> event) const { |
| 110 for (RawEventSubscriber* s : subscribers_) | 110 for (RawEventSubscriber* s : subscribers_) |
| 111 s->OnReceivePacketEvent(*event); | 111 s->OnReceivePacketEvent(*event); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void LogEventDispatcher::Impl::DispatchBatchOfEvents( | 114 void LogEventDispatcher::Impl::DispatchBatchOfEvents( |
| 115 scoped_ptr<std::vector<FrameEvent>> frame_events, | 115 std::unique_ptr<std::vector<FrameEvent>> frame_events, |
| 116 scoped_ptr<std::vector<PacketEvent>> packet_events) const { | 116 std::unique_ptr<std::vector<PacketEvent>> packet_events) const { |
| 117 for (RawEventSubscriber* s : subscribers_) { | 117 for (RawEventSubscriber* s : subscribers_) { |
| 118 for (const FrameEvent& e : *frame_events) | 118 for (const FrameEvent& e : *frame_events) |
| 119 s->OnReceiveFrameEvent(e); | 119 s->OnReceiveFrameEvent(e); |
| 120 for (const PacketEvent& e : *packet_events) | 120 for (const PacketEvent& e : *packet_events) |
| 121 s->OnReceivePacketEvent(e); | 121 s->OnReceivePacketEvent(e); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 void LogEventDispatcher::Impl::Subscribe(RawEventSubscriber* subscriber) { | 125 void LogEventDispatcher::Impl::Subscribe(RawEventSubscriber* subscriber) { |
| 126 DCHECK(std::find(subscribers_.begin(), subscribers_.end(), subscriber) == | 126 DCHECK(std::find(subscribers_.begin(), subscribers_.end(), subscriber) == |
| 127 subscribers_.end()); | 127 subscribers_.end()); |
| 128 subscribers_.push_back(subscriber); | 128 subscribers_.push_back(subscriber); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void LogEventDispatcher::Impl::Unsubscribe(RawEventSubscriber* subscriber) { | 131 void LogEventDispatcher::Impl::Unsubscribe(RawEventSubscriber* subscriber) { |
| 132 const auto it = | 132 const auto it = |
| 133 std::find(subscribers_.begin(), subscribers_.end(), subscriber); | 133 std::find(subscribers_.begin(), subscribers_.end(), subscriber); |
| 134 DCHECK(it != subscribers_.end()); | 134 DCHECK(it != subscribers_.end()); |
| 135 subscribers_.erase(it); | 135 subscribers_.erase(it); |
| 136 } | 136 } |
| 137 | 137 |
| 138 } // namespace cast | 138 } // namespace cast |
| 139 } // namespace media | 139 } // namespace media |
| OLD | NEW |