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

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: fixes, working w/ Layout tests 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::Entry::Entry() {}
42 : refcount(refcount), state(state) {}
43 42
44 BlobStorageRegistry::Entry::~Entry() {} 43 BlobStorageRegistry::Entry::~Entry() {}
45 44
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() {} 45 BlobStorageRegistry::BlobStorageRegistry() {}
55 46
56 BlobStorageRegistry::~BlobStorageRegistry() { 47 BlobStorageRegistry::~BlobStorageRegistry() {
57 // Note: We don't bother calling the construction complete callbacks, as we 48 // 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. 49 // are only being destructed at the end of the life of the browser process.
59 // So it shouldn't matter. 50 // So it shouldn't matter.
60 } 51 }
61 52
62 BlobStorageRegistry::Entry* BlobStorageRegistry::CreateEntry( 53 BlobStorageRegistry::Entry* BlobStorageRegistry::CreateEntry(
63 const std::string& uuid, 54 const std::string& uuid,
64 const std::string& content_type, 55 const std::string& content_type,
65 const std::string& content_disposition) { 56 const std::string& content_disposition) {
66 DCHECK(!ContainsKey(blob_map_, uuid)); 57 DCHECK(!ContainsKey(blob_map_, uuid));
67 std::unique_ptr<Entry> entry(new Entry(1, BlobState::PENDING)); 58 std::unique_ptr<Entry> entry(new Entry());
68 entry->content_type = content_type; 59 entry->content_type = content_type;
69 entry->content_disposition = content_disposition; 60 entry->content_disposition = content_disposition;
70 Entry* entry_ptr = entry.get(); 61 Entry* entry_ptr = entry.get();
71 blob_map_.add(uuid, std::move(entry)); 62 blob_map_.add(uuid, std::move(entry));
72 return entry_ptr; 63 return entry_ptr;
73 } 64 }
74 65
75 bool BlobStorageRegistry::DeleteEntry(const std::string& uuid) { 66 bool BlobStorageRegistry::DeleteEntry(const std::string& uuid) {
76 return blob_map_.erase(uuid) == 1; 67 return blob_map_.erase(uuid) == 1;
77 } 68 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 url_to_uuid_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); 116 url_to_uuid_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url);
126 if (found == url_to_uuid_.end()) 117 if (found == url_to_uuid_.end())
127 return nullptr; 118 return nullptr;
128 Entry* entry = GetEntry(found->second); 119 Entry* entry = GetEntry(found->second);
129 if (entry && uuid) 120 if (entry && uuid)
130 uuid->assign(found->second); 121 uuid->assign(found->second);
131 return entry; 122 return entry;
132 } 123 }
133 124
134 } // namespace storage 125 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698