| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ | 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ |
| 6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ | 6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 13 #include "base/supports_user_data.h" | 12 #include "base/supports_user_data.h" |
| 14 #include "storage/browser/storage_browser_export.h" | 13 #include "storage/browser/storage_browser_export.h" |
| 15 | 14 |
| 16 namespace base { | 15 namespace base { |
| 17 class SequencedTaskRunner; | 16 class SequencedTaskRunner; |
| 18 } | 17 } |
| 19 | 18 |
| 20 namespace storage { | 19 namespace storage { |
| 21 | 20 |
| 22 class BlobDataSnapshot; | 21 class BlobDataSnapshot; |
| 23 class BlobReader; | |
| 24 class BlobStorageContext; | 22 class BlobStorageContext; |
| 25 class FileSystemContext; | |
| 26 | 23 |
| 27 // BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains | 24 // BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains |
| 28 // in the BlobStorageContext's collection while this object is alive. Anything | 25 // in the BlobStorageContext's collection while this object is alive. Anything |
| 29 // that needs to keep a blob alive needs to store this handle. | 26 // that needs to keep a blob alive needs to store this handle. |
| 30 // When the blob data itself is needed, clients must call the CreateSnapshot() | 27 // When the blob data itself is needed, clients must call the CreateSnapshot() |
| 31 // method on the IO thread to create a snapshot of the blob data. This snapshot | 28 // method on the IO thread to create a snapshot of the blob data. This snapshot |
| 32 // is not intended to be persisted, and serves to ensure that the backing | 29 // is not intended to be persisted, and serves to ensure that the backing |
| 33 // resources remain around for the duration of reading the blob. This snapshot | 30 // resources remain around for the duration of reading the blob. This snapshot |
| 34 // can be read on any thread, but it must be destructed on the IO thread. | 31 // can be read on any thread, but it must be destructed on the IO thread. |
| 35 // This object has delete semantics and may be deleted on any thread. | 32 // This object has delete semantics and may be deleted on any thread. |
| 36 class STORAGE_EXPORT BlobDataHandle | 33 class STORAGE_EXPORT BlobDataHandle |
| 37 : public base::SupportsUserData::Data { | 34 : public base::SupportsUserData::Data { |
| 38 public: | 35 public: |
| 39 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread. | 36 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread. |
| 40 ~BlobDataHandle() override; // May be deleted on any thread. | 37 ~BlobDataHandle() override; // May be deleted on any thread. |
| 41 | 38 |
| 42 // A BlobReader is used to read the data from the blob. This object is | 39 // A BlobDataSnapshot is used to read the data from the blob. This object is |
| 43 // intended to be transient and should not be stored for any extended period | 40 // intended to be transient and should not be stored for any extended period |
| 44 // of time. | 41 // of time. |
| 45 scoped_ptr<BlobReader> CreateReader( | |
| 46 FileSystemContext* file_system_context, | |
| 47 base::SequencedTaskRunner* file_task_runner) const; | |
| 48 | |
| 49 // May be accessed on any thread. | |
| 50 const std::string& uuid() const; | |
| 51 // May be accessed on any thread. | |
| 52 const std::string& content_type() const; | |
| 53 // May be accessed on any thread. | |
| 54 const std::string& content_disposition() const; | |
| 55 | |
| 56 // This call and the destruction of the returned snapshot must be called | 42 // This call and the destruction of the returned snapshot must be called |
| 57 // on the IO thread. | 43 // on the IO thread. |
| 58 // TODO(dmurph): Make this protected, where only the BlobReader can call it. | |
| 59 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; | 44 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; |
| 60 | 45 |
| 46 const std::string& uuid() const; // May be accessed on any thread. |
| 47 |
| 61 private: | 48 private: |
| 62 // Internal class whose destructor is guarenteed to be called on the IO | 49 // Internal class whose destructor is guarenteed to be called on the IO |
| 63 // thread. | 50 // thread. |
| 64 class BlobDataHandleShared | 51 class BlobDataHandleShared |
| 65 : public base::RefCountedThreadSafe<BlobDataHandleShared> { | 52 : public base::RefCountedThreadSafe<BlobDataHandleShared> { |
| 66 public: | 53 public: |
| 67 BlobDataHandleShared(const std::string& uuid, | 54 BlobDataHandleShared(const std::string& uuid, |
| 68 const std::string& content_type, | 55 BlobStorageContext* context, |
| 69 const std::string& content_disposition, | 56 base::SequencedTaskRunner* task_runner); |
| 70 BlobStorageContext* context); | |
| 71 | 57 |
| 72 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; | 58 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; |
| 59 const std::string& uuid() const; |
| 73 | 60 |
| 74 private: | 61 private: |
| 75 friend class base::DeleteHelper<BlobDataHandleShared>; | 62 friend class base::DeleteHelper<BlobDataHandleShared>; |
| 76 friend class base::RefCountedThreadSafe<BlobDataHandleShared>; | 63 friend class base::RefCountedThreadSafe<BlobDataHandleShared>; |
| 77 friend class BlobDataHandle; | 64 friend class BlobDataHandle; |
| 78 | 65 |
| 79 virtual ~BlobDataHandleShared(); | 66 virtual ~BlobDataHandleShared(); |
| 80 | 67 |
| 81 const std::string uuid_; | 68 const std::string uuid_; |
| 82 const std::string content_type_; | |
| 83 const std::string content_disposition_; | |
| 84 base::WeakPtr<BlobStorageContext> context_; | 69 base::WeakPtr<BlobStorageContext> context_; |
| 85 | 70 |
| 86 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); | 71 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); |
| 87 }; | 72 }; |
| 88 | 73 |
| 89 friend class BlobStorageContext; | 74 friend class BlobStorageContext; |
| 90 BlobDataHandle(const std::string& uuid, | 75 BlobDataHandle(const std::string& uuid, |
| 91 const std::string& content_type, | |
| 92 const std::string& content_disposition, | |
| 93 BlobStorageContext* context, | 76 BlobStorageContext* context, |
| 94 base::SequencedTaskRunner* io_task_runner); | 77 base::SequencedTaskRunner* task_runner); |
| 95 | 78 |
| 96 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 79 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
| 97 scoped_refptr<BlobDataHandleShared> shared_; | 80 scoped_refptr<BlobDataHandleShared> shared_; |
| 98 }; | 81 }; |
| 99 | 82 |
| 100 } // namespace storage | 83 } // namespace storage |
| 101 | 84 |
| 102 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ | 85 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ |
| OLD | NEW |