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

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

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 #include "storage/browser/blob/blob_storage_registry.h" 5 #include "storage/browser/blob/blob_storage_registry.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 20 matching lines...) Expand all
31 31
32 GURL ClearBlobUrlRef(const GURL& url) { 32 GURL ClearBlobUrlRef(const GURL& url) {
33 size_t hash_pos = url.spec().find('#'); 33 size_t hash_pos = url.spec().find('#');
34 if (hash_pos == std::string::npos) 34 if (hash_pos == std::string::npos)
35 return url; 35 return url;
36 return GURL(url.spec().substr(0, hash_pos)); 36 return GURL(url.spec().substr(0, hash_pos));
37 } 37 }
38 38
39 } // namespace 39 } // namespace
40 40
41 BlobStorageRegistry::Entry::Entry(int refcount, BlobState state) 41 BlobStorageRegistry::ItemCopyEntry::ItemCopyEntry(
42 : refcount(refcount), state(state) {} 42 scoped_refptr<ShareableBlobDataItem> source_item,
43 size_t source_item_offset,
44 scoped_refptr<ShareableBlobDataItem> dest_item)
45 : source_item(std::move(source_item)),
46 source_item_offset(source_item_offset),
47 dest_item(std::move(dest_item)) {}
48
49 BlobStorageRegistry::ItemCopyEntry::ItemCopyEntry(const ItemCopyEntry&) =
50 default;
51
52 BlobStorageRegistry::ItemCopyEntry::~ItemCopyEntry() {}
53
54 BlobStorageRegistry::Entry::Entry() {}
43 55
44 BlobStorageRegistry::Entry::~Entry() {} 56 BlobStorageRegistry::Entry::~Entry() {}
45 57
46 bool BlobStorageRegistry::Entry::TestAndSetState(BlobState expected,
47 BlobState set) {
48 if (state != expected)
49 return false;
50 state = set;
51 return true;
52 }
53
54 BlobStorageRegistry::BlobStorageRegistry() {} 58 BlobStorageRegistry::BlobStorageRegistry() {}
55 59
56 BlobStorageRegistry::~BlobStorageRegistry() { 60 BlobStorageRegistry::~BlobStorageRegistry() {
57 // Note: We don't bother calling the construction complete callbacks, as we 61 // Note: We don't bother calling the construction complete callbacks, as we
58 // are only being destructed at the end of the life of the browser process. 62 // are only being destructed at the end of the life of the browser process.
59 // So it shouldn't matter. 63 // So it shouldn't matter.
60 } 64 }
61 65
62 BlobStorageRegistry::Entry* BlobStorageRegistry::CreateEntry( 66 BlobStorageRegistry::Entry* BlobStorageRegistry::CreateEntry(
63 const std::string& uuid, 67 const std::string& uuid,
64 const std::string& content_type, 68 const std::string& content_type,
65 const std::string& content_disposition) { 69 const std::string& content_disposition) {
66 DCHECK(!ContainsKey(blob_map_, uuid)); 70 DCHECK(!ContainsKey(blob_map_, uuid));
67 std::unique_ptr<Entry> entry(new Entry(1, BlobState::PENDING)); 71 std::unique_ptr<Entry> entry(new Entry());
68 entry->content_type = content_type; 72 entry->content_type = content_type;
69 entry->content_disposition = content_disposition; 73 entry->content_disposition = content_disposition;
70 Entry* entry_ptr = entry.get(); 74 Entry* entry_ptr = entry.get();
71 blob_map_.add(uuid, std::move(entry)); 75 blob_map_.add(uuid, std::move(entry));
72 return entry_ptr; 76 return entry_ptr;
73 } 77 }
74 78
75 bool BlobStorageRegistry::DeleteEntry(const std::string& uuid) { 79 bool BlobStorageRegistry::DeleteEntry(const std::string& uuid) {
76 return blob_map_.erase(uuid) == 1; 80 return blob_map_.erase(uuid) == 1;
77 } 81 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 url_to_uuid_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); 129 url_to_uuid_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url);
126 if (found == url_to_uuid_.end()) 130 if (found == url_to_uuid_.end())
127 return nullptr; 131 return nullptr;
128 Entry* entry = GetEntry(found->second); 132 Entry* entry = GetEntry(found->second);
129 if (entry && uuid) 133 if (entry && uuid)
130 uuid->assign(found->second); 134 uuid->assign(found->second);
131 return entry; 135 return entry;
132 } 136 }
133 137
134 } // namespace storage 138 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698