| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/linked_ptr.h" | |
| 13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/string16.h" | 13 #include "base/string16.h" |
| 15 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 16 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 17 | 16 |
| 18 class ExtensionGlobalErrorBadge; | 17 class ExtensionGlobalErrorBadge; |
| 19 class ExtensionService; | 18 class ExtensionService; |
| 20 class Profile; | 19 class Profile; |
| 21 | 20 |
| 22 // TODO(battre) Remove the Extension prefix. | 21 // TODO(battre) Remove the Extension prefix. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 int message_id_; | 94 int message_id_; |
| 96 // Parameters to be filled into the string identified by |message_id_|. | 95 // Parameters to be filled into the string identified by |message_id_|. |
| 97 std::vector<std::string> message_parameters_; | 96 std::vector<std::string> message_parameters_; |
| 98 | 97 |
| 99 DISALLOW_COPY_AND_ASSIGN(ExtensionWarning); | 98 DISALLOW_COPY_AND_ASSIGN(ExtensionWarning); |
| 100 }; | 99 }; |
| 101 | 100 |
| 102 // Compare ExtensionWarnings based on the tuple of (extension_id, type). | 101 // Compare ExtensionWarnings based on the tuple of (extension_id, type). |
| 103 // The message associated with ExtensionWarnings is purely informational | 102 // The message associated with ExtensionWarnings is purely informational |
| 104 // and does not contribute to distinguishing extensions. | 103 // and does not contribute to distinguishing extensions. |
| 105 bool operator<(const linked_ptr<ExtensionWarning>& a, | 104 class ExtensionWarningComparator |
| 106 const linked_ptr<ExtensionWarning>& b); | 105 : public std::binary_function<ExtensionWarning*, ExtensionWarning*, bool> { |
| 106 public: |
| 107 bool operator()(ExtensionWarning* a, ExtensionWarning* b) const; |
| 108 }; |
| 107 | 109 |
| 108 // Container for ExtensionWarnings intended to be passed between threads. | 110 // Container for ExtensionWarnings intended to be passed between threads. |
| 109 // This exists to work around the lack of thread-safety of linke_ptrs. | 111 // This exists to work around the lack of thread-safety of linke_ptrs. |
| 110 // Only one thread should have access to an ExtensionWarningSet at any time. | 112 // Only one thread should have access to an ExtensionWarningSet at any time. |
| 111 class ExtensionWarningSet { | 113 class ExtensionWarningSet { |
| 112 public: | 114 public: |
| 115 typedef std::set<ExtensionWarning*, ExtensionWarningComparator> Set; |
| 116 |
| 113 ExtensionWarningSet(); | 117 ExtensionWarningSet(); |
| 114 ~ExtensionWarningSet(); | 118 ~ExtensionWarningSet(); |
| 115 | 119 |
| 116 // Inserts |warning| into the warning set if it is unique under operator<(): | 120 // Inserts |warning| into the warning set if it is unique under operator<(): |
| 117 // If |warnings_| contains an entry of the same type and extension_id, the | 121 // If |warnings_| contains an entry of the same type and extension_id, the |
| 118 // insertion is ignored. | 122 // insertion is ignored. |
| 119 void Insert(scoped_ptr<ExtensionWarning> warning); | 123 void Insert(scoped_ptr<ExtensionWarning> warning); |
| 120 | 124 |
| 121 // Returns and resets |warnings_|. | 125 // Returns and resets |warnings_|. The ownership of the ExtensionWarnings |
| 122 std::set<linked_ptr<ExtensionWarning> > Release(); | 126 // is passed to the caller. |
| 127 Set Release(); |
| 123 | 128 |
| 124 bool IsEmpty() const; | 129 bool IsEmpty() const; |
| 125 | 130 |
| 126 private: | 131 private: |
| 127 std::set<linked_ptr<ExtensionWarning> > warnings_; | 132 // We own the objects in this dictionary. |
| 133 Set warnings_; |
| 128 | 134 |
| 129 DISALLOW_COPY_AND_ASSIGN(ExtensionWarningSet); | 135 DISALLOW_COPY_AND_ASSIGN(ExtensionWarningSet); |
| 130 }; | 136 }; |
| 131 | 137 |
| 132 // Manages a set of warnings caused by extensions. These warnings (e.g. | 138 // Manages a set of warnings caused by extensions. These warnings (e.g. |
| 133 // conflicting modifications of network requests by extensions, slow extensions, | 139 // conflicting modifications of network requests by extensions, slow extensions, |
| 134 // etc.) trigger a warning badge in the UI and and provide means to resolve | 140 // etc.) trigger a warning badge in the UI and and provide means to resolve |
| 135 // them. This class must be used on the UI thread only. | 141 // them. This class must be used on the UI thread only. |
| 136 class ExtensionWarningService : public base::NonThreadSafe { | 142 class ExtensionWarningService : public base::NonThreadSafe { |
| 137 public: | 143 public: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // |warnings| occurred and triggers a warning badge. | 178 // |warnings| occurred and triggers a warning badge. |
| 173 static void NotifyWarningsOnUI( | 179 static void NotifyWarningsOnUI( |
| 174 void* profile_id, | 180 void* profile_id, |
| 175 scoped_ptr<ExtensionWarningSet> warnings); | 181 scoped_ptr<ExtensionWarningSet> warnings); |
| 176 | 182 |
| 177 protected: | 183 protected: |
| 178 // Virtual for testing. | 184 // Virtual for testing. |
| 179 virtual void NotifyWarningsChanged(); | 185 virtual void NotifyWarningsChanged(); |
| 180 | 186 |
| 181 private: | 187 private: |
| 182 typedef std::set<linked_ptr<ExtensionWarning> >::const_iterator | 188 typedef ExtensionWarningSet::Set::const_iterator const_iterator; |
| 183 const_iterator; | 189 typedef ExtensionWarningSet::Set::iterator iterator; |
| 184 typedef std::set<linked_ptr<ExtensionWarning> >::iterator iterator; | |
| 185 | 190 |
| 186 // Shows or hides the warning badge on the wrench menu depending on whether | 191 // Shows or hides the warning badge on the wrench menu depending on whether |
| 187 // any non-suppressed warnings exist. | 192 // any non-suppressed warnings exist. |
| 188 void UpdateWarningBadge(); | 193 void UpdateWarningBadge(); |
| 189 | 194 |
| 190 // Currently existing warnings. | 195 // Currently existing warnings. We own these warnings. |
| 191 std::set<linked_ptr<ExtensionWarning> > warnings_; | 196 ExtensionWarningSet::Set warnings_; |
| 192 | 197 |
| 193 // Warnings that do not trigger a badge on the wrench menu. | 198 // Warnings that do not trigger a badge on the wrench menu. |
| 194 std::set<linked_ptr<ExtensionWarning> > badge_suppressions_; | 199 // Weak pointers to objects in |warnings_|. |
| 200 ExtensionWarningSet::Set badge_suppressions_; |
| 195 | 201 |
| 196 Profile* profile_; | 202 Profile* profile_; |
| 197 }; | 203 }; |
| 198 | 204 |
| 199 } // namespace extensions | 205 } // namespace extensions |
| 200 | 206 |
| 201 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ | 207 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WARNING_SET_H_ |
| OLD | NEW |