// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef EXTENSIONS_BROWSER_ERROR_MAP_H_ #define EXTENSIONS_BROWSER_ERROR_MAP_H_ #include #include #include #include #include #include "base/containers/circular_deque.h" #include "extensions/browser/extension_error.h" namespace extensions { using ErrorList = base::circular_deque>; // An ErrorMap is responsible for storing Extension-related errors, keyed by // Extension ID. class ErrorMap { public: ErrorMap(); ErrorMap(const ErrorMap&) = delete; ErrorMap& operator=(const ErrorMap&) = delete; ~ErrorMap(); struct Filter { Filter(const std::string& restrict_to_extension_id, int restrict_to_type, const std::set& restrict_to_ids, bool restrict_to_incognito); Filter(const Filter& other); ~Filter(); // Convenience methods to get a specific type of filter. Prefer these over // the constructor when possible. static Filter ErrorsForExtension(const std::string& extension_id); static Filter ErrorsForExtensionWithType(const std::string& extension_id, ExtensionError::Type type); static Filter ErrorsForExtensionWithIds(const std::string& extension_id, const std::set& ids); static Filter ErrorsForExtensionWithTypeAndIds( const std::string& extension_id, ExtensionError::Type type, const std::set& ids); static Filter IncognitoErrors(); bool Matches(const ExtensionError* error) const; const std::string restrict_to_extension_id; const int restrict_to_type; const std::set restrict_to_ids; const bool restrict_to_incognito; }; // Return the list of all errors associated with the given extension. const ErrorList& GetErrorsForExtension(const std::string& extension_id) const; // Add the |error| to the ErrorMap. const ExtensionError* AddError(std::unique_ptr error); // Removes errors that match the given |filter| from the map. If non-null, // |affected_ids| will be populated with the set of extension ids that were // affected by this removal. void RemoveErrors(const Filter& filter, std::set* affected_ids); // Remove all errors for all extensions, and clear the map. void RemoveAllErrors(); size_t size() const { return map_.size(); } private: // An Entry is created for each Extension ID, and stores the errors related to // that Extension. class ExtensionEntry; // The mapping between Extension IDs and their corresponding Entries. std::map> map_; }; } // namespace extensions #endif // EXTENSIONS_BROWSER_ERROR_MAP_H_