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

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: Created 5 years, 11 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
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 const RawPrepopulatedPage kRawPrepopulatedPages[] = {
33 #if !defined(OS_ANDROID)
34 {
35 IDS_CHROME_WELCOME_URL,
36 IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE,
37 IDR_PRODUCT_LOGO_16,
38 IDR_NEWTAB_CHROME_WELCOME_PAGE_THUMBNAIL,
39 SkColorSetRGB(0, 147, 60),
40 },
41 {
42 IDS_WEBSTORE_URL,
43 IDS_EXTENSION_WEB_STORE_TITLE,
44 IDR_WEBSTORE_ICON_16,
45 IDR_NEWTAB_WEBSTORE_THUMBNAIL,
46 SkColorSetRGB(63, 132, 197),
47 }
48 #endif
49 };
50
51 } // namespace
12 52
13 // static 53 // static
14 scoped_refptr<history::TopSites> TopSitesFactory::GetForProfile( 54 scoped_refptr<history::TopSites> TopSitesFactory::GetForProfile(
15 Profile* profile) { 55 Profile* profile) {
16 return static_cast<history::TopSites*>( 56 return static_cast<history::TopSites*>(
17 GetInstance()->GetServiceForBrowserContext(profile, true).get()); 57 GetInstance()->GetServiceForBrowserContext(profile, true).get());
18 } 58 }
19 59
20 // static 60 // static
21 scoped_refptr<history::TopSites> TopSitesFactory::GetForProfileIfExists( 61 scoped_refptr<history::TopSites> TopSitesFactory::GetForProfileIfExists(
(...skipping 11 matching lines...) Expand all
33 : RefcountedBrowserContextKeyedServiceFactory( 73 : RefcountedBrowserContextKeyedServiceFactory(
34 "TopSites", 74 "TopSites",
35 BrowserContextDependencyManager::GetInstance()) { 75 BrowserContextDependencyManager::GetInstance()) {
36 } 76 }
37 77
38 TopSitesFactory::~TopSitesFactory() { 78 TopSitesFactory::~TopSitesFactory() {
39 } 79 }
40 80
41 scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor( 81 scoped_refptr<RefcountedKeyedService> TopSitesFactory::BuildServiceInstanceFor(
42 content::BrowserContext* context) const { 82 content::BrowserContext* context) const {
43 history::TopSitesImpl* top_sites = 83 history::PrepopulatedPageList prepopulated_pages;
44 new history::TopSitesImpl(static_cast<Profile*>(context)); 84 prepopulated_pages.resize(arraysize(kRawPrepopulatedPages));
45 top_sites->Init(context->GetPath().Append(chrome::kTopSitesFilename)); 85 for (size_t i = 0; i < arraysize(kRawPrepopulatedPages); ++i) {
droger 2015/01/27 10:08:36 optional nit: use some temporary variable here for
sdefresne 2015/01/27 13:55:16 Done.
86 prepopulated_pages[i] = history::PrepopulatedPage(
87 GURL(l10n_util::GetStringUTF8(kRawPrepopulatedPages[i].url_id)),
88 l10n_util::GetStringUTF16(kRawPrepopulatedPages[i].title_id),
89 kRawPrepopulatedPages[i].favicon_id,
90 kRawPrepopulatedPages[i].thumbnail_id, kRawPrepopulatedPages[i].color);
91 }
92
93 history::TopSitesImpl* top_sites = new history::TopSitesImpl(
94 static_cast<Profile*>(context), prepopulated_pages);
95 top_sites->Init(context->GetPath().Append(chrome::kTopSitesFilename),
96 content::BrowserThread::GetMessageLoopProxyForThread(
97 content::BrowserThread::DB));
46 return make_scoped_refptr(top_sites); 98 return make_scoped_refptr(top_sites);
47 } 99 }
48 100
49 bool TopSitesFactory::ServiceIsNULLWhileTesting() const { 101 bool TopSitesFactory::ServiceIsNULLWhileTesting() const {
50 return true; 102 return true;
51 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698