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

Unified Diff: chrome/browser/ui/webui/ntp/suggestions_combiner.cc

Issue 10666009: Added already_open column to chrome://suggestions-internals. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Cleanup 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/ntp/suggestions_combiner.cc
diff --git a/chrome/browser/ui/webui/ntp/suggestions_combiner.cc b/chrome/browser/ui/webui/ntp/suggestions_combiner.cc
index affa03a86c69476ac64492c4796640e3208d4d9f..f79261f33d9d5a8183c088d76778aa9cf0cbca64 100644
--- a/chrome/browser/ui/webui/ntp/suggestions_combiner.cc
+++ b/chrome/browser/ui/webui/ntp/suggestions_combiner.cc
@@ -10,10 +10,13 @@
#include "chrome/browser/extensions/api/discovery/suggested_links_registry.h"
#include "chrome/browser/extensions/api/discovery/suggested_links_registry_factory.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.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"
+#include "content/public/browser/web_contents.h"
namespace {
@@ -22,12 +25,14 @@ static const size_t kSuggestionsCount = 8;
} // namespace
SuggestionsCombiner::SuggestionsCombiner(
- SuggestionsCombiner::Delegate* delegate)
+ SuggestionsCombiner::Delegate* delegate,
+ Profile* profile)
: sources_fetching_count_(0),
delegate_(delegate),
suggestions_count_(kSuggestionsCount),
page_values_(new base::ListValue()),
- debug_enabled_(false) {
+ debug_enabled_(false),
+ profile_(profile) {
}
SuggestionsCombiner::~SuggestionsCombiner() {
@@ -73,7 +78,7 @@ void SuggestionsCombiner::SetSuggestionsCount(size_t suggestions_count) {
// static
SuggestionsCombiner* SuggestionsCombiner::Create(
SuggestionsCombiner::Delegate* delegate, Profile* profile) {
- SuggestionsCombiner* combiner = new SuggestionsCombiner(delegate);
+ SuggestionsCombiner* combiner = new SuggestionsCombiner(delegate, profile);
combiner->AddSource(new SuggestionsSourceTopSites());
extensions::SuggestedLinksRegistry* registry =
@@ -128,4 +133,38 @@ void SuggestionsCombiner::FillPageValues() {
extra_items_added++;
}
}
+
+ // Add page value information common to all sources.
+ for (size_t i = 0; i < page_values_->GetSize(); i++) {
+ base::DictionaryValue* page_value;
+ if (page_values_->GetDictionary(i, &page_value))
+ AddExtraPageValueInformation(page_value);
macourteau 2012/06/26 19:21:49 Nit: maybe this could be renamed to something alon
Rune Fevang 2012/06/27 00:28:59 Done.
+ }
+}
+
+void SuggestionsCombiner::AddExtraPageValueInformation(
+ base::DictionaryValue* page_value) {
+ if (debug_enabled_) {
+ std::string url_string;
+ if (page_value->GetString("url", &url_string)) {
+ GURL url(url_string);
+ page_value->SetBoolean("already_open", IsURLAlreadyOpen(url));
+ }
+ }
+}
+
+bool SuggestionsCombiner::IsURLAlreadyOpen(const GURL &url) {
+ for (BrowserList::const_iterator it = BrowserList::begin();
+ it != BrowserList::end(); ++it) {
+ const Browser* browser = *it;
+ if (browser->profile()->IsOffTheRecord() ||
+ !browser->profile()->IsSameProfile(profile_))
+ continue;
+ for (int i = 0; i < browser->tab_count(); i++) {
+ const content::WebContents* tab = browser->GetWebContentsAt(i);
+ if (tab->GetURL() == url)
+ return true;
+ }
+ }
+ return false;
}

Powered by Google App Engine
This is Rietveld 408576698