Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1457)

Side by Side Diff: chrome/browser/history/top_sites_factory.cc

Issue 870063002: Componentize TopSites, TopSitesBackend, TopSitesDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@815983002
Patch Set: Fix typo Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/history/top_sites_factory.h ('k') | chrome/browser/history/top_sites_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/macros.h"
7 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
8 #include "chrome/browser/history/top_sites_impl.h" 9 #include "chrome/browser/history/top_sites_impl.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/chrome_constants.h" 11 #include "chrome/common/chrome_constants.h"
12 #include "chrome/grit/chromium_strings.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "chrome/grit/locale_settings.h"
11 #include "components/keyed_service/content/browser_context_dependency_manager.h" 15 #include "components/keyed_service/content/browser_context_dependency_manager.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "grit/theme_resources.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "url/gurl.h"
20
21 namespace {
22
23 struct RawPrepopulatedPage {
24 int url_id; // The resource for the page URL.
25 int title_id; // The resource for the page title.
26 int favicon_id; // The raw data resource for the favicon.
27 int thumbnail_id; // The raw data resource for the thumbnail.
28 SkColor color; // The best color to highlight the page (should roughly
29 // match favicon).
30 };
31
32 #if !defined(OS_ANDROID)
33 // Android does not use prepopulated pages.
34 const RawPrepopulatedPage kRawPrepopulatedPages[] = {
35 {
36 IDS_CHROME_WELCOME_URL,
37 IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE,
38 IDR_PRODUCT_LOGO_16,
39 IDR_NEWTAB_CHROME_WELCOME_PAGE_THUMBNAIL,
40 SkColorSetRGB(0, 147, 60),
41 },
42 {
43 IDS_WEBSTORE_URL,
44 IDS_EXTENSION_WEB_STORE_TITLE,
45 IDR_WEBSTORE_ICON_16,
46 IDR_NEWTAB_WEBSTORE_THUMBNAIL,
47 SkColorSetRGB(63, 132, 197),
48 },
49 };
50 #endif
51
52 void InitializePrepopulatedPageList(
53 history::PrepopulatedPageList* prepopulated_pages) {
54 #if !defined(OS_ANDROID)
55 DCHECK(prepopulated_pages);
56 prepopulated_pages->reserve(arraysize(kRawPrepopulatedPages));
57 for (size_t i = 0; i < arraysize(kRawPrepopulatedPages); ++i) {
58 const RawPrepopulatedPage& page = kRawPrepopulatedPages[i];
59 prepopulated_pages->push_back(history::PrepopulatedPage(
60 GURL(l10n_util::GetStringUTF8(page.url_id)),
61 l10n_util::GetStringUTF16(page.title_id), page.favicon_id,
62 page.thumbnail_id, page.color));
63 }
64 #endif
65 }
66
67 } // namespace
12 68
13 // static 69 // static
14 scoped_refptr<history::TopSites> TopSitesFactory::GetForProfile( 70 scoped_refptr<history::TopSites> TopSitesFactory::GetForProfile(
15 Profile* profile) { 71 Profile* profile) {
16 return static_cast<history::TopSites*>( 72 return static_cast<history::TopSites*>(
17 GetInstance()->GetServiceForBrowserContext(profile, true).get()); 73 GetInstance()->GetServiceForBrowserContext(profile, true).get());
18 } 74 }
19 75
20 // static 76 // static
21 scoped_refptr<history::TopSites> TopSitesFactory::GetForProfileIfExists( 77 scoped_refptr<history::TopSites> TopSitesFactory::GetForProfileIfExists(
(...skipping 11 matching lines...) Expand all
33 : RefcountedBrowserContextKeyedServiceFactory( 89 : RefcountedBrowserContextKeyedServiceFactory(
34 "TopSites", 90 "TopSites",
35 BrowserContextDependencyManager::GetInstance()) { 91 BrowserContextDependencyManager::GetInstance()) {
36 } 92 }
37 93
38 TopSitesFactory::~TopSitesFactory() { 94 TopSitesFactory::~TopSitesFactory() {
39 } 95 }
40 96
41 scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor( 97 scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor(
42 content::BrowserContext* context) const { 98 content::BrowserContext* context) const {
43 history::TopSitesImpl* top_sites = 99 history::PrepopulatedPageList prepopulated_pages;
44 new history::TopSitesImpl(static_cast<Profile*>(context)); 100 InitializePrepopulatedPageList(&prepopulated_pages);
45 top_sites->Init(context->GetPath().Append(chrome::kTopSitesFilename)); 101
102 history::TopSitesImpl* top_sites = new history::TopSitesImpl(
103 static_cast<Profile*>(context), prepopulated_pages);
104 top_sites->Init(context->GetPath().Append(chrome::kTopSitesFilename),
105 content::BrowserThread::GetMessageLoopProxyForThread(
106 content::BrowserThread::DB));
46 return make_scoped_refptr(top_sites); 107 return make_scoped_refptr(top_sites);
47 } 108 }
48 109
49 bool TopSitesFactory::ServiceIsNULLWhileTesting() const { 110 bool TopSitesFactory::ServiceIsNULLWhileTesting() const {
50 return true; 111 return true;
51 } 112 }
OLDNEW
« no previous file with comments | « chrome/browser/history/top_sites_factory.h ('k') | chrome/browser/history/top_sites_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698