Revert of Output closure-compiled JavaScript files (patchset #10 id:180001 of https...
[chromium-blink-merge.git] / extensions / browser / error_map.h
blob216d13669e7656ab8952a6612707a61a1cbed0be
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 <string>
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "extensions/browser/extension_error.h"
16 namespace extensions {
18 typedef std::deque<const ExtensionError*> ErrorList;
20 // An ErrorMap is responsible for storing Extension-related errors, keyed by
21 // Extension ID. The errors are owned by the ErrorMap, and are deleted upon
22 // destruction.
23 class ErrorMap {
24 public:
25 ErrorMap();
26 ~ErrorMap();
28 // Return the list of all errors associated with the given extension.
29 const ErrorList& GetErrorsForExtension(const std::string& extension_id) const;
31 // Add the |error| to the ErrorMap.
32 const ExtensionError* AddError(scoped_ptr<ExtensionError> error);
34 // Remove an extension from the ErrorMap, deleting all associated errors.
35 void Remove(const std::string& extension_id);
36 // Remove all errors of a given type for an extension.
37 void RemoveErrorsForExtensionOfType(const std::string& extension_id,
38 ExtensionError::Type type);
39 // Remove all incognito errors for all extensions.
40 void RemoveIncognitoErrors();
41 // Remove all errors for all extensions, and clear the map.
42 void RemoveAllErrors();
44 size_t size() const { return map_.size(); }
46 private:
47 // An Entry is created for each Extension ID, and stores the errors related to
48 // that Extension.
49 class ExtensionEntry {
50 public:
51 ExtensionEntry();
52 ~ExtensionEntry();
54 // Delete all errors associated with this extension.
55 void DeleteAllErrors();
56 // Delete all incognito errors associated with this extension.
57 void DeleteIncognitoErrors();
58 // Delete all errors of the given |type| associated with this extension.
59 void DeleteErrorsOfType(ExtensionError::Type type);
61 // Add the error to the list, and return a weak reference.
62 const ExtensionError* AddError(scoped_ptr<ExtensionError> error);
64 const ErrorList* list() const { return &list_; }
66 private:
67 // The list of all errors associated with the extension. The errors are
68 // owned by the Entry (in turn owned by the ErrorMap) and are deleted upon
69 // destruction.
70 ErrorList list_;
72 DISALLOW_COPY_AND_ASSIGN(ExtensionEntry);
74 typedef std::map<std::string, ExtensionEntry*> EntryMap;
76 // The mapping between Extension IDs and their corresponding Entries.
77 EntryMap map_;
79 DISALLOW_COPY_AND_ASSIGN(ErrorMap);
82 } // namespace extensions
84 #endif // EXTENSIONS_BROWSER_ERROR_MAP_H_