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

Side by Side Diff: content/renderer/media/webrtc/track_observer.cc

Issue 2924033002: TrackObserver DCHECK not on main thread, tests updated. (Closed)
Patch Set: MediaStreamRemoteVideoSourceTest using the signaling thread Created 3 years, 6 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
« no previous file with comments | « content/renderer/media/webrtc/media_stream_remote_video_source_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/media/webrtc/track_observer.h" 5 #include "content/renderer/media/webrtc/track_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/threading/thread_checker.h"
10 9
11 namespace content { 10 namespace content {
12 11
13 class CONTENT_EXPORT TrackObserver::TrackObserverImpl 12 class CONTENT_EXPORT TrackObserver::TrackObserverImpl
14 : public base::RefCountedThreadSafe<TrackObserver::TrackObserverImpl>, 13 : public base::RefCountedThreadSafe<TrackObserver::TrackObserverImpl>,
15 NON_EXPORTED_BASE(public webrtc::ObserverInterface) { 14 NON_EXPORTED_BASE(public webrtc::ObserverInterface) {
16 public: 15 public:
17 TrackObserverImpl( 16 TrackObserverImpl(
18 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread, 17 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
19 const scoped_refptr<webrtc::MediaStreamTrackInterface>& track) 18 const scoped_refptr<webrtc::MediaStreamTrackInterface>& track)
20 : main_thread_(main_thread), track_(track) { 19 : main_thread_(main_thread), track_(track) {
21 // We're on the signaling thread. 20 // We're on the signaling thread.
21 DCHECK(!main_thread_->BelongsToCurrentThread());
22 track->RegisterObserver(this); 22 track->RegisterObserver(this);
23 } 23 }
24 24
25 const scoped_refptr<webrtc::MediaStreamTrackInterface>& track() const { 25 const scoped_refptr<webrtc::MediaStreamTrackInterface>& track() const {
26 return track_; 26 return track_;
27 } 27 }
28 28
29 const scoped_refptr<base::SingleThreadTaskRunner> main_thread() const { 29 const scoped_refptr<base::SingleThreadTaskRunner> main_thread() const {
30 return main_thread_; 30 return main_thread_;
31 } 31 }
(...skipping 26 matching lines...) Expand all
58 } 58 }
59 59
60 private: 60 private:
61 friend class base::RefCountedThreadSafe<TrackObserverImpl>; 61 friend class base::RefCountedThreadSafe<TrackObserverImpl>;
62 ~TrackObserverImpl() override { 62 ~TrackObserverImpl() override {
63 DCHECK(!track_.get()) << "must have been unregistered before deleting"; 63 DCHECK(!track_.get()) << "must have been unregistered before deleting";
64 } 64 }
65 65
66 // webrtc::ObserverInterface implementation. 66 // webrtc::ObserverInterface implementation.
67 void OnChanged() override { 67 void OnChanged() override {
68 DCHECK(signaling_thread_.CalledOnValidThread()); 68 DCHECK(!main_thread_->BelongsToCurrentThread());
69 webrtc::MediaStreamTrackInterface::TrackState state = track_->state(); 69 webrtc::MediaStreamTrackInterface::TrackState state = track_->state();
70 main_thread_->PostTask(FROM_HERE, 70 main_thread_->PostTask(FROM_HERE,
71 base::Bind(&TrackObserverImpl::OnChangedOnMainThread, this, state)); 71 base::Bind(&TrackObserverImpl::OnChangedOnMainThread, this, state));
72 } 72 }
73 73
74 void OnChangedOnMainThread( 74 void OnChangedOnMainThread(
75 webrtc::MediaStreamTrackInterface::TrackState state) { 75 webrtc::MediaStreamTrackInterface::TrackState state) {
76 DCHECK(main_thread_->BelongsToCurrentThread()); 76 DCHECK(main_thread_->BelongsToCurrentThread());
77 if (!callback_.is_null()) 77 if (!callback_.is_null())
78 callback_.Run(state); 78 callback_.Run(state);
79 } 79 }
80 80
81 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; 81 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
82 scoped_refptr<webrtc::MediaStreamTrackInterface> track_; 82 scoped_refptr<webrtc::MediaStreamTrackInterface> track_;
83 OnChangedCallback callback_; // Only touched on the main thread. 83 OnChangedCallback callback_; // Only touched on the main thread.
84 base::ThreadChecker signaling_thread_;
85 }; 84 };
86 85
87 TrackObserver::TrackObserver( 86 TrackObserver::TrackObserver(
88 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread, 87 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
89 const scoped_refptr<webrtc::MediaStreamTrackInterface>& track) 88 const scoped_refptr<webrtc::MediaStreamTrackInterface>& track)
90 : observer_(new TrackObserverImpl(main_thread, track)) { 89 : observer_(new TrackObserverImpl(main_thread, track)) {
91 } 90 }
92 91
93 TrackObserver::~TrackObserver() { 92 TrackObserver::~TrackObserver() {
94 // Explicitly unregister before releasing our reference. 93 // Explicitly unregister before releasing our reference.
95 // We do this to avoid a race that could happen if we try to unregister 94 // We do this to avoid a race that could happen if we try to unregister
96 // inside the dtor of the observer and then receive an event that causes 95 // inside the dtor of the observer and then receive an event that causes
97 // the ref count to go up while being destroyed. 96 // the ref count to go up while being destroyed.
98 observer_->Unregister(); 97 observer_->Unregister();
99 } 98 }
100 99
101 void TrackObserver::SetCallback(const OnChangedCallback& callback) { 100 void TrackObserver::SetCallback(const OnChangedCallback& callback) {
102 DCHECK(observer_->main_thread()->BelongsToCurrentThread()); 101 DCHECK(observer_->main_thread()->BelongsToCurrentThread());
103 observer_->SetCallback(callback); 102 observer_->SetCallback(callback);
104 } 103 }
105 104
106 const scoped_refptr<webrtc::MediaStreamTrackInterface>& 105 const scoped_refptr<webrtc::MediaStreamTrackInterface>&
107 TrackObserver::track() const { 106 TrackObserver::track() const {
108 return observer_->track(); 107 return observer_->track();
109 } 108 }
110 109
111 } // namespace content 110 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc/media_stream_remote_video_source_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698