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/enhanced_bookmarks/bookmark_server_cluster_service_factory.h"
7 #include "base/logging.h"
8 #include "base/memory/singleton.h"
9 #include "components/enhanced_bookmarks/bookmark_server_cluster_service.h"
10 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
11 #include "components/signin/core/browser/profile_oauth2_token_service.h"
12 #include "components/signin/core/browser/signin_manager.h"
13 #include "ios/chrome/browser/application_context.h"
14 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
15 #include "ios/chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h"
16 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h"
17 #include "ios/chrome/browser/signin/signin_manager_factory.h"
18 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
19 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
20 #include "ios/public/provider/chrome/browser/keyed_service_provider.h"
22 namespace enhanced_bookmarks
{
25 BookmarkServerClusterServiceFactory
*
26 BookmarkServerClusterServiceFactory::GetInstance() {
27 return Singleton
<BookmarkServerClusterServiceFactory
>::get();
31 BookmarkServerClusterService
*
32 BookmarkServerClusterServiceFactory::GetForBrowserState(
33 ios::ChromeBrowserState
* browser_state
) {
34 return static_cast<BookmarkServerClusterService
*>(
35 GetInstance()->GetServiceForBrowserState(browser_state
, true));
38 BookmarkServerClusterServiceFactory::BookmarkServerClusterServiceFactory()
39 : BrowserStateKeyedServiceFactory(
40 "BookmarkServerClusterService",
41 BrowserStateDependencyManager::GetInstance()) {
42 ios::KeyedServiceProvider
* provider
= ios::GetKeyedServiceProvider();
43 DependsOn(OAuth2TokenServiceFactory::GetInstance());
44 DependsOn(ios::SigninManagerFactory::GetInstance());
45 DependsOn(EnhancedBookmarkModelFactory::GetInstance());
46 DependsOn(provider
->GetSyncServiceFactory());
49 BookmarkServerClusterServiceFactory::~BookmarkServerClusterServiceFactory() {
52 scoped_ptr
<KeyedService
>
53 BookmarkServerClusterServiceFactory::BuildServiceInstanceFor(
54 web::BrowserState
* context
) const {
55 DCHECK(!context
->IsOffTheRecord());
56 ios::ChromeBrowserState
* browser_state
=
57 ios::ChromeBrowserState::FromBrowserState(context
);
58 ios::KeyedServiceProvider
* provider
= ios::GetKeyedServiceProvider();
59 return make_scoped_ptr(new BookmarkServerClusterService(
60 GetApplicationContext()->GetApplicationLocale(),
61 browser_state
->GetRequestContext(),
62 OAuth2TokenServiceFactory::GetForBrowserState(browser_state
),
63 ios::SigninManagerFactory::GetForBrowserState(browser_state
),
64 EnhancedBookmarkModelFactory::GetForBrowserState(browser_state
),
65 provider
->GetSyncServiceForBrowserState(browser_state
),
66 browser_state
->GetPrefs()));
69 web::BrowserState
* BookmarkServerClusterServiceFactory::GetBrowserStateToUse(
70 web::BrowserState
* context
) const {
71 return GetBrowserStateRedirectedInIncognito(context
);
74 } // namespace enhanced_bookmarks