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/public/test/test_keyed_service_provider.h"
7 #include "base/logging.h"
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/singleton.h"
11 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
14 #include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
15 #include "components/sync_driver/fake_sync_service.h"
16 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
17 #include "ios/public/test/fake_sync_service_factory.h"
22 class MissingServiceKeyedServiceFactory
23 : public BrowserStateKeyedServiceFactory
{
25 static MissingServiceKeyedServiceFactory
* GetInstance();
28 friend struct DefaultSingletonTraits
<MissingServiceKeyedServiceFactory
>;
30 MissingServiceKeyedServiceFactory();
31 ~MissingServiceKeyedServiceFactory() override
;
33 // BrowserStateKeyedServiceFactory implementation.
34 scoped_ptr
<KeyedService
> BuildServiceInstanceFor(
35 web::BrowserState
* context
) const override
;
37 DISALLOW_COPY_AND_ASSIGN(MissingServiceKeyedServiceFactory
);
41 MissingServiceKeyedServiceFactory
*
42 MissingServiceKeyedServiceFactory::GetInstance() {
43 return Singleton
<MissingServiceKeyedServiceFactory
>::get();
46 MissingServiceKeyedServiceFactory::MissingServiceKeyedServiceFactory()
47 : BrowserStateKeyedServiceFactory(
49 BrowserStateDependencyManager::GetInstance()) {
52 MissingServiceKeyedServiceFactory::~MissingServiceKeyedServiceFactory() {
55 scoped_ptr
<KeyedService
>
56 MissingServiceKeyedServiceFactory::BuildServiceInstanceFor(
57 web::BrowserState
* context
) const {
64 TestKeyedServiceProvider::TestKeyedServiceProvider() {
67 TestKeyedServiceProvider::~TestKeyedServiceProvider() {
70 void TestKeyedServiceProvider::AssertKeyedFactoriesBuilt() {
71 FakeSyncServiceFactory::GetInstance();
72 MissingServiceKeyedServiceFactory::GetInstance();
75 KeyedServiceBaseFactory
* TestKeyedServiceProvider::GetBookmarkModelFactory() {
76 return MissingServiceKeyedServiceFactory::GetInstance();
79 bookmarks::BookmarkModel
*
80 TestKeyedServiceProvider::GetBookmarkModelForBrowserState(
81 ChromeBrowserState
* browser_state
) {
85 KeyedServiceBaseFactory
* TestKeyedServiceProvider::GetSyncServiceFactory() {
86 return FakeSyncServiceFactory::GetInstance();
89 sync_driver::SyncService
*
90 TestKeyedServiceProvider::GetSyncServiceForBrowserState(
91 ChromeBrowserState
* browser_state
) {
92 return FakeSyncServiceFactory::GetForBrowserState(browser_state
);