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

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: Finished comments, added new pending enum state 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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "storage/browser/blob/blob_data_handle.h"
18 #include "storage/browser/blob/shareable_blob_data_item.h"
17 #include "url/gurl.h" 19 #include "url/gurl.h"
18 20
19 namespace storage { 21 namespace storage {
20 using BlobState = BlobStorageRegistry::BlobState;
21 22
22 namespace { 23 namespace {
23 // We can't use GURL directly for these hash fragment manipulations 24 // We can't use GURL directly for these hash fragment manipulations
24 // since it doesn't have specific knowlege of the BlobURL format. GURL 25 // since it doesn't have specific knowlege of the BlobURL format. GURL
25 // treats BlobURLs as if they were PathURLs which don't support hash 26 // treats BlobURLs as if they were PathURLs which don't support hash
26 // fragments. 27 // fragments.
27 28
28 bool BlobUrlHasRef(const GURL& url) { 29 bool BlobUrlHasRef(const GURL& url) {
29 return url.spec().find('#') != std::string::npos; 30 return url.spec().find('#') != std::string::npos;
30 } 31 }
31 32
32 GURL ClearBlobUrlRef(const GURL& url) { 33 GURL ClearBlobUrlRef(const GURL& url) {
33 size_t hash_pos = url.spec().find('#'); 34 size_t hash_pos = url.spec().find('#');
34 if (hash_pos == std::string::npos) 35 if (hash_pos == std::string::npos)
35 return url; 36 return url;
36 return GURL(url.spec().substr(0, hash_pos)); 37 return GURL(url.spec().substr(0, hash_pos));
37 } 38 }
38 39
39 } // namespace 40 } // namespace
40 41
41 BlobStorageRegistry::Entry::Entry(int refcount, BlobState state) 42 BlobStorageRegistry::ItemCopyEntry::ItemCopyEntry(
42 : refcount(refcount), state(state) {} 43 scoped_refptr<ShareableBlobDataItem> source_item,
44 size_t source_item_offset,
45 scoped_refptr<ShareableBlobDataItem> dest_item)
46 : source_item(std::move(source_item)),
47 source_item_offset(source_item_offset),
48 dest_item(std::move(dest_item)) {}
49
50 BlobStorageRegistry::ItemCopyEntry::ItemCopyEntry(const ItemCopyEntry&) =
51 default;
52
53 BlobStorageRegistry::ItemCopyEntry::~ItemCopyEntry() {}
54
55 BlobStorageRegistry::Entry::Entry() {}
43 56
44 BlobStorageRegistry::Entry::~Entry() {} 57 BlobStorageRegistry::Entry::~Entry() {}
45 58
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() {} 59 BlobStorageRegistry::BlobStorageRegistry() {}
55 60
56 BlobStorageRegistry::~BlobStorageRegistry() { 61 BlobStorageRegistry::~BlobStorageRegistry() {
57 // Note: We don't bother calling the construction complete callbacks, as we 62 // 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. 63 // are only being destructed at the end of the life of the browser process.
59 // So it shouldn't matter. 64 // So it shouldn't matter.
60 } 65 }
61 66
62 BlobStorageRegistry::Entry* BlobStorageRegistry::CreateEntry( 67 BlobStorageRegistry::Entry* BlobStorageRegistry::CreateEntry(
63 const std::string& uuid, 68 const std::string& uuid,
64 const std::string& content_type, 69 const std::string& content_type,
65 const std::string& content_disposition) { 70 const std::string& content_disposition) {
66 DCHECK(!ContainsKey(blob_map_, uuid)); 71 DCHECK(!ContainsKey(blob_map_, uuid));
67 std::unique_ptr<Entry> entry(new Entry(1, BlobState::PENDING)); 72 std::unique_ptr<Entry> entry(new Entry());
68 entry->content_type = content_type; 73 entry->content_type = content_type;
69 entry->content_disposition = content_disposition; 74 entry->content_disposition = content_disposition;
70 Entry* entry_ptr = entry.get(); 75 Entry* entry_ptr = entry.get();
71 blob_map_.add(uuid, std::move(entry)); 76 blob_map_.add(uuid, std::move(entry));
72 return entry_ptr; 77 return entry_ptr;
73 } 78 }
74 79
75 bool BlobStorageRegistry::DeleteEntry(const std::string& uuid) { 80 bool BlobStorageRegistry::DeleteEntry(const std::string& uuid) {
76 return blob_map_.erase(uuid) == 1; 81 return blob_map_.erase(uuid) == 1;
77 } 82 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 url_to_uuid_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); 130 url_to_uuid_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url);
126 if (found == url_to_uuid_.end()) 131 if (found == url_to_uuid_.end())
127 return nullptr; 132 return nullptr;
128 Entry* entry = GetEntry(found->second); 133 Entry* entry = GetEntry(found->second);
129 if (entry && uuid) 134 if (entry && uuid)
130 uuid->assign(found->second); 135 uuid->assign(found->second);
131 return entry; 136 return entry;
132 } 137 }
133 138
134 } // namespace storage 139 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698