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

Unified Diff: chrome/browser/media/router/discovery/dial/dial_media_sink_cache_service.cc

Issue 2701633002: [Media Router] Add DialMediaSinkService and DeviceDescriptionService (Closed)
Patch Set: resolve code review comments from Mark cont Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/router/discovery/dial/dial_media_sink_cache_service.cc
diff --git a/chrome/browser/media/router/discovery/dial/dial_media_sink_cache_service.cc b/chrome/browser/media/router/discovery/dial/dial_media_sink_cache_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b35105629d33e9516ae7a9854b870fb48c15bf68
--- /dev/null
+++ b/chrome/browser/media/router/discovery/dial/dial_media_sink_cache_service.cc
@@ -0,0 +1,67 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media/router/discovery/dial/dial_media_sink_cache_service.h"
+
+#include "base/time/time.h"
+
+using base::Time;
+using base::TimeDelta;
+
+namespace {
+// The maximum time a response is expected after a M-SEARCH request.
+const int kSinkAliveTimeoutSecs = 2 * 60;
+}
+
+namespace media_router {
+
+DialMediaSinkCacheService::DialMediaSinkCacheService() {}
+DialMediaSinkCacheService::~DialMediaSinkCacheService() {}
+
+std::vector<MediaSinkInternal> DialMediaSinkCacheService::GetAliveSinks() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ std::vector<MediaSinkInternal> alive_sinks;
+ for (const auto& sink_it : cached_sinks_) {
+ if (IsAlive(sink_it.second))
+ alive_sinks.push_back(sink_it.second.sink);
+ }
+ return alive_sinks;
+}
+
+void DialMediaSinkCacheService::MayAddOrUpdateSink(
+ const DialDeviceData& device_data,
+ const ParsedDialDeviceDescription& device_description) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ MediaSink sink(device_description.unique_id, device_description.friendly_name,
+ MediaSink::IconType::CAST);
imcheng 2017/04/12 19:33:51 Should IconType be GENERIC?
zhaobin 2017/04/18 06:58:27 Done.
+ DialSinkExtraData extra_data;
+ extra_data.app_url = device_description.app_url;
+ extra_data.model_name = device_description.model_name;
+ 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.
+ device_data.device_description_url().host()));
+
+ CachedDialMediaSink cached_sink;
+ cached_sink.sink = MediaSinkInternal(sink, extra_data);
+ 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.
+
+ const auto& sink_it = cached_sinks_.find(sink.id());
+ if (sink_it == cached_sinks_.end()) {
+ cached_sinks_.insert(std::make_pair(sink.id(), cached_sink));
+ return;
+ }
+
+ 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.
+}
+
+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
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ return sink.last_update_time +
+ base::TimeDelta::FromSeconds(kSinkAliveTimeoutSecs) >
+ base::Time::Now();
+}
+
+} // namespace media_router

Powered by Google App Engine
This is Rietveld 408576698