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

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

Issue 1234813004: [BlobAsync] Asynchronous Blob Construction Final Patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-protocol-change
Patch Set: comments Created 4 years, 9 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 "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 19 matching lines...) Expand all
30 GURL ClearBlobUrlRef(const GURL& url) { 30 GURL ClearBlobUrlRef(const GURL& url) {
31 size_t hash_pos = url.spec().find('#'); 31 size_t hash_pos = url.spec().find('#');
32 if (hash_pos == std::string::npos) 32 if (hash_pos == std::string::npos)
33 return url; 33 return url;
34 return GURL(url.spec().substr(0, hash_pos)); 34 return GURL(url.spec().substr(0, hash_pos));
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 BlobStorageRegistry::Entry::Entry(int refcount, BlobState state) 39 BlobStorageRegistry::Entry::Entry(int refcount, BlobState state)
40 : refcount(refcount), state(state), exceeded_memory(false) {} 40 : refcount(refcount), state(state) {}
41 41
42 BlobStorageRegistry::Entry::~Entry() {} 42 BlobStorageRegistry::Entry::~Entry() {}
43 43
44 bool BlobStorageRegistry::Entry::TestAndSetState(BlobState expected, 44 bool BlobStorageRegistry::Entry::TestAndSetState(BlobState expected,
45 BlobState set) { 45 BlobState set) {
46 if (state != expected) 46 if (state != expected)
47 return false; 47 return false;
48 state = set; 48 state = set;
49 return true; 49 return true;
50 } 50 }
51 51
52 BlobStorageRegistry::BlobStorageRegistry() {} 52 BlobStorageRegistry::BlobStorageRegistry() {}
53 53
54 BlobStorageRegistry::~BlobStorageRegistry() { 54 BlobStorageRegistry::~BlobStorageRegistry() {
55 // Note: We don't bother calling the construction complete callbacks, as we 55 // Note: We don't bother calling the construction complete callbacks, as we
56 // are only being destructed at the end of the life of the browser process. 56 // are only being destructed at the end of the life of the browser process.
57 // So it shouldn't matter. 57 // So it shouldn't matter.
58 } 58 }
59 59
60 BlobStorageRegistry::Entry* BlobStorageRegistry::CreateEntry( 60 BlobStorageRegistry::Entry* BlobStorageRegistry::CreateEntry(
61 const std::string& uuid) { 61 const std::string& uuid,
62 const std::string& content_type,
63 const std::string& content_disposition) {
62 DCHECK(!ContainsKey(blob_map_, uuid)); 64 DCHECK(!ContainsKey(blob_map_, uuid));
63 Entry* entry = new Entry(1, BlobState::RESERVED); 65 scoped_ptr<Entry> entry(new Entry(1, BlobState::PENDING));
64 blob_map_.add(uuid, make_scoped_ptr(entry)); 66 entry->content_type = content_type;
65 return entry; 67 entry->content_disposition = content_disposition;
68 Entry* entry_ptr = entry.get();
69 blob_map_.add(uuid, std::move(entry));
70 return entry_ptr;
66 } 71 }
67 72
68 bool BlobStorageRegistry::DeleteEntry(const std::string& uuid) { 73 bool BlobStorageRegistry::DeleteEntry(const std::string& uuid) {
69 return blob_map_.erase(uuid) == 1; 74 return blob_map_.erase(uuid) == 1;
70 } 75 }
71 76
77 bool BlobStorageRegistry::HasEntry(const std::string& uuid) const {
78 return blob_map_.find(uuid) != blob_map_.end();
79 }
80
72 BlobStorageRegistry::Entry* BlobStorageRegistry::GetEntry( 81 BlobStorageRegistry::Entry* BlobStorageRegistry::GetEntry(
73 const std::string& uuid) { 82 const std::string& uuid) {
74 BlobMap::iterator found = blob_map_.find(uuid); 83 BlobMap::iterator found = blob_map_.find(uuid);
75 if (found == blob_map_.end()) 84 if (found == blob_map_.end())
76 return nullptr; 85 return nullptr;
77 return found->second; 86 return found->second;
78 } 87 }
79 88
89 const BlobStorageRegistry::Entry* BlobStorageRegistry::GetEntry(
90 const std::string& uuid) const {
91 return const_cast<BlobStorageRegistry*>(this)->GetEntry(uuid);
92 }
93
80 bool BlobStorageRegistry::CreateUrlMapping(const GURL& blob_url, 94 bool BlobStorageRegistry::CreateUrlMapping(const GURL& blob_url,
81 const std::string& uuid) { 95 const std::string& uuid) {
82 DCHECK(!BlobUrlHasRef(blob_url)); 96 DCHECK(!BlobUrlHasRef(blob_url));
83 if (blob_map_.find(uuid) == blob_map_.end() || IsURLMapped(blob_url)) 97 if (blob_map_.find(uuid) == blob_map_.end() || IsURLMapped(blob_url))
84 return false; 98 return false;
85 url_to_uuid_[blob_url] = uuid; 99 url_to_uuid_[blob_url] = uuid;
86 return true; 100 return true;
87 } 101 }
88 102
89 bool BlobStorageRegistry::DeleteURLMapping(const GURL& blob_url, 103 bool BlobStorageRegistry::DeleteURLMapping(const GURL& blob_url,
(...skipping 19 matching lines...) Expand all
109 url_to_uuid_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); 123 url_to_uuid_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url);
110 if (found == url_to_uuid_.end()) 124 if (found == url_to_uuid_.end())
111 return nullptr; 125 return nullptr;
112 Entry* entry = GetEntry(found->second); 126 Entry* entry = GetEntry(found->second);
113 if (entry && uuid) 127 if (entry && uuid)
114 uuid->assign(found->second); 128 uuid->assign(found->second);
115 return entry; 129 return entry;
116 } 130 }
117 131
118 } // namespace storage 132 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698