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

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

Issue 17114002: Field trial removing tiles from NTP if URL is already open - for 1993 clients (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed asvitkines comments Created 7 years, 5 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/most_visited_handler.cc
diff --git a/chrome/browser/ui/webui/ntp/most_visited_handler.cc b/chrome/browser/ui/webui/ntp/most_visited_handler.cc
index fc538c16645519feecaf57405dd952de0d08e881..a8254e4410c4833dab3ed0465dd4231ed0457268 100644
--- a/chrome/browser/ui/webui/ntp/most_visited_handler.cc
+++ b/chrome/browser/ui/webui/ntp/most_visited_handler.cc
@@ -12,7 +12,6 @@
#include "base/md5.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/singleton.h"
-#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string16.h"
@@ -52,14 +51,6 @@ using content::UserMetricsAction;
namespace {
-// Constants for the most visited tile placement field trial.
-const char kMostVisitedFieldTrialName[] = "MostVisitedTilePlacement";
-const char kTabsGroupName[] = "DontShowOpenTabs";
-
-// Minimum number of suggestions that |pages_value_| must hold for the Most
-// Visited Field Trial to remove a URL if already open in the browser.
-const size_t kMinUrlSuggestions = 8;
-
// Creates a set containing the canonical URLs of the currently open tabs.
void GetOpenUrls(const TabStripModel& tabs,
const history::TopSites& ts,
@@ -170,15 +161,7 @@ void MostVisitedHandler::SendPagesValue() {
if (ts) {
has_blacklisted_urls = ts->HasBlacklistedItems();
- // The following experiment removes recommended URLs if a matching URL is
- // already open in the Browser. Note: this targets only the
- // top-level of sites i.e. if www.foo.com/bar is open in browser, and
- // www.foo.com is a recommended URL, www.foo.com will still appear on the
- // next NTP open.
- if (base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName) ==
- kTabsGroupName) {
- RemovePageValuesMatchingOpenTabs();
- }
+ MaybeRemovePageValues();
}
base::FundamentalValue has_blacklisted_urls_value(has_blacklisted_urls);
@@ -299,8 +282,15 @@ std::string MostVisitedHandler::GetDictionaryKeyForUrl(const std::string& url) {
return base::MD5String(url);
}
-void MostVisitedHandler::RemovePageValuesMatchingOpenTabs() {
+void MostVisitedHandler::MaybeRemovePageValues() {
+// The following #if is due to the facts that tabstripmodel cannot be accessed
+// in the same way, that chrome::FindBrowserWithWebContents is undefined in
+// Android and, moreover, that this experiment is not designed to run on Android
+// devices due to different NTP presentation.
#if !defined(OS_ANDROID)
+ if (!history::TopSites::IsClientInTabsGroup())
+ return;
+
TabStripModel* tab_strip_model = chrome::FindBrowserWithWebContents(
web_ui()->GetWebContents())->tab_strip_model();
history::TopSites* ts = Profile::FromWebUI(web_ui())->GetTopSites();
@@ -309,23 +299,11 @@ void MostVisitedHandler::RemovePageValuesMatchingOpenTabs() {
return;
}
- // Iterate through most visited suggestions and remove pages already open in
- // current browser, making sure to not drop below 8 suggestions.
std::set<std::string> open_urls;
GetOpenUrls(*tab_strip_model, *ts, &open_urls);
- size_t i = 0;
- while (i < pages_value_->GetSize() &&
- pages_value_->GetSize() > kMinUrlSuggestions) {
- base::DictionaryValue* page_value;
- std::string url;
- if (pages_value_->GetDictionary(i, &page_value) &&
- page_value->GetString("url", &url) &&
- open_urls.count(url) != 0) {
- pages_value_->Remove(*page_value, &i);
- } else {
- ++i;
- }
- }
+ history::TopSites::RemovePageValuesMatchingOpenTabs(
+ open_urls,
+ pages_value_.get());
#endif
}

Powered by Google App Engine
This is Rietveld 408576698