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 uint64 offset() const { return item_->offset(); } | 31 uint64 offset() const { return GetLength(); } |
31 uint64 length() const { return item_->length(); } | 32 uint64 length() const { return GetOffset(); } |
32 const base::Time& expected_modification_time() const { | 33 const base::Time& expected_modification_time() const { |
33 return item_->expected_modification_time(); | 34 return item_->expected_modification_time(); |
34 } | 35 } |
35 const DataElement& data_element() const { return *item_; } | 36 const DataElement& data_element() const { return *item_; } |
36 const DataElement* data_element_ptr() const { return item_.get(); } | 37 const DataElement* data_element_ptr() const { return item_.get(); } |
37 | 38 |
| 39 const disk_cache::ScopedEntryPtr& disk_cache_entry() const { |
| 40 return disk_cache_entry_; |
| 41 } |
| 42 int disk_cache_stream_index() const { return disk_cache_stream_index_; } |
| 43 |
| 44 uint64 GetLength() const; |
| 45 uint64 GetOffset() const; |
| 46 |
| 47 |
38 private: | 48 private: |
39 friend class BlobDataBuilder; | 49 friend class BlobDataBuilder; |
40 friend class BlobStorageContext; | 50 friend class BlobStorageContext; |
41 friend class base::RefCounted<BlobDataItem>; | 51 friend class base::RefCounted<BlobDataItem>; |
42 | 52 |
43 BlobDataItem(scoped_ptr<DataElement> item); | 53 BlobDataItem(scoped_ptr<DataElement> item); |
44 BlobDataItem(scoped_ptr<DataElement> item, | 54 BlobDataItem(scoped_ptr<DataElement> item, |
45 scoped_refptr<ShareableFileReference> file_handle); | 55 scoped_refptr<ShareableFileReference> file_handle); |
| 56 BlobDataItem(scoped_ptr<DataElement> item, |
| 57 disk_cache::ScopedEntryPtr disk_cache_entry_, |
| 58 int disk_cache_stream_index_); |
46 virtual ~BlobDataItem(); | 59 virtual ~BlobDataItem(); |
47 | 60 |
48 scoped_ptr<DataElement> item_; | 61 scoped_ptr<DataElement> item_; |
49 scoped_refptr<ShareableFileReference> file_handle_; | 62 scoped_refptr<ShareableFileReference> file_handle_; |
| 63 |
| 64 disk_cache::ScopedEntryPtr disk_cache_entry_; // For TYPE_DISK_CACHE_ENTRY. |
| 65 int disk_cache_stream_index_; // For TYPE_DISK_CACHE_ENTRY. |
50 }; | 66 }; |
51 | 67 |
52 #if defined(UNIT_TEST) | 68 #if defined(UNIT_TEST) |
53 inline bool operator==(const BlobDataItem& a, const BlobDataItem& b) { | 69 inline bool operator==(const BlobDataItem& a, const BlobDataItem& b) { |
54 return a.data_element() == b.data_element(); | 70 return a.disk_cache_entry() == b.disk_cache_entry() && |
| 71 a.data_element() == b.data_element(); |
55 } | 72 } |
56 | 73 |
57 inline bool operator!=(const BlobDataItem& a, const BlobDataItem& b) { | 74 inline bool operator!=(const BlobDataItem& a, const BlobDataItem& b) { |
58 return !(a == b); | 75 return !(a == b); |
59 } | 76 } |
60 #endif // defined(UNIT_TEST) | 77 #endif // defined(UNIT_TEST) |
61 | 78 |
62 } // namespace storage | 79 } // namespace storage |
63 | 80 |
64 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ | 81 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ |
OLD | NEW |