| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_BLINK_URL_INDEX_H_ | 5 #ifndef MEDIA_BLINK_URL_INDEX_H_ |
| 6 #define MEDIA_BLINK_URL_INDEX_H_ | 6 #define MEDIA_BLINK_URL_INDEX_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "media/blink/lru.h" | 18 #include "media/blink/lru.h" |
| 19 #include "media/blink/media_blink_export.h" | 19 #include "media/blink/media_blink_export.h" |
| 20 #include "media/blink/multibuffer.h" | 20 #include "media/blink/multibuffer.h" |
| 21 #include "third_party/WebKit/public/web/WebFrame.h" | 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 | 25 |
| 26 const int64_t kPositionNotSpecified = -1; | 26 const int64_t kPositionNotSpecified = -1; |
| 27 | 27 |
| 28 class UrlData; | 28 class UrlData; |
| 29 | 29 |
| 30 // A multibuffer for loading media resources which knows | 30 // A multibuffer for loading media resources which knows |
| 31 // how to create MultiBufferDataProviders to load data | 31 // how to create MultiBufferDataProviders to load data |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 // Returns true it is valid to keep using this to access cached data. | 134 // Returns true it is valid to keep using this to access cached data. |
| 135 // A single media player instance may choose to ignore this for resources | 135 // A single media player instance may choose to ignore this for resources |
| 136 // that have already been opened. | 136 // that have already been opened. |
| 137 bool Valid(); | 137 bool Valid(); |
| 138 | 138 |
| 139 // Virtual so we can override it for testing. | 139 // Virtual so we can override it for testing. |
| 140 virtual ResourceMultiBuffer* multibuffer(); | 140 virtual ResourceMultiBuffer* multibuffer(); |
| 141 | 141 |
| 142 // Accessor | 142 // Accessor |
| 143 blink::WebFrame* frame() const { return frame_; } | 143 blink::WebLocalFrame* frame() const { return frame_; } |
| 144 | 144 |
| 145 void AddBytesRead(int64_t b) { bytes_read_from_cache_ += b; } | 145 void AddBytesRead(int64_t b) { bytes_read_from_cache_ += b; } |
| 146 int64_t BytesReadFromCache() { return bytes_read_from_cache_; } | 146 int64_t BytesReadFromCache() { return bytes_read_from_cache_; } |
| 147 | 147 |
| 148 protected: | 148 protected: |
| 149 UrlData(const GURL& url, | 149 UrlData(const GURL& url, |
| 150 CORSMode cors_mode, | 150 CORSMode cors_mode, |
| 151 const base::WeakPtr<UrlIndex>& url_index); | 151 const base::WeakPtr<UrlIndex>& url_index); |
| 152 virtual ~UrlData(); | 152 virtual ~UrlData(); |
| 153 | 153 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 199 |
| 200 // Last modification time according to http headers. | 200 // Last modification time according to http headers. |
| 201 base::Time last_modified_; | 201 base::Time last_modified_; |
| 202 | 202 |
| 203 // Etag from HTTP reply. | 203 // Etag from HTTP reply. |
| 204 std::string etag_; | 204 std::string etag_; |
| 205 | 205 |
| 206 ResourceMultiBuffer multibuffer_; | 206 ResourceMultiBuffer multibuffer_; |
| 207 std::vector<RedirectCB> redirect_callbacks_; | 207 std::vector<RedirectCB> redirect_callbacks_; |
| 208 | 208 |
| 209 blink::WebFrame* frame_; | 209 blink::WebLocalFrame* frame_; |
| 210 | 210 |
| 211 base::ThreadChecker thread_checker_; | 211 base::ThreadChecker thread_checker_; |
| 212 DISALLOW_COPY_AND_ASSIGN(UrlData); | 212 DISALLOW_COPY_AND_ASSIGN(UrlData); |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 // The UrlIndex lets you look up UrlData instances by url. | 215 // The UrlIndex lets you look up UrlData instances by url. |
| 216 class MEDIA_BLINK_EXPORT UrlIndex { | 216 class MEDIA_BLINK_EXPORT UrlIndex { |
| 217 public: | 217 public: |
| 218 explicit UrlIndex(blink::WebFrame*); | 218 explicit UrlIndex(blink::WebLocalFrame*); |
| 219 UrlIndex(blink::WebFrame*, int block_shift); | 219 UrlIndex(blink::WebLocalFrame*, int block_shift); |
| 220 virtual ~UrlIndex(); | 220 virtual ~UrlIndex(); |
| 221 | 221 |
| 222 // Look up an UrlData in the index and return it. If none is found, | 222 // Look up an UrlData in the index and return it. If none is found, |
| 223 // create a new one. Note that newly created UrlData entries are NOT | 223 // create a new one. Note that newly created UrlData entries are NOT |
| 224 // added to the index, instead you must call TryInsert on them after | 224 // added to the index, instead you must call TryInsert on them after |
| 225 // initializing relevant parameters, like whether it support | 225 // initializing relevant parameters, like whether it support |
| 226 // ranges and it's last modified time. | 226 // ranges and it's last modified time. |
| 227 scoped_refptr<UrlData> GetByUrl(const GURL& gurl, | 227 scoped_refptr<UrlData> GetByUrl(const GURL& gurl, |
| 228 UrlData::CORSMode cors_mode); | 228 UrlData::CORSMode cors_mode); |
| 229 | 229 |
| 230 // Add the given UrlData to the index if possible. If a better UrlData | 230 // Add the given UrlData to the index if possible. If a better UrlData |
| 231 // is already present in the index, return it instead. (If not, we just | 231 // is already present in the index, return it instead. (If not, we just |
| 232 // return the given UrlData.) Please make sure to initialize all the data | 232 // return the given UrlData.) Please make sure to initialize all the data |
| 233 // that can be gathered from HTTP headers in |url_data| before calling this. | 233 // that can be gathered from HTTP headers in |url_data| before calling this. |
| 234 // In particular, the following fields are important: | 234 // In particular, the following fields are important: |
| 235 // o range_supported: Entries which do not support ranges cannot be | 235 // o range_supported: Entries which do not support ranges cannot be |
| 236 // shared and are not added to the index. | 236 // shared and are not added to the index. |
| 237 // o valid_until, last_used: Entries have to be valid to be inserted | 237 // o valid_until, last_used: Entries have to be valid to be inserted |
| 238 // into the index, this means that they have to have been recently | 238 // into the index, this means that they have to have been recently |
| 239 // used or have an Expires: header that says when they stop being valid. | 239 // used or have an Expires: header that says when they stop being valid. |
| 240 // o last_modified: Expired cache entries can be re-used if last_modified | 240 // o last_modified: Expired cache entries can be re-used if last_modified |
| 241 // matches. | 241 // matches. |
| 242 // TODO(hubbe): Add etag support. | 242 // TODO(hubbe): Add etag support. |
| 243 scoped_refptr<UrlData> TryInsert(const scoped_refptr<UrlData>& url_data); | 243 scoped_refptr<UrlData> TryInsert(const scoped_refptr<UrlData>& url_data); |
| 244 | 244 |
| 245 blink::WebFrame* frame() const { return frame_; } | 245 blink::WebLocalFrame* frame() const { return frame_; } |
| 246 int block_shift() const { return block_shift_; } | 246 int block_shift() const { return block_shift_; } |
| 247 | 247 |
| 248 private: | 248 private: |
| 249 friend class UrlData; | 249 friend class UrlData; |
| 250 friend class ResourceMultiBuffer; | 250 friend class ResourceMultiBuffer; |
| 251 void RemoveUrlDataIfEmpty(const scoped_refptr<UrlData>& url_data); | 251 void RemoveUrlDataIfEmpty(const scoped_refptr<UrlData>& url_data); |
| 252 | 252 |
| 253 // Virtual so we can override it in tests. | 253 // Virtual so we can override it in tests. |
| 254 virtual scoped_refptr<UrlData> NewUrlData(const GURL& url, | 254 virtual scoped_refptr<UrlData> NewUrlData(const GURL& url, |
| 255 UrlData::CORSMode cors_mode); | 255 UrlData::CORSMode cors_mode); |
| 256 | 256 |
| 257 std::map<UrlData::KeyType, scoped_refptr<UrlData>> by_url_; | 257 std::map<UrlData::KeyType, scoped_refptr<UrlData>> by_url_; |
| 258 blink::WebFrame* frame_; | 258 blink::WebLocalFrame* frame_; |
| 259 scoped_refptr<MultiBuffer::GlobalLRU> lru_; | 259 scoped_refptr<MultiBuffer::GlobalLRU> lru_; |
| 260 | 260 |
| 261 // log2 of block size in multibuffer cache. Defaults to kBlockSizeShift. | 261 // log2 of block size in multibuffer cache. Defaults to kBlockSizeShift. |
| 262 // Currently only changed for testing purposes. | 262 // Currently only changed for testing purposes. |
| 263 const int block_shift_; | 263 const int block_shift_; |
| 264 | 264 |
| 265 protected: | 265 protected: |
| 266 base::WeakPtrFactory<UrlIndex> weak_factory_; | 266 base::WeakPtrFactory<UrlIndex> weak_factory_; |
| 267 }; | 267 }; |
| 268 | 268 |
| 269 } // namespace media | 269 } // namespace media |
| 270 #endif // MEDIA_BLINK_URL_INDEX_H_ | 270 #endif // MEDIA_BLINK_URL_INDEX_H_ |
| OLD | NEW |