| OLD | NEW |
| 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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 | 9 |
| 10 namespace extensions { | 10 namespace extensions { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 //////////////////////////////////////////////////////////////////////////////// | 81 //////////////////////////////////////////////////////////////////////////////// |
| 82 // ErrorMap::ExtensionEntry | 82 // ErrorMap::ExtensionEntry |
| 83 class ErrorMap::ExtensionEntry { | 83 class ErrorMap::ExtensionEntry { |
| 84 public: | 84 public: |
| 85 ExtensionEntry(); | 85 ExtensionEntry(); |
| 86 ~ExtensionEntry(); | 86 ~ExtensionEntry(); |
| 87 | 87 |
| 88 // Delete any errors in the entry that match the given ids and type, if | 88 // Delete any errors in the entry that match the given ids and type, if |
| 89 // provided. | 89 // provided. |
| 90 void DeleteErrors(const ErrorMap::Filter& filter); | 90 // Returns true if any errors were deleted. |
| 91 bool DeleteErrors(const ErrorMap::Filter& filter); |
| 91 // Delete all errors in the entry. | 92 // Delete all errors in the entry. |
| 92 void DeleteAllErrors(); | 93 void DeleteAllErrors(); |
| 93 | 94 |
| 94 // Add the error to the list, and return a weak reference. | 95 // Add the error to the list, and return a weak reference. |
| 95 const ExtensionError* AddError(scoped_ptr<ExtensionError> error); | 96 const ExtensionError* AddError(scoped_ptr<ExtensionError> error); |
| 96 | 97 |
| 97 const ErrorList* list() const { return &list_; } | 98 const ErrorList* list() const { return &list_; } |
| 98 | 99 |
| 99 private: | 100 private: |
| 100 // The list of all errors associated with the extension. The errors are | 101 // The list of all errors associated with the extension. The errors are |
| 101 // owned by the Entry (in turn owned by the ErrorMap) and are deleted upon | 102 // owned by the Entry (in turn owned by the ErrorMap) and are deleted upon |
| 102 // destruction. | 103 // destruction. |
| 103 ErrorList list_; | 104 ErrorList list_; |
| 104 | 105 |
| 105 DISALLOW_COPY_AND_ASSIGN(ExtensionEntry); | 106 DISALLOW_COPY_AND_ASSIGN(ExtensionEntry); |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 ErrorMap::ExtensionEntry::ExtensionEntry() { | 109 ErrorMap::ExtensionEntry::ExtensionEntry() { |
| 109 } | 110 } |
| 110 | 111 |
| 111 ErrorMap::ExtensionEntry::~ExtensionEntry() { | 112 ErrorMap::ExtensionEntry::~ExtensionEntry() { |
| 112 DeleteAllErrors(); | 113 DeleteAllErrors(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void ErrorMap::ExtensionEntry::DeleteErrors(const Filter& filter) { | 116 bool ErrorMap::ExtensionEntry::DeleteErrors(const Filter& filter) { |
| 117 bool deleted = false; |
| 116 for (ErrorList::iterator iter = list_.begin(); iter != list_.end();) { | 118 for (ErrorList::iterator iter = list_.begin(); iter != list_.end();) { |
| 117 if (filter.Matches(*iter)) { | 119 if (filter.Matches(*iter)) { |
| 118 delete *iter; | 120 delete *iter; |
| 119 iter = list_.erase(iter); | 121 iter = list_.erase(iter); |
| 122 deleted = true; |
| 120 } else { | 123 } else { |
| 121 ++iter; | 124 ++iter; |
| 122 } | 125 } |
| 123 } | 126 } |
| 127 return deleted; |
| 124 } | 128 } |
| 125 | 129 |
| 126 void ErrorMap::ExtensionEntry::DeleteAllErrors() { | 130 void ErrorMap::ExtensionEntry::DeleteAllErrors() { |
| 127 STLDeleteContainerPointers(list_.begin(), list_.end()); | 131 STLDeleteContainerPointers(list_.begin(), list_.end()); |
| 128 list_.clear(); | 132 list_.clear(); |
| 129 } | 133 } |
| 130 | 134 |
| 131 const ExtensionError* ErrorMap::ExtensionEntry::AddError( | 135 const ExtensionError* ErrorMap::ExtensionEntry::AddError( |
| 132 scoped_ptr<ExtensionError> error) { | 136 scoped_ptr<ExtensionError> error) { |
| 133 for (ErrorList::iterator iter = list_.begin(); iter != list_.end(); ++iter) { | 137 for (ErrorList::iterator iter = list_.begin(); iter != list_.end(); ++iter) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 179 |
| 176 const ExtensionError* ErrorMap::AddError(scoped_ptr<ExtensionError> error) { | 180 const ExtensionError* ErrorMap::AddError(scoped_ptr<ExtensionError> error) { |
| 177 EntryMap::iterator iter = map_.find(error->extension_id()); | 181 EntryMap::iterator iter = map_.find(error->extension_id()); |
| 178 if (iter == map_.end()) { | 182 if (iter == map_.end()) { |
| 179 iter = map_.insert(std::pair<std::string, ExtensionEntry*>( | 183 iter = map_.insert(std::pair<std::string, ExtensionEntry*>( |
| 180 error->extension_id(), new ExtensionEntry)).first; | 184 error->extension_id(), new ExtensionEntry)).first; |
| 181 } | 185 } |
| 182 return iter->second->AddError(error.Pass()); | 186 return iter->second->AddError(error.Pass()); |
| 183 } | 187 } |
| 184 | 188 |
| 185 void ErrorMap::RemoveErrors(const Filter& filter) { | 189 void ErrorMap::RemoveErrors(const Filter& filter, |
| 190 std::set<std::string>* affected_ids) { |
| 186 if (!filter.restrict_to_extension_id.empty()) { | 191 if (!filter.restrict_to_extension_id.empty()) { |
| 187 EntryMap::iterator iter = map_.find(filter.restrict_to_extension_id); | 192 EntryMap::iterator iter = map_.find(filter.restrict_to_extension_id); |
| 188 if (iter != map_.end()) | 193 if (iter != map_.end()) { |
| 189 iter->second->DeleteErrors(filter); | 194 if (iter->second->DeleteErrors(filter) && affected_ids) |
| 195 affected_ids->insert(filter.restrict_to_extension_id); |
| 196 } |
| 190 } else { | 197 } else { |
| 191 for (auto& key_val : map_) | 198 for (auto& key_val : map_) { |
| 192 key_val.second->DeleteErrors(filter); | 199 if (key_val.second->DeleteErrors(filter) && affected_ids) |
| 200 affected_ids->insert(key_val.first); |
| 201 } |
| 193 } | 202 } |
| 194 } | 203 } |
| 195 | 204 |
| 196 void ErrorMap::RemoveAllErrors() { | 205 void ErrorMap::RemoveAllErrors() { |
| 197 for (EntryMap::iterator iter = map_.begin(); iter != map_.end(); ++iter) | 206 for (EntryMap::iterator iter = map_.begin(); iter != map_.end(); ++iter) |
| 198 delete iter->second; | 207 delete iter->second; |
| 199 map_.clear(); | 208 map_.clear(); |
| 200 } | 209 } |
| 201 | 210 |
| 202 } // namespace extensions | 211 } // namespace extensions |
| OLD | NEW |