Index: storage/browser/blob/blob_data_handle.h |
diff --git a/storage/browser/blob/blob_data_handle.h b/storage/browser/blob/blob_data_handle.h |
index 0b1d151c612e078ae6a91c3c052657a4f7d08e6a..c90eca56b212848f9aece4adcddf42c5df369abd 100644 |
--- a/storage/browser/blob/blob_data_handle.h |
+++ b/storage/browser/blob/blob_data_handle.h |
@@ -18,31 +18,41 @@ class SequencedTaskRunner; |
namespace storage { |
-class BlobData; |
+class BlobDataSnapshot; |
class BlobStorageContext; |
-// A scoper object for use in chrome's main browser process, ensures |
-// the underlying BlobData and its uuid remain in BlobStorageContext's |
-// collection for the duration. This object has delete semantics and |
-// maybe deleted on any thread. |
+// BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains |
+// in the BlobStorageContext's collection while this object is alive. Anything |
+// that needs to keep a blob alive needs to store this handle. |
+// When the blob data itself is needed, clients must call the CreateSnapshot() |
+// method on the IO thread to create a snapshot of the blob data. This snapshot |
+// is not intended to be persisted, and serves to ensure that the backing |
+// resources remain around for the duration of reading the blob. This snapshot |
+// can be read on any thread. |
+// This object has delete semantics and may be deleted on any thread. |
class STORAGE_EXPORT BlobDataHandle |
: public base::SupportsUserData::Data { |
public: |
BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread. |
- ~BlobDataHandle() override; // Maybe be deleted on any thread. |
- BlobData* data() const; // May only be accessed on the IO thread. |
+ ~BlobDataHandle() override; // May be deleted on any thread. |
- std::string uuid() const; // May be accessed on any thread. |
+ // This must be called on the IO thread, but the snapshot can be accessed |
+ // from any thread. |
+ scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; |
+ |
+ const std::string& uuid() const; // May be accessed on any thread. |
private: |
+ // Internal class whose destructor is guarenteed to be called on the IO |
+ // thread. |
class BlobDataHandleShared |
: public base::RefCountedThreadSafe<BlobDataHandleShared> { |
public: |
- BlobDataHandleShared(BlobData* blob_data, |
+ BlobDataHandleShared(const std::string& uuid, |
BlobStorageContext* context, |
base::SequencedTaskRunner* task_runner); |
- BlobData* data() const; |
+ scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; |
const std::string& uuid() const; |
private: |
@@ -52,14 +62,15 @@ class STORAGE_EXPORT BlobDataHandle |
virtual ~BlobDataHandleShared(); |
- scoped_refptr<BlobData> blob_data_; |
+ const std::string uuid_; |
base::WeakPtr<BlobStorageContext> context_; |
DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); |
}; |
friend class BlobStorageContext; |
- BlobDataHandle(BlobData* blob_data, BlobStorageContext* context, |
+ BlobDataHandle(const std::string& uuid, |
+ BlobStorageContext* context, |
base::SequencedTaskRunner* task_runner); |
scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |