Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / favicon / favicon_service_factory.cc
blob726b5620c91df5a58159a09a9f0f57d8b7b1877b
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.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"
16 namespace {
18 scoped_ptr<KeyedService> BuildFaviconService(content::BrowserContext* context) {
19 Profile* profile = Profile::FromBrowserContext(context);
20 return make_scoped_ptr(new favicon::FaviconService(
21 make_scoped_ptr(new ChromeFaviconClient(profile)),
22 HistoryServiceFactory::GetForProfile(
23 profile, ServiceAccessType::EXPLICIT_ACCESS)));
26 } // namespace
28 // static
29 favicon::FaviconService* FaviconServiceFactory::GetForProfile(
30 Profile* profile,
31 ServiceAccessType sat) {
32 if (!profile->IsOffTheRecord()) {
33 return static_cast<favicon::FaviconService*>(
34 GetInstance()->GetServiceForBrowserContext(profile, true));
35 } else if (sat == ServiceAccessType::EXPLICIT_ACCESS) {
36 // Profile must be OffTheRecord in this case.
37 return static_cast<favicon::FaviconService*>(
38 GetInstance()->GetServiceForBrowserContext(
39 profile->GetOriginalProfile(), true));
42 // Profile is OffTheRecord without access.
43 NOTREACHED() << "This profile is OffTheRecord";
44 return NULL;
47 // static
48 FaviconServiceFactory* FaviconServiceFactory::GetInstance() {
49 return base::Singleton<FaviconServiceFactory>::get();
52 // static
53 BrowserContextKeyedServiceFactory::TestingFactoryFunction
54 FaviconServiceFactory::GetDefaultFactory() {
55 return &BuildFaviconService;
58 FaviconServiceFactory::FaviconServiceFactory()
59 : BrowserContextKeyedServiceFactory(
60 "FaviconService",
61 BrowserContextDependencyManager::GetInstance()) {
62 DependsOn(HistoryServiceFactory::GetInstance());
65 FaviconServiceFactory::~FaviconServiceFactory() {
68 KeyedService* FaviconServiceFactory::BuildServiceInstanceFor(
69 content::BrowserContext* context) const {
70 return BuildFaviconService(context).release();
73 bool FaviconServiceFactory::ServiceIsNULLWhileTesting() const {
74 return true;