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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 #ifndef CHROME_BROWSER_MEDIA_ROUTER_DIAL_MEDIA_SINK_CACHE_SERVICE_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_DIAL_MEDIA_SINK_CACHE_SERVICE_H_
7
8 #include <memory>
9
10 #include "base/threading/thread_checker.h"
11 #include "chrome/browser/extensions/api/dial/dial_registry.h"
12 #include "chrome/browser/media/router/device_description_service.h"
13 #include "chrome/browser/media/router/discovery/media_sink_internal.h"
14 #include "chrome/browser/media/router/media_sink_service.h"
15
16 namespace net {
17 class URLRequestContextGetter;
18 }
19
20 namespace media_router {
21
22 class DeviceDescriptionService;
23
24 struct CachedDialMediaSink {
25 MediaSinkInternal sink;
26 GURL description_url;
27 base::Time last_update_time;
28 };
29
30 class DialMediaSinkCacheService {
31 public:
32 DialMediaSinkCacheService();
33 virtual ~DialMediaSinkCacheService();
34
35 // Returns all media sinks with lastUpdateTime + aliveTimeout > currentTime
36 virtual std::vector<MediaSinkInternal> GetAliveSinks();
37
38 // Remove all dead media sinks if |network_connected| is true. No op if
39 // |network_connected| is false;
40 void PruneInactiveSinks(bool network_connected,
41 DeviceDescriptionService* description_service,
42 net::URLRequestContextGetter* request_context);
43
44 // Create a media sink from |device_description|. If sink exists in cache,
45 // update it if any field has changed since last update and update
46 // lastUpdateTime. If sink deos not exist, add it to cache.
47 // Returns true if add or update actually happens.
48 bool AddOrUpdateSink(const DialDeviceDescription& device_description);
49
50 private:
51 friend class DialMediaSinkCacheServiceTest;
52
53 // Returns true if sink's lastUpdateTime + aliveTimeout > currentTime.
54 bool IsAlive(const CachedDialMediaSink& sink);
55
56 void OnCheckAccessCompleted(const std::string& sink_id, bool is_accessible);
57
58 // Map of <sink id, CachedDialMediaSink>
59 std::map<std::string, CachedDialMediaSink> cached_sinks_;
60
61 base::ThreadChecker thread_checker_;
62 };
63
64 } // namespace media_router
65
66 #endif // CHROME_BROWSER_MEDIA_ROUTER_DIAL_MEDIA_SINK_CACHE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698