| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/api/discovery/suggested_links_registry.h" |
| 6 |
| 7 namespace { |
| 8 |
| 9 typedef extensions::SuggestedLinksRegistry::SuggestedLinkList SuggestedLinkList; |
| 10 |
| 11 void RemoveLinkFromList(const std::string& link_url, SuggestedLinkList* list) { |
| 12 SuggestedLinkList::iterator found = list->begin(); |
| 13 for (; found != list->end(); ++found) |
| 14 if (link_url.compare((*found)->link_url()) == 0) break; |
| 15 if (found != list->end()) |
| 16 list->erase(found); |
| 17 } |
| 18 |
| 19 } // namespace |
| 20 |
| 21 namespace extensions { |
| 22 |
| 23 SuggestedLinksRegistry::SuggestedLinksRegistry() {} |
| 24 |
| 25 SuggestedLinksRegistry::~SuggestedLinksRegistry() { |
| 26 } |
| 27 |
| 28 void SuggestedLinksRegistry::Add(const std::string& extension_id, |
| 29 scoped_ptr<extensions::SuggestedLink> item) { |
| 30 SuggestedLinkList& list = GetAllInternal(extension_id); |
| 31 list.push_back(linked_ptr<extensions::SuggestedLink>(item.release())); |
| 32 } |
| 33 |
| 34 const SuggestedLinkList* SuggestedLinksRegistry::GetAll( |
| 35 const std::string& extension_id) const { |
| 36 SuggestedLinksMap::const_iterator found = suggested_links_.find(extension_id); |
| 37 if (found != suggested_links_.end()) |
| 38 return &found->second; |
| 39 return NULL; |
| 40 } |
| 41 |
| 42 void SuggestedLinksRegistry::Remove(const std::string& extension_id, |
| 43 const std::string& link_url) { |
| 44 SuggestedLinksMap::iterator found = suggested_links_.find(extension_id); |
| 45 if (found != suggested_links_.end()) |
| 46 RemoveLinkFromList(link_url, &found->second); |
| 47 } |
| 48 |
| 49 void SuggestedLinksRegistry::ClearAll(const std::string& extension_id) { |
| 50 SuggestedLinksMap::iterator found = suggested_links_.find(extension_id); |
| 51 if (found != suggested_links_.end()) |
| 52 suggested_links_.erase(found); |
| 53 } |
| 54 |
| 55 SuggestedLinkList& SuggestedLinksRegistry::GetAllInternal( |
| 56 const std::string& extension_id) { |
| 57 // |insert| returns the element if it's already in the map. |
| 58 SuggestedLinksMap::iterator found = suggested_links_.insert( |
| 59 SuggestedLinksMap::value_type(extension_id, SuggestedLinkList())).first; |
| 60 CHECK(found != suggested_links_.end()); |
| 61 return found->second; |
| 62 } |
| 63 |
| 64 } // namespace extensions |
| OLD | NEW |