OLD | NEW |
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" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 void MostVisitedHandler::RegisterMessages() { | 78 void MostVisitedHandler::RegisterMessages() { |
79 Profile* profile = Profile::FromWebUI(web_ui()); | 79 Profile* profile = Profile::FromWebUI(web_ui()); |
80 // Set up our sources for thumbnail and favicon data. | 80 // Set up our sources for thumbnail and favicon data. |
81 content::URLDataSource::Add(profile, new ThumbnailSource(profile, false)); | 81 content::URLDataSource::Add(profile, new ThumbnailSource(profile, false)); |
82 content::URLDataSource::Add(profile, new ThumbnailSource(profile, true)); | 82 content::URLDataSource::Add(profile, new ThumbnailSource(profile, true)); |
83 | 83 |
84 // Set up our sources for top-sites data. | 84 // Set up our sources for top-sites data. |
85 content::URLDataSource::Add(profile, new ThumbnailListSource(profile)); | 85 content::URLDataSource::Add(profile, new ThumbnailListSource(profile)); |
86 | 86 |
87 #if defined(OS_ANDROID) | |
88 // Register chrome://touch-icon as a data source for touch icons or favicons. | |
89 content::URLDataSource::Add(profile, | |
90 new FaviconSource(profile, FaviconSource::ANY)); | |
91 #endif | |
92 // Register chrome://favicon as a data source for favicons. | 87 // Register chrome://favicon as a data source for favicons. |
93 content::URLDataSource::Add( | 88 content::URLDataSource::Add( |
94 profile, new FaviconSource(profile, FaviconSource::FAVICON)); | 89 profile, new FaviconSource(profile, FaviconSource::FAVICON)); |
95 | 90 |
96 history::TopSites* ts = profile->GetTopSites(); | 91 history::TopSites* ts = profile->GetTopSites(); |
97 if (ts) { | 92 if (ts) { |
98 // TopSites updates itself after a delay. This is especially noticable when | 93 // TopSites updates itself after a delay. This is especially noticable when |
99 // your profile is empty. Ask TopSites to update itself when we're about to | 94 // your profile is empty. Ask TopSites to update itself when we're about to |
100 // show the new tab page. | 95 // show the new tab page. |
101 ts->SyncWithHistory(); | 96 ts->SyncWithHistory(); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if (ts) | 263 if (ts) |
269 ts->AddBlacklistedURL(url); | 264 ts->AddBlacklistedURL(url); |
270 content::RecordAction(UserMetricsAction("MostVisited_UrlBlacklisted")); | 265 content::RecordAction(UserMetricsAction("MostVisited_UrlBlacklisted")); |
271 } | 266 } |
272 | 267 |
273 std::string MostVisitedHandler::GetDictionaryKeyForUrl(const std::string& url) { | 268 std::string MostVisitedHandler::GetDictionaryKeyForUrl(const std::string& url) { |
274 return base::MD5String(url); | 269 return base::MD5String(url); |
275 } | 270 } |
276 | 271 |
277 void MostVisitedHandler::MaybeRemovePageValues() { | 272 void MostVisitedHandler::MaybeRemovePageValues() { |
278 // The code below uses APIs not available on Android and the experiment should | |
279 // not run there. | |
280 #if !defined(OS_ANDROID) | |
281 if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled()) | 273 if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled()) |
282 return; | 274 return; |
283 | 275 |
284 TabStripModel* tab_strip_model = chrome::FindBrowserWithWebContents( | 276 TabStripModel* tab_strip_model = chrome::FindBrowserWithWebContents( |
285 web_ui()->GetWebContents())->tab_strip_model(); | 277 web_ui()->GetWebContents())->tab_strip_model(); |
286 history::TopSites* top_sites = Profile::FromWebUI(web_ui())->GetTopSites(); | 278 history::TopSites* top_sites = Profile::FromWebUI(web_ui())->GetTopSites(); |
287 if (!tab_strip_model || !top_sites) { | 279 if (!tab_strip_model || !top_sites) { |
288 NOTREACHED(); | 280 NOTREACHED(); |
289 return; | 281 return; |
290 } | 282 } |
291 | 283 |
292 std::set<std::string> open_urls; | 284 std::set<std::string> open_urls; |
293 chrome::GetOpenUrls(*tab_strip_model, *top_sites, &open_urls); | 285 chrome::GetOpenUrls(*tab_strip_model, *top_sites, &open_urls); |
294 history::MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs( | 286 history::MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs( |
295 open_urls, | 287 open_urls, |
296 pages_value_.get()); | 288 pages_value_.get()); |
297 #endif | |
298 } | 289 } |
299 | 290 |
300 // static | 291 // static |
301 void MostVisitedHandler::RegisterProfilePrefs( | 292 void MostVisitedHandler::RegisterProfilePrefs( |
302 user_prefs::PrefRegistrySyncable* registry) { | 293 user_prefs::PrefRegistrySyncable* registry) { |
303 registry->RegisterDictionaryPref( | 294 registry->RegisterDictionaryPref( |
304 prefs::kNtpMostVisitedURLsBlacklist, | 295 prefs::kNtpMostVisitedURLsBlacklist, |
305 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 296 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
306 } | 297 } |
OLD | NEW |