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/macros.h" | 8 #include "base/macros.h" |
8 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
9 #include "chrome/browser/history/history_service_factory.h" | 10 #include "chrome/browser/history/history_service_factory.h" |
10 #include "chrome/browser/history/top_sites_impl.h" | 11 #include "chrome/browser/history/history_utils.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
14 #include "chrome/grit/chromium_strings.h" | 15 #include "chrome/grit/chromium_strings.h" |
15 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
16 #include "chrome/grit/locale_settings.h" | 17 #include "chrome/grit/locale_settings.h" |
| 18 #include "components/history/core/browser/top_sites_impl.h" |
17 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 19 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
19 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
20 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
21 #include "url/gurl.h" | 23 #include "url/gurl.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 struct RawPrepopulatedPage { | 27 struct RawPrepopulatedPage { |
26 int url_id; // The resource for the page URL. | 28 int url_id; // The resource for the page URL. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 90 } |
89 | 91 |
90 // static | 92 // static |
91 scoped_refptr<history::TopSites> TopSitesFactory::BuildTopSites( | 93 scoped_refptr<history::TopSites> TopSitesFactory::BuildTopSites( |
92 content::BrowserContext* context, | 94 content::BrowserContext* context, |
93 const std::vector<history::PrepopulatedPage>& prepopulated_page_list) { | 95 const std::vector<history::PrepopulatedPage>& prepopulated_page_list) { |
94 Profile* profile = Profile::FromBrowserContext(context); | 96 Profile* profile = Profile::FromBrowserContext(context); |
95 scoped_refptr<history::TopSitesImpl> top_sites(new history::TopSitesImpl( | 97 scoped_refptr<history::TopSitesImpl> top_sites(new history::TopSitesImpl( |
96 profile->GetPrefs(), HistoryServiceFactory::GetForProfile( | 98 profile->GetPrefs(), HistoryServiceFactory::GetForProfile( |
97 profile, ServiceAccessType::EXPLICIT_ACCESS), | 99 profile, ServiceAccessType::EXPLICIT_ACCESS), |
98 prefs::kNtpMostVisitedURLsBlacklist, prepopulated_page_list)); | 100 prefs::kNtpMostVisitedURLsBlacklist, prepopulated_page_list, |
| 101 base::Bind(CanAddURLToHistory))); |
99 top_sites->Init(context->GetPath().Append(chrome::kTopSitesFilename), | 102 top_sites->Init(context->GetPath().Append(chrome::kTopSitesFilename), |
100 content::BrowserThread::GetMessageLoopProxyForThread( | 103 content::BrowserThread::GetMessageLoopProxyForThread( |
101 content::BrowserThread::DB)); | 104 content::BrowserThread::DB)); |
102 return top_sites; | 105 return top_sites; |
103 } | 106 } |
104 | 107 |
105 TopSitesFactory::TopSitesFactory() | 108 TopSitesFactory::TopSitesFactory() |
106 : RefcountedBrowserContextKeyedServiceFactory( | 109 : RefcountedBrowserContextKeyedServiceFactory( |
107 "TopSites", | 110 "TopSites", |
108 BrowserContextDependencyManager::GetInstance()) { | 111 BrowserContextDependencyManager::GetInstance()) { |
109 DependsOn(HistoryServiceFactory::GetInstance()); | 112 DependsOn(HistoryServiceFactory::GetInstance()); |
110 } | 113 } |
111 | 114 |
112 TopSitesFactory::~TopSitesFactory() { | 115 TopSitesFactory::~TopSitesFactory() { |
113 } | 116 } |
114 | 117 |
115 scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor( | 118 scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor( |
116 content::BrowserContext* context) const { | 119 content::BrowserContext* context) const { |
117 history::PrepopulatedPageList prepopulated_pages; | 120 history::PrepopulatedPageList prepopulated_pages; |
118 InitializePrepopulatedPageList(&prepopulated_pages); | 121 InitializePrepopulatedPageList(&prepopulated_pages); |
119 return BuildTopSites(context, prepopulated_pages); | 122 return BuildTopSites(context, prepopulated_pages); |
120 } | 123 } |
121 | 124 |
122 bool TopSitesFactory::ServiceIsNULLWhileTesting() const { | 125 bool TopSitesFactory::ServiceIsNULLWhileTesting() const { |
123 return true; | 126 return true; |
124 } | 127 } |
OLD | NEW |