Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/media/router/discovery/dial/dial_media_sink_cache_servi ce.h" | |
| 6 | |
| 7 #include "base/time/time.h" | |
| 8 | |
| 9 using base::Time; | |
| 10 using base::TimeDelta; | |
| 11 | |
| 12 namespace { | |
| 13 // The maximum time a response is expected after a M-SEARCH request. | |
| 14 const int kSinkAliveTimeoutSecs = 2 * 60; | |
| 15 } | |
| 16 | |
| 17 namespace media_router { | |
| 18 | |
| 19 DialMediaSinkCacheService::DialMediaSinkCacheService() {} | |
| 20 DialMediaSinkCacheService::~DialMediaSinkCacheService() {} | |
| 21 | |
| 22 std::vector<MediaSinkInternal> DialMediaSinkCacheService::GetAliveSinks() { | |
| 23 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 24 | |
| 25 std::vector<MediaSinkInternal> alive_sinks; | |
| 26 for (const auto& sink_it : cached_sinks_) { | |
| 27 if (IsAlive(sink_it.second)) | |
| 28 alive_sinks.push_back(sink_it.second.sink); | |
| 29 } | |
| 30 return alive_sinks; | |
| 31 } | |
| 32 | |
| 33 void DialMediaSinkCacheService::MayAddOrUpdateSink( | |
| 34 const DialDeviceData& device_data, | |
| 35 const ParsedDialDeviceDescription& device_description) { | |
| 36 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 37 | |
| 38 MediaSink sink(device_description.unique_id, device_description.friendly_name, | |
| 39 MediaSink::IconType::CAST); | |
|
imcheng
2017/04/12 19:33:51
Should IconType be GENERIC?
zhaobin
2017/04/18 06:58:27
Done.
| |
| 40 DialSinkExtraData extra_data; | |
| 41 extra_data.app_url = device_description.app_url; | |
| 42 extra_data.model_name = device_description.model_name; | |
| 43 DCHECK(extra_data.ip_address.AssignFromIPLiteral( | |
|
mark a. foltz
2017/04/12 00:17:18
Does this need to run in release builds?
zhaobin
2017/04/18 06:58:27
Yes. Changed to if.
| |
| 44 device_data.device_description_url().host())); | |
| 45 | |
| 46 CachedDialMediaSink cached_sink; | |
| 47 cached_sink.sink = MediaSinkInternal(sink, extra_data); | |
| 48 cached_sink.last_update_time = base::Time::Now(); | |
|
mark a. foltz
2017/04/12 00:17:18
Maybe it would be simpler to track a per-sink expi
zhaobin
2017/04/18 06:58:27
Done.
| |
| 49 | |
| 50 const auto& sink_it = cached_sinks_.find(sink.id()); | |
| 51 if (sink_it == cached_sinks_.end()) { | |
| 52 cached_sinks_.insert(std::make_pair(sink.id(), cached_sink)); | |
| 53 return; | |
| 54 } | |
| 55 | |
| 56 sink_it->second = cached_sink; | |
|
mark a. foltz
2017/04/12 00:17:18
Do you think it would be simpler to assign fields
zhaobin
2017/04/18 06:58:27
Done.
| |
| 57 } | |
| 58 | |
| 59 bool DialMediaSinkCacheService::IsAlive(const CachedDialMediaSink& sink) { | |
|
imcheng
2017/04/12 19:33:51
It seems we never erase from cached_sinks_; should
zhaobin
2017/04/18 06:58:27
I have removed all CheckAccess() related logic her
| |
| 60 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 61 | |
| 62 return sink.last_update_time + | |
| 63 base::TimeDelta::FromSeconds(kSinkAliveTimeoutSecs) > | |
| 64 base::Time::Now(); | |
| 65 } | |
| 66 | |
| 67 } // namespace media_router | |
| OLD | NEW |