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

Side by Side Diff: extensions/browser/error_map.cc

Issue 1909773002: Convert //extensions/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
« no previous file with comments | « extensions/browser/error_map.h ('k') | extensions/browser/error_map_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/error_map.h" 5 #include "extensions/browser/error_map.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 ~ExtensionEntry(); 91 ~ExtensionEntry();
92 92
93 // Delete any errors in the entry that match the given ids and type, if 93 // Delete any errors in the entry that match the given ids and type, if
94 // provided. 94 // provided.
95 // Returns true if any errors were deleted. 95 // Returns true if any errors were deleted.
96 bool DeleteErrors(const ErrorMap::Filter& filter); 96 bool DeleteErrors(const ErrorMap::Filter& filter);
97 // Delete all errors in the entry. 97 // Delete all errors in the entry.
98 void DeleteAllErrors(); 98 void DeleteAllErrors();
99 99
100 // Add the error to the list, and return a weak reference. 100 // Add the error to the list, and return a weak reference.
101 const ExtensionError* AddError(scoped_ptr<ExtensionError> error); 101 const ExtensionError* AddError(std::unique_ptr<ExtensionError> error);
102 102
103 const ErrorList* list() const { return &list_; } 103 const ErrorList* list() const { return &list_; }
104 104
105 private: 105 private:
106 // The list of all errors associated with the extension. The errors are 106 // The list of all errors associated with the extension. The errors are
107 // owned by the Entry (in turn owned by the ErrorMap) and are deleted upon 107 // owned by the Entry (in turn owned by the ErrorMap) and are deleted upon
108 // destruction. 108 // destruction.
109 ErrorList list_; 109 ErrorList list_;
110 110
111 DISALLOW_COPY_AND_ASSIGN(ExtensionEntry); 111 DISALLOW_COPY_AND_ASSIGN(ExtensionEntry);
(...skipping 19 matching lines...) Expand all
131 } 131 }
132 return deleted; 132 return deleted;
133 } 133 }
134 134
135 void ErrorMap::ExtensionEntry::DeleteAllErrors() { 135 void ErrorMap::ExtensionEntry::DeleteAllErrors() {
136 STLDeleteContainerPointers(list_.begin(), list_.end()); 136 STLDeleteContainerPointers(list_.begin(), list_.end());
137 list_.clear(); 137 list_.clear();
138 } 138 }
139 139
140 const ExtensionError* ErrorMap::ExtensionEntry::AddError( 140 const ExtensionError* ErrorMap::ExtensionEntry::AddError(
141 scoped_ptr<ExtensionError> error) { 141 std::unique_ptr<ExtensionError> error) {
142 for (ErrorList::iterator iter = list_.begin(); iter != list_.end(); ++iter) { 142 for (ErrorList::iterator iter = list_.begin(); iter != list_.end(); ++iter) {
143 // If we find a duplicate error, remove the old error and add the new one, 143 // If we find a duplicate error, remove the old error and add the new one,
144 // incrementing the occurrence count of the error. We use the new error 144 // incrementing the occurrence count of the error. We use the new error
145 // for runtime errors, so we can link to the latest context, inspectable 145 // for runtime errors, so we can link to the latest context, inspectable
146 // view, etc. 146 // view, etc.
147 if (error->IsEqual(*iter)) { 147 if (error->IsEqual(*iter)) {
148 error->set_occurrences((*iter)->occurrences() + 1); 148 error->set_occurrences((*iter)->occurrences() + 1);
149 error->set_id((*iter)->id()); 149 error->set_id((*iter)->id());
150 delete *iter; 150 delete *iter;
151 list_.erase(iter); 151 list_.erase(iter);
(...skipping 23 matching lines...) Expand all
175 ErrorMap::~ErrorMap() { 175 ErrorMap::~ErrorMap() {
176 RemoveAllErrors(); 176 RemoveAllErrors();
177 } 177 }
178 178
179 const ErrorList& ErrorMap::GetErrorsForExtension( 179 const ErrorList& ErrorMap::GetErrorsForExtension(
180 const std::string& extension_id) const { 180 const std::string& extension_id) const {
181 EntryMap::const_iterator iter = map_.find(extension_id); 181 EntryMap::const_iterator iter = map_.find(extension_id);
182 return iter != map_.end() ? *iter->second->list() : g_empty_error_list.Get(); 182 return iter != map_.end() ? *iter->second->list() : g_empty_error_list.Get();
183 } 183 }
184 184
185 const ExtensionError* ErrorMap::AddError(scoped_ptr<ExtensionError> error) { 185 const ExtensionError* ErrorMap::AddError(
186 std::unique_ptr<ExtensionError> error) {
186 EntryMap::iterator iter = map_.find(error->extension_id()); 187 EntryMap::iterator iter = map_.find(error->extension_id());
187 if (iter == map_.end()) { 188 if (iter == map_.end()) {
188 iter = map_.insert(std::pair<std::string, ExtensionEntry*>( 189 iter = map_.insert(std::pair<std::string, ExtensionEntry*>(
189 error->extension_id(), new ExtensionEntry)).first; 190 error->extension_id(), new ExtensionEntry)).first;
190 } 191 }
191 return iter->second->AddError(std::move(error)); 192 return iter->second->AddError(std::move(error));
192 } 193 }
193 194
194 void ErrorMap::RemoveErrors(const Filter& filter, 195 void ErrorMap::RemoveErrors(const Filter& filter,
195 std::set<std::string>* affected_ids) { 196 std::set<std::string>* affected_ids) {
(...skipping 11 matching lines...) Expand all
207 } 208 }
208 } 209 }
209 210
210 void ErrorMap::RemoveAllErrors() { 211 void ErrorMap::RemoveAllErrors() {
211 for (EntryMap::iterator iter = map_.begin(); iter != map_.end(); ++iter) 212 for (EntryMap::iterator iter = map_.begin(); iter != map_.end(); ++iter)
212 delete iter->second; 213 delete iter->second;
213 map_.clear(); 214 map_.clear();
214 } 215 }
215 216
216 } // namespace extensions 217 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/error_map.h ('k') | extensions/browser/error_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698