OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/dom_ui/most_visited_handler.h" | 5 #include "chrome/browser/dom_ui/most_visited_handler.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/md5.h" | 8 #include "base/md5.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/thread.h" | 10 #include "base/thread.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/chrome_thread.h" |
12 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 13 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
13 #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" | 14 #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" |
14 #include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h" | 15 #include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h" |
15 #include "chrome/browser/dom_ui/new_tab_ui.h" | 16 #include "chrome/browser/dom_ui/new_tab_ui.h" |
16 #include "chrome/browser/browser_process.h" | |
17 #include "chrome/browser/history/page_usage_data.h" | 17 #include "chrome/browser/history/page_usage_data.h" |
18 #include "chrome/browser/history/history.h" | 18 #include "chrome/browser/history/history.h" |
19 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
20 #include "chrome/common/notification_type.h" | 20 #include "chrome/common/notification_type.h" |
21 #include "chrome/common/notification_source.h" | 21 #include "chrome/common/notification_source.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
25 #include "grit/locale_settings.h" | 25 #include "grit/locale_settings.h" |
26 | 26 |
(...skipping 21 matching lines...) Expand all Loading... |
48 : url_blacklist_(NULL), | 48 : url_blacklist_(NULL), |
49 pinned_urls_(NULL), | 49 pinned_urls_(NULL), |
50 got_first_most_visited_request_(false) { | 50 got_first_most_visited_request_(false) { |
51 } | 51 } |
52 | 52 |
53 DOMMessageHandler* MostVisitedHandler::Attach(DOMUI* dom_ui) { | 53 DOMMessageHandler* MostVisitedHandler::Attach(DOMUI* dom_ui) { |
54 url_blacklist_ = dom_ui->GetProfile()->GetPrefs()-> | 54 url_blacklist_ = dom_ui->GetProfile()->GetPrefs()-> |
55 GetMutableDictionary(prefs::kNTPMostVisitedURLsBlacklist); | 55 GetMutableDictionary(prefs::kNTPMostVisitedURLsBlacklist); |
56 pinned_urls_ = dom_ui->GetProfile()->GetPrefs()-> | 56 pinned_urls_ = dom_ui->GetProfile()->GetPrefs()-> |
57 GetMutableDictionary(prefs::kNTPMostVisitedPinnedURLs); | 57 GetMutableDictionary(prefs::kNTPMostVisitedPinnedURLs); |
58 // Set up our sources for thumbnail and favicon data. Since we may be in | 58 // Set up our sources for thumbnail and favicon data. |
59 // testing mode with no I/O thread, only add our handler when an I/O thread | 59 ChromeThread::PostTask( |
60 // exists. Ownership is passed to the ChromeURLDataManager. | 60 ChromeThread::IO, FROM_HERE, |
61 if (g_browser_process->io_thread()) { | 61 NewRunnableMethod(&chrome_url_data_manager, |
62 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 62 &ChromeURLDataManager::AddDataSource, |
63 NewRunnableMethod(&chrome_url_data_manager, | 63 new DOMUIThumbnailSource(dom_ui->GetProfile()))); |
64 &ChromeURLDataManager::AddDataSource, | 64 ChromeThread::PostTask( |
65 new DOMUIThumbnailSource(dom_ui->GetProfile()))); | 65 ChromeThread::IO, FROM_HERE, |
66 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 66 NewRunnableMethod(&chrome_url_data_manager, |
67 NewRunnableMethod(&chrome_url_data_manager, | 67 &ChromeURLDataManager::AddDataSource, |
68 &ChromeURLDataManager::AddDataSource, | 68 new DOMUIFavIconSource(dom_ui->GetProfile()))); |
69 new DOMUIFavIconSource(dom_ui->GetProfile()))); | |
70 } | |
71 | 69 |
72 // Get notifications when history is cleared. | 70 // Get notifications when history is cleared. |
73 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, | 71 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, |
74 Source<Profile>(dom_ui->GetProfile())); | 72 Source<Profile>(dom_ui->GetProfile())); |
75 | 73 |
76 DOMMessageHandler* result = DOMMessageHandler::Attach(dom_ui); | 74 DOMMessageHandler* result = DOMMessageHandler::Attach(dom_ui); |
77 | 75 |
78 // We pre-emptively make a fetch for the most visited pages so we have the | 76 // We pre-emptively make a fetch for the most visited pages so we have the |
79 // results sooner. | 77 // results sooner. |
80 StartQueryForMostVisited(); | 78 StartQueryForMostVisited(); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 std::wstring MostVisitedHandler::GetDictionaryKeyForURL( | 437 std::wstring MostVisitedHandler::GetDictionaryKeyForURL( |
440 const std::string& url) { | 438 const std::string& url) { |
441 return ASCIIToWide(MD5String(url)); | 439 return ASCIIToWide(MD5String(url)); |
442 } | 440 } |
443 | 441 |
444 // static | 442 // static |
445 void MostVisitedHandler::RegisterUserPrefs(PrefService* prefs) { | 443 void MostVisitedHandler::RegisterUserPrefs(PrefService* prefs) { |
446 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedURLsBlacklist); | 444 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedURLsBlacklist); |
447 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedPinnedURLs); | 445 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedPinnedURLs); |
448 } | 446 } |
OLD | NEW |