Index: media/blink/url_index.h |
diff --git a/media/blink/url_index.h b/media/blink/url_index.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b780d21107ed81f934e312565ca84302b7773ec6 |
--- /dev/null |
+++ b/media/blink/url_index.h |
@@ -0,0 +1,128 @@ |
+// Copyright 2015 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 MEDIA_BLINK_URL_INDEX_H_ |
+#define MEDIA_BLINK_URL_INDEX_H_ |
+ |
+#include <map> |
+#include <vector> |
+ |
+#include "base/memory/ref_counted.h" |
+#include "base/threading/thread_checker.h" |
+#include "media/base/media_export.h" |
+#include "media/blink/lru.h" |
+#include "url/gurl.h" |
+ |
+namespace media { |
+ |
+#ifndef MEDIA_BLINK_BUFFERED_RESOURCE_LOADER_H_ |
+const int64 kPositionNotSpecified = -1; |
+#endif |
+ |
+class UrlIndex; |
+ |
+class MEDIA_EXPORT UrlData : public base::RefCounted<UrlData> { |
+public: |
+ // Keep in sync with WebMediaPlayer::CORSMode. |
+ enum CORSMode { kUnspecified, kAnonymous, kUseCredentials }; |
+ typedef std::pair<GURL, CORSMode> KeyType; |
+ |
+ const GURL url() const { return url_; } |
+ const GURL redirects_to() const { return redirects_to_; } |
+ CORSMode cors_mode() const { return cors_mode_; } |
+ bool range_supported() const { return range_supported_; } |
+ bool cacheable() const { return cacheable_; } |
+ base::TimeTicks last_used() const { return last_used_; } |
+ base::Time last_modified() const { return last_modified_; } |
+ base::TimeTicks valid_until() const { return valid_until_; } |
+ KeyType key() const; |
+ |
+ // Notifies the url index that this is currently used. |
+ // The URL will get a new ID if this is not called |
+ // regularly. |
+ void Use(); |
+ |
+ // Length of data associated with url or |kPositionNotSpecified| |
+ int64 length() const { return length_; } |
+ |
+ // DO NOT call this function unless the redirect is to the same |
+ // origin or a CORS check has been performed. |
+ void set_redirects_to(const GURL& url); |
+ |
+ void set_range_supported(); |
+ void set_length(int64 length); |
+ void set_cacheable(bool cacheable); |
+ void set_valid_until(base::TimeTicks t); |
+ |
+ // Set the last_modified time on |urldata|. This also allows the url |
+ // index to re-use previously expired UrlData instances. If such |
+ // an instance is discovered, it is returned, otherwise |urldata| |
+ // is returned. |
+ scoped_refptr<UrlData> set_last_modified(base::Time last_modified); |
+ |
+ // Returns true it is valid to keep using this to access cached data. |
+ // A single media player instance may choose to ignore this for resources |
+ // that have already been opened. |
+ bool Valid() const; |
+ |
+ private: |
+ friend class UrlIndex; |
+ friend class base::RefCounted<UrlData>; |
+ |
+ ~UrlData(); |
+ UrlData(const GURL& url, |
+ CORSMode cors_mode_, |
+ UrlIndex* url_index_); |
+ void set_last_modified_internal(base::Time t); |
+ void DisconnectFromIndex(); |
+ |
+ const GURL url_; |
+ const CORSMode cors_mode_; |
+ |
+ GURL redirects_to_; |
+ int64 length_; |
+ bool range_supported_; |
+ bool cacheable_; |
+ |
+ base::TimeTicks last_used_; |
+ base::TimeTicks valid_until_; |
+ base::Time last_modified_; |
+ |
+ base::ThreadChecker thread_checker_; |
+ UrlIndex* url_index_; |
+ DISALLOW_COPY_AND_ASSIGN(UrlData); |
+}; |
+ |
+// The UrlIndex lets you look up UrlData instances by url. |
+// It keeps a weak reference to UrlData that it has returned. |
+// Since the multibuffer cache key contains an UrlData reference |
+// we can be sure that UrlData instances with zero references |
+// do not have any cached data associated with them, and they |
+// can safely be removed from the UrlIndex. |
+class MEDIA_EXPORT UrlIndex { |
+public: |
+ UrlIndex(); |
+ ~UrlIndex(); |
+ // Creates a new UrlData if not found. |
+ // |last_modified| may be null if not known. |
+ // Normally you'll want to call Use() on the returned object right away. |
+ scoped_refptr<UrlData> GetByUrl(const GURL& gurl, |
+ UrlData::CORSMode cors_mode); |
+ |
DaleCurtis
2015/10/19 21:45:26
Extra line.
hubbe
2015/10/20 00:31:39
Done.
|
+ |
+private: |
+ friend class UrlData; |
+ void RemoveUrlData(const UrlData* url_data); |
+ // TODO(hubbe): Add support for etag validation. |
+ scoped_refptr<UrlData> SetLastModified(scoped_refptr<UrlData> urldata, |
+ base::Time last_modified); |
+ |
+ std::map<UrlData::KeyType, UrlData*> by_url_; |
+ std::map<UrlData::KeyType, UrlData*> with_last_modified_; |
+ std::list<scoped_refptr<UrlData> > to_prune_; |
+ bool prune_cb_active_; |
+}; |
+ |
+} // namespace media |
+#endif // MEDIA_BLINK_URL_INDEX_H_ |