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

Side by Side Diff: chrome/browser/extensions/api/discovery/suggested_links_registry.cc

Issue 10438004: Hooking the discovery API to the NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added OWNERS for experimental discovery api. Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/discovery/suggested_links_registry.h" 5 #include "chrome/browser/extensions/api/discovery/suggested_links_registry.h"
6 6
7 namespace { 7 namespace {
8 8
9 typedef extensions::SuggestedLinksRegistry::SuggestedLinkList SuggestedLinkList; 9 typedef extensions::SuggestedLinksRegistry::SuggestedLinkList SuggestedLinkList;
10 10
(...skipping 24 matching lines...) Expand all
35 scoped_ptr<extensions::SuggestedLink> item) { 35 scoped_ptr<extensions::SuggestedLink> item) {
36 SuggestedLinkList& list = GetAllInternal(extension_id); 36 SuggestedLinkList& list = GetAllInternal(extension_id);
37 SuggestedLinkList::iterator found = FindUrlInList(item->link_url(), &list); 37 SuggestedLinkList::iterator found = FindUrlInList(item->link_url(), &list);
38 linked_ptr<extensions::SuggestedLink> new_item(item.release()); 38 linked_ptr<extensions::SuggestedLink> new_item(item.release());
39 if (found != list.end()) 39 if (found != list.end())
40 *found = new_item; 40 *found = new_item;
41 else 41 else
42 list.push_back(new_item); 42 list.push_back(new_item);
43 } 43 }
44 44
45 scoped_ptr<std::vector<std::string> >
46 SuggestedLinksRegistry::GetExtensionIds() const {
47 scoped_ptr<std::vector<std::string> > result(new std::vector<std::string>());
48 for (SuggestedLinksMap::const_iterator it = suggested_links_.begin();
49 it != suggested_links_.end(); ++it) {
50 result->push_back((*it).first);
51 }
52 return result.Pass();
53 }
54
45 const SuggestedLinkList* SuggestedLinksRegistry::GetAll( 55 const SuggestedLinkList* SuggestedLinksRegistry::GetAll(
46 const std::string& extension_id) const { 56 const std::string& extension_id) const {
47 SuggestedLinksMap::const_iterator found = suggested_links_.find(extension_id); 57 SuggestedLinksMap::const_iterator found = suggested_links_.find(extension_id);
48 if (found != suggested_links_.end()) 58 if (found != suggested_links_.end())
49 return &found->second; 59 return &found->second;
50 return &empty_list_; 60 return &empty_list_;
51 } 61 }
52 62
53 void SuggestedLinksRegistry::Remove(const std::string& extension_id, 63 void SuggestedLinksRegistry::Remove(const std::string& extension_id,
54 const std::string& link_url) { 64 const std::string& link_url) {
55 SuggestedLinksMap::iterator found = suggested_links_.find(extension_id); 65 SuggestedLinksMap::iterator found = suggested_links_.find(extension_id);
56 if (found != suggested_links_.end()) 66 if (found != suggested_links_.end()) {
57 RemoveLinkFromList(link_url, &found->second); 67 RemoveLinkFromList(link_url, &found->second);
68 if (found->second.empty()) {
69 suggested_links_.erase(found);
70 }
71 }
58 } 72 }
59 73
60 void SuggestedLinksRegistry::ClearAll(const std::string& extension_id) { 74 void SuggestedLinksRegistry::ClearAll(const std::string& extension_id) {
61 SuggestedLinksMap::iterator found = suggested_links_.find(extension_id); 75 SuggestedLinksMap::iterator found = suggested_links_.find(extension_id);
62 if (found != suggested_links_.end()) 76 if (found != suggested_links_.end())
63 suggested_links_.erase(found); 77 suggested_links_.erase(found);
64 } 78 }
65 79
66 SuggestedLinkList& SuggestedLinksRegistry::GetAllInternal( 80 SuggestedLinkList& SuggestedLinksRegistry::GetAllInternal(
67 const std::string& extension_id) { 81 const std::string& extension_id) {
68 // |insert| returns the element if it's already in the map. 82 // |insert| returns the element if it's already in the map.
69 SuggestedLinksMap::iterator found = suggested_links_.insert( 83 SuggestedLinksMap::iterator found = suggested_links_.insert(
70 SuggestedLinksMap::value_type(extension_id, SuggestedLinkList())).first; 84 SuggestedLinksMap::value_type(extension_id, SuggestedLinkList())).first;
71 CHECK(found != suggested_links_.end()); 85 CHECK(found != suggested_links_.end());
72 return found->second; 86 return found->second;
73 } 87 }
74 88
75 } // namespace extensions 89 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/discovery/suggested_links_registry.h ('k') | chrome/browser/ui/webui/ntp/suggestions_combiner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698