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..7e08906d5b9831d206d6658df4f0eebf27099958 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" |
@@ -21,6 +20,7 @@ |
#include "base/threading/thread.h" |
#include "base/values.h" |
#include "chrome/browser/chrome_notification_types.h" |
+#include "chrome/browser/history/most_visited_tiles_experiment.h" |
#include "chrome/browser/history/page_usage_data.h" |
#include "chrome/browser/history/top_sites.h" |
#include "chrome/browser/prefs/scoped_user_pref_update.h" |
@@ -52,14 +52,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 +162,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); |
@@ -253,7 +237,7 @@ void MostVisitedHandler::SetPagesValueFromTopSites( |
pages_value_.reset(new ListValue); |
history::MostVisitedURLList top_sites(data); |
- history::TopSites::MaybeShuffle(&top_sites); |
+ history::MostVisitedTilesExperiment::MaybeShuffle(&top_sites); |
for (size_t i = 0; i < top_sites.size(); i++) { |
const history::MostVisitedURL& url = top_sites[i]; |
@@ -299,33 +283,28 @@ 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. |
Alexei Svitkine (slow)
2013/07/23 20:10:51
Too verbose. How about:
// The code below uses AP
annark1
2013/07/24 01:23:58
Done.
|
#if !defined(OS_ANDROID) |
+ if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled()) |
+ return; |
+ |
TabStripModel* tab_strip_model = chrome::FindBrowserWithWebContents( |
web_ui()->GetWebContents())->tab_strip_model(); |
- history::TopSites* ts = Profile::FromWebUI(web_ui())->GetTopSites(); |
- if (!tab_strip_model || !ts) { |
+ history::TopSites* top_sites = Profile::FromWebUI(web_ui())->GetTopSites(); |
+ if (!tab_strip_model || !top_sites) { |
NOTREACHED(); |
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; |
- } |
- } |
+ GetOpenUrls(*tab_strip_model, *top_sites, &open_urls); |
+ history::MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs( |
+ open_urls, |
+ pages_value_.get()); |
#endif |
} |