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

Unified Diff: chrome/browser/media/router/dial_media_sink_cache_service.h

Issue 2701633002: [Media Router] Add DialMediaSinkService and DeviceDescriptionService (Closed)
Patch Set: Add DialMediaSinkCacheService and unit test Created 3 years, 9 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/dial_media_sink_cache_service.h
diff --git a/chrome/browser/media/router/dial_media_sink_cache_service.h b/chrome/browser/media/router/dial_media_sink_cache_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..b680f729f458f145f1ec386176d8f751473f4a95
--- /dev/null
+++ b/chrome/browser/media/router/dial_media_sink_cache_service.h
@@ -0,0 +1,66 @@
+// 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.
+
+#ifndef CHROME_BROWSER_MEDIA_ROUTER_DIAL_MEDIA_SINK_CACHE_SERVICE_H_
+#define CHROME_BROWSER_MEDIA_ROUTER_DIAL_MEDIA_SINK_CACHE_SERVICE_H_
+
+#include <memory>
+
+#include "base/threading/thread_checker.h"
+#include "chrome/browser/extensions/api/dial/dial_registry.h"
+#include "chrome/browser/media/router/device_description_service.h"
+#include "chrome/browser/media/router/discovery/media_sink_internal.h"
+#include "chrome/browser/media/router/media_sink_service.h"
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+namespace media_router {
+
+class DeviceDescriptionService;
+
+struct CachedDialMediaSink {
+ MediaSinkInternal sink;
+ GURL description_url;
+ base::Time last_update_time;
+};
+
+class DialMediaSinkCacheService {
+ public:
+ DialMediaSinkCacheService();
+ virtual ~DialMediaSinkCacheService();
+
+ // Returns all media sinks with lastUpdateTime + aliveTimeout > currentTime
+ virtual std::vector<MediaSinkInternal> GetAliveSinks();
+
+ // Remove all dead media sinks if |network_connected| is true. No op if
+ // |network_connected| is false;
+ void PruneInactiveSinks(bool network_connected,
+ DeviceDescriptionService* description_service,
+ net::URLRequestContextGetter* request_context);
+
+ // Create a media sink from |device_description|. If sink exists in cache,
+ // update it if any field has changed since last update and update
+ // lastUpdateTime. If sink deos not exist, add it to cache.
+ // Returns true if add or update actually happens.
+ bool AddOrUpdateSink(const DialDeviceDescription& device_description);
+
+ private:
+ friend class DialMediaSinkCacheServiceTest;
+
+ // Returns true if sink's lastUpdateTime + aliveTimeout > currentTime.
+ bool IsAlive(const CachedDialMediaSink& sink);
+
+ void OnCheckAccessCompleted(const std::string& sink_id, bool is_accessible);
+
+ // Map of <sink id, CachedDialMediaSink>
+ std::map<std::string, CachedDialMediaSink> cached_sinks_;
+
+ base::ThreadChecker thread_checker_;
+};
+
+} // namespace media_router
+
+#endif // CHROME_BROWSER_MEDIA_ROUTER_DIAL_MEDIA_SINK_CACHE_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698