Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / ios / chrome / browser / favicon / favicon_service_factory.cc
bloba101ca7affdd61d18aad8b10793d0a13ad1b5f52
1 // Copyright 2015 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 "ios/chrome/browser/favicon/favicon_service_factory.h"
7 #include "base/memory/singleton.h"
8 #include "components/favicon/core/favicon_service.h"
9 #include "components/keyed_service/core/service_access_type.h"
10 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
11 #include "ios/chrome/browser/favicon/favicon_client_impl.h"
12 #include "ios/chrome/browser/history/history_service_factory.h"
13 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
15 namespace ios {
17 // static
18 favicon::FaviconService* FaviconServiceFactory::GetForBrowserState(
19 ios::ChromeBrowserState* browser_state,
20 ServiceAccessType access_type) {
21 if (!browser_state->IsOffTheRecord()) {
22 return static_cast<favicon::FaviconService*>(
23 GetInstance()->GetServiceForBrowserState(browser_state, true));
24 } else if (access_type == ServiceAccessType::EXPLICIT_ACCESS) {
25 return static_cast<favicon::FaviconService*>(
26 GetInstance()->GetServiceForBrowserState(
27 browser_state->GetOriginalChromeBrowserState(), true));
30 // ios::ChromeBrowserState is OffTheRecord without access.
31 NOTREACHED() << "ChromeBrowserState is OffTheRecord";
32 return nullptr;
35 // static
36 FaviconServiceFactory* FaviconServiceFactory::GetInstance() {
37 return Singleton<FaviconServiceFactory>::get();
40 FaviconServiceFactory::FaviconServiceFactory()
41 : BrowserStateKeyedServiceFactory(
42 "FaviconService",
43 BrowserStateDependencyManager::GetInstance()) {
44 DependsOn(ios::HistoryServiceFactory::GetInstance());
47 FaviconServiceFactory::~FaviconServiceFactory() {
50 scoped_ptr<KeyedService> FaviconServiceFactory::BuildServiceInstanceFor(
51 web::BrowserState* context) const {
52 ios::ChromeBrowserState* browser_state =
53 ios::ChromeBrowserState::FromBrowserState(context);
54 return make_scoped_ptr(new favicon::FaviconService(
55 make_scoped_ptr(new FaviconClientImpl),
56 ios::HistoryServiceFactory::GetForBrowserState(
57 browser_state, ServiceAccessType::EXPLICIT_ACCESS)));
60 bool FaviconServiceFactory::ServiceIsNULLWhileTesting() const {
61 return true;
64 } // namespace ios