| 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/favicon/favicon_service_factory.h" | 5 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 6 | 6 |
| 7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" | 9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" |
| 10 #include "chrome/browser/history/history_service_factory.h" | 10 #include "chrome/browser/history/history_service_factory.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "components/favicon/core/favicon_service.h" | 12 #include "components/favicon/core/favicon_service.h" |
| 13 #include "components/history/core/browser/history_service.h" | 13 #include "components/history/core/browser/history_service.h" |
| 14 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 14 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 15 #include "content/public/browser/browser_context.h" |
| 15 | 16 |
| 16 // static | 17 // static |
| 17 favicon::FaviconService* FaviconServiceFactory::GetForProfile( | 18 favicon::FaviconService* FaviconServiceFactory::GetForProfile( |
| 18 Profile* profile, | 19 Profile* profile, |
| 19 ServiceAccessType sat) { | 20 ServiceAccessType sat) { |
| 20 if (!profile->IsOffTheRecord()) { | 21 if (!profile->IsOffTheRecord()) { |
| 21 return static_cast<favicon::FaviconService*>( | 22 return static_cast<favicon::FaviconService*>( |
| 22 GetInstance()->GetServiceForBrowserContext(profile, true)); | 23 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 23 } else if (sat == ServiceAccessType::EXPLICIT_ACCESS) { | 24 } else if (sat == ServiceAccessType::EXPLICIT_ACCESS) { |
| 24 // Profile must be OffTheRecord in this case. | 25 // Profile must be OffTheRecord in this case. |
| 25 return static_cast<favicon::FaviconService*>( | 26 return static_cast<favicon::FaviconService*>( |
| 26 GetInstance()->GetServiceForBrowserContext( | 27 GetInstance()->GetServiceForBrowserContext( |
| 27 profile->GetOriginalProfile(), true)); | 28 profile->GetOriginalProfile(), true)); |
| 28 } | 29 } |
| 29 | 30 |
| 30 // Profile is OffTheRecord without access. | 31 // Profile is OffTheRecord without access. |
| 31 NOTREACHED() << "This profile is OffTheRecord"; | 32 NOTREACHED() << "This profile is OffTheRecord"; |
| 32 return NULL; | 33 return NULL; |
| 33 } | 34 } |
| 34 | 35 |
| 35 // static | 36 // static |
| 37 favicon::FaviconService* FaviconServiceFactory::GetForBrowserContext( |
| 38 content::BrowserContext* context) { |
| 39 return static_cast<favicon::FaviconService*>( |
| 40 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 41 } |
| 42 |
| 43 // static |
| 36 FaviconServiceFactory* FaviconServiceFactory::GetInstance() { | 44 FaviconServiceFactory* FaviconServiceFactory::GetInstance() { |
| 37 return Singleton<FaviconServiceFactory>::get(); | 45 return Singleton<FaviconServiceFactory>::get(); |
| 38 } | 46 } |
| 39 | 47 |
| 40 FaviconServiceFactory::FaviconServiceFactory() | 48 FaviconServiceFactory::FaviconServiceFactory() |
| 41 : BrowserContextKeyedServiceFactory( | 49 : BrowserContextKeyedServiceFactory( |
| 42 "FaviconService", | 50 "FaviconService", |
| 43 BrowserContextDependencyManager::GetInstance()) { | 51 BrowserContextDependencyManager::GetInstance()) { |
| 44 DependsOn(HistoryServiceFactory::GetInstance()); | 52 DependsOn(HistoryServiceFactory::GetInstance()); |
| 45 DependsOn(ChromeFaviconClientFactory::GetInstance()); | 53 DependsOn(ChromeFaviconClientFactory::GetInstance()); |
| 46 } | 54 } |
| 47 | 55 |
| 48 FaviconServiceFactory::~FaviconServiceFactory() { | 56 FaviconServiceFactory::~FaviconServiceFactory() { |
| 49 } | 57 } |
| 50 | 58 |
| 51 KeyedService* FaviconServiceFactory::BuildServiceInstanceFor( | 59 KeyedService* FaviconServiceFactory::BuildServiceInstanceFor( |
| 52 content::BrowserContext* context) const { | 60 content::BrowserContext* context) const { |
| 53 Profile* profile = Profile::FromBrowserContext(context); | 61 Profile* profile = Profile::FromBrowserContext(context); |
| 54 return new favicon::FaviconService( | 62 return new favicon::FaviconService( |
| 55 ChromeFaviconClientFactory::GetForProfile(profile), | 63 ChromeFaviconClientFactory::GetForProfile(profile), |
| 56 HistoryServiceFactory::GetForProfile(profile, | 64 HistoryServiceFactory::GetForProfile(profile, |
| 57 ServiceAccessType::EXPLICIT_ACCESS)); | 65 ServiceAccessType::EXPLICIT_ACCESS)); |
| 58 } | 66 } |
| 59 | 67 |
| 60 bool FaviconServiceFactory::ServiceIsNULLWhileTesting() const { | 68 bool FaviconServiceFactory::ServiceIsNULLWhileTesting() const { |
| 61 return true; | 69 return true; |
| 62 } | 70 } |
| OLD | NEW |