summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormacourteau@chromium.org <macourteau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-16 15:14:28 +0000
committermacourteau@chromium.org <macourteau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-16 15:14:28 +0000
commit97570b99a4341b1d1d6512f5d82b43c3123eb927 (patch)
treea53ea1873a6a672fc87269d500bf931b1a6e7cb7
parent24728d6824d7c8ea23db306ebe5a709a7568f18d (diff)
downloadchromium_src-97570b99a4341b1d1d6512f5d82b43c3123eb927.zip
chromium_src-97570b99a4341b1d1d6512f5d82b43c3123eb927.tar.gz
chromium_src-97570b99a4341b1d1d6512f5d82b43c3123eb927.tar.bz2
Extracts common code to setup the SuggestionsCombiner in a static method.
BUG=none TEST=No user visible change Review URL: https://chromiumcodereview.appspot.com/10391146 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137429 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/webui/ntp/suggestions_combiner.cc37
-rw-r--r--chrome/browser/ui/webui/ntp/suggestions_combiner.h9
-rw-r--r--chrome/browser/ui/webui/ntp/suggestions_page_handler.cc6
-rw-r--r--chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui.cc3
-rw-r--r--chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui_handler.cc6
5 files changed, 37 insertions, 24 deletions
diff --git a/chrome/browser/ui/webui/ntp/suggestions_combiner.cc b/chrome/browser/ui/webui/ntp/suggestions_combiner.cc
index 2500d2f..cdc71b3 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_combiner.cc
+++ b/chrome/browser/ui/webui/ntp/suggestions_combiner.cc
@@ -10,6 +10,8 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h"
#include "chrome/browser/ui/webui/ntp/suggestions_source.h"
+#include "chrome/browser/ui/webui/ntp/suggestions_source_discovery.h"
+#include "chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h"
namespace {
@@ -44,6 +46,28 @@ void SuggestionsCombiner::AddSource(SuggestionsSource* source) {
sources_.push_back(source);
}
+void SuggestionsCombiner::OnItemsReady() {
+ DCHECK_GT(sources_fetching_count_, 0);
+ sources_fetching_count_--;
+ if (sources_fetching_count_ == 0) {
+ FillPageValues();
+ delegate_->OnSuggestionsReady();
+ }
+}
+
+void SuggestionsCombiner::SetSuggestionsCount(size_t suggestions_count) {
+ suggestions_count_ = suggestions_count;
+}
+
+// static
+SuggestionsCombiner* SuggestionsCombiner::Create(
+ SuggestionsCombiner::Delegate* delegate) {
+ SuggestionsCombiner* combiner = new SuggestionsCombiner(delegate);
+ combiner->AddSource(new SuggestionsSourceTopSites());
+ combiner->AddSource(new SuggestionsSourceDiscovery());
+ return combiner;
+}
+
void SuggestionsCombiner::FillPageValues() {
int total_weight = 0;
for (size_t i = 0; i < sources_.size(); ++i)
@@ -86,16 +110,3 @@ void SuggestionsCombiner::FillPageValues() {
}
}
}
-
-void SuggestionsCombiner::OnItemsReady() {
- DCHECK_GT(sources_fetching_count_, 0);
- sources_fetching_count_--;
- if (sources_fetching_count_ == 0) {
- FillPageValues();
- delegate_->OnSuggestionsReady();
- }
-}
-
-void SuggestionsCombiner::SetSuggestionsCount(size_t suggestions_count) {
- suggestions_count_ = suggestions_count;
-}
diff --git a/chrome/browser/ui/webui/ntp/suggestions_combiner.h b/chrome/browser/ui/webui/ntp/suggestions_combiner.h
index 5548efa..5b32aea 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_combiner.h
+++ b/chrome/browser/ui/webui/ntp/suggestions_combiner.h
@@ -34,7 +34,6 @@ class SuggestionsCombiner {
virtual void OnSuggestionsReady() = 0;
};
- explicit SuggestionsCombiner(SuggestionsCombiner::Delegate* delegate);
virtual ~SuggestionsCombiner();
// Add a new source. The SuggestionsCombiner takes ownership of |source|.
@@ -52,7 +51,15 @@ class SuggestionsCombiner {
void SetSuggestionsCount(size_t suggestions_count);
+ // Creates a new instance of the SuggestionsCombiner (owned by the callee),
+ // and sets up the default sources.
+ static SuggestionsCombiner* Create(SuggestionsCombiner::Delegate* delegate);
+
private:
+ friend class SuggestionsCombinerTest;
+
+ explicit SuggestionsCombiner(SuggestionsCombiner::Delegate* delegate);
+
// Fill the page values from the suggestion sources so they can be sent to
// the JavaScript side. This should only be called when all the suggestion
// sources have items ready.
diff --git a/chrome/browser/ui/webui/ntp/suggestions_page_handler.cc b/chrome/browser/ui/webui/ntp/suggestions_page_handler.cc
index b6c2ffc..35f579c 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_page_handler.cc
+++ b/chrome/browser/ui/webui/ntp/suggestions_page_handler.cc
@@ -21,8 +21,6 @@
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/browser/ui/webui/favicon_source.h"
#include "chrome/browser/ui/webui/ntp/suggestions_combiner.h"
-#include "chrome/browser/ui/webui/ntp/suggestions_source_discovery.h"
-#include "chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h"
#include "chrome/browser/ui/webui/ntp/ntp_stats.h"
#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
#include "chrome/common/chrome_notification_types.h"
@@ -84,9 +82,7 @@ void SuggestionsHandler::RegisterMessages() {
}
// Setup the suggestions sources.
- suggestions_combiner_.reset(new SuggestionsCombiner(this));
- suggestions_combiner_->AddSource(new SuggestionsSourceTopSites());
- suggestions_combiner_->AddSource(new SuggestionsSourceDiscovery());
+ suggestions_combiner_.reset(SuggestionsCombiner::Create(this));
// We pre-emptively make a fetch for suggestions so we have the results
// sooner.
diff --git a/chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui.cc b/chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui.cc
index e952a1b..d66bb0f 100644
--- a/chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui.cc
+++ b/chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
+#include "chrome/browser/ui/webui/favicon_source.h"
#include "chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui_handler.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/web_ui.h"
@@ -25,6 +26,8 @@ SuggestionsInternalsUI::SuggestionsInternalsUI(content::WebUI* web_ui)
Profile* profile = Profile::FromWebUI(web_ui);
ChromeURLDataManager::AddDataSource(profile, html_source);
+ ChromeURLDataManager::AddDataSource(profile,
+ new FaviconSource(profile, FaviconSource::FAVICON));
// AddMessageHandler takes ownership of SuggestionsInternalsUIHandler
web_ui->AddMessageHandler(new SuggestionsInternalsUIHandler(profile));
diff --git a/chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui_handler.cc b/chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui_handler.cc
index 48d621ba..c3c0673 100644
--- a/chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui_handler.cc
+++ b/chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui_handler.cc
@@ -9,8 +9,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
#include "chrome/browser/ui/webui/ntp/suggestions_combiner.h"
-#include "chrome/browser/ui/webui/ntp/suggestions_source_discovery.h"
-#include "chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h"
#include "content/public/browser/web_ui.h"
namespace {
@@ -33,9 +31,7 @@ void SuggestionsInternalsUIHandler::OnSuggestionsReady() {
void SuggestionsInternalsUIHandler::RegisterMessages() {
// Setup the suggestions sources.
- suggestions_combiner_.reset(new SuggestionsCombiner(this));
- suggestions_combiner_->AddSource(new SuggestionsSourceTopSites());
- suggestions_combiner_->AddSource(new SuggestionsSourceDiscovery());
+ suggestions_combiner_.reset(SuggestionsCombiner::Create(this));
suggestions_combiner_->SetSuggestionsCount(kSuggestionsCount);
web_ui()->RegisterMessageCallback("getSuggestions",