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/string16.h" | 15 #include "base/string16.h" |
16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "chrome/browser/history/page_usage_data.h" | 20 #include "chrome/browser/history/page_usage_data.h" |
21 #include "chrome/browser/history/top_sites.h" | 21 #include "chrome/browser/history/top_sites.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 23 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 25 #include "chrome/browser/ui/webui/chrome_url_data_manager_factory.h" |
26 #include "chrome/browser/ui/webui/favicon_source.h" | 26 #include "chrome/browser/ui/webui/favicon_source.h" |
27 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 27 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
28 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 28 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
29 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
31 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
32 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
34 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
35 #include "content/public/browser/web_ui.h" | 35 #include "content/public/browser/web_ui.h" |
36 #include "googleurl/src/gurl.h" | 36 #include "googleurl/src/gurl.h" |
37 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
38 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
39 #include "grit/locale_settings.h" | 39 #include "grit/locale_settings.h" |
40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
41 | 41 |
42 using content::UserMetricsAction; | 42 using content::UserMetricsAction; |
43 | 43 |
44 MostVisitedHandler::MostVisitedHandler() | 44 MostVisitedHandler::MostVisitedHandler() |
45 : got_first_most_visited_request_(false) { | 45 : got_first_most_visited_request_(false) { |
46 } | 46 } |
47 | 47 |
48 MostVisitedHandler::~MostVisitedHandler() { | 48 MostVisitedHandler::~MostVisitedHandler() { |
49 } | 49 } |
50 | 50 |
51 void MostVisitedHandler::RegisterMessages() { | 51 void MostVisitedHandler::RegisterMessages() { |
52 Profile* profile = Profile::FromWebUI(web_ui()); | 52 Profile* profile = Profile::FromWebUI(web_ui()); |
53 // Set up our sources for thumbnail and favicon data. | 53 // Set up our sources for thumbnail and favicon data. |
54 ThumbnailSource* thumbnail_src = new ThumbnailSource(profile); | 54 ThumbnailSource* thumbnail_src = new ThumbnailSource(profile); |
55 profile->GetChromeURLDataManager()->AddDataSource(thumbnail_src); | 55 ChromeURLDataManagerFactory::GetForProfile(profile)-> |
| 56 AddDataSource(thumbnail_src); |
56 | 57 |
57 profile->GetChromeURLDataManager()->AddDataSource( | 58 ChromeURLDataManagerFactory::GetForProfile(profile)-> |
58 new FaviconSource(profile, FaviconSource::FAVICON)); | 59 AddDataSource(new FaviconSource(profile, FaviconSource::FAVICON)); |
59 | 60 |
60 history::TopSites* ts = profile->GetTopSites(); | 61 history::TopSites* ts = profile->GetTopSites(); |
61 if (ts) { | 62 if (ts) { |
62 // TopSites updates itself after a delay. This is especially noticable when | 63 // TopSites updates itself after a delay. This is especially noticable when |
63 // your profile is empty. Ask TopSites to update itself when we're about to | 64 // your profile is empty. Ask TopSites to update itself when we're about to |
64 // show the new tab page. | 65 // show the new tab page. |
65 ts->SyncWithHistory(); | 66 ts->SyncWithHistory(); |
66 | 67 |
67 // Register for notification when TopSites changes so that we can update | 68 // Register for notification when TopSites changes so that we can update |
68 // ourself. | 69 // ourself. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 204 |
204 std::string MostVisitedHandler::GetDictionaryKeyForURL(const std::string& url) { | 205 std::string MostVisitedHandler::GetDictionaryKeyForURL(const std::string& url) { |
205 return base::MD5String(url); | 206 return base::MD5String(url); |
206 } | 207 } |
207 | 208 |
208 // static | 209 // static |
209 void MostVisitedHandler::RegisterUserPrefs(PrefService* prefs) { | 210 void MostVisitedHandler::RegisterUserPrefs(PrefService* prefs) { |
210 prefs->RegisterDictionaryPref(prefs::kNtpMostVisitedURLsBlacklist, | 211 prefs->RegisterDictionaryPref(prefs::kNtpMostVisitedURLsBlacklist, |
211 PrefService::UNSYNCABLE_PREF); | 212 PrefService::UNSYNCABLE_PREF); |
212 } | 213 } |
OLD | NEW |