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.h" | 8 #include "chrome/browser/bookmarks/bookmark_model.h" |
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
10 #include "chrome/browser/history/history_service.h" | 10 #include "chrome/browser/history/history_service.h" |
11 #include "chrome/browser/profiles/incognito_helpers.h" | 11 #include "chrome/browser/profiles/incognito_helpers.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 13 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
14 | 14 |
15 // static | 15 // static |
16 HistoryService* HistoryServiceFactory::GetForProfile( | 16 HistoryService* HistoryServiceFactory::GetForProfile( |
17 Profile* profile, Profile::ServiceAccessType sat) { | 17 Profile* profile, Profile::ServiceAccessType sat) { |
18 // If saving history is disabled, only allow explicit access. | 18 // If saving history is disabled, only allow explicit access. |
19 if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && | 19 if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && |
20 sat != Profile::EXPLICIT_ACCESS) | 20 sat != Profile::EXPLICIT_ACCESS) |
21 return NULL; | 21 return NULL; |
22 | 22 |
23 return static_cast<HistoryService*>( | 23 return static_cast<HistoryService*>( |
24 GetInstance()->GetServiceForProfile(profile, true)); | 24 GetInstance()->GetServiceForBrowserContext(profile, true)); |
25 } | 25 } |
26 | 26 |
27 // static | 27 // static |
28 HistoryService* | 28 HistoryService* |
29 HistoryServiceFactory::GetForProfileIfExists( | 29 HistoryServiceFactory::GetForProfileIfExists( |
30 Profile* profile, Profile::ServiceAccessType sat) { | 30 Profile* profile, Profile::ServiceAccessType sat) { |
31 // If saving history is disabled, only allow explicit access. | 31 // If saving history is disabled, only allow explicit access. |
32 if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && | 32 if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && |
33 sat != Profile::EXPLICIT_ACCESS) | 33 sat != Profile::EXPLICIT_ACCESS) |
34 return NULL; | 34 return NULL; |
35 | 35 |
36 return static_cast<HistoryService*>( | 36 return static_cast<HistoryService*>( |
37 GetInstance()->GetServiceForProfile(profile, false)); | 37 GetInstance()->GetServiceForBrowserContext(profile, false)); |
38 } | 38 } |
39 | 39 |
40 // static | 40 // static |
41 HistoryService* | 41 HistoryService* |
42 HistoryServiceFactory::GetForProfileWithoutCreating(Profile* profile) { | 42 HistoryServiceFactory::GetForProfileWithoutCreating(Profile* profile) { |
43 return static_cast<HistoryService*>( | 43 return static_cast<HistoryService*>( |
44 GetInstance()->GetServiceForProfile(profile, false)); | 44 GetInstance()->GetServiceForBrowserContext(profile, false)); |
45 } | 45 } |
46 | 46 |
47 // static | 47 // static |
48 HistoryServiceFactory* HistoryServiceFactory::GetInstance() { | 48 HistoryServiceFactory* HistoryServiceFactory::GetInstance() { |
49 return Singleton<HistoryServiceFactory>::get(); | 49 return Singleton<HistoryServiceFactory>::get(); |
50 } | 50 } |
51 | 51 |
52 // static | 52 // static |
53 void HistoryServiceFactory::ShutdownForProfile(Profile* profile) { | 53 void HistoryServiceFactory::ShutdownForProfile(Profile* profile) { |
54 HistoryServiceFactory* factory = GetInstance(); | 54 HistoryServiceFactory* factory = GetInstance(); |
55 factory->ProfileDestroyed(profile); | 55 factory->BrowserContextDestroyed(profile); |
56 } | 56 } |
57 | 57 |
58 HistoryServiceFactory::HistoryServiceFactory() | 58 HistoryServiceFactory::HistoryServiceFactory() |
59 : ProfileKeyedServiceFactory( | 59 : BrowserContextKeyedServiceFactory( |
60 "HistoryService", ProfileDependencyManager::GetInstance()) { | 60 "HistoryService", BrowserContextDependencyManager::GetInstance()) { |
61 DependsOn(BookmarkModelFactory::GetInstance()); | 61 DependsOn(BookmarkModelFactory::GetInstance()); |
62 } | 62 } |
63 | 63 |
64 HistoryServiceFactory::~HistoryServiceFactory() { | 64 HistoryServiceFactory::~HistoryServiceFactory() { |
65 } | 65 } |
66 | 66 |
67 ProfileKeyedService* | 67 BrowserContextKeyedService* |
68 HistoryServiceFactory::BuildServiceInstanceFor( | 68 HistoryServiceFactory::BuildServiceInstanceFor( |
69 content::BrowserContext* context) const { | 69 content::BrowserContext* context) const { |
70 Profile* profile = static_cast<Profile*>(context); | 70 Profile* profile = static_cast<Profile*>(context); |
71 HistoryService* history_service = new HistoryService(profile); | 71 HistoryService* history_service = new HistoryService(profile); |
72 if (!history_service->Init(profile->GetPath(), | 72 if (!history_service->Init(profile->GetPath(), |
73 BookmarkModelFactory::GetForProfile(profile))) { | 73 BookmarkModelFactory::GetForProfile(profile))) { |
74 return NULL; | 74 return NULL; |
75 } | 75 } |
76 return history_service; | 76 return history_service; |
77 } | 77 } |
78 | 78 |
79 content::BrowserContext* HistoryServiceFactory::GetBrowserContextToUse( | 79 content::BrowserContext* HistoryServiceFactory::GetBrowserContextToUse( |
80 content::BrowserContext* context) const { | 80 content::BrowserContext* context) const { |
81 return chrome::GetBrowserContextRedirectedInIncognito(context); | 81 return chrome::GetBrowserContextRedirectedInIncognito(context); |
82 } | 82 } |
83 | 83 |
84 bool HistoryServiceFactory::ServiceIsNULLWhileTesting() const { | 84 bool HistoryServiceFactory::ServiceIsNULLWhileTesting() const { |
85 return true; | 85 return true; |
86 } | 86 } |
OLD | NEW |