Roll src/third_party/skia ce86687:b880d7f
[chromium-blink-merge.git] / extensions / browser / error_map.h
blobf0e6b2c4aa942204235de6f78b84ec702328d8ea
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_
8 #include <deque>
9 #include <map>
10 #include <set>
11 #include <string>
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
23 // destruction.
24 class ErrorMap {
25 public:
26 ErrorMap();
27 ~ErrorMap();
29 struct Filter {
30 Filter(const std::string& restrict_to_extension_id,
31 int restrict_to_type,
32 const std::set<int>& restrict_to_ids,
33 bool restrict_to_incognito);
34 ~Filter();
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.
64 void RemoveErrors(const Filter& filter);
66 // Remove all errors for all extensions, and clear the map.
67 void RemoveAllErrors();
69 size_t size() const { return map_.size(); }
71 private:
72 // An Entry is created for each Extension ID, and stores the errors related to
73 // that Extension.
74 class ExtensionEntry;
75 using EntryMap = std::map<std::string, ExtensionEntry*>;
77 // The mapping between Extension IDs and their corresponding Entries.
78 EntryMap map_;
80 DISALLOW_COPY_AND_ASSIGN(ErrorMap);
83 } // namespace extensions
85 #endif // EXTENSIONS_BROWSER_ERROR_MAP_H_