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

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

Issue 2604913002: Remove base::ScopedPtrHashMap from storage/. (Closed)
Patch Set: Created 3 years, 11 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/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/stl_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "storage/browser/blob/blob_entry.h" 15 #include "storage/browser/blob/blob_entry.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 namespace storage { 18 namespace storage {
19 19
20 namespace { 20 namespace {
21 // We can't use GURL directly for these hash fragment manipulations 21 // We can't use GURL directly for these hash fragment manipulations
22 // since it doesn't have specific knowlege of the BlobURL format. GURL 22 // since it doesn't have specific knowlege of the BlobURL format. GURL
23 // treats BlobURLs as if they were PathURLs which don't support hash 23 // treats BlobURLs as if they were PathURLs which don't support hash
24 // fragments. 24 // fragments.
(...skipping 17 matching lines...) Expand all
42 BlobStorageRegistry::~BlobStorageRegistry() { 42 BlobStorageRegistry::~BlobStorageRegistry() {
43 // Note: We don't bother calling the construction complete callbacks, as we 43 // Note: We don't bother calling the construction complete callbacks, as we
44 // are only being destructed at the end of the life of the browser process. 44 // are only being destructed at the end of the life of the browser process.
45 // So it shouldn't matter. 45 // So it shouldn't matter.
46 } 46 }
47 47
48 BlobEntry* BlobStorageRegistry::CreateEntry( 48 BlobEntry* BlobStorageRegistry::CreateEntry(
49 const std::string& uuid, 49 const std::string& uuid,
50 const std::string& content_type, 50 const std::string& content_type,
51 const std::string& content_disposition) { 51 const std::string& content_disposition) {
52 DCHECK(!ContainsKey(blob_map_, uuid)); 52 DCHECK(blob_map_.find(uuid) == blob_map_.end());
53 std::unique_ptr<BlobEntry> entry( 53 std::unique_ptr<BlobEntry> entry =
54 new BlobEntry(content_type, content_disposition)); 54 base::MakeUnique<BlobEntry>(content_type, content_disposition);
55 BlobEntry* entry_ptr = entry.get(); 55 BlobEntry* entry_ptr = entry.get();
56 blob_map_.add(uuid, std::move(entry)); 56 blob_map_[uuid] = std::move(entry);
57 return entry_ptr; 57 return entry_ptr;
58 } 58 }
59 59
60 bool BlobStorageRegistry::DeleteEntry(const std::string& uuid) { 60 bool BlobStorageRegistry::DeleteEntry(const std::string& uuid) {
61 return blob_map_.erase(uuid) == 1; 61 return blob_map_.erase(uuid) == 1;
62 } 62 }
63 63
64 bool BlobStorageRegistry::HasEntry(const std::string& uuid) const { 64 bool BlobStorageRegistry::HasEntry(const std::string& uuid) const {
65 return blob_map_.find(uuid) != blob_map_.end(); 65 return blob_map_.find(uuid) != blob_map_.end();
66 } 66 }
67 67
68 BlobEntry* BlobStorageRegistry::GetEntry(const std::string& uuid) { 68 BlobEntry* BlobStorageRegistry::GetEntry(const std::string& uuid) {
69 BlobMap::iterator found = blob_map_.find(uuid); 69 auto found = blob_map_.find(uuid);
70 if (found == blob_map_.end()) 70 if (found == blob_map_.end())
71 return nullptr; 71 return nullptr;
72 return found->second; 72 return found->second.get();
73 } 73 }
74 74
75 const BlobEntry* BlobStorageRegistry::GetEntry(const std::string& uuid) const { 75 const BlobEntry* BlobStorageRegistry::GetEntry(const std::string& uuid) const {
76 return const_cast<BlobStorageRegistry*>(this)->GetEntry(uuid); 76 return const_cast<BlobStorageRegistry*>(this)->GetEntry(uuid);
77 } 77 }
78 78
79 bool BlobStorageRegistry::CreateUrlMapping(const GURL& blob_url, 79 bool BlobStorageRegistry::CreateUrlMapping(const GURL& blob_url,
80 const std::string& uuid) { 80 const std::string& uuid) {
81 DCHECK(!BlobUrlHasRef(blob_url)); 81 DCHECK(!BlobUrlHasRef(blob_url));
82 if (blob_map_.find(uuid) == blob_map_.end() || IsURLMapped(blob_url)) 82 if (blob_map_.find(uuid) == blob_map_.end() || IsURLMapped(blob_url))
83 return false; 83 return false;
84 url_to_uuid_[blob_url] = uuid; 84 url_to_uuid_[blob_url] = uuid;
85 return true; 85 return true;
86 } 86 }
87 87
88 bool BlobStorageRegistry::DeleteURLMapping(const GURL& blob_url, 88 bool BlobStorageRegistry::DeleteURLMapping(const GURL& blob_url,
89 std::string* uuid) { 89 std::string* uuid) {
90 DCHECK(!BlobUrlHasRef(blob_url)); 90 DCHECK(!BlobUrlHasRef(blob_url));
91 URLMap::iterator found = url_to_uuid_.find(blob_url); 91 auto found = url_to_uuid_.find(blob_url);
92 if (found == url_to_uuid_.end()) 92 if (found == url_to_uuid_.end())
93 return false; 93 return false;
94 if (uuid) 94 if (uuid)
95 uuid->assign(found->second); 95 uuid->assign(found->second);
96 url_to_uuid_.erase(found); 96 url_to_uuid_.erase(found);
97 return true; 97 return true;
98 } 98 }
99 99
100 bool BlobStorageRegistry::IsURLMapped(const GURL& blob_url) const { 100 bool BlobStorageRegistry::IsURLMapped(const GURL& blob_url) const {
101 return base::ContainsKey(url_to_uuid_, blob_url); 101 return url_to_uuid_.find(blob_url) != url_to_uuid_.end();
102 } 102 }
103 103
104 BlobEntry* BlobStorageRegistry::GetEntryFromURL(const GURL& url, 104 BlobEntry* BlobStorageRegistry::GetEntryFromURL(const GURL& url,
105 std::string* uuid) { 105 std::string* uuid) {
106 URLMap::iterator found = 106 auto found =
107 url_to_uuid_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url); 107 url_to_uuid_.find(BlobUrlHasRef(url) ? ClearBlobUrlRef(url) : url);
108 if (found == url_to_uuid_.end()) 108 if (found == url_to_uuid_.end())
109 return nullptr; 109 return nullptr;
110 BlobEntry* entry = GetEntry(found->second); 110 BlobEntry* entry = GetEntry(found->second);
111 if (entry && uuid) 111 if (entry && uuid)
112 uuid->assign(found->second); 112 uuid->assign(found->second);
113 return entry; 113 return entry;
114 } 114 }
115 115
116 } // namespace storage 116 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/blob/blob_storage_registry.h ('k') | storage/browser/blob/view_blob_internals_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698