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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_ERROR_MAP_H_
6 #define EXTENSIONS_BROWSER_ERROR_MAP_H_
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "extensions/browser/extension_error.h"
17 namespace extensions
{
19 typedef std::deque
<const ExtensionError
*> ErrorList
;
21 // An ErrorMap is responsible for storing Extension-related errors, keyed by
22 // Extension ID. The errors are owned by the ErrorMap, and are deleted upon
30 Filter(const std::string
& restrict_to_extension_id
,
32 const std::set
<int>& restrict_to_ids
,
33 bool restrict_to_incognito
);
36 // Convenience methods to get a specific type of filter. Prefer these over
37 // the constructor when possible.
38 static Filter
ErrorsForExtension(const std::string
& extension_id
);
39 static Filter
ErrorsForExtensionWithType(const std::string
& extension_id
,
40 ExtensionError::Type type
);
41 static Filter
ErrorsForExtensionWithIds(const std::string
& extension_id
,
42 const std::set
<int>& ids
);
43 static Filter
ErrorsForExtensionWithTypeAndIds(
44 const std::string
& extension_id
,
45 ExtensionError::Type type
,
46 const std::set
<int>& ids
);
47 static Filter
IncognitoErrors();
49 bool Matches(const ExtensionError
* error
) const;
51 const std::string restrict_to_extension_id
;
52 const int restrict_to_type
;
53 const std::set
<int> restrict_to_ids
;
54 const bool restrict_to_incognito
;
57 // Return the list of all errors associated with the given extension.
58 const ErrorList
& GetErrorsForExtension(const std::string
& extension_id
) const;
60 // Add the |error| to the ErrorMap.
61 const ExtensionError
* AddError(scoped_ptr
<ExtensionError
> error
);
63 // Removes errors that match the given |filter| from the map. If non-null,
64 // |affected_ids| will be populated with the set of extension ids that were
65 // affected by this removal.
66 void RemoveErrors(const Filter
& filter
, std::set
<std::string
>* affected_ids
);
68 // Remove all errors for all extensions, and clear the map.
69 void RemoveAllErrors();
71 size_t size() const { return map_
.size(); }
74 // An Entry is created for each Extension ID, and stores the errors related to
77 using EntryMap
= std::map
<std::string
, ExtensionEntry
*>;
79 // The mapping between Extension IDs and their corresponding Entries.
82 DISALLOW_COPY_AND_ASSIGN(ErrorMap
);
85 } // namespace extensions
87 #endif // EXTENSIONS_BROWSER_ERROR_MAP_H_