Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/internal_blob_data.h" | 18 #include "storage/browser/blob/internal_blob_data.h" |
| 19 #include "storage/browser/blob/blob_data_handle.h" | |
| 20 #include "storage/browser/blob/blob_memory_controller.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. |
| 28 // Implementation notes: | 30 // Implementation notes: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 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() {} | |
| 55 ItemCopyEntry(std::string uuid, | |
|
michaeln
2016/07/07 20:05:21
const ref
| |
| 56 size_t source_item_index, | |
| 57 size_t source_item_offset, | |
| 58 size_t dest_item_index, | |
| 59 size_t size) | |
| 60 : uuid(uuid), | |
| 61 source_item_index(source_item_index), | |
| 62 source_item_offset(source_item_offset), | |
| 63 dest_item_index(dest_item_index), | |
| 64 size(size) {} | |
| 65 | |
| 66 std::string uuid; | |
| 67 | |
| 68 size_t source_item_index = 0; | |
| 69 size_t source_item_offset = 0; | |
| 70 size_t dest_item_index = 0; | |
| 71 size_t size = 0; | |
| 72 }; | |
| 73 | |
| 51 struct STORAGE_EXPORT Entry { | 74 struct STORAGE_EXPORT Entry { |
| 52 size_t refcount; | 75 size_t refcount = 1; |
| 53 BlobState state; | 76 BlobState state = BlobState::PENDING; |
| 54 std::vector<BlobConstructedCallback> build_completion_callbacks; | 77 std::vector<BlobConstructedCallback> build_completion_callbacks; |
| 55 | 78 |
| 56 // Only applicable if the state == BROKEN. | 79 // Only applicable if the state == BROKEN. |
| 57 IPCBlobCreationCancelCode broken_reason = | 80 IPCBlobCreationCancelCode broken_reason = |
| 58 IPCBlobCreationCancelCode::UNKNOWN; | 81 IPCBlobCreationCancelCode::UNKNOWN; |
| 59 | 82 |
| 60 // data and data_builder are mutually exclusive. | 83 // Blob items. During construction these can be |
|
michaeln
2016/07/07 20:05:21
can be what?
| |
| 61 std::unique_ptr<InternalBlobData> data; | 84 InternalBlobData data; |
| 62 std::unique_ptr<InternalBlobData::Builder> data_builder; | 85 bool waiting_until_user_population = false; |
| 63 | 86 |
| 87 // Metadata | |
| 64 std::string content_type; | 88 std::string content_type; |
| 65 std::string content_disposition; | 89 std::string content_disposition; |
| 66 | 90 |
| 67 Entry() = delete; | 91 bool can_fit_copies = true; |
| 68 Entry(int refcount, BlobState state); | 92 BlobMemoryController::PendingContructionEntry pending_copies_memory_entry; |
| 93 std::vector<ItemCopyEntry> copies_from_built_reference; | |
| 94 std::vector<ItemCopyEntry> copies_to_when_built; | |
| 95 | |
| 96 std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs; | |
| 97 size_t dependent_blobs_building = 0; | |
| 98 | |
| 99 Entry(); | |
| 69 ~Entry(); | 100 ~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 }; | 101 }; |
| 76 | 102 |
| 77 BlobStorageRegistry(); | 103 BlobStorageRegistry(); |
| 78 ~BlobStorageRegistry(); | 104 ~BlobStorageRegistry(); |
| 79 | 105 |
| 80 // Creates the blob entry with a refcount of 1 and a state of PENDING. If | 106 // 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. | 107 // the blob is already in use, we return null. |
| 82 Entry* CreateEntry(const std::string& uuid, | 108 Entry* CreateEntry(const std::string& uuid, |
| 83 const std::string& content_type, | 109 const std::string& content_type, |
| 84 const std::string& content_disposition); | 110 const std::string& content_disposition); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 using URLMap = std::map<GURL, std::string>; | 144 using URLMap = std::map<GURL, std::string>; |
| 119 | 145 |
| 120 BlobMap blob_map_; | 146 BlobMap blob_map_; |
| 121 URLMap url_to_uuid_; | 147 URLMap url_to_uuid_; |
| 122 | 148 |
| 123 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); | 149 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); |
| 124 }; | 150 }; |
| 125 | 151 |
| 126 } // namespace storage | 152 } // namespace storage |
| 127 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ | 153 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ |
| OLD | NEW |