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

Side by Side Diff: chrome/browser/media/router/discovery/dial/dial_media_sink_cache_service.h

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 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_DISCOVERY_DIAL_DIAL_MEDIA_SINK_CACHE_SERVICE _H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_CACHE_SERVICE _H_
7
8 #include <map>
9 #include <memory>
10
11 #include "base/threading/thread_checker.h"
12 #include "chrome/browser/media/router/discovery/dial/dial_device_data.h"
13 #include "chrome/browser/media/router/discovery/dial/parsed_dial_device_descript ion.h"
14 #include "chrome/browser/media/router/discovery/media_sink_internal.h"
15
16 namespace media_router {
17
18 // Represents cached media sink.
19 struct CachedDialMediaSink {
20 // The time the media sink was updated, in ms after the epoch.
21 base::Time last_update_time;
22
23 // The expiration time from the cache, in ms after the epoch.
24 base::Time expire_time;
25
26 // Underlying media sink object.
27 MediaSinkInternal sink;
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 // Create a media sink from |device_data| and |description_data|. If sink
39 // exists in cache, update it if any field has changed since last update and
40 // update lastUpdateTime. If sink deos not exist, add it to cache.
41 void MayAddOrUpdateSink(const DialDeviceData& device_data,
42 const ParsedDialDeviceDescription& description_data);
43
44 private:
45 friend class DialMediaSinkCacheServiceTest;
46
47 // Returns true if sink's lastUpdateTime + aliveTimeout > currentTime.
48 bool IsAlive(const CachedDialMediaSink& sink);
49
50 // Map of <sink id, CachedDialMediaSink>
51 std::map<std::string, CachedDialMediaSink> cached_sinks_;
52
53 base::ThreadChecker thread_checker_;
54 };
55
56 } // namespace media_router
57
58 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_CACHE_SERV ICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698