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

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

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments, simplifications Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 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_STORAGE_REGISTRY_H_ 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ 6 #define STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback_forward.h" 15 #include "base/callback_forward.h"
16 #include "base/containers/scoped_ptr_hash_map.h" 16 #include "base/containers/scoped_ptr_hash_map.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "storage/browser/blob/blob_data_handle.h"
19 #include "storage/browser/blob/blob_memory_controller.h"
18 #include "storage/browser/blob/internal_blob_data.h" 20 #include "storage/browser/blob/internal_blob_data.h"
19 #include "storage/browser/storage_browser_export.h" 21 #include "storage/browser/storage_browser_export.h"
20 #include "storage/common/blob_storage/blob_storage_constants.h" 22 #include "storage/common/blob_storage/blob_storage_constants.h"
21 23
22 class GURL; 24 class GURL;
23 25
24 namespace storage { 26 namespace storage {
25 27
26 // This class stores the blob data in the various states of construction, as 28 // This class stores the blob data in the various states of construction, as
27 // well as URL mappings to blob uuids. 29 // well as URL mappings to blob uuids.
(...skipping 13 matching lines...) Expand all
41 // The blob is pending transportation from the renderer. This is the default 43 // The blob is pending transportation from the renderer. This is the default
42 // state on entry construction. 44 // state on entry construction.
43 PENDING, 45 PENDING,
44 // The blob is complete and can be read from. 46 // The blob is complete and can be read from.
45 COMPLETE, 47 COMPLETE,
46 // The blob is broken and no longer holds data. This happens when there was 48 // The blob is broken and no longer holds data. This happens when there was
47 // a problem constructing the blob, or we've run out of memory. 49 // a problem constructing the blob, or we've run out of memory.
48 BROKEN 50 BROKEN
49 }; 51 };
50 52
53 struct STORAGE_EXPORT ItemCopyEntry {
54 ItemCopyEntry(scoped_refptr<ShareableBlobDataItem> source_item,
55 size_t source_item_offset,
56 scoped_refptr<ShareableBlobDataItem> dest_item);
57 ~ItemCopyEntry();
58 ItemCopyEntry(const ItemCopyEntry&);
59
60 scoped_refptr<ShareableBlobDataItem> source_item;
61 size_t source_item_offset = 0;
62 scoped_refptr<ShareableBlobDataItem> dest_item;
63 };
64
51 struct STORAGE_EXPORT Entry { 65 struct STORAGE_EXPORT Entry {
52 size_t refcount; 66 size_t refcount = 1;
53 BlobState state; 67 BlobState state = BlobState::PENDING;
54 std::vector<BlobConstructedCallback> build_completion_callbacks; 68 std::vector<BlobConstructedCallback> build_completion_callbacks;
55 69
56 // Only applicable if the state == BROKEN. 70 // Only applicable if the state == BROKEN.
57 IPCBlobCreationCancelCode broken_reason = 71 IPCBlobCreationCancelCode broken_reason =
58 IPCBlobCreationCancelCode::UNKNOWN; 72 IPCBlobCreationCancelCode::UNKNOWN;
59 73
60 // data and data_builder are mutually exclusive. 74 // Blob items. During construction these can be
61 std::unique_ptr<InternalBlobData> data; 75 InternalBlobData data;
62 std::unique_ptr<InternalBlobData::Builder> data_builder; 76 bool waiting_until_user_population = false;
77 BlobConstructedCallback ready_for_user_population_callback;
63 78
79 // Metadata
64 std::string content_type; 80 std::string content_type;
65 std::string content_disposition; 81 std::string content_disposition;
66 82
67 Entry() = delete; 83 bool can_fit = true;
68 Entry(int refcount, BlobState state); 84 BlobMemoryController::PendingContructionEntry pending_copies_memory_entry;
85 // These are copies from a referenced blob item to our blob items. Some of
86 // these entries may have changed from bytes to files if they were paged.
87 // We must handle this case.
88 std::vector<ItemCopyEntry> copies;
89
90 std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs;
91 size_t dependent_blobs_building = 0;
92
93 Entry();
69 ~Entry(); 94 ~Entry();
70
71 // Performs a test-and-set on the state of the given blob. If the state
72 // isn't as expected, we return false. Otherwise we set the new state and
73 // return true.
74 bool TestAndSetState(BlobState expected, BlobState set);
75 }; 95 };
76 96
77 BlobStorageRegistry(); 97 BlobStorageRegistry();
78 ~BlobStorageRegistry(); 98 ~BlobStorageRegistry();
79 99
80 // Creates the blob entry with a refcount of 1 and a state of PENDING. If 100 // Creates the blob entry with a refcount of 1 and a state of PENDING. If
81 // the blob is already in use, we return null. 101 // the blob is already in use, we return null.
82 Entry* CreateEntry(const std::string& uuid, 102 Entry* CreateEntry(const std::string& uuid,
83 const std::string& content_type, 103 const std::string& content_type,
84 const std::string& content_disposition); 104 const std::string& content_disposition);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 using URLMap = std::map<GURL, std::string>; 138 using URLMap = std::map<GURL, std::string>;
119 139
120 BlobMap blob_map_; 140 BlobMap blob_map_;
121 URLMap url_to_uuid_; 141 URLMap url_to_uuid_;
122 142
123 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); 143 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry);
124 }; 144 };
125 145
126 } // namespace storage 146 } // namespace storage
127 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ 147 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698