| Index: chrome/browser/media/router/discovery/dial/dial_media_sink_cache_service.h
|
| diff --git a/chrome/browser/media/router/discovery/dial/dial_media_sink_cache_service.h b/chrome/browser/media/router/discovery/dial/dial_media_sink_cache_service.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cf379990904f4bb72913b5e13201b722c457f9be
|
| --- /dev/null
|
| +++ b/chrome/browser/media/router/discovery/dial/dial_media_sink_cache_service.h
|
| @@ -0,0 +1,58 @@
|
| +// 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_DISCOVERY_DIAL_DIAL_MEDIA_SINK_CACHE_SERVICE_H_
|
| +#define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_CACHE_SERVICE_H_
|
| +
|
| +#include <map>
|
| +#include <memory>
|
| +
|
| +#include "base/threading/thread_checker.h"
|
| +#include "chrome/browser/media/router/discovery/dial/dial_device_data.h"
|
| +#include "chrome/browser/media/router/discovery/dial/parsed_dial_device_description.h"
|
| +#include "chrome/browser/media/router/discovery/media_sink_internal.h"
|
| +
|
| +namespace media_router {
|
| +
|
| +// Represents cached media sink.
|
| +struct CachedDialMediaSink {
|
| + // The time the media sink was updated, in ms after the epoch.
|
| + base::Time last_update_time;
|
| +
|
| + // The expiration time from the cache, in ms after the epoch.
|
| + base::Time expire_time;
|
| +
|
| + // Underlying media sink object.
|
| + MediaSinkInternal sink;
|
| +};
|
| +
|
| +class DialMediaSinkCacheService {
|
| + public:
|
| + DialMediaSinkCacheService();
|
| + virtual ~DialMediaSinkCacheService();
|
| +
|
| + // Returns all media sinks with lastUpdateTime + aliveTimeout > currentTime
|
| + virtual std::vector<MediaSinkInternal> GetAliveSinks();
|
| +
|
| + // Create a media sink from |device_data| and |description_data|. 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.
|
| + void MayAddOrUpdateSink(const DialDeviceData& device_data,
|
| + const ParsedDialDeviceDescription& description_data);
|
| +
|
| + private:
|
| + friend class DialMediaSinkCacheServiceTest;
|
| +
|
| + // Returns true if sink's lastUpdateTime + aliveTimeout > currentTime.
|
| + bool IsAlive(const CachedDialMediaSink& sink);
|
| +
|
| + // Map of <sink id, CachedDialMediaSink>
|
| + std::map<std::string, CachedDialMediaSink> cached_sinks_;
|
| +
|
| + base::ThreadChecker thread_checker_;
|
| +};
|
| +
|
| +} // namespace media_router
|
| +
|
| +#endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_DIAL_DIAL_MEDIA_SINK_CACHE_SERVICE_H_
|
|
|