OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/history/top_sites_service_factory.h" |
| 6 |
| 7 #include "chrome/browser/history/top_sites_impl.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/common/chrome_constants.h" |
| 10 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 11 |
| 12 using namespace history; |
| 13 |
| 14 // static |
| 15 scoped_refptr<history::TopSites> TopSitesServiceFactory::GetForProfile( |
| 16 Profile* profile) { |
| 17 return static_cast<history::TopSites*>( |
| 18 GetInstance()->GetServiceForBrowserContext(profile, true).get()); |
| 19 } |
| 20 |
| 21 // static |
| 22 scoped_refptr<history::TopSites> TopSitesServiceFactory::GetForProfileIfExists( |
| 23 Profile* profile) { |
| 24 return static_cast<history::TopSites*>( |
| 25 GetInstance()->GetServiceForBrowserContext(profile, false).get()); |
| 26 } |
| 27 |
| 28 // static |
| 29 TopSitesServiceFactory* TopSitesServiceFactory::GetInstance() { |
| 30 return Singleton<TopSitesServiceFactory>::get(); |
| 31 } |
| 32 |
| 33 // static |
| 34 scoped_refptr<RefcountedKeyedService> |
| 35 TopSitesServiceFactory::BuildProfileForTesting( |
| 36 content::BrowserContext* profile) { |
| 37 scoped_refptr<TopSitesImpl> provider( |
| 38 new TopSitesImpl(static_cast<Profile*>(profile))); |
| 39 provider->Init(profile->GetPath().Append(chrome::kTopSitesFilename)); |
| 40 return provider; |
| 41 } |
| 42 |
| 43 // static |
| 44 scoped_refptr<RefcountedKeyedService> |
| 45 TopSitesServiceFactory::CreateCustomTopSitesServiceFactory( |
| 46 history::TopSites* top_sites) { |
| 47 scoped_refptr<history::TopSites> provider(top_sites); |
| 48 return provider; |
| 49 } |
| 50 |
| 51 TopSitesServiceFactory::TopSitesServiceFactory() |
| 52 : RefcountedBrowserContextKeyedServiceFactory( |
| 53 "TopSitesService", |
| 54 BrowserContextDependencyManager::GetInstance()) { |
| 55 } |
| 56 |
| 57 TopSitesServiceFactory::~TopSitesServiceFactory() { |
| 58 } |
| 59 |
| 60 scoped_refptr<RefcountedKeyedService> |
| 61 TopSitesServiceFactory::BuildServiceInstanceFor( |
| 62 content::BrowserContext* profile) const { |
| 63 scoped_refptr<TopSitesImpl> provider( |
| 64 new TopSitesImpl(static_cast<Profile*>(profile))); |
| 65 provider->Init(profile->GetPath().Append(chrome::kTopSitesFilename)); |
| 66 return provider; |
| 67 } |
OLD | NEW |