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

Side by Side Diff: chrome/browser/ui/webui/ntp/most_visited_handler.cc

Issue 437803003: [Most Visited] Removing Most Visited Tiles experiment code, which is obsolete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" 5 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/md5.h" 12 #include "base/md5.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
17 #include "base/prefs/scoped_user_pref_update.h" 17 #include "base/prefs/scoped_user_pref_update.h"
18 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "chrome/browser/chrome_notification_types.h" 23 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/history/most_visited_tiles_experiment.h"
25 #include "chrome/browser/history/page_usage_data.h" 24 #include "chrome/browser/history/page_usage_data.h"
26 #include "chrome/browser/history/top_sites.h" 25 #include "chrome/browser/history/top_sites.h"
27 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/thumbnails/thumbnail_list_source.h" 27 #include "chrome/browser/thumbnails/thumbnail_list_source.h"
29 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
30 #include "chrome/browser/ui/browser_finder.h" 29 #include "chrome/browser/ui/browser_finder.h"
31 #include "chrome/browser/ui/tabs/tab_strip_model.h" 30 #include "chrome/browser/ui/tabs/tab_strip_model.h"
32 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" 31 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h"
33 #include "chrome/browser/ui/webui/favicon_source.h" 32 #include "chrome/browser/ui/webui/favicon_source.h"
34 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 33 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 136 }
138 } 137 }
139 138
140 void MostVisitedHandler::SendPagesValue() { 139 void MostVisitedHandler::SendPagesValue() {
141 if (pages_value_) { 140 if (pages_value_) {
142 Profile* profile = Profile::FromWebUI(web_ui()); 141 Profile* profile = Profile::FromWebUI(web_ui());
143 const base::DictionaryValue* url_blacklist = 142 const base::DictionaryValue* url_blacklist =
144 profile->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedURLsBlacklist); 143 profile->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedURLsBlacklist);
145 bool has_blacklisted_urls = !url_blacklist->empty(); 144 bool has_blacklisted_urls = !url_blacklist->empty();
146 history::TopSites* ts = profile->GetTopSites(); 145 history::TopSites* ts = profile->GetTopSites();
147 if (ts) { 146 if (ts)
148 has_blacklisted_urls = ts->HasBlacklistedItems(); 147 has_blacklisted_urls = ts->HasBlacklistedItems();
149 148
150 MaybeRemovePageValues();
151 }
152
153 base::FundamentalValue has_blacklisted_urls_value(has_blacklisted_urls); 149 base::FundamentalValue has_blacklisted_urls_value(has_blacklisted_urls);
154 web_ui()->CallJavascriptFunction("ntp.setMostVisitedPages", 150 web_ui()->CallJavascriptFunction("ntp.setMostVisitedPages",
155 *pages_value_, 151 *pages_value_,
156 has_blacklisted_urls_value); 152 has_blacklisted_urls_value);
157 pages_value_.reset(); 153 pages_value_.reset();
158 } 154 }
159 } 155 }
160 156
161 void MostVisitedHandler::StartQueryForMostVisited() { 157 void MostVisitedHandler::StartQueryForMostVisited() {
162 history::TopSites* ts = Profile::FromWebUI(web_ui())->GetTopSites(); 158 history::TopSites* ts = Profile::FromWebUI(web_ui())->GetTopSites();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 void MostVisitedHandler::HandleMostVisitedSelected( 212 void MostVisitedHandler::HandleMostVisitedSelected(
217 const base::ListValue* args) { 213 const base::ListValue* args) {
218 most_visited_viewed_ = true; 214 most_visited_viewed_ = true;
219 } 215 }
220 216
221 void MostVisitedHandler::SetPagesValueFromTopSites( 217 void MostVisitedHandler::SetPagesValueFromTopSites(
222 const history::MostVisitedURLList& data) { 218 const history::MostVisitedURLList& data) {
223 pages_value_.reset(new base::ListValue); 219 pages_value_.reset(new base::ListValue);
224 220
225 history::MostVisitedURLList top_sites(data); 221 history::MostVisitedURLList top_sites(data);
226 history::MostVisitedTilesExperiment::MaybeShuffle(&top_sites);
227
228 for (size_t i = 0; i < top_sites.size(); i++) { 222 for (size_t i = 0; i < top_sites.size(); i++) {
229 const history::MostVisitedURL& url = top_sites[i]; 223 const history::MostVisitedURL& url = top_sites[i];
230 base::DictionaryValue* page_value = new base::DictionaryValue(); 224 base::DictionaryValue* page_value = new base::DictionaryValue();
231 if (url.url.is_empty()) { 225 if (url.url.is_empty()) {
232 page_value->SetBoolean("filler", true); 226 page_value->SetBoolean("filler", true);
233 pages_value_->Append(page_value); 227 pages_value_->Append(page_value);
234 continue; 228 continue;
235 } 229 }
236 230
237 NewTabUI::SetUrlTitleAndDirection(page_value, 231 NewTabUI::SetUrlTitleAndDirection(page_value,
(...skipping 24 matching lines...) Expand all
262 history::TopSites* ts = Profile::FromWebUI(web_ui())->GetTopSites(); 256 history::TopSites* ts = Profile::FromWebUI(web_ui())->GetTopSites();
263 if (ts) 257 if (ts)
264 ts->AddBlacklistedURL(url); 258 ts->AddBlacklistedURL(url);
265 content::RecordAction(UserMetricsAction("MostVisited_UrlBlacklisted")); 259 content::RecordAction(UserMetricsAction("MostVisited_UrlBlacklisted"));
266 } 260 }
267 261
268 std::string MostVisitedHandler::GetDictionaryKeyForUrl(const std::string& url) { 262 std::string MostVisitedHandler::GetDictionaryKeyForUrl(const std::string& url) {
269 return base::MD5String(url); 263 return base::MD5String(url);
270 } 264 }
271 265
272 void MostVisitedHandler::MaybeRemovePageValues() {
273 if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled())
274 return;
275
276 TabStripModel* tab_strip_model = chrome::FindBrowserWithWebContents(
277 web_ui()->GetWebContents())->tab_strip_model();
278 history::TopSites* top_sites = Profile::FromWebUI(web_ui())->GetTopSites();
279 if (!tab_strip_model || !top_sites) {
280 NOTREACHED();
281 return;
282 }
283
284 std::set<std::string> open_urls;
285 chrome::GetOpenUrls(*tab_strip_model, *top_sites, &open_urls);
286 history::MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs(
287 open_urls,
288 pages_value_.get());
289 }
290
291 // static 266 // static
292 void MostVisitedHandler::RegisterProfilePrefs( 267 void MostVisitedHandler::RegisterProfilePrefs(
293 user_prefs::PrefRegistrySyncable* registry) { 268 user_prefs::PrefRegistrySyncable* registry) {
294 registry->RegisterDictionaryPref( 269 registry->RegisterDictionaryPref(
295 prefs::kNtpMostVisitedURLsBlacklist, 270 prefs::kNtpMostVisitedURLsBlacklist,
296 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 271 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
297 } 272 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698