OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/discovery/dial/dial_media_sink_service_imp l.h" | 5 #include "chrome/browser/media/router/discovery/dial/dial_media_sink_service_imp l.h" |
6 | 6 |
7 #include "chrome/browser/media/router/discovery/dial/dial_device_data.h" | 7 #include "chrome/browser/media/router/discovery/dial/dial_device_data.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "net/url_request/url_request_context_getter.h" | 10 #include "net/url_request/url_request_context_getter.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 } | 27 } |
28 | 28 |
29 void DialMediaSinkServiceImpl::Start() { | 29 void DialMediaSinkServiceImpl::Start() { |
30 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 30 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
31 if (dial_registry_) | 31 if (dial_registry_) |
32 return; | 32 return; |
33 | 33 |
34 dial_registry_ = DialRegistry::GetInstance(); | 34 dial_registry_ = DialRegistry::GetInstance(); |
35 dial_registry_->RegisterObserver(this); | 35 dial_registry_->RegisterObserver(this); |
36 dial_registry_->OnListenerAdded(); | 36 dial_registry_->OnListenerAdded(); |
37 StartTimer(); | |
37 } | 38 } |
38 | 39 |
39 void DialMediaSinkServiceImpl::Stop() { | 40 void DialMediaSinkServiceImpl::Stop() { |
40 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 41 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
41 if (!dial_registry_) | 42 if (!dial_registry_) |
42 return; | 43 return; |
43 | 44 |
44 dial_registry_->OnListenerRemoved(); | 45 dial_registry_->OnListenerRemoved(); |
45 dial_registry_->UnregisterObserver(this); | 46 dial_registry_->UnregisterObserver(this); |
46 dial_registry_ = nullptr; | 47 dial_registry_ = nullptr; |
48 finish_timer_.reset(); | |
Kevin M
2017/05/24 00:52:55
This is calling unique_ptr::reset() which will des
zhaobin
2017/05/24 17:45:51
On purpose. Need to destroy timer so that OnDevice
Kevin M
2017/05/24 18:13:29
OnDeviceDescriptionAvailable() will segfault, thou
zhaobin
2017/05/25 21:27:06
No segfault in the latest patch.
| |
47 } | 49 } |
48 | 50 |
49 DeviceDescriptionService* DialMediaSinkServiceImpl::GetDescriptionService() { | 51 DeviceDescriptionService* DialMediaSinkServiceImpl::GetDescriptionService() { |
50 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 52 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
51 if (!description_service_.get()) { | 53 if (!description_service_.get()) { |
52 description_service_.reset(new DeviceDescriptionService( | 54 description_service_.reset(new DeviceDescriptionService( |
53 base::Bind(&DialMediaSinkServiceImpl::OnDeviceDescriptionAvailable, | 55 base::Bind(&DialMediaSinkServiceImpl::OnDeviceDescriptionAvailable, |
54 base::Unretained(this)), | 56 base::Unretained(this)), |
55 base::Bind(&DialMediaSinkServiceImpl::OnDeviceDescriptionError, | 57 base::Bind(&DialMediaSinkServiceImpl::OnDeviceDescriptionError, |
56 base::Unretained(this)))); | 58 base::Unretained(this)))); |
(...skipping 16 matching lines...) Expand all Loading... | |
73 DCHECK(!description_service_); | 75 DCHECK(!description_service_); |
74 description_service_ = std::move(description_service); | 76 description_service_ = std::move(description_service); |
75 } | 77 } |
76 | 78 |
77 void DialMediaSinkServiceImpl::OnDialDeviceEvent( | 79 void DialMediaSinkServiceImpl::OnDialDeviceEvent( |
78 const DialRegistry::DeviceList& devices) { | 80 const DialRegistry::DeviceList& devices) { |
79 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 81 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
80 DVLOG(2) << "DialMediaSinkServiceImpl::OnDialDeviceEvent found " | 82 DVLOG(2) << "DialMediaSinkServiceImpl::OnDialDeviceEvent found " |
81 << devices.size() << " devices"; | 83 << devices.size() << " devices"; |
82 | 84 |
83 // Timer starts in |OnDialDeviceEvent()|, and expires 3 seconds later. If | |
84 // |OnDeviceDescriptionAvailable()| is called after |finish_timer_| expires, | |
85 // |finish_timer_| is restarted. | |
86 StartTimer(); | |
87 | |
88 current_sinks_.clear(); | 85 current_sinks_.clear(); |
89 current_devices_ = devices; | 86 current_devices_ = devices; |
90 | 87 |
91 GetDescriptionService()->GetDeviceDescriptions(devices, | 88 GetDescriptionService()->GetDeviceDescriptions(devices, |
92 request_context_.get()); | 89 request_context_.get()); |
93 } | 90 } |
94 | 91 |
95 void DialMediaSinkServiceImpl::OnDialError(DialRegistry::DialErrorCode type) { | 92 void DialMediaSinkServiceImpl::OnDialError(DialRegistry::DialErrorCode type) { |
96 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
97 DVLOG(2) << "OnDialError [DialErrorCode]: " << static_cast<int>(type); | 94 DVLOG(2) << "OnDialError [DialErrorCode]: " << static_cast<int>(type); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 } | 127 } |
131 | 128 |
132 void DialMediaSinkServiceImpl::OnDeviceDescriptionError( | 129 void DialMediaSinkServiceImpl::OnDeviceDescriptionError( |
133 const DialDeviceData& device, | 130 const DialDeviceData& device, |
134 const std::string& error_message) { | 131 const std::string& error_message) { |
135 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 132 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
136 DVLOG(2) << "OnDescriptionFetchesError [message]: " << error_message; | 133 DVLOG(2) << "OnDescriptionFetchesError [message]: " << error_message; |
137 } | 134 } |
138 | 135 |
139 } // namespace media_router | 136 } // namespace media_router |
OLD | NEW |