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

Side by Side Diff: storage/browser/blob/blob_data_item.h

Issue 1108083002: Create blobs from Disk Cache entries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit test memory leak Created 5 years, 6 months 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 unified diff | Download patch
« no previous file with comments | « storage/browser/blob/blob_data_builder.cc ('k') | storage/browser/blob/blob_data_item.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "storage/browser/blob/shareable_file_reference.h"
11 #include "storage/browser/storage_browser_export.h" 10 #include "storage/browser/storage_browser_export.h"
12 #include "storage/common/data_element.h" 11 #include "storage/common/data_element.h"
13 12
13 namespace disk_cache {
14 class Entry;
15 }
16
14 namespace storage { 17 namespace storage {
15 class BlobDataBuilder; 18 class BlobDataBuilder;
16 class BlobStorageContext; 19 class BlobStorageContext;
17 20
18 // Ref counted blob item. This class owns the backing data of the blob item. 21 // 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. 22 // 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 23 // 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 24 // after the resource was swapped in the blob (either to disk or to memory) by
22 // to memory) by the BlobStorageContext. 25 // the BlobStorageContext.
23 class STORAGE_EXPORT BlobDataItem : public base::RefCounted<BlobDataItem> { 26 class STORAGE_EXPORT BlobDataItem : public base::RefCounted<BlobDataItem> {
24 public: 27 public:
28 // The DataHandle class is used to persist resources that are needed for
29 // reading this BlobDataItem. This object will stay around while any reads are
30 // pending. If all blobs with this item are deleted or the item is swapped for
31 // a different backend version (mem-to-disk or the reverse), then the item
32 // will be destructed after all pending reads are complete.
33 class STORAGE_EXPORT DataHandle : public base::RefCounted<DataHandle> {
34 protected:
35 virtual ~DataHandle() = 0;
36
37 private:
38 friend class base::RefCounted<DataHandle>;
39 };
40
25 DataElement::Type type() const { return item_->type(); } 41 DataElement::Type type() const { return item_->type(); }
26 const char* bytes() const { return item_->bytes(); } 42 const char* bytes() const { return item_->bytes(); }
27 const base::FilePath& path() const { return item_->path(); } 43 const base::FilePath& path() const { return item_->path(); }
28 const GURL& filesystem_url() const { return item_->filesystem_url(); } 44 const GURL& filesystem_url() const { return item_->filesystem_url(); }
29 const std::string& blob_uuid() const { return item_->blob_uuid(); } 45 const std::string& blob_uuid() const { return item_->blob_uuid(); }
30 uint64 offset() const { return item_->offset(); } 46 uint64 offset() const { return item_->offset(); }
31 uint64 length() const { return item_->length(); } 47 uint64 length() const { return item_->length(); }
32 const base::Time& expected_modification_time() const { 48 const base::Time& expected_modification_time() const {
33 return item_->expected_modification_time(); 49 return item_->expected_modification_time();
34 } 50 }
35 const DataElement& data_element() const { return *item_; } 51 const DataElement& data_element() const { return *item_; }
36 const DataElement* data_element_ptr() const { return item_.get(); } 52 const DataElement* data_element_ptr() const { return item_.get(); }
37 53
54 disk_cache::Entry* disk_cache_entry() const { return disk_cache_entry_; }
55 int disk_cache_stream_index() const { return disk_cache_stream_index_; }
56
38 private: 57 private:
39 friend class BlobDataBuilder; 58 friend class BlobDataBuilder;
40 friend class BlobStorageContext; 59 friend class BlobStorageContext;
41 friend class base::RefCounted<BlobDataItem>; 60 friend class base::RefCounted<BlobDataItem>;
42 61
43 BlobDataItem(scoped_ptr<DataElement> item); 62 BlobDataItem(scoped_ptr<DataElement> item);
44 BlobDataItem(scoped_ptr<DataElement> item, 63 BlobDataItem(scoped_ptr<DataElement> item,
45 scoped_refptr<ShareableFileReference> file_handle); 64 const scoped_refptr<DataHandle>& data_handle);
65 BlobDataItem(scoped_ptr<DataElement> item,
66 const scoped_refptr<DataHandle>& data_handle,
67 disk_cache::Entry* entry,
68 int disk_cache_stream_index_);
46 virtual ~BlobDataItem(); 69 virtual ~BlobDataItem();
47 70
48 scoped_ptr<DataElement> item_; 71 scoped_ptr<DataElement> item_;
49 scoped_refptr<ShareableFileReference> file_handle_; 72 scoped_refptr<DataHandle> data_handle_;
73
74 // This naked pointer is safe because the scope is protected by the DataHandle
75 // instance for disk cache entries during the lifetime of this BlobDataItem.
76 disk_cache::Entry* disk_cache_entry_;
michaeln 2015/06/16 21:52:54 This special case is icky. Its here only because t
gavinp 2015/06/16 22:28:02 Yes. In an earlier revision of this CL, the DataHa
dmurph 2015/06/16 22:38:41 Michael: ideally, we don't really *need* the DataE
gavinp 2015/06/16 22:42:45 Also worth mentioning: We can't put a member of di
77 int disk_cache_stream_index_; // For TYPE_DISK_CACHE_ENTRY.
50 }; 78 };
51 79
52 #if defined(UNIT_TEST) 80 #if defined(UNIT_TEST)
53 inline bool operator==(const BlobDataItem& a, const BlobDataItem& b) { 81 inline bool operator==(const BlobDataItem& a, const BlobDataItem& b) {
54 return a.data_element() == b.data_element(); 82 return a.disk_cache_entry() == b.disk_cache_entry() &&
83 a.disk_cache_stream_index() == b.disk_cache_stream_index() &&
84 a.data_element() == b.data_element();
55 } 85 }
56 86
57 inline bool operator!=(const BlobDataItem& a, const BlobDataItem& b) { 87 inline bool operator!=(const BlobDataItem& a, const BlobDataItem& b) {
58 return !(a == b); 88 return !(a == b);
59 } 89 }
60 #endif // defined(UNIT_TEST) 90 #endif // defined(UNIT_TEST)
61 91
62 } // namespace storage 92 } // namespace storage
63 93
64 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ 94 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_
OLDNEW
« no previous file with comments | « storage/browser/blob/blob_data_builder.cc ('k') | storage/browser/blob/blob_data_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698