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

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

Issue 2339933004: [BlobStorage] BlobMemoryController & tests (Closed)
Patch Set: rebase Created 4 years, 3 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
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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <ostream> 11 #include <ostream>
12 #include <string> 12 #include <string>
13 13
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "storage/browser/storage_browser_export.h" 15 #include "storage/browser/storage_browser_export.h"
16 #include "storage/common/data_element.h" 16 #include "storage/common/data_element.h"
17 17
18 namespace disk_cache { 18 namespace disk_cache {
19 class Entry; 19 class Entry;
20 } 20 }
21 21
22 namespace storage { 22 namespace storage {
23 class BlobDataBuilder; 23 class BlobDataBuilder;
24 class BlobStorageContext; 24 class BlobStorageContext;
25 class DataElement;
pwnall 2016/09/21 09:03:35 Does this forward declaration mean you don't need
dmurph 2016/09/21 23:45:52 Done.
25 26
26 // Ref counted blob item. This class owns the backing data of the blob item. The 27 // Ref counted blob item. This class owns the backing data of the blob item. The
27 // backing data is immutable, and cannot change after creation. The purpose of 28 // backing data is immutable, and cannot change after creation. The purpose of
28 // this class is to allow the resource to stick around in the snapshot even 29 // this class is to allow the resource to stick around in the snapshot even
29 // after the resource was swapped in the blob (either to disk or to memory) by 30 // after the resource was swapped in the blob (either to disk or to memory) by
30 // the BlobStorageContext. 31 // the BlobStorageContext.
31 class STORAGE_EXPORT BlobDataItem : public base::RefCounted<BlobDataItem> { 32 class STORAGE_EXPORT BlobDataItem : public base::RefCounted<BlobDataItem> {
32 public: 33 public:
33 // The DataHandle class is used to persist resources that are needed for 34 // The DataHandle class is used to persist resources that are needed for
34 // reading this BlobDataItem. This object will stay around while any reads are 35 // reading this BlobDataItem. This object will stay around while any reads are
35 // pending. If all blobs with this item are deleted or the item is swapped for 36 // pending. If all blobs with this item are deleted or the item is swapped for
36 // a different backend version (mem-to-disk or the reverse), then the item 37 // a different backend version (mem-to-disk or the reverse), then the item
37 // will be destructed after all pending reads are complete. 38 // will be destructed after all pending reads are complete.
38 class STORAGE_EXPORT DataHandle : public base::RefCounted<DataHandle> { 39 class STORAGE_EXPORT DataHandle : public base::RefCounted<DataHandle> {
39 protected: 40 protected:
40 virtual ~DataHandle() = 0; 41 virtual ~DataHandle() = 0;
41 42
42 private: 43 private:
43 friend class base::RefCounted<DataHandle>; 44 friend class base::RefCounted<DataHandle>;
44 }; 45 };
45 46
47 explicit BlobDataItem(std::unique_ptr<DataElement> item);
48 BlobDataItem(std::unique_ptr<DataElement> item,
49 const scoped_refptr<DataHandle>& data_handle);
50 BlobDataItem(std::unique_ptr<DataElement> item,
51 const scoped_refptr<DataHandle>& data_handle,
52 disk_cache::Entry* entry,
53 int disk_cache_stream_index,
54 int disk_cache_side_stream_index);
55
46 DataElement::Type type() const { return item_->type(); } 56 DataElement::Type type() const { return item_->type(); }
47 const char* bytes() const { return item_->bytes(); } 57 const char* bytes() const { return item_->bytes(); }
48 const base::FilePath& path() const { return item_->path(); } 58 const base::FilePath& path() const { return item_->path(); }
49 const GURL& filesystem_url() const { return item_->filesystem_url(); } 59 const GURL& filesystem_url() const { return item_->filesystem_url(); }
50 const std::string& blob_uuid() const { return item_->blob_uuid(); } 60 const std::string& blob_uuid() const { return item_->blob_uuid(); }
51 uint64_t offset() const { return item_->offset(); } 61 uint64_t offset() const { return item_->offset(); }
52 uint64_t length() const { return item_->length(); } 62 uint64_t length() const { return item_->length(); }
53 const base::Time& expected_modification_time() const { 63 const base::Time& expected_modification_time() const {
54 return item_->expected_modification_time(); 64 return item_->expected_modification_time();
55 } 65 }
56 const DataElement& data_element() const { return *item_; } 66 const DataElement& data_element() const { return *item_; }
57 const DataElement* data_element_ptr() const { return item_.get(); } 67 const DataElement* data_element_ptr() const { return item_.get(); }
58 DataElement* data_element_ptr() { return item_.get(); } 68 DataElement* data_element_ptr() { return item_.get(); }
59 69
60 disk_cache::Entry* disk_cache_entry() const { return disk_cache_entry_; } 70 disk_cache::Entry* disk_cache_entry() const { return disk_cache_entry_; }
61 int disk_cache_stream_index() const { return disk_cache_stream_index_; } 71 int disk_cache_stream_index() const { return disk_cache_stream_index_; }
62 int disk_cache_side_stream_index() const { 72 int disk_cache_side_stream_index() const {
63 return disk_cache_side_stream_index_; 73 return disk_cache_side_stream_index_;
64 } 74 }
65 75
76 const scoped_refptr<DataHandle>& data_handle() const { return data_handle_; }
77
66 private: 78 private:
67 friend class BlobDataBuilder; 79 friend class BlobDataBuilder;
80 // friend class BlobMemoryController;
pwnall 2016/09/21 09:03:35 Is this on purpose? Did you mean to leave this fri
dmurph 2016/09/21 23:45:52 removed.
68 friend class BlobStorageContext; 81 friend class BlobStorageContext;
82 friend struct BlobSlice;
69 friend class base::RefCounted<BlobDataItem>; 83 friend class base::RefCounted<BlobDataItem>;
70 friend STORAGE_EXPORT void PrintTo(const BlobDataItem& x, ::std::ostream* os); 84 friend STORAGE_EXPORT void PrintTo(const BlobDataItem& x, ::std::ostream* os);
71 85
72 explicit BlobDataItem(std::unique_ptr<DataElement> item);
73 BlobDataItem(std::unique_ptr<DataElement> item,
74 const scoped_refptr<DataHandle>& data_handle);
75 BlobDataItem(std::unique_ptr<DataElement> item,
76 const scoped_refptr<DataHandle>& data_handle,
77 disk_cache::Entry* entry,
78 int disk_cache_stream_index,
79 int disk_cache_side_stream_index);
80 virtual ~BlobDataItem(); 86 virtual ~BlobDataItem();
81 87
82 std::unique_ptr<DataElement> item_; 88 std::unique_ptr<DataElement> item_;
83 scoped_refptr<DataHandle> data_handle_; 89 scoped_refptr<DataHandle> data_handle_;
84 90
85 // This naked pointer is safe because the scope is protected by the DataHandle 91 // This naked pointer is safe because the scope is protected by the DataHandle
86 // instance for disk cache entries during the lifetime of this BlobDataItem. 92 // instance for disk cache entries during the lifetime of this BlobDataItem.
87 disk_cache::Entry* disk_cache_entry_; 93 disk_cache::Entry* disk_cache_entry_;
88 int disk_cache_stream_index_; // For TYPE_DISK_CACHE_ENTRY. 94 int disk_cache_stream_index_; // For TYPE_DISK_CACHE_ENTRY.
89 int disk_cache_side_stream_index_; // For TYPE_DISK_CACHE_ENTRY. 95 int disk_cache_side_stream_index_; // For TYPE_DISK_CACHE_ENTRY.
90 }; 96 };
91 97
92 STORAGE_EXPORT bool operator==(const BlobDataItem& a, const BlobDataItem& b); 98 STORAGE_EXPORT bool operator==(const BlobDataItem& a, const BlobDataItem& b);
93 STORAGE_EXPORT bool operator!=(const BlobDataItem& a, const BlobDataItem& b); 99 STORAGE_EXPORT bool operator!=(const BlobDataItem& a, const BlobDataItem& b);
94 100
95 } // namespace storage 101 } // namespace storage
96 102
97 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ 103 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698