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.
5 #include "chrome/browser/favicon/favicon_service_factory.h"
7 #include "base/memory/singleton.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h"
10 #include "chrome/browser/history/history_service_factory.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "components/favicon/core/favicon_service.h"
13 #include "components/history/core/browser/history_service.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
17 favicon::FaviconService
* FaviconServiceFactory::GetForProfile(
19 ServiceAccessType sat
) {
20 if (!profile
->IsOffTheRecord()) {
21 return static_cast<favicon::FaviconService
*>(
22 GetInstance()->GetServiceForBrowserContext(profile
, true));
23 } else if (sat
== ServiceAccessType::EXPLICIT_ACCESS
) {
24 // Profile must be OffTheRecord in this case.
25 return static_cast<favicon::FaviconService
*>(
26 GetInstance()->GetServiceForBrowserContext(
27 profile
->GetOriginalProfile(), true));
30 // Profile is OffTheRecord without access.
31 NOTREACHED() << "This profile is OffTheRecord";
36 FaviconServiceFactory
* FaviconServiceFactory::GetInstance() {
37 return Singleton
<FaviconServiceFactory
>::get();
40 FaviconServiceFactory::FaviconServiceFactory()
41 : BrowserContextKeyedServiceFactory(
43 BrowserContextDependencyManager::GetInstance()) {
44 DependsOn(HistoryServiceFactory::GetInstance());
45 DependsOn(ChromeFaviconClientFactory::GetInstance());
48 FaviconServiceFactory::~FaviconServiceFactory() {
51 KeyedService
* FaviconServiceFactory::BuildServiceInstanceFor(
52 content::BrowserContext
* context
) const {
53 Profile
* profile
= Profile::FromBrowserContext(context
);
54 return new favicon::FaviconService(
55 ChromeFaviconClientFactory::GetForProfile(profile
),
56 HistoryServiceFactory::GetForProfile(profile
,
57 ServiceAccessType::EXPLICIT_ACCESS
));
60 bool FaviconServiceFactory::ServiceIsNULLWhileTesting() const {