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

Side by Side Diff: chrome/browser/ui/webui/ntp/suggestions_combiner.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/ui/webui/ntp/suggestions_combiner.h" 5 #include "chrome/browser/ui/webui/ntp/suggestions_combiner.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/api/discovery/suggested_links_registry.h"
11 #include "chrome/browser/extensions/api/discovery/suggested_links_registry_facto ry.h"
10 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" 13 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h"
12 #include "chrome/browser/ui/webui/ntp/suggestions_source.h" 14 #include "chrome/browser/ui/webui/ntp/suggestions_source.h"
13 #include "chrome/browser/ui/webui/ntp/suggestions_source_discovery.h" 15 #include "chrome/browser/ui/webui/ntp/suggestions_source_discovery.h"
14 #include "chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h" 16 #include "chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h"
15 17
16 namespace { 18 namespace {
17 19
18 static const size_t kSuggestionsCount = 8; 20 static const size_t kSuggestionsCount = 8;
19 21
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 delegate_->OnSuggestionsReady(); 56 delegate_->OnSuggestionsReady();
55 } 57 }
56 } 58 }
57 59
58 void SuggestionsCombiner::SetSuggestionsCount(size_t suggestions_count) { 60 void SuggestionsCombiner::SetSuggestionsCount(size_t suggestions_count) {
59 suggestions_count_ = suggestions_count; 61 suggestions_count_ = suggestions_count;
60 } 62 }
61 63
62 // static 64 // static
63 SuggestionsCombiner* SuggestionsCombiner::Create( 65 SuggestionsCombiner* SuggestionsCombiner::Create(
64 SuggestionsCombiner::Delegate* delegate) { 66 SuggestionsCombiner::Delegate* delegate, Profile* profile) {
65 SuggestionsCombiner* combiner = new SuggestionsCombiner(delegate); 67 SuggestionsCombiner* combiner = new SuggestionsCombiner(delegate);
66 combiner->AddSource(new SuggestionsSourceTopSites()); 68 combiner->AddSource(new SuggestionsSourceTopSites());
67 combiner->AddSource(new SuggestionsSourceDiscovery()); 69
70 extensions::SuggestedLinksRegistry* registry =
71 extensions::SuggestedLinksRegistryFactory::GetForProfile(profile);
72 scoped_ptr<std::vector<std::string> > list = registry->GetExtensionIds();
73 for (std::vector<std::string>::iterator it = list->begin();
74 it != list->end(); ++it) {
75 combiner->AddSource(new SuggestionsSourceDiscovery(*it));
76 }
77
68 return combiner; 78 return combiner;
69 } 79 }
70 80
71 void SuggestionsCombiner::FillPageValues() { 81 void SuggestionsCombiner::FillPageValues() {
72 int total_weight = 0; 82 int total_weight = 0;
73 for (size_t i = 0; i < sources_.size(); ++i) 83 for (size_t i = 0; i < sources_.size(); ++i)
74 total_weight += sources_[i]->GetWeight(); 84 total_weight += sources_[i]->GetWeight();
75 DCHECK_GT(total_weight, 0); 85 DCHECK_GT(total_weight, 0);
76 86
77 page_values_.reset(new base::ListValue()); 87 page_values_.reset(new base::ListValue());
(...skipping 25 matching lines...) Expand all
103 page_values_->GetSize() < suggestions_count_; ++i) { 113 page_values_->GetSize() < suggestions_count_; ++i) {
104 114
105 size_t index = next_item_index_for_source[i] + extra_items_added; 115 size_t index = next_item_index_for_source[i] + extra_items_added;
106 while (page_values_->GetSize() < suggestions_count_ && 116 while (page_values_->GetSize() < suggestions_count_ &&
107 (item = sources_[i]->PopItem())) { 117 (item = sources_[i]->PopItem())) {
108 page_values_->Insert(index++, item); 118 page_values_->Insert(index++, item);
109 extra_items_added++; 119 extra_items_added++;
110 } 120 }
111 } 121 }
112 } 122 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/suggestions_combiner.h ('k') | chrome/browser/ui/webui/ntp/suggestions_page_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698