OLD | NEW |
---|---|
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ | 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ |
6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ | 6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "net/disk_cache/disk_cache.h" | |
10 #include "storage/browser/blob/shareable_file_reference.h" | 11 #include "storage/browser/blob/shareable_file_reference.h" |
11 #include "storage/browser/storage_browser_export.h" | 12 #include "storage/browser/storage_browser_export.h" |
12 #include "storage/common/data_element.h" | 13 #include "storage/common/data_element.h" |
13 | 14 |
14 namespace storage { | 15 namespace storage { |
15 class BlobDataBuilder; | 16 class BlobDataBuilder; |
16 class BlobStorageContext; | 17 class BlobStorageContext; |
17 | 18 |
18 // Ref counted blob item. This class owns the backing data of the blob item. | 19 // Ref counted blob item. This class owns the backing data of the blob item. The |
19 // The backing data is immutable, and cannot change after creation. | 20 // backing data is immutable, and cannot change after creation. The purpose of |
20 // The purpose of this class is to allow the resource to stick around in the | 21 // this class is to allow the resource to stick around in the snapshot even |
21 // snapshot even after the resource was swapped in the blob (either to disk or | 22 // after the resource was swapped in the blob (either to disk or to memory) by |
22 // to memory) by the BlobStorageContext. | 23 // the BlobStorageContext. |
23 class STORAGE_EXPORT BlobDataItem : public base::RefCounted<BlobDataItem> { | 24 class STORAGE_EXPORT BlobDataItem : public base::RefCounted<BlobDataItem> { |
24 public: | 25 public: |
25 DataElement::Type type() const { return item_->type(); } | 26 DataElement::Type type() const { return item_->type(); } |
26 const char* bytes() const { return item_->bytes(); } | 27 const char* bytes() const { return item_->bytes(); } |
27 const base::FilePath& path() const { return item_->path(); } | 28 const base::FilePath& path() const { return item_->path(); } |
28 const GURL& filesystem_url() const { return item_->filesystem_url(); } | 29 const GURL& filesystem_url() const { return item_->filesystem_url(); } |
29 const std::string& blob_uuid() const { return item_->blob_uuid(); } | 30 const std::string& blob_uuid() const { return item_->blob_uuid(); } |
30 const base::Time& expected_modification_time() const { | 31 const base::Time& expected_modification_time() const { |
31 return item_->expected_modification_time(); | 32 return item_->expected_modification_time(); |
32 } | 33 } |
33 const DataElement& data_element() const { return *item_; } | 34 const DataElement& data_element() const { return *item_; } |
34 const DataElement* data_element_ptr() const { return item_.get(); } | 35 const DataElement* data_element_ptr() const { return item_.get(); } |
35 | 36 |
36 uint64 GetOffset() const { return item_->offset(); } | 37 const disk_cache::ScopedEntryPtr& disk_cache_entry() const { |
37 uint64 GetLength() const { return item_->length(); } | 38 return disk_cache_entry_; |
39 } | |
40 int disk_cache_stream_index() const { return disk_cache_stream_index_; } | |
41 | |
42 uint64 GetLength() const; | |
43 uint64 GetOffset() const; | |
38 | 44 |
39 private: | 45 private: |
46 // The ExtraData class owns data for the lifetime of this BlobDataItem. It is | |
47 // used to ensure that required data for backing the blob has a lifetime of at | |
48 // least the life of the blob. | |
49 class ExtraData { | |
50 public: | |
51 virtual ~ExtraData() {} | |
52 }; | |
dmurph
2015/05/29 19:13:43
Hm, what about
// The DataHandle class is used to
gavinp
2015/06/04 18:40:00
Done. I avoided an extra layer of indirection in t
| |
53 | |
40 friend class BlobDataBuilder; | 54 friend class BlobDataBuilder; |
41 friend class BlobStorageContext; | 55 friend class BlobStorageContext; |
42 friend class base::RefCounted<BlobDataItem>; | 56 friend class base::RefCounted<BlobDataItem>; |
43 | 57 |
44 BlobDataItem(scoped_ptr<DataElement> item); | 58 BlobDataItem(scoped_ptr<DataElement> item); |
45 BlobDataItem(scoped_ptr<DataElement> item, | 59 BlobDataItem(scoped_ptr<DataElement> item, |
46 scoped_refptr<ShareableFileReference> file_handle); | 60 const scoped_refptr<ShareableFileReference>& file_handle); |
61 BlobDataItem(scoped_ptr<DataElement> item, | |
62 scoped_ptr<ExtraData> extra_data, | |
63 disk_cache::ScopedEntryPtr disk_cache_entry_, | |
64 int disk_cache_stream_index_); | |
47 virtual ~BlobDataItem(); | 65 virtual ~BlobDataItem(); |
48 | 66 |
49 scoped_ptr<DataElement> item_; | 67 scoped_ptr<DataElement> item_; |
50 scoped_refptr<ShareableFileReference> file_handle_; | 68 scoped_refptr<ShareableFileReference> file_handle_; |
69 scoped_ptr<ExtraData> extra_data_; | |
70 | |
71 disk_cache::ScopedEntryPtr disk_cache_entry_; // For TYPE_DISK_CACHE_ENTRY. | |
72 int disk_cache_stream_index_; // For TYPE_DISK_CACHE_ENTRY. | |
51 }; | 73 }; |
52 | 74 |
53 #if defined(UNIT_TEST) | 75 #if defined(UNIT_TEST) |
54 inline bool operator==(const BlobDataItem& a, const BlobDataItem& b) { | 76 inline bool operator==(const BlobDataItem& a, const BlobDataItem& b) { |
55 return a.data_element() == b.data_element(); | 77 return a.disk_cache_entry() == b.disk_cache_entry() && |
78 a.data_element() == b.data_element(); | |
56 } | 79 } |
57 | 80 |
58 inline bool operator!=(const BlobDataItem& a, const BlobDataItem& b) { | 81 inline bool operator!=(const BlobDataItem& a, const BlobDataItem& b) { |
59 return !(a == b); | 82 return !(a == b); |
60 } | 83 } |
61 #endif // defined(UNIT_TEST) | 84 #endif // defined(UNIT_TEST) |
62 | 85 |
63 } // namespace storage | 86 } // namespace storage |
64 | 87 |
65 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ | 88 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ |
OLD | NEW |