Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/history/top_sites_factory.h" | 5 #include "chrome/browser/history/top_sites_factory.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "chrome/browser/history/history_service_factory.h" | 10 #include "chrome/browser/history/history_service_factory.h" |
| 11 #include "chrome/browser/history/history_utils.h" | 11 #include "chrome/browser/history/history_utils.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/grit/chromium_strings.h" | 14 #include "chrome/grit/chromium_strings.h" |
| 15 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 16 #include "chrome/grit/locale_settings.h" | 16 #include "chrome/grit/locale_settings.h" |
| 17 #include "components/history/core/browser/history_constants.h" | 17 #include "components/history/core/browser/history_constants.h" |
| 18 #include "components/history/core/browser/top_sites_impl.h" | 18 #include "components/history/core/browser/top_sites_impl.h" |
| 19 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 19 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 20 #include "components/pref_registry/pref_registry_syncable.h" | |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 struct RawPrepopulatedPage { | 28 struct RawPrepopulatedPage { |
| 28 int url_id; // The resource for the page URL. | 29 int url_id; // The resource for the page URL. |
| 29 int title_id; // The resource for the page title. | 30 int title_id; // The resource for the page title. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 } | 84 } |
| 84 | 85 |
| 85 // static | 86 // static |
| 86 scoped_refptr<history::TopSites> TopSitesFactory::BuildTopSites( | 87 scoped_refptr<history::TopSites> TopSitesFactory::BuildTopSites( |
| 87 content::BrowserContext* context, | 88 content::BrowserContext* context, |
| 88 const std::vector<history::PrepopulatedPage>& prepopulated_page_list) { | 89 const std::vector<history::PrepopulatedPage>& prepopulated_page_list) { |
| 89 Profile* profile = Profile::FromBrowserContext(context); | 90 Profile* profile = Profile::FromBrowserContext(context); |
| 90 scoped_refptr<history::TopSitesImpl> top_sites(new history::TopSitesImpl( | 91 scoped_refptr<history::TopSitesImpl> top_sites(new history::TopSitesImpl( |
| 91 profile->GetPrefs(), HistoryServiceFactory::GetForProfile( | 92 profile->GetPrefs(), HistoryServiceFactory::GetForProfile( |
| 92 profile, ServiceAccessType::EXPLICIT_ACCESS), | 93 profile, ServiceAccessType::EXPLICIT_ACCESS), |
| 93 prefs::kNtpMostVisitedURLsBlacklist, prepopulated_page_list, | 94 prefs::kNtpMostVisitedURLsBlacklist, prepopulated_page_list, |
|
Dan Beam
2015/05/19 21:51:31
this is the only class that needs to know how blac
| |
| 94 base::Bind(CanAddURLToHistory))); | 95 base::Bind(CanAddURLToHistory))); |
| 95 top_sites->Init(context->GetPath().Append(history::kTopSitesFilename), | 96 top_sites->Init(context->GetPath().Append(history::kTopSitesFilename), |
| 96 content::BrowserThread::GetMessageLoopProxyForThread( | 97 content::BrowserThread::GetMessageLoopProxyForThread( |
| 97 content::BrowserThread::DB)); | 98 content::BrowserThread::DB)); |
| 98 return top_sites; | 99 return top_sites; |
| 99 } | 100 } |
| 100 | 101 |
| 101 TopSitesFactory::TopSitesFactory() | 102 TopSitesFactory::TopSitesFactory() |
| 102 : RefcountedBrowserContextKeyedServiceFactory( | 103 : RefcountedBrowserContextKeyedServiceFactory( |
| 103 "TopSites", | 104 "TopSites", |
| 104 BrowserContextDependencyManager::GetInstance()) { | 105 BrowserContextDependencyManager::GetInstance()) { |
| 105 DependsOn(HistoryServiceFactory::GetInstance()); | 106 DependsOn(HistoryServiceFactory::GetInstance()); |
| 106 } | 107 } |
| 107 | 108 |
| 108 TopSitesFactory::~TopSitesFactory() { | 109 TopSitesFactory::~TopSitesFactory() { |
| 109 } | 110 } |
| 110 | 111 |
| 111 scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor( | 112 scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor( |
| 112 content::BrowserContext* context) const { | 113 content::BrowserContext* context) const { |
| 113 history::PrepopulatedPageList prepopulated_pages; | 114 history::PrepopulatedPageList prepopulated_pages; |
| 114 InitializePrepopulatedPageList(&prepopulated_pages); | 115 InitializePrepopulatedPageList(&prepopulated_pages); |
| 115 return BuildTopSites(context, prepopulated_pages); | 116 return BuildTopSites(context, prepopulated_pages); |
| 116 } | 117 } |
| 117 | 118 |
| 119 void TopSitesFactory::RegisterProfilePrefs( | |
| 120 user_prefs::PrefRegistrySyncable* registry) { | |
| 121 registry->RegisterDictionaryPref(prefs::kNtpMostVisitedURLsBlacklist); | |
| 122 } | |
| 123 | |
| 118 bool TopSitesFactory::ServiceIsNULLWhileTesting() const { | 124 bool TopSitesFactory::ServiceIsNULLWhileTesting() const { |
| 119 return true; | 125 return true; |
| 120 } | 126 } |
| OLD | NEW |