| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/md5.h" | 11 #include "base/md5.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/history/page_usage_data.h" | 19 #include "chrome/browser/history/page_usage_data.h" |
| 20 #include "chrome/browser/history/top_sites.h" | 20 #include "chrome/browser/history/top_sites.h" |
| 21 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
| 22 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 22 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 25 #include "chrome/browser/ui/webui/favicon_source.h" | 25 #include "chrome/browser/ui/webui/favicon_source.h" |
| 26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 27 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 27 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
| 28 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 30 #include "content/browser/browser_thread.h" | 31 #include "content/browser/browser_thread.h" |
| 31 #include "content/browser/user_metrics.h" | 32 #include "content/browser/user_metrics.h" |
| 32 #include "content/common/notification_source.h" | 33 #include "content/common/notification_source.h" |
| 33 #include "content/common/notification_type.h" | |
| 34 #include "googleurl/src/gurl.h" | 34 #include "googleurl/src/gurl.h" |
| 35 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
| 36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 37 #include "grit/locale_settings.h" | 37 #include "grit/locale_settings.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 39 | 39 |
| 40 // This struct is used when getting the pre-populated pages in case the user | 40 // This struct is used when getting the pre-populated pages in case the user |
| 41 // hasn't filled up his most visited pages. | 41 // hasn't filled up his most visited pages. |
| 42 struct MostVisitedHandler::MostVisitedPage { | 42 struct MostVisitedHandler::MostVisitedPage { |
| 43 string16 title; | 43 string16 title; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 66 | 66 |
| 67 history::TopSites* ts = profile->GetTopSites(); | 67 history::TopSites* ts = profile->GetTopSites(); |
| 68 if (ts) { | 68 if (ts) { |
| 69 // TopSites updates itself after a delay. This is especially noticable when | 69 // TopSites updates itself after a delay. This is especially noticable when |
| 70 // your profile is empty. Ask TopSites to update itself when we're about to | 70 // your profile is empty. Ask TopSites to update itself when we're about to |
| 71 // show the new tab page. | 71 // show the new tab page. |
| 72 ts->SyncWithHistory(); | 72 ts->SyncWithHistory(); |
| 73 | 73 |
| 74 // Register for notification when TopSites changes so that we can update | 74 // Register for notification when TopSites changes so that we can update |
| 75 // ourself. | 75 // ourself. |
| 76 registrar_.Add(this, NotificationType::TOP_SITES_CHANGED, | 76 registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, |
| 77 Source<history::TopSites>(ts)); | 77 Source<history::TopSites>(ts)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // We pre-emptively make a fetch for the most visited pages so we have the | 80 // We pre-emptively make a fetch for the most visited pages so we have the |
| 81 // results sooner. | 81 // results sooner. |
| 82 StartQueryForMostVisited(); | 82 StartQueryForMostVisited(); |
| 83 return result; | 83 return result; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void MostVisitedHandler::RegisterMessages() { | 86 void MostVisitedHandler::RegisterMessages() { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 l10n_util::GetStringUTF16(IDS_NEW_TAB_THEMES_GALLERY_PAGE_TITLE), | 342 l10n_util::GetStringUTF16(IDS_NEW_TAB_THEMES_GALLERY_PAGE_TITLE), |
| 343 GURL(l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_URL)), | 343 GURL(l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_URL)), |
| 344 GURL("chrome://theme/IDR_NEWTAB_THEMES_GALLERY_THUMBNAIL"), | 344 GURL("chrome://theme/IDR_NEWTAB_THEMES_GALLERY_THUMBNAIL"), |
| 345 GURL("chrome://theme/IDR_NEWTAB_THEMES_GALLERY_FAVICON")}; | 345 GURL("chrome://theme/IDR_NEWTAB_THEMES_GALLERY_FAVICON")}; |
| 346 pages.push_back(gallery_page); | 346 pages.push_back(gallery_page); |
| 347 } | 347 } |
| 348 | 348 |
| 349 return pages; | 349 return pages; |
| 350 } | 350 } |
| 351 | 351 |
| 352 void MostVisitedHandler::Observe(NotificationType type, | 352 void MostVisitedHandler::Observe(int type, |
| 353 const NotificationSource& source, | 353 const NotificationSource& source, |
| 354 const NotificationDetails& details) { | 354 const NotificationDetails& details) { |
| 355 DCHECK_EQ(type.value, NotificationType::TOP_SITES_CHANGED); | 355 DCHECK_EQ(type, chrome::NOTIFICATION_TOP_SITES_CHANGED); |
| 356 | 356 |
| 357 // Most visited urls changed, query again. | 357 // Most visited urls changed, query again. |
| 358 StartQueryForMostVisited(); | 358 StartQueryForMostVisited(); |
| 359 } | 359 } |
| 360 | 360 |
| 361 void MostVisitedHandler::BlacklistURL(const GURL& url) { | 361 void MostVisitedHandler::BlacklistURL(const GURL& url) { |
| 362 history::TopSites* ts = web_ui_->GetProfile()->GetTopSites(); | 362 history::TopSites* ts = web_ui_->GetProfile()->GetTopSites(); |
| 363 if (ts) | 363 if (ts) |
| 364 ts->AddBlacklistedURL(url); | 364 ts->AddBlacklistedURL(url); |
| 365 UserMetrics::RecordAction(UserMetricsAction("MostVisited_UrlBlacklisted")); | 365 UserMetrics::RecordAction(UserMetricsAction("MostVisited_UrlBlacklisted")); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 379 | 379 |
| 380 // static | 380 // static |
| 381 std::vector<GURL> MostVisitedHandler::GetPrePopulatedUrls() { | 381 std::vector<GURL> MostVisitedHandler::GetPrePopulatedUrls() { |
| 382 const std::vector<MostVisitedPage> pages = | 382 const std::vector<MostVisitedPage> pages = |
| 383 MostVisitedHandler::GetPrePopulatedPages(); | 383 MostVisitedHandler::GetPrePopulatedPages(); |
| 384 std::vector<GURL> page_urls; | 384 std::vector<GURL> page_urls; |
| 385 for (size_t i = 0; i < pages.size(); ++i) | 385 for (size_t i = 0; i < pages.size(); ++i) |
| 386 page_urls.push_back(pages[i].url); | 386 page_urls.push_back(pages[i].url); |
| 387 return page_urls; | 387 return page_urls; |
| 388 } | 388 } |
| OLD | NEW |