| 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" |
| 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/favicon/fallback_icon_service_factory.h" |
| 24 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 23 #include "chrome/browser/history/top_sites_factory.h" | 25 #include "chrome/browser/history/top_sites_factory.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/thumbnails/thumbnail_list_source.h" | 27 #include "chrome/browser/thumbnails/thumbnail_list_source.h" |
| 26 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 27 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
| 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 30 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 29 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" | 31 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" |
| 30 #include "chrome/browser/ui/webui/fallback_icon_source.h" | 32 #include "chrome/browser/ui/webui/fallback_icon_source.h" |
| 31 #include "chrome/browser/ui/webui/favicon_source.h" | 33 #include "chrome/browser/ui/webui/favicon_source.h" |
| 32 #include "chrome/browser/ui/webui/large_icon_source.h" | 34 #include "chrome/browser/ui/webui/large_icon_source.h" |
| 33 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 35 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 34 #include "chrome/browser/ui/webui/ntp/ntp_stats.h" | 36 #include "chrome/browser/ui/webui/ntp/ntp_stats.h" |
| 35 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 37 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
| 36 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 37 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
| 40 #include "components/favicon/core/fallback_icon_service.h" |
| 41 #include "components/favicon/core/favicon_service.h" |
| 38 #include "components/history/core/browser/page_usage_data.h" | 42 #include "components/history/core/browser/page_usage_data.h" |
| 39 #include "components/history/core/browser/top_sites.h" | 43 #include "components/history/core/browser/top_sites.h" |
| 44 #include "components/keyed_service/core/service_access_type.h" |
| 40 #include "components/pref_registry/pref_registry_syncable.h" | 45 #include "components/pref_registry/pref_registry_syncable.h" |
| 41 #include "content/public/browser/navigation_controller.h" | 46 #include "content/public/browser/navigation_controller.h" |
| 42 #include "content/public/browser/navigation_entry.h" | 47 #include "content/public/browser/navigation_entry.h" |
| 43 #include "content/public/browser/url_data_source.h" | 48 #include "content/public/browser/url_data_source.h" |
| 44 #include "content/public/browser/user_metrics.h" | 49 #include "content/public/browser/user_metrics.h" |
| 45 #include "content/public/browser/web_contents.h" | 50 #include "content/public/browser/web_contents.h" |
| 46 #include "content/public/browser/web_ui.h" | 51 #include "content/public/browser/web_ui.h" |
| 47 #include "url/gurl.h" | 52 #include "url/gurl.h" |
| 48 | 53 |
| 49 using base::UserMetricsAction; | 54 using base::UserMetricsAction; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 74 | 79 |
| 75 void MostVisitedHandler::RegisterMessages() { | 80 void MostVisitedHandler::RegisterMessages() { |
| 76 Profile* profile = Profile::FromWebUI(web_ui()); | 81 Profile* profile = Profile::FromWebUI(web_ui()); |
| 77 // Set up our sources for thumbnail and favicon data. | 82 // Set up our sources for thumbnail and favicon data. |
| 78 content::URLDataSource::Add(profile, new ThumbnailSource(profile, false)); | 83 content::URLDataSource::Add(profile, new ThumbnailSource(profile, false)); |
| 79 content::URLDataSource::Add(profile, new ThumbnailSource(profile, true)); | 84 content::URLDataSource::Add(profile, new ThumbnailSource(profile, true)); |
| 80 | 85 |
| 81 // Set up our sources for top-sites data. | 86 // Set up our sources for top-sites data. |
| 82 content::URLDataSource::Add(profile, new ThumbnailListSource(profile)); | 87 content::URLDataSource::Add(profile, new ThumbnailListSource(profile)); |
| 83 | 88 |
| 89 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 90 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 91 FallbackIconService* fallback_icon_service = |
| 92 FallbackIconServiceFactory::GetForBrowserContext(profile); |
| 93 |
| 84 // Register chrome://large-icon as a data source for large icons. | 94 // Register chrome://large-icon as a data source for large icons. |
| 85 content::URLDataSource::Add(profile, new LargeIconSource(profile)); | 95 content::URLDataSource::Add(profile, |
| 86 | 96 new LargeIconSource(favicon_service, fallback_icon_service)); |
| 87 // Register chrome://fallback-icon as a data source for fallback icons. | 97 content::URLDataSource::Add(profile, |
| 88 content::URLDataSource::Add(profile, new FallbackIconSource()); | 98 new FallbackIconSource(fallback_icon_service)); |
| 89 | 99 |
| 90 // Register chrome://favicon as a data source for favicons. | 100 // Register chrome://favicon as a data source for favicons. |
| 91 content::URLDataSource::Add( | 101 content::URLDataSource::Add( |
| 92 profile, new FaviconSource(profile, FaviconSource::FAVICON)); | 102 profile, new FaviconSource(profile, FaviconSource::FAVICON)); |
| 93 | 103 |
| 94 scoped_refptr<history::TopSites> top_sites = | 104 scoped_refptr<history::TopSites> top_sites = |
| 95 TopSitesFactory::GetForProfile(profile); | 105 TopSitesFactory::GetForProfile(profile); |
| 96 if (top_sites) { | 106 if (top_sites) { |
| 97 // TopSites updates itself after a delay. This is especially noticable when | 107 // TopSites updates itself after a delay. This is especially noticable when |
| 98 // your profile is empty. Ask TopSites to update itself when we're about to | 108 // your profile is empty. Ask TopSites to update itself when we're about to |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 return base::MD5String(url); | 285 return base::MD5String(url); |
| 276 } | 286 } |
| 277 | 287 |
| 278 // static | 288 // static |
| 279 void MostVisitedHandler::RegisterProfilePrefs( | 289 void MostVisitedHandler::RegisterProfilePrefs( |
| 280 user_prefs::PrefRegistrySyncable* registry) { | 290 user_prefs::PrefRegistrySyncable* registry) { |
| 281 registry->RegisterDictionaryPref( | 291 registry->RegisterDictionaryPref( |
| 282 prefs::kNtpMostVisitedURLsBlacklist, | 292 prefs::kNtpMostVisitedURLsBlacklist, |
| 283 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 293 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 284 } | 294 } |
| OLD | NEW |