summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/ntp
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/ui/webui/ntp')
-rw-r--r--chrome/browser/ui/webui/ntp/suggestions_combiner.cc23
-rw-r--r--chrome/browser/ui/webui/ntp/suggestions_combiner.h9
-rw-r--r--chrome/browser/ui/webui/ntp/suggestions_combiner_unittest.cc7
-rw-r--r--chrome/browser/ui/webui/ntp/suggestions_source.h4
-rw-r--r--chrome/browser/ui/webui/ntp/suggestions_source_discovery.cc7
-rw-r--r--chrome/browser/ui/webui/ntp/suggestions_source_discovery.h4
-rw-r--r--chrome/browser/ui/webui/ntp/suggestions_source_top_sites.cc30
-rw-r--r--chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h4
8 files changed, 77 insertions, 11 deletions
diff --git a/chrome/browser/ui/webui/ntp/suggestions_combiner.cc b/chrome/browser/ui/webui/ntp/suggestions_combiner.cc
index 0e6137c..affa03a 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_combiner.cc
+++ b/chrome/browser/ui/webui/ntp/suggestions_combiner.cc
@@ -26,14 +26,24 @@ SuggestionsCombiner::SuggestionsCombiner(
: sources_fetching_count_(0),
delegate_(delegate),
suggestions_count_(kSuggestionsCount),
- page_values_(new base::ListValue()) {
+ page_values_(new base::ListValue()),
+ debug_enabled_(false) {
}
SuggestionsCombiner::~SuggestionsCombiner() {
}
-base::ListValue* SuggestionsCombiner::GetPageValues() {
- return page_values_.get();
+void SuggestionsCombiner::AddSource(SuggestionsSource* source) {
+ source->SetCombiner(this);
+ source->SetDebug(debug_enabled_);
+ sources_.push_back(source);
+}
+
+void SuggestionsCombiner::EnableDebug(bool enable) {
+ debug_enabled_ = enable;
+ for (size_t i = 0; i < sources_.size(); ++i) {
+ sources_[i]->SetDebug(enable);
+ }
}
void SuggestionsCombiner::FetchItems(Profile* profile) {
@@ -43,9 +53,8 @@ void SuggestionsCombiner::FetchItems(Profile* profile) {
}
}
-void SuggestionsCombiner::AddSource(SuggestionsSource* source) {
- source->SetCombiner(this);
- sources_.push_back(source);
+base::ListValue* SuggestionsCombiner::GetPageValues() {
+ return page_values_.get();
}
void SuggestionsCombiner::OnItemsReady() {
@@ -86,7 +95,7 @@ void SuggestionsCombiner::FillPageValues() {
page_values_.reset(new base::ListValue());
- // Evaluate how many items to obtain from each sources. We use error diffusion
+ // Evaluate how many items to obtain from each source. We use error diffusion
// to ensure that we get the total desired number of items.
int error = 0;
diff --git a/chrome/browser/ui/webui/ntp/suggestions_combiner.h b/chrome/browser/ui/webui/ntp/suggestions_combiner.h
index f559430..5932321 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_combiner.h
+++ b/chrome/browser/ui/webui/ntp/suggestions_combiner.h
@@ -39,6 +39,11 @@ class SuggestionsCombiner {
// Add a new source. The SuggestionsCombiner takes ownership of |source|.
void AddSource(SuggestionsSource* source);
+ // Enables or disables debug mode. If debug mode is enabled, the sources are
+ // expected to provide additional data, which could be displayed, for example,
+ // in the chrome://suggestions-internals/ page.
+ void EnableDebug(bool enable);
+
// Fetch a new set of items from the various suggestion sources.
void FetchItems(Profile* profile);
@@ -86,6 +91,10 @@ class SuggestionsCombiner {
// Informations to send to the javascript side.
scoped_ptr<base::ListValue> page_values_;
+ // Whether debug mode is enabled or not (debug mode provides more data in the
+ // results).
+ bool debug_enabled_;
+
DISALLOW_COPY_AND_ASSIGN(SuggestionsCombiner);
};
diff --git a/chrome/browser/ui/webui/ntp/suggestions_combiner_unittest.cc b/chrome/browser/ui/webui/ntp/suggestions_combiner_unittest.cc
index 01cea13..7b6f0bc 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_combiner_unittest.cc
+++ b/chrome/browser/ui/webui/ntp/suggestions_combiner_unittest.cc
@@ -138,7 +138,8 @@ class SuggestionsSourceStub : public SuggestionsSource {
: combiner_(NULL),
weight_(weight),
source_name_(source_name),
- number_of_suggestions_(number_of_suggestions) {
+ number_of_suggestions_(number_of_suggestions),
+ debug_(false) {
}
virtual ~SuggestionsSourceStub() {
STLDeleteElements(&items_);
@@ -152,6 +153,9 @@ class SuggestionsSourceStub : public SuggestionsSource {
private:
// SuggestionsSource Override and implementation.
+ virtual void SetDebug(bool enable) OVERRIDE {
+ debug_ = enable;
+ }
virtual int GetWeight() OVERRIDE {
return weight_;
}
@@ -193,6 +197,7 @@ class SuggestionsSourceStub : public SuggestionsSource {
int weight_;
std::string source_name_;
int number_of_suggestions_;
+ bool debug_;
// Keep the results of the db query here.
std::deque<base::DictionaryValue*> items_;
diff --git a/chrome/browser/ui/webui/ntp/suggestions_source.h b/chrome/browser/ui/webui/ntp/suggestions_source.h
index 067f0d7..10ef8d8 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_source.h
+++ b/chrome/browser/ui/webui/ntp/suggestions_source.h
@@ -27,6 +27,10 @@ class SuggestionsSource {
friend class SuggestionsCombiner;
+ // Enables or disables debug mode for the current source. The source is
+ // expected to provide additional data when debug mode is enabled.
+ virtual void SetDebug(bool enable) = 0;
+
// The source's weight indicates how many items from this source will be
// selected by the combiner. If a source weight is x and the total weight of
// all the sources is y, then the combiner will select x/y items from it.
diff --git a/chrome/browser/ui/webui/ntp/suggestions_source_discovery.cc b/chrome/browser/ui/webui/ntp/suggestions_source_discovery.cc
index 1ab266b..2aa5955 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_source_discovery.cc
+++ b/chrome/browser/ui/webui/ntp/suggestions_source_discovery.cc
@@ -34,12 +34,17 @@ const int kSuggestionsDiscoveryWeight = 1;
SuggestionsSourceDiscovery::SuggestionsSourceDiscovery(
const std::string& extension_id)
: combiner_(NULL),
- extension_id_(extension_id) {}
+ extension_id_(extension_id),
+ debug_(false) {}
SuggestionsSourceDiscovery::~SuggestionsSourceDiscovery() {
STLDeleteElements(&items_);
}
+void SuggestionsSourceDiscovery::SetDebug(bool enable) {
+ debug_ = enable;
+}
+
inline int SuggestionsSourceDiscovery::GetWeight() {
return kSuggestionsDiscoveryWeight;
}
diff --git a/chrome/browser/ui/webui/ntp/suggestions_source_discovery.h b/chrome/browser/ui/webui/ntp/suggestions_source_discovery.h
index a38ef34..788edd3 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_source_discovery.h
+++ b/chrome/browser/ui/webui/ntp/suggestions_source_discovery.h
@@ -29,6 +29,7 @@ class SuggestionsSourceDiscovery : public SuggestionsSource {
protected:
// SuggestionsSource overrides:
+ virtual void SetDebug(bool enable) OVERRIDE;
virtual int GetWeight() OVERRIDE;
virtual int GetItemCount() OVERRIDE;
virtual base::DictionaryValue* PopItem() OVERRIDE;
@@ -45,6 +46,9 @@ class SuggestionsSourceDiscovery : public SuggestionsSource {
// The extension associated with this source.
std::string extension_id_;
+ // Whether the source should provide additional debug information or not.
+ bool debug_;
+
DISALLOW_COPY_AND_ASSIGN(SuggestionsSourceDiscovery);
};
diff --git a/chrome/browser/ui/webui/ntp/suggestions_source_top_sites.cc b/chrome/browser/ui/webui/ntp/suggestions_source_top_sites.cc
index 8a8f5be..7e50c55 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_source_top_sites.cc
+++ b/chrome/browser/ui/webui/ntp/suggestions_source_top_sites.cc
@@ -26,13 +26,19 @@ const int kSuggestionsTopListWeight = 1;
} // namespace
-SuggestionsSourceTopSites::SuggestionsSourceTopSites() : combiner_(NULL) {
+SuggestionsSourceTopSites::SuggestionsSourceTopSites()
+ : combiner_(NULL),
+ debug_(false) {
}
SuggestionsSourceTopSites::~SuggestionsSourceTopSites() {
STLDeleteElements(&items_);
}
+void SuggestionsSourceTopSites::SetDebug(bool enable) {
+ debug_ = enable;
+}
+
inline int SuggestionsSourceTopSites::GetWeight() {
return kSuggestionsTopListWeight;
}
@@ -64,7 +70,7 @@ void SuggestionsSourceTopSites::FetchItems(Profile* profile) {
time_filter.SetFilterWidth(GetFilterWidth());
time_filter.set_sorting_order(GetSortingOrder());
- history->QueryFilteredURLs(0, time_filter, &history_consumer_,
+ history->QueryFilteredURLs(0, time_filter, debug_, &history_consumer_,
base::Bind(&SuggestionsSourceTopSites::OnSuggestionsURLsAvailable,
base::Unretained(this)));
}
@@ -89,6 +95,26 @@ void SuggestionsSourceTopSites::OnSuggestionsURLsAvailable(
suggested_url.title,
suggested_url.url);
page_value->SetDouble("score", suggested_url.score);
+ if (debug_) {
+ if (suggested_url.extended_info.total_visits) {
+ page_value->SetInteger("extended_info.total visits",
+ suggested_url.extended_info.total_visits);
+ }
+ if (suggested_url.extended_info.visits) {
+ page_value->SetInteger("extended_info.visits",
+ suggested_url.extended_info.visits);
+ }
+ if (suggested_url.extended_info.duration_opened) {
+ page_value->SetInteger("extended_info.duration opened",
+ suggested_url.extended_info.duration_opened);
+ }
+ if (!suggested_url.extended_info.last_visit_time.is_null()) {
+ base::TimeDelta deltaTime =
+ base::Time::Now() - suggested_url.extended_info.last_visit_time;
+ page_value->SetInteger("extended_info.seconds since last visit",
+ deltaTime.InSeconds());
+ }
+ }
items_.push_back(page_value);
}
diff --git a/chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h b/chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h
index d59ba5b..50f4470 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h
+++ b/chrome/browser/ui/webui/ntp/suggestions_source_top_sites.h
@@ -30,6 +30,7 @@ class SuggestionsSourceTopSites : public SuggestionsSource {
protected:
// SuggestionsSource overrides:
+ virtual void SetDebug(bool enable) OVERRIDE;
virtual int GetWeight() OVERRIDE;
virtual int GetItemCount() OVERRIDE;
virtual base::DictionaryValue* PopItem() OVERRIDE;
@@ -57,6 +58,9 @@ class SuggestionsSourceTopSites : public SuggestionsSource {
// Keep the results of the db query here.
std::deque<base::DictionaryValue*> items_;
+ // Whether the source should provide additional debug information or not.
+ bool debug_;
+
CancelableRequestConsumer history_consumer_;
DISALLOW_COPY_AND_ASSIGN(SuggestionsSourceTopSites);