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

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

Issue 10391034: Scaffolding for an experimental discovery API letting users inject links in the recommended pane of… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Answered review comments from PatchSet 4. 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
new file mode 100644
index 0000000000000000000000000000000000000000..7c7f5fe1b932fde948eeab0685dd5ee7699cb837
--- /dev/null
+++ b/chrome/browser/extensions/api/discovery/suggested_links_registry.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/discovery/suggested_links_registry.h"
+
+namespace {
+
+typedef extensions::SuggestedLinksRegistry::SuggestedLinkList SuggestedLinkList;
+
+void RemoveLinkFromList(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;
+ if (found != list->end())
+ list->erase(found);
+}
+
+} // namespace
+
+namespace extensions {
+
+SuggestedLinksRegistry::SuggestedLinksRegistry() {}
+
+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()));
+}
+
+const SuggestedLinkList* SuggestedLinksRegistry::GetAll(
+ const std::string& extension_id) const {
+ SuggestedLinksMap::const_iterator found = suggested_links_.find(extension_id);
+ if (found != suggested_links_.end())
+ return &found->second;
+ return NULL;
+}
+
+void SuggestedLinksRegistry::Remove(const std::string& extension_id,
+ const std::string& link_url) {
+ SuggestedLinksMap::iterator found = suggested_links_.find(extension_id);
+ if (found != suggested_links_.end())
+ RemoveLinkFromList(link_url, &found->second);
+}
+
+void SuggestedLinksRegistry::ClearAll(const std::string& extension_id) {
+ SuggestedLinksMap::iterator found = suggested_links_.find(extension_id);
+ if (found != suggested_links_.end())
+ suggested_links_.erase(found);
+}
+
+SuggestedLinkList& SuggestedLinksRegistry::GetAllInternal(
+ const std::string& extension_id) {
+ // |insert| returns the element if it's already in the map.
+ SuggestedLinksMap::iterator found = suggested_links_.insert(
+ SuggestedLinksMap::value_type(extension_id, SuggestedLinkList())).first;
+ CHECK(found != suggested_links_.end());
+ return found->second;
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698