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