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

Unified Diff: media/blink/multibuffer.h

Issue 1399603003: Tie multibuffers to URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_cache
Patch Set: removed VLOG(0), oops Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: media/blink/multibuffer.h
diff --git a/media/blink/multibuffer.h b/media/blink/multibuffer.h
index d469d43fc146f5c6c323bb371bfc4ecdbd4853e6..b7c0091a519754adc9088b2a42ad61b6726641e9 100644
--- a/media/blink/multibuffer.h
+++ b/media/blink/multibuffer.h
@@ -23,8 +23,14 @@
namespace media {
+// Used to identify a block of data in the multibuffer.
+// Our blocks are 32kb (1 << 15), so our maximum cacheable file size
+// is 1 << (15 + 31) = 64Tb
typedef int32_t MultiBufferBlockId;
class MultiBuffer;
+
+// This type is used to identify a block in the LRU, which is shared between
+// multibuffers.
typedef std::pair<MultiBuffer*, MultiBufferBlockId> MultiBufferGlobalBlockId;
} // namespace media
@@ -72,8 +78,6 @@ const int kMaxWaitForWriterOffset = 5;
// This is the size of the look-behind region.
const int kMaxWaitForReaderOffset = 50;
-class MultiBuffer;
-
// MultiBuffers are multi-reader multi-writer cache/buffers with
// prefetching and pinning. Data is stored internally in ref-counted
// blocks of identical size. |block_size_shift| is log2 of the block
@@ -119,9 +123,6 @@ class MEDIA_BLINK_EXPORT MultiBuffer {
// DataBuffer.
virtual scoped_refptr<DataBuffer> Read() = 0;
- // |cb| is called every time Available() becomes true.
- virtual void SetAvailableCallback(const base::Closure& cb) = 0;
-
// Ask the data provider to stop giving us data.
// It's ok if the effect is not immediate.
virtual void SetDeferred(bool deferred) = 0;
@@ -229,8 +230,8 @@ class MEDIA_BLINK_EXPORT MultiBuffer {
// not call it anymore.
scoped_ptr<DataProvider> RemoveProvider(DataProvider* provider);
- // Add a writer to this cache. Cache takes ownership and
- // may choose to destroy it.
+ // Add a writer to this cache. Cache takes ownership, and may
+ // destroy |provider| later. (Not during this call.)
void AddProvider(scoped_ptr<DataProvider> provider);
// Transfer all data from |other| to this.
@@ -240,13 +241,23 @@ class MEDIA_BLINK_EXPORT MultiBuffer {
const DataMap& map() const { return data_; }
int32_t block_size_shift() const { return block_size_shift_; }
+ // Callback which notifies us that a data provider has
+ // some data for us. Also called when it might be appropriate
+ // for a provider in a deferred state to wake up.
+ void OnDataProviderEvent(DataProvider* provider);
+
protected:
// Create a new writer at |pos| and return it.
// Users needs to implemement this method.
- virtual DataProvider* CreateWriter(const BlockId& pos) = 0;
+ virtual scoped_ptr<DataProvider> CreateWriter(const BlockId& pos) = 0;
virtual bool RangeSupported() const = 0;
+ // Called when the cache becomes empty. Implementations can use this
+ // as a signal for when we should free this object and any metadata
+ // that goes with it.
+ virtual void OnEmpty();
+
private:
// For testing.
friend class TestMultiBuffer;
@@ -276,11 +287,6 @@ class MEDIA_BLINK_EXPORT MultiBuffer {
void NotifyAvailableRange(const Interval<MultiBufferBlockId>& observer_range,
const Interval<MultiBufferBlockId>& new_range);
- // Callback which notifies us that a data provider has
- // some data for us. Also called when it might be apprperiate
- // for a provider in a deferred state to wake up.
- void DataProviderEvent(DataProvider* provider);
-
// Max number of blocks.
int64_t max_size_;
@@ -295,8 +301,7 @@ class MEDIA_BLINK_EXPORT MultiBuffer {
// Keeps track of writers by their position.
// The writers are owned by this class.
- // TODO(hubbe): Use ScopedPtrMap here. (must add upper/lower_bound first)
- std::map<BlockId, DataProvider*> writer_index_;
+ std::map<BlockId, scoped_ptr<DataProvider>> writer_index_;
// Gloabally shared LRU, decides which block to free next.
scoped_refptr<GlobalLRU> lru_;

Powered by Google App Engine
This is Rietveld 408576698