Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1119)

Unified Diff: chrome/browser/extensions/extension_dom_ui.cc

Issue 1518028: Fix bug that caused us to have many duplicate registrations (Closed)
Patch Set: Also clean up existing occurences Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_dom_ui.cc
diff --git a/chrome/browser/extensions/extension_dom_ui.cc b/chrome/browser/extensions/extension_dom_ui.cc
index 40f11f1f2636523d85e4aad2cb56ee71d92e33d1..531407830b337aa3839c07d8416ef33536cdf26b 100644
--- a/chrome/browser/extensions/extension_dom_ui.cc
+++ b/chrome/browser/extensions/extension_dom_ui.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/extensions/extension_dom_ui.h"
+#include <set>
+
#include "base/file_path.h"
#include "base/file_util.h"
#include "net/base/file_stream.h"
@@ -23,8 +25,6 @@
#include "chrome/common/url_constants.h"
namespace {
-const wchar_t kExtensionURLOverrides[] = L"extensions.chrome_url_overrides";
-
// Returns a piece of memory with the contents of the file |path|.
RefCountedMemory* ReadFileData(const FilePath& path) {
// TODO(arv): We currently read this on the UI thread since extension objects
@@ -45,8 +45,30 @@ RefCountedMemory* ReadFileData(const FilePath& path) {
return result;
}
+// De-dupes the items in |list|. Assumes the values are strings.
Erik does not do reviews 2010/04/14 20:48:42 Add comment referencing bug and mention that this
+void CleanUpDuplicates(ListValue* list) {
+ std::set<std::string> seen_values;
+
+ // Loop backwards as we may be removing items.
Erik does not do reviews 2010/04/14 20:48:42 this also has the cool side effect of preserving p
+ for (size_t i = list->GetSize() - 1; (i + 1) > 0; --i) {
+ std::string value;
+ if (!list->GetString(i, &value)) {
+ NOTREACHED();
+ continue;
+ }
+
+ if (seen_values.find(value) == seen_values.end())
+ seen_values.insert(value);
+ else
+ list->Remove(i, NULL);
+ }
+}
+
} // namespace
+const wchar_t ExtensionDOMUI::kExtensionURLOverrides[] =
+ L"extensions.chrome_url_overrides";
+
ExtensionDOMUI::ExtensionDOMUI(TabContents* tab_contents)
: DOMUI(tab_contents) {
should_hide_url_ = true;
@@ -222,6 +244,8 @@ void ExtensionDOMUI::RegisterChromeURLOverrides(
page_overrides = new ListValue();
all_overrides->Set(key, page_overrides);
} else {
+ CleanUpDuplicates(page_overrides);
+
// Verify that the override isn't already in the list.
ListValue::iterator i = page_overrides->begin();
for (; i != page_overrides->end(); ++i) {
@@ -230,7 +254,7 @@ void ExtensionDOMUI::RegisterChromeURLOverrides(
NOTREACHED();
continue;
}
- if (override_val == (*iter).first)
+ if (override_val == (*iter).second.spec())
break;
}
// This value is already in the list, leave it alone.
« no previous file with comments | « chrome/browser/extensions/extension_dom_ui.h ('k') | chrome/browser/extensions/extension_override_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698