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/history/chrome_history_client.h" | |
9 #include "chrome/browser/history/history_service.h" | 10 #include "chrome/browser/history/history_service.h" |
10 #include "chrome/browser/profiles/incognito_helpers.h" | 11 #include "chrome/browser/profiles/incognito_helpers.h" |
11 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
12 #include "components/bookmarks/browser/bookmark_model.h" | 13 #include "components/bookmarks/browser/bookmark_model.h" |
13 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 14 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
14 | 15 |
16 using history::ChromeHistoryClient; | |
17 | |
15 // static | 18 // static |
16 HistoryService* HistoryServiceFactory::GetForProfile( | 19 HistoryService* HistoryServiceFactory::GetForProfile( |
17 Profile* profile, Profile::ServiceAccessType sat) { | 20 Profile* profile, Profile::ServiceAccessType sat) { |
18 // If saving history is disabled, only allow explicit access. | 21 // If saving history is disabled, only allow explicit access. |
19 if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && | 22 if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && |
20 sat != Profile::EXPLICIT_ACCESS) | 23 sat != Profile::EXPLICIT_ACCESS) |
21 return NULL; | 24 return NULL; |
22 | 25 |
23 return static_cast<HistoryService*>( | 26 ChromeHistoryClient* history_client = static_cast<ChromeHistoryClient*>( |
blundell
2014/05/27 09:56:38
If you're keeping HistoryServiceFactory, I think y
sdefresne
2014/05/28 17:10:42
Done with %s/FaviconService/HistoryService/g.
| |
24 GetInstance()->GetServiceForBrowserContext(profile, true)); | 27 GetInstance()->GetServiceForBrowserContext(profile, true)); |
28 return history_client ? history_client->history_service() : NULL; | |
25 } | 29 } |
26 | 30 |
27 // static | 31 // static |
28 HistoryService* | 32 HistoryService* |
29 HistoryServiceFactory::GetForProfileIfExists( | 33 HistoryServiceFactory::GetForProfileIfExists( |
30 Profile* profile, Profile::ServiceAccessType sat) { | 34 Profile* profile, Profile::ServiceAccessType sat) { |
31 // If saving history is disabled, only allow explicit access. | 35 // If saving history is disabled, only allow explicit access. |
32 if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && | 36 if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && |
33 sat != Profile::EXPLICIT_ACCESS) | 37 sat != Profile::EXPLICIT_ACCESS) |
34 return NULL; | 38 return NULL; |
35 | 39 |
36 return static_cast<HistoryService*>( | 40 ChromeHistoryClient* history_client = static_cast<ChromeHistoryClient*>( |
37 GetInstance()->GetServiceForBrowserContext(profile, false)); | 41 GetInstance()->GetServiceForBrowserContext(profile, false)); |
42 return history_client ? history_client->history_service() : NULL; | |
38 } | 43 } |
39 | 44 |
40 // static | 45 // static |
41 HistoryService* | 46 HistoryService* |
42 HistoryServiceFactory::GetForProfileWithoutCreating(Profile* profile) { | 47 HistoryServiceFactory::GetForProfileWithoutCreating(Profile* profile) { |
43 return static_cast<HistoryService*>( | 48 ChromeHistoryClient* history_client = static_cast<ChromeHistoryClient*>( |
44 GetInstance()->GetServiceForBrowserContext(profile, false)); | 49 GetInstance()->GetServiceForBrowserContext(profile, false)); |
50 return history_client ? history_client->history_service() : NULL; | |
45 } | 51 } |
46 | 52 |
47 // static | 53 // static |
48 HistoryServiceFactory* HistoryServiceFactory::GetInstance() { | 54 HistoryServiceFactory* HistoryServiceFactory::GetInstance() { |
49 return Singleton<HistoryServiceFactory>::get(); | 55 return Singleton<HistoryServiceFactory>::get(); |
50 } | 56 } |
51 | 57 |
52 // static | 58 // static |
53 void HistoryServiceFactory::ShutdownForProfile(Profile* profile) { | 59 void HistoryServiceFactory::ShutdownForProfile(Profile* profile) { |
54 HistoryServiceFactory* factory = GetInstance(); | 60 HistoryServiceFactory* factory = GetInstance(); |
55 factory->BrowserContextDestroyed(profile); | 61 factory->BrowserContextDestroyed(profile); |
56 } | 62 } |
57 | 63 |
58 HistoryServiceFactory::HistoryServiceFactory() | 64 HistoryServiceFactory::HistoryServiceFactory() |
59 : BrowserContextKeyedServiceFactory( | 65 : BrowserContextKeyedServiceFactory( |
60 "HistoryService", BrowserContextDependencyManager::GetInstance()) { | 66 "HistoryService", BrowserContextDependencyManager::GetInstance()) { |
61 DependsOn(BookmarkModelFactory::GetInstance()); | 67 DependsOn(BookmarkModelFactory::GetInstance()); |
62 } | 68 } |
63 | 69 |
64 HistoryServiceFactory::~HistoryServiceFactory() { | 70 HistoryServiceFactory::~HistoryServiceFactory() { |
65 } | 71 } |
66 | 72 |
67 KeyedService* HistoryServiceFactory::BuildServiceInstanceFor( | 73 KeyedService* HistoryServiceFactory::BuildServiceInstanceFor( |
68 content::BrowserContext* context) const { | 74 content::BrowserContext* context) const { |
69 Profile* profile = static_cast<Profile*>(context); | 75 Profile* profile = static_cast<Profile*>(context); |
70 HistoryService* history_service = new HistoryService(profile); | 76 ChromeHistoryClient* history_client = new ChromeHistoryClient(profile); |
77 HistoryService* history_service = history_client->history_service(); | |
71 if (!history_service->Init(profile->GetPath(), | 78 if (!history_service->Init(profile->GetPath(), |
72 BookmarkModelFactory::GetForProfile(profile))) { | 79 BookmarkModelFactory::GetForProfile(profile))) { |
73 return NULL; | 80 return NULL; |
74 } | 81 } |
75 return history_service; | 82 return history_client; |
76 } | 83 } |
77 | 84 |
78 content::BrowserContext* HistoryServiceFactory::GetBrowserContextToUse( | 85 content::BrowserContext* HistoryServiceFactory::GetBrowserContextToUse( |
79 content::BrowserContext* context) const { | 86 content::BrowserContext* context) const { |
80 return chrome::GetBrowserContextRedirectedInIncognito(context); | 87 return chrome::GetBrowserContextRedirectedInIncognito(context); |
81 } | 88 } |
82 | 89 |
83 bool HistoryServiceFactory::ServiceIsNULLWhileTesting() const { | 90 bool HistoryServiceFactory::ServiceIsNULLWhileTesting() const { |
84 return true; | 91 return true; |
85 } | 92 } |
OLD | NEW |