OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/history/history_service_factory.h" |
| 6 |
| 7 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 9 #include "chrome/browser/history/history.h" |
| 10 #include "chrome/browser/prefs/pref_service.h" |
| 11 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 12 #include "chrome/common/pref_names.h" |
| 13 |
| 14 // static |
| 15 scoped_refptr<HistoryService> HistoryServiceFactory::GetForProfile( |
| 16 Profile* profile, Profile::ServiceAccessType sat) { |
| 17 // If saving history is disabled, only allow explicit access. |
| 18 if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && |
| 19 sat != Profile::EXPLICIT_ACCESS) |
| 20 return NULL; |
| 21 |
| 22 return static_cast<HistoryService*>( |
| 23 GetInstance()->GetServiceForProfile(profile, true).get()); |
| 24 } |
| 25 |
| 26 // static |
| 27 scoped_refptr<HistoryService> |
| 28 HistoryServiceFactory::GetForProfileIfExists(Profile* profile) { |
| 29 return static_cast<HistoryService*>( |
| 30 GetInstance()->GetServiceForProfile(profile, false).get()); |
| 31 } |
| 32 |
| 33 // static |
| 34 HistoryServiceFactory* HistoryServiceFactory::GetInstance() { |
| 35 return Singleton<HistoryServiceFactory>::get(); |
| 36 } |
| 37 |
| 38 // static |
| 39 void HistoryServiceFactory::ShutdownForProfile(Profile* profile) { |
| 40 HistoryServiceFactory* factory = GetInstance(); |
| 41 factory->ProfileDestroyed(profile); |
| 42 } |
| 43 |
| 44 HistoryServiceFactory::HistoryServiceFactory() |
| 45 : RefcountedProfileKeyedServiceFactory( |
| 46 "HistoryService", ProfileDependencyManager::GetInstance()) { |
| 47 DependsOn(BookmarkModelFactory::GetInstance()); |
| 48 } |
| 49 |
| 50 HistoryServiceFactory::~HistoryServiceFactory() { |
| 51 } |
| 52 |
| 53 scoped_refptr<RefcountedProfileKeyedService> |
| 54 HistoryServiceFactory::BuildServiceInstanceFor(Profile* profile) const { |
| 55 scoped_refptr<HistoryService> history_service( |
| 56 new HistoryService(profile)); |
| 57 if (!history_service->Init(profile->GetPath(), |
| 58 BookmarkModelFactory::GetForProfile(profile))) { |
| 59 return NULL; |
| 60 } |
| 61 return history_service; |
| 62 } |
| 63 |
| 64 bool HistoryServiceFactory::ServiceRedirectedInIncognito() { |
| 65 return true; |
| 66 } |
| 67 |
| 68 bool HistoryServiceFactory::ServiceIsNULLWhileTesting() { |
| 69 return true; |
| 70 } |
OLD | NEW |