summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/values.cc14
-rw-r--r--base/values.h5
-rw-r--r--base/values_unittest.cc4
-rw-r--r--chrome/browser/chromeos/user_cros_settings_provider.cc2
-rw-r--r--chrome/browser/content_settings/content_settings_notification_provider.cc12
-rw-r--r--chrome/browser/extensions/extension_web_ui.cc9
-rw-r--r--chrome/browser/extensions/external_policy_extension_loader_unittest.cc2
-rw-r--r--chrome/browser/translate/translate_prefs.cc2
8 files changed, 27 insertions, 23 deletions
diff --git a/base/values.cc b/base/values.cc
index b215812..7a364bd 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -818,21 +818,19 @@ bool ListValue::Remove(size_t index, Value** out_value) {
return true;
}
-int ListValue::Remove(const Value& value) {
+bool ListValue::Remove(const Value& value, size_t* index) {
for (ValueVector::iterator i(list_.begin()); i != list_.end(); ++i) {
if ((*i)->Equals(&value)) {
- size_t index = i - list_.begin();
+ size_t previous_index = i - list_.begin();
delete *i;
list_.erase(i);
- // TODO(anyone): Returning a signed int type here is just wrong.
- // Change this interface to return a size_t.
- DCHECK(index <= INT_MAX);
- int return_index = static_cast<int>(index);
- return return_index;
+ if (index)
+ *index = previous_index;
+ return true;
}
}
- return -1;
+ return false;
}
void ListValue::Append(Value* in_value) {
diff --git a/base/values.h b/base/values.h
index 3af36c0..a30791b 100644
--- a/base/values.h
+++ b/base/values.h
@@ -402,8 +402,9 @@ class BASE_EXPORT ListValue : public Value {
bool Remove(size_t index, Value** out_value);
// Removes the first instance of |value| found in the list, if any, and
- // deletes it. Returns the index that it was located at (-1 for not present).
- int Remove(const Value& value);
+ // deletes it. |index| is the location where |value| was found. Returns false
+ // if not found.
+ bool Remove(const Value& value, size_t* index);
// Appends a Value to the end of the list.
void Append(Value* in_value);
diff --git a/base/values_unittest.cc b/base/values_unittest.cc
index b5bcbe1..553e8e1 100644
--- a/base/values_unittest.cc
+++ b/base/values_unittest.cc
@@ -236,7 +236,9 @@ TEST(ValuesTest, ListRemoval) {
DeletionTestValue* value = new DeletionTestValue(&deletion_flag);
list.Append(value);
EXPECT_FALSE(deletion_flag);
- EXPECT_EQ(0, list.Remove(*value));
+ size_t index = 0;
+ list.Remove(*value, &index);
+ EXPECT_EQ(0U, index);
EXPECT_TRUE(deletion_flag);
EXPECT_EQ(0U, list.GetSize());
}
diff --git a/chrome/browser/chromeos/user_cros_settings_provider.cc b/chrome/browser/chromeos/user_cros_settings_provider.cc
index 3914d4a..825f1da 100644
--- a/chrome/browser/chromeos/user_cros_settings_provider.cc
+++ b/chrome/browser/chromeos/user_cros_settings_provider.cc
@@ -661,7 +661,7 @@ void UserCrosSettingsProvider::UnwhitelistUser(const std::string& email) {
PrefService* prefs = g_browser_process->local_state();
ListPrefUpdate cached_whitelist_update(prefs, kAccountsPrefUsers);
StringValue email_value(email);
- if (cached_whitelist_update->Remove(email_value) != -1)
+ if (cached_whitelist_update->Remove(email_value, NULL))
prefs->ScheduleSavePersistentPrefs();
}
diff --git a/chrome/browser/content_settings/content_settings_notification_provider.cc b/chrome/browser/content_settings/content_settings_notification_provider.cc
index 17c1403..98893be 100644
--- a/chrome/browser/content_settings/content_settings_notification_provider.cc
+++ b/chrome/browser/content_settings/content_settings_notification_provider.cc
@@ -281,7 +281,7 @@ void NotificationProvider::PersistPermissionChange(
// Remove from one list and add to the other.
if (is_allowed) {
// Remove from the denied list.
- if (denied_sites->Remove(*value) != -1)
+ if (denied_sites->Remove(*value, NULL))
denied_changed = true;
// Add to the allowed list.
@@ -289,7 +289,7 @@ void NotificationProvider::PersistPermissionChange(
allowed_changed = true;
} else {
// Remove from the allowed list.
- if (allowed_sites->Remove(*value) != -1)
+ if (allowed_sites->Remove(*value, NULL))
allowed_changed = true;
// Add to the denied list.
@@ -336,8 +336,8 @@ void NotificationProvider::ResetAllowedOrigin(const GURL& origin) {
ListPrefUpdate update(prefs, prefs::kDesktopNotificationAllowedOrigins);
ListValue* allowed_sites = update.Get();
StringValue value(origin.spec());
- int removed_index = allowed_sites->Remove(value);
- DCHECK_NE(-1, removed_index) << origin << " was not allowed";
+ bool removed = allowed_sites->Remove(value, NULL);
+ DCHECK_NE(false, removed) << origin << " was not allowed";
}
prefs->ScheduleSavePersistentPrefs();
}
@@ -353,8 +353,8 @@ void NotificationProvider::ResetBlockedOrigin(const GURL& origin) {
ListPrefUpdate update(prefs, prefs::kDesktopNotificationDeniedOrigins);
ListValue* denied_sites = update.Get();
StringValue value(origin.spec());
- int removed_index = denied_sites->Remove(value);
- DCHECK_NE(-1, removed_index) << origin << " was not blocked";
+ bool removed = denied_sites->Remove(value, NULL);
+ DCHECK_NE(false, removed) << origin << " was not blocked";
}
prefs->ScheduleSavePersistentPrefs();
}
diff --git a/chrome/browser/extensions/extension_web_ui.cc b/chrome/browser/extensions/extension_web_ui.cc
index dd40192..67999de 100644
--- a/chrome/browser/extensions/extension_web_ui.cc
+++ b/chrome/browser/extensions/extension_web_ui.cc
@@ -332,9 +332,12 @@ void ExtensionWebUI::RegisterChromeURLOverrides(
// static
void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page,
- Profile* profile, ListValue* list, Value* override) {
- int index = list->Remove(*override);
- if (index == 0) {
+ Profile* profile,
+ ListValue* list,
+ Value* override) {
+ size_t index = 0;
+ bool found = list->Remove(*override, &index);
+ if (found && index == 0) {
// This is the active override, so we need to find all existing
// tabs for this override and get them to reload the original URL.
for (TabContentsIterator iterator; !iterator.done(); ++iterator) {
diff --git a/chrome/browser/extensions/external_policy_extension_loader_unittest.cc b/chrome/browser/extensions/external_policy_extension_loader_unittest.cc
index a8da195..1598b62 100644
--- a/chrome/browser/extensions/external_policy_extension_loader_unittest.cc
+++ b/chrome/browser/extensions/external_policy_extension_loader_unittest.cc
@@ -85,7 +85,7 @@ class MockExternalPolicyExtensionProviderVisitor
// Remove the extension from our list.
StringValue ext_str(id + ";" + update_url.spec());
- EXPECT_NE(-1, remaining_extensions->Remove(ext_str));
+ EXPECT_NE(false, remaining_extensions->Remove(ext_str, NULL));
}
virtual void OnExternalProviderReady() {
diff --git a/chrome/browser/translate/translate_prefs.cc b/chrome/browser/translate/translate_prefs.cc
index 3aca798..290340f 100644
--- a/chrome/browser/translate/translate_prefs.cc
+++ b/chrome/browser/translate/translate_prefs.cc
@@ -255,7 +255,7 @@ void TranslatePrefs::RemoveValueFromBlacklist(const char* pref_id,
return;
}
StringValue string_value(value);
- schedule_save = blacklist->Remove(string_value) != -1;
+ schedule_save = blacklist->Remove(string_value, NULL);
}
if (schedule_save)
prefs_->ScheduleSavePersistentPrefs();