Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 MEDIA_BLINK_URL_INDEX_H_ | |
| 6 #define MEDIA_BLINK_URL_INDEX_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/threading/thread_checker.h" | |
| 13 #include "media/base/media_export.h" | |
| 14 #include "media/blink/lru.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 namespace media { | |
| 18 | |
| 19 #ifndef MEDIA_BLINK_BUFFERED_RESOURCE_LOADER_H_ | |
| 20 const int64 kPositionNotSpecified = -1; | |
| 21 #endif | |
| 22 | |
| 23 class UrlIndex; | |
| 24 | |
| 25 class MEDIA_EXPORT UrlData : public base::RefCounted<UrlData> { | |
| 26 public: | |
| 27 // Keep in sync with WebMediaPlayer::CORSMode. | |
| 28 enum CORSMode { kUnspecified, kAnonymous, kUseCredentials }; | |
| 29 typedef std::pair<GURL, CORSMode> KeyType; | |
| 30 | |
| 31 const GURL url() const { return url_; } | |
| 32 const GURL redirects_to() const { return redirects_to_; } | |
| 33 CORSMode cors_mode() const { return cors_mode_; } | |
| 34 bool range_supported() const { return range_supported_; } | |
| 35 bool cacheable() const { return cacheable_; } | |
| 36 base::TimeTicks last_used() const { return last_used_; } | |
| 37 base::Time last_modified() const { return last_modified_; } | |
| 38 base::TimeTicks valid_until() const { return valid_until_; } | |
| 39 KeyType key() const; | |
| 40 | |
| 41 // Notifies the url index that this is currently used. | |
| 42 // The URL will get a new ID if this is not called | |
| 43 // regularly. | |
| 44 void Use(); | |
| 45 | |
| 46 // Length of data associated with url or |kPositionNotSpecified| | |
| 47 int64 length() const { return length_; } | |
| 48 | |
| 49 // DO NOT call this function unless the redirect is to the same | |
| 50 // origin or a CORS check has been performed. | |
| 51 void set_redirects_to(const GURL& url); | |
| 52 | |
| 53 void set_range_supported(); | |
| 54 void set_length(int64 length); | |
| 55 void set_cacheable(bool cacheable); | |
| 56 void set_valid_until(base::TimeTicks t); | |
| 57 | |
| 58 // Set the last_modified time on |urldata|. This also allows the url | |
| 59 // index to re-use previously expired UrlData instances. If such | |
| 60 // an instance is discovered, it is returned, otherwise |urldata| | |
| 61 // is returned. | |
| 62 scoped_refptr<UrlData> set_last_modified(base::Time last_modified); | |
| 63 | |
| 64 // Returns true it is valid to keep using this to access cached data. | |
| 65 // A single media player instance may choose to ignore this for resources | |
| 66 // that have already been opened. | |
| 67 bool Valid() const; | |
| 68 | |
| 69 private: | |
| 70 friend class UrlIndex; | |
| 71 friend class base::RefCounted<UrlData>; | |
| 72 | |
| 73 ~UrlData(); | |
| 74 UrlData(const GURL& url, | |
| 75 CORSMode cors_mode_, | |
| 76 UrlIndex* url_index_); | |
| 77 void set_last_modified_internal(base::Time t); | |
| 78 void DisconnectFromIndex(); | |
| 79 | |
| 80 const GURL url_; | |
| 81 const CORSMode cors_mode_; | |
| 82 | |
| 83 GURL redirects_to_; | |
| 84 int64 length_; | |
| 85 bool range_supported_; | |
| 86 bool cacheable_; | |
| 87 | |
| 88 base::TimeTicks last_used_; | |
| 89 base::TimeTicks valid_until_; | |
| 90 base::Time last_modified_; | |
| 91 | |
| 92 base::ThreadChecker thread_checker_; | |
| 93 UrlIndex* url_index_; | |
| 94 DISALLOW_COPY_AND_ASSIGN(UrlData); | |
| 95 }; | |
| 96 | |
| 97 // The UrlIndex lets you look up UrlData instances by url. | |
| 98 // It keeps a weak reference to UrlData that it has returned. | |
| 99 // Since the multibuffer cache key contains an UrlData reference | |
| 100 // we can be sure that UrlData instances with zero references | |
| 101 // do not have any cached data associated with them, and they | |
| 102 // can safely be removed from the UrlIndex. | |
| 103 class MEDIA_EXPORT UrlIndex { | |
| 104 public: | |
| 105 UrlIndex(); | |
| 106 ~UrlIndex(); | |
| 107 // Creates a new UrlData if not found. | |
| 108 // |last_modified| may be null if not known. | |
| 109 // Normally you'll want to call Use() on the returned object right away. | |
| 110 scoped_refptr<UrlData> GetByUrl(const GURL& gurl, | |
| 111 UrlData::CORSMode cors_mode); | |
| 112 | |
|
DaleCurtis
2015/10/19 21:45:26
Extra line.
hubbe
2015/10/20 00:31:39
Done.
| |
| 113 | |
| 114 private: | |
| 115 friend class UrlData; | |
| 116 void RemoveUrlData(const UrlData* url_data); | |
| 117 // TODO(hubbe): Add support for etag validation. | |
| 118 scoped_refptr<UrlData> SetLastModified(scoped_refptr<UrlData> urldata, | |
| 119 base::Time last_modified); | |
| 120 | |
| 121 std::map<UrlData::KeyType, UrlData*> by_url_; | |
| 122 std::map<UrlData::KeyType, UrlData*> with_last_modified_; | |
| 123 std::list<scoped_refptr<UrlData> > to_prune_; | |
| 124 bool prune_cb_active_; | |
| 125 }; | |
| 126 | |
| 127 } // namespace media | |
| 128 #endif // MEDIA_BLINK_URL_INDEX_H_ | |
| OLD | NEW |