| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/chrome_history_client_factory.h" | 5 #include "chrome/browser/history/chrome_history_client_factory.h" |
| 6 | 6 |
| 7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 9 #include "chrome/browser/history/chrome_history_client.h" | 9 #include "chrome/browser/history/chrome_history_client.h" |
| 10 #include "chrome/browser/history/top_sites_service_factory.h" |
| 10 #include "chrome/browser/profiles/incognito_helpers.h" | 11 #include "chrome/browser/profiles/incognito_helpers.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 13 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 13 | 14 |
| 14 // static | 15 // static |
| 15 ChromeHistoryClient* ChromeHistoryClientFactory::GetForProfile( | 16 ChromeHistoryClient* ChromeHistoryClientFactory::GetForProfile( |
| 16 Profile* profile) { | 17 Profile* profile) { |
| 17 return static_cast<ChromeHistoryClient*>( | 18 return static_cast<ChromeHistoryClient*>( |
| 18 GetInstance()->GetServiceForBrowserContext(profile, true)); | 19 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 19 } | 20 } |
| 20 | 21 |
| 21 // static | 22 // static |
| 22 ChromeHistoryClient* ChromeHistoryClientFactory::GetForProfileWithoutCreating( | 23 ChromeHistoryClient* ChromeHistoryClientFactory::GetForProfileWithoutCreating( |
| 23 Profile* profile) { | 24 Profile* profile) { |
| 24 return static_cast<ChromeHistoryClient*>( | 25 return static_cast<ChromeHistoryClient*>( |
| 25 GetInstance()->GetServiceForBrowserContext(profile, false)); | 26 GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 26 } | 27 } |
| 27 | 28 |
| 28 // static | 29 // static |
| 29 ChromeHistoryClientFactory* ChromeHistoryClientFactory::GetInstance() { | 30 ChromeHistoryClientFactory* ChromeHistoryClientFactory::GetInstance() { |
| 30 return Singleton<ChromeHistoryClientFactory>::get(); | 31 return Singleton<ChromeHistoryClientFactory>::get(); |
| 31 } | 32 } |
| 32 | 33 |
| 33 ChromeHistoryClientFactory::ChromeHistoryClientFactory() | 34 ChromeHistoryClientFactory::ChromeHistoryClientFactory() |
| 34 : BrowserContextKeyedServiceFactory( | 35 : BrowserContextKeyedServiceFactory( |
| 35 "ChromeHistoryClient", | 36 "ChromeHistoryClient", |
| 36 BrowserContextDependencyManager::GetInstance()) { | 37 BrowserContextDependencyManager::GetInstance()) { |
| 37 DependsOn(BookmarkModelFactory::GetInstance()); | 38 DependsOn(BookmarkModelFactory::GetInstance()); |
| 39 DependsOn(TopSitesServiceFactory::GetInstance()); |
| 38 } | 40 } |
| 39 | 41 |
| 40 ChromeHistoryClientFactory::~ChromeHistoryClientFactory() { | 42 ChromeHistoryClientFactory::~ChromeHistoryClientFactory() { |
| 41 } | 43 } |
| 42 | 44 |
| 43 KeyedService* ChromeHistoryClientFactory::BuildServiceInstanceFor( | 45 KeyedService* ChromeHistoryClientFactory::BuildServiceInstanceFor( |
| 44 content::BrowserContext* context) const { | 46 content::BrowserContext* context) const { |
| 45 Profile* profile = static_cast<Profile*>(context); | 47 Profile* profile = static_cast<Profile*>(context); |
| 48 scoped_refptr<history::TopSites> top_sites = |
| 49 TopSitesServiceFactory::GetForProfile(profile); |
| 46 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile), | 50 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile), |
| 47 profile, | 51 profile, top_sites.get()); |
| 48 profile->GetTopSites()); | |
| 49 } | 52 } |
| 50 | 53 |
| 51 content::BrowserContext* ChromeHistoryClientFactory::GetBrowserContextToUse( | 54 content::BrowserContext* ChromeHistoryClientFactory::GetBrowserContextToUse( |
| 52 content::BrowserContext* context) const { | 55 content::BrowserContext* context) const { |
| 53 return chrome::GetBrowserContextRedirectedInIncognito(context); | 56 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 54 } | 57 } |
| 55 | 58 |
| 56 bool ChromeHistoryClientFactory::ServiceIsNULLWhileTesting() const { | 59 bool ChromeHistoryClientFactory::ServiceIsNULLWhileTesting() const { |
| 57 return true; | 60 return true; |
| 58 } | 61 } |
| OLD | NEW |