Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Unified Diff: chrome/browser/extensions/api/discovery/suggested_links_registry.cc

Issue 10388192: Initial unit tests for the discovery API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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/api/discovery/suggested_links_registry.cc
diff --git a/chrome/browser/extensions/api/discovery/suggested_links_registry.cc b/chrome/browser/extensions/api/discovery/suggested_links_registry.cc
index 7c7f5fe1b932fde948eeab0685dd5ee7699cb837..0265690f79ead8c0eccd3050907ca1a431961929 100644
--- a/chrome/browser/extensions/api/discovery/suggested_links_registry.cc
+++ b/chrome/browser/extensions/api/discovery/suggested_links_registry.cc
@@ -8,10 +8,16 @@ namespace {
typedef extensions::SuggestedLinksRegistry::SuggestedLinkList SuggestedLinkList;
-void RemoveLinkFromList(const std::string& link_url, SuggestedLinkList* list) {
+SuggestedLinkList::iterator FindUrlInList(const std::string& link_url,
+ SuggestedLinkList* list) {
SuggestedLinkList::iterator found = list->begin();
for (; found != list->end(); ++found)
if (link_url.compare((*found)->link_url()) == 0) break;
+ return found;
+}
+
+void RemoveLinkFromList(const std::string& link_url, SuggestedLinkList* list) {
+ SuggestedLinkList::iterator found = FindUrlInList(link_url, list);
if (found != list->end())
list->erase(found);
}
@@ -28,7 +34,12 @@ SuggestedLinksRegistry::~SuggestedLinksRegistry() {
void SuggestedLinksRegistry::Add(const std::string& extension_id,
scoped_ptr<extensions::SuggestedLink> item) {
SuggestedLinkList& list = GetAllInternal(extension_id);
- list.push_back(linked_ptr<extensions::SuggestedLink>(item.release()));
+ SuggestedLinkList::iterator found = FindUrlInList(item->link_url(), &list);
+ linked_ptr<extensions::SuggestedLink> new_item(item.release());
+ if (found != list.end())
+ *found = new_item;
+ else
+ list.push_back(new_item);
}
const SuggestedLinkList* SuggestedLinksRegistry::GetAll(
@@ -36,7 +47,7 @@ const SuggestedLinkList* SuggestedLinksRegistry::GetAll(
SuggestedLinksMap::const_iterator found = suggested_links_.find(extension_id);
if (found != suggested_links_.end())
return &found->second;
- return NULL;
+ return &empty_list_;
}
void SuggestedLinksRegistry::Remove(const std::string& extension_id,

Powered by Google App Engine
This is Rietveld 408576698