OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ios/chrome/browser/suggestions/suggestions_service_factory.h" | 5 #include "ios/chrome/browser/suggestions/suggestions_service_factory.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "components/browser_sync/browser/profile_sync_service.h" |
13 #include "components/keyed_service/ios/browser_state_dependency_manager.h" | 14 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
14 #include "components/leveldb_proto/proto_database_impl.h" | 15 #include "components/leveldb_proto/proto_database_impl.h" |
15 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 16 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
16 #include "components/signin/core/browser/signin_manager.h" | 17 #include "components/signin/core/browser/signin_manager.h" |
17 #include "components/suggestions/blacklist_store.h" | 18 #include "components/suggestions/blacklist_store.h" |
18 #include "components/suggestions/image_fetcher.h" | 19 #include "components/suggestions/image_fetcher.h" |
19 #include "components/suggestions/image_manager.h" | 20 #include "components/suggestions/image_manager.h" |
20 #include "components/suggestions/suggestions_service.h" | 21 #include "components/suggestions/suggestions_service.h" |
21 #include "components/suggestions/suggestions_store.h" | 22 #include "components/suggestions/suggestions_store.h" |
22 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 23 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
23 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h" | 24 #include "ios/chrome/browser/signin/oauth2_token_service_factory.h" |
24 #include "ios/chrome/browser/signin/signin_manager_factory.h" | 25 #include "ios/chrome/browser/signin/signin_manager_factory.h" |
25 #include "ios/chrome/browser/suggestions/image_fetcher_impl.h" | 26 #include "ios/chrome/browser/suggestions/image_fetcher_impl.h" |
| 27 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
26 #include "ios/web/public/browser_state.h" | 28 #include "ios/web/public/browser_state.h" |
27 #include "ios/web/public/web_thread.h" | 29 #include "ios/web/public/web_thread.h" |
28 | 30 |
29 namespace suggestions { | 31 namespace suggestions { |
30 namespace { | 32 namespace { |
31 const base::FilePath::CharType kThumbnailDirectory[] = | 33 const base::FilePath::CharType kThumbnailDirectory[] = |
32 FILE_PATH_LITERAL("Thumbnail"); | 34 FILE_PATH_LITERAL("Thumbnail"); |
33 } | 35 } |
34 | 36 |
35 // static | 37 // static |
36 SuggestionsServiceFactory* SuggestionsServiceFactory::GetInstance() { | 38 SuggestionsServiceFactory* SuggestionsServiceFactory::GetInstance() { |
37 return base::Singleton<SuggestionsServiceFactory>::get(); | 39 return base::Singleton<SuggestionsServiceFactory>::get(); |
38 } | 40 } |
39 | 41 |
40 // static | 42 // static |
41 SuggestionsService* SuggestionsServiceFactory::GetForBrowserState( | 43 SuggestionsService* SuggestionsServiceFactory::GetForBrowserState( |
42 ios::ChromeBrowserState* browser_state) { | 44 ios::ChromeBrowserState* browser_state) { |
43 return static_cast<SuggestionsService*>( | 45 return static_cast<SuggestionsService*>( |
44 GetInstance()->GetServiceForBrowserState(browser_state, true)); | 46 GetInstance()->GetServiceForBrowserState(browser_state, true)); |
45 } | 47 } |
46 | 48 |
47 SuggestionsServiceFactory::SuggestionsServiceFactory() | 49 SuggestionsServiceFactory::SuggestionsServiceFactory() |
48 : BrowserStateKeyedServiceFactory( | 50 : BrowserStateKeyedServiceFactory( |
49 "SuggestionsService", | 51 "SuggestionsService", |
50 BrowserStateDependencyManager::GetInstance()) { | 52 BrowserStateDependencyManager::GetInstance()) { |
51 DependsOn(ios::SigninManagerFactory::GetInstance()); | 53 DependsOn(ios::SigninManagerFactory::GetInstance()); |
52 DependsOn(OAuth2TokenServiceFactory::GetInstance()); | 54 DependsOn(OAuth2TokenServiceFactory::GetInstance()); |
| 55 DependsOn(IOSChromeProfileSyncServiceFactory::GetInstance()); |
53 } | 56 } |
54 | 57 |
55 SuggestionsServiceFactory::~SuggestionsServiceFactory() { | 58 SuggestionsServiceFactory::~SuggestionsServiceFactory() { |
56 } | 59 } |
57 | 60 |
58 scoped_ptr<KeyedService> SuggestionsServiceFactory::BuildServiceInstanceFor( | 61 scoped_ptr<KeyedService> SuggestionsServiceFactory::BuildServiceInstanceFor( |
59 web::BrowserState* context) const { | 62 web::BrowserState* context) const { |
60 base::SequencedWorkerPool* sequenced_worker_pool = | 63 base::SequencedWorkerPool* sequenced_worker_pool = |
61 web::WebThread::GetBlockingPool(); | 64 web::WebThread::GetBlockingPool(); |
62 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 65 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
63 sequenced_worker_pool->GetSequencedTaskRunner( | 66 sequenced_worker_pool->GetSequencedTaskRunner( |
64 sequenced_worker_pool->GetSequenceToken()); | 67 sequenced_worker_pool->GetSequenceToken()); |
65 | 68 |
66 ios::ChromeBrowserState* browser_state = | 69 ios::ChromeBrowserState* browser_state = |
67 ios::ChromeBrowserState::FromBrowserState(context); | 70 ios::ChromeBrowserState::FromBrowserState(context); |
68 SigninManager* signin_manager = | 71 SigninManager* signin_manager = |
69 ios::SigninManagerFactory::GetForBrowserState(browser_state); | 72 ios::SigninManagerFactory::GetForBrowserState(browser_state); |
70 ProfileOAuth2TokenService* token_service = | 73 ProfileOAuth2TokenService* token_service = |
71 OAuth2TokenServiceFactory::GetForBrowserState(browser_state); | 74 OAuth2TokenServiceFactory::GetForBrowserState(browser_state); |
| 75 ProfileSyncService* sync_service = |
| 76 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state); |
72 base::FilePath database_dir( | 77 base::FilePath database_dir( |
73 browser_state->GetStatePath().Append(kThumbnailDirectory)); | 78 browser_state->GetStatePath().Append(kThumbnailDirectory)); |
74 scoped_ptr<SuggestionsStore> suggestions_store( | 79 scoped_ptr<SuggestionsStore> suggestions_store( |
75 new SuggestionsStore(browser_state->GetPrefs())); | 80 new SuggestionsStore(browser_state->GetPrefs())); |
76 scoped_ptr<BlacklistStore> blacklist_store( | 81 scoped_ptr<BlacklistStore> blacklist_store( |
77 new BlacklistStore(browser_state->GetPrefs())); | 82 new BlacklistStore(browser_state->GetPrefs())); |
78 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ImageData>> db( | 83 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ImageData>> db( |
79 new leveldb_proto::ProtoDatabaseImpl<ImageData>(background_task_runner)); | 84 new leveldb_proto::ProtoDatabaseImpl<ImageData>(background_task_runner)); |
80 scoped_ptr<ImageFetcher> image_fetcher(new ImageFetcherImpl( | 85 scoped_ptr<ImageFetcher> image_fetcher(new ImageFetcherImpl( |
81 browser_state->GetRequestContext(), sequenced_worker_pool)); | 86 browser_state->GetRequestContext(), sequenced_worker_pool)); |
82 scoped_ptr<ImageManager> thumbnail_manager(new ImageManager( | 87 scoped_ptr<ImageManager> thumbnail_manager(new ImageManager( |
83 std::move(image_fetcher), std::move(db), database_dir, | 88 std::move(image_fetcher), std::move(db), database_dir, |
84 web::WebThread::GetTaskRunnerForThread(web::WebThread::DB))); | 89 web::WebThread::GetTaskRunnerForThread(web::WebThread::DB))); |
85 return make_scoped_ptr(new SuggestionsService( | 90 return make_scoped_ptr(new SuggestionsService( |
86 signin_manager, token_service, browser_state->GetRequestContext(), | 91 signin_manager, token_service, sync_service, |
87 std::move(suggestions_store), std::move(thumbnail_manager), | 92 browser_state->GetRequestContext(), std::move(suggestions_store), |
88 std::move(blacklist_store))); | 93 std::move(thumbnail_manager), std::move(blacklist_store))); |
89 } | 94 } |
90 | 95 |
91 void SuggestionsServiceFactory::RegisterBrowserStatePrefs( | 96 void SuggestionsServiceFactory::RegisterBrowserStatePrefs( |
92 user_prefs::PrefRegistrySyncable* registry) { | 97 user_prefs::PrefRegistrySyncable* registry) { |
93 SuggestionsService::RegisterProfilePrefs(registry); | 98 SuggestionsService::RegisterProfilePrefs(registry); |
94 } | 99 } |
95 | 100 |
96 } // namespace suggestions | 101 } // namespace suggestions |
OLD | NEW |