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/bookmarks/bookmark_client_factory.h"
7 #include "base/memory/singleton.h"
8 #include "components/keyed_service/core/service_access_type.h"
9 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
10 #include "ios/chrome/browser/bookmarks/bookmark_client_impl.h"
11 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
12 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
13 #include "ios/public/provider/chrome/browser/keyed_service_provider.h"
17 scoped_ptr
<KeyedService
> BuildBookmarkClientImpl(web::BrowserState
* context
) {
18 ios::ChromeBrowserState
* browser_state
=
19 ios::ChromeBrowserState::FromBrowserState(context
);
20 return make_scoped_ptr(new BookmarkClientImpl(
22 ios::GetKeyedServiceProvider()->GetManagedBookmarkServiceForBrowserState(
29 BookmarkClientImpl
* BookmarkClientFactory::GetForBrowserState(
30 ios::ChromeBrowserState
* browser_state
) {
31 return static_cast<BookmarkClientImpl
*>(
32 GetInstance()->GetServiceForBrowserState(browser_state
, true));
36 BookmarkClientFactory
* BookmarkClientFactory::GetInstance() {
37 return Singleton
<BookmarkClientFactory
>::get();
41 BrowserStateKeyedServiceFactory::TestingFactoryFunction
42 BookmarkClientFactory::GetDefaultFactory() {
43 return &BuildBookmarkClientImpl
;
46 BookmarkClientFactory::BookmarkClientFactory()
47 : BrowserStateKeyedServiceFactory(
49 BrowserStateDependencyManager::GetInstance()) {
50 DependsOn(ios::GetKeyedServiceProvider()->GetManagedBookmarkServiceFactory());
53 BookmarkClientFactory::~BookmarkClientFactory() {}
55 scoped_ptr
<KeyedService
> BookmarkClientFactory::BuildServiceInstanceFor(
56 web::BrowserState
* context
) const {
57 return BuildBookmarkClientImpl(context
).Pass();
60 web::BrowserState
* BookmarkClientFactory::GetBrowserStateToUse(
61 web::BrowserState
* context
) const {
62 return GetBrowserStateRedirectedInIncognito(context
);
65 bool BookmarkClientFactory::ServiceIsNULLWhileTesting() const {