| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/history_service_factory.h" | 5 #include "chrome/browser/history/history_service_factory.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 9 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | |
| 10 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | |
| 11 #include "chrome/browser/history/chrome_history_client.h" | 9 #include "chrome/browser/history/chrome_history_client.h" |
| 12 #include "chrome/browser/profiles/incognito_helpers.h" | 10 #include "chrome/browser/profiles/incognito_helpers.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 15 #include "components/bookmarks/browser/bookmark_model.h" | 13 #include "components/bookmarks/browser/bookmark_model.h" |
| 16 #include "components/history/content/browser/content_visit_delegate.h" | 14 #include "components/history/content/browser/content_visit_delegate.h" |
| 17 #include "components/history/content/browser/history_database_helper.h" | 15 #include "components/history/content/browser/history_database_helper.h" |
| 18 #include "components/history/core/browser/history_database_params.h" | 16 #include "components/history/core/browser/history_database_params.h" |
| 19 #include "components/history/core/browser/history_service.h" | 17 #include "components/history/core/browser/history_service.h" |
| 20 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 18 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 21 #include "components/keyed_service/core/service_access_type.h" | 19 #include "components/keyed_service/core/service_access_type.h" |
| 22 | 20 |
| 23 // static | 21 // static |
| 24 history::HistoryService* HistoryServiceFactory::GetForProfile( | 22 history::HistoryService* HistoryServiceFactory::GetForProfile( |
| 25 Profile* profile, | 23 Profile* profile, |
| 26 ServiceAccessType sat) { | 24 ServiceAccessType sat) { |
| 27 // If saving history is disabled, only allow explicit access. | 25 // If saving history is disabled, only allow explicit access. |
| 28 if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && | 26 if (sat != ServiceAccessType::EXPLICIT_ACCESS && |
| 29 sat != ServiceAccessType::EXPLICIT_ACCESS) | 27 profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled)) { |
| 30 return NULL; | 28 return nullptr; |
| 29 } |
| 31 | 30 |
| 32 return static_cast<history::HistoryService*>( | 31 return static_cast<history::HistoryService*>( |
| 33 GetInstance()->GetServiceForBrowserContext(profile, true)); | 32 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 34 } | 33 } |
| 35 | 34 |
| 36 // static | 35 // static |
| 37 history::HistoryService* HistoryServiceFactory::GetForProfileIfExists( | 36 history::HistoryService* HistoryServiceFactory::GetForProfileIfExists( |
| 38 Profile* profile, | 37 Profile* profile, |
| 39 ServiceAccessType sat) { | 38 ServiceAccessType sat) { |
| 40 // If saving history is disabled, only allow explicit access. | 39 // If saving history is disabled, only allow explicit access. |
| 41 if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && | 40 if (sat != ServiceAccessType::EXPLICIT_ACCESS && |
| 42 sat != ServiceAccessType::EXPLICIT_ACCESS) | 41 profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled)) { |
| 43 return NULL; | 42 return nullptr; |
| 43 } |
| 44 | 44 |
| 45 return static_cast<history::HistoryService*>( | 45 return static_cast<history::HistoryService*>( |
| 46 GetInstance()->GetServiceForBrowserContext(profile, false)); | 46 GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 // static | 49 // static |
| 50 history::HistoryService* HistoryServiceFactory::GetForProfileWithoutCreating( | 50 history::HistoryService* HistoryServiceFactory::GetForProfileWithoutCreating( |
| 51 Profile* profile) { | 51 Profile* profile) { |
| 52 return static_cast<history::HistoryService*>( | 52 return static_cast<history::HistoryService*>( |
| 53 GetInstance()->GetServiceForBrowserContext(profile, false)); | 53 GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // static | 56 // static |
| 57 HistoryServiceFactory* HistoryServiceFactory::GetInstance() { | 57 HistoryServiceFactory* HistoryServiceFactory::GetInstance() { |
| 58 return Singleton<HistoryServiceFactory>::get(); | 58 return Singleton<HistoryServiceFactory>::get(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // static | 61 // static |
| 62 void HistoryServiceFactory::ShutdownForProfile(Profile* profile) { | 62 void HistoryServiceFactory::ShutdownForProfile(Profile* profile) { |
| 63 HistoryServiceFactory* factory = GetInstance(); | 63 HistoryServiceFactory* factory = GetInstance(); |
| 64 factory->BrowserContextDestroyed(profile); | 64 factory->BrowserContextDestroyed(profile); |
| 65 } | 65 } |
| 66 | 66 |
| 67 HistoryServiceFactory::HistoryServiceFactory() | 67 HistoryServiceFactory::HistoryServiceFactory() |
| 68 : BrowserContextKeyedServiceFactory( | 68 : BrowserContextKeyedServiceFactory( |
| 69 "HistoryService", | 69 "HistoryService", |
| 70 BrowserContextDependencyManager::GetInstance()) { | 70 BrowserContextDependencyManager::GetInstance()) { |
| 71 DependsOn(BookmarkModelFactory::GetInstance()); | 71 DependsOn(BookmarkModelFactory::GetInstance()); |
| 72 DependsOn(ChromeBookmarkClientFactory::GetInstance()); | |
| 73 } | 72 } |
| 74 | 73 |
| 75 HistoryServiceFactory::~HistoryServiceFactory() { | 74 HistoryServiceFactory::~HistoryServiceFactory() { |
| 76 } | 75 } |
| 77 | 76 |
| 78 KeyedService* HistoryServiceFactory::BuildServiceInstanceFor( | 77 KeyedService* HistoryServiceFactory::BuildServiceInstanceFor( |
| 79 content::BrowserContext* context) const { | 78 content::BrowserContext* context) const { |
| 80 Profile* profile = Profile::FromBrowserContext(context); | 79 Profile* profile = Profile::FromBrowserContext(context); |
| 81 scoped_ptr<history::HistoryService> history_service( | 80 scoped_ptr<history::HistoryService> history_service( |
| 82 new history::HistoryService( | 81 new history::HistoryService( |
| 83 make_scoped_ptr(new ChromeHistoryClient( | 82 make_scoped_ptr(new ChromeHistoryClient( |
| 84 BookmarkModelFactory::GetForProfile(profile))), | 83 BookmarkModelFactory::GetForProfile(profile))), |
| 85 make_scoped_ptr(new history::ContentVisitDelegate(profile)))); | 84 make_scoped_ptr(new history::ContentVisitDelegate(profile)))); |
| 86 if (!history_service->Init( | 85 if (!history_service->Init( |
| 87 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), | 86 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 88 history::HistoryDatabaseParamsForPath(profile->GetPath()))) { | 87 history::HistoryDatabaseParamsForPath(profile->GetPath()))) { |
| 89 return nullptr; | 88 return nullptr; |
| 90 } | 89 } |
| 91 ChromeBookmarkClientFactory::GetForProfile(profile) | |
| 92 ->SetHistoryService(history_service.get()); | |
| 93 return history_service.release(); | 90 return history_service.release(); |
| 94 } | 91 } |
| 95 | 92 |
| 96 content::BrowserContext* HistoryServiceFactory::GetBrowserContextToUse( | 93 content::BrowserContext* HistoryServiceFactory::GetBrowserContextToUse( |
| 97 content::BrowserContext* context) const { | 94 content::BrowserContext* context) const { |
| 98 return chrome::GetBrowserContextRedirectedInIncognito(context); | 95 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 99 } | 96 } |
| 100 | 97 |
| 101 bool HistoryServiceFactory::ServiceIsNULLWhileTesting() const { | 98 bool HistoryServiceFactory::ServiceIsNULLWhileTesting() const { |
| 102 return true; | 99 return true; |
| 103 } | 100 } |
| OLD | NEW |