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/ptr_util.h" |
10 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
11 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
13 #include "components/browser_sync/browser/profile_sync_service.h" | 14 #include "components/browser_sync/browser/profile_sync_service.h" |
14 #include "components/keyed_service/ios/browser_state_dependency_manager.h" | 15 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
15 #include "components/leveldb_proto/proto_database_impl.h" | 16 #include "components/leveldb_proto/proto_database_impl.h" |
16 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 17 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
17 #include "components/signin/core/browser/signin_manager.h" | 18 #include "components/signin/core/browser/signin_manager.h" |
18 #include "components/suggestions/blacklist_store.h" | 19 #include "components/suggestions/blacklist_store.h" |
19 #include "components/suggestions/image_fetcher.h" | 20 #include "components/suggestions/image_fetcher.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 "SuggestionsService", | 52 "SuggestionsService", |
52 BrowserStateDependencyManager::GetInstance()) { | 53 BrowserStateDependencyManager::GetInstance()) { |
53 DependsOn(ios::SigninManagerFactory::GetInstance()); | 54 DependsOn(ios::SigninManagerFactory::GetInstance()); |
54 DependsOn(OAuth2TokenServiceFactory::GetInstance()); | 55 DependsOn(OAuth2TokenServiceFactory::GetInstance()); |
55 DependsOn(IOSChromeProfileSyncServiceFactory::GetInstance()); | 56 DependsOn(IOSChromeProfileSyncServiceFactory::GetInstance()); |
56 } | 57 } |
57 | 58 |
58 SuggestionsServiceFactory::~SuggestionsServiceFactory() { | 59 SuggestionsServiceFactory::~SuggestionsServiceFactory() { |
59 } | 60 } |
60 | 61 |
61 scoped_ptr<KeyedService> SuggestionsServiceFactory::BuildServiceInstanceFor( | 62 std::unique_ptr<KeyedService> |
| 63 SuggestionsServiceFactory::BuildServiceInstanceFor( |
62 web::BrowserState* context) const { | 64 web::BrowserState* context) const { |
63 base::SequencedWorkerPool* sequenced_worker_pool = | 65 base::SequencedWorkerPool* sequenced_worker_pool = |
64 web::WebThread::GetBlockingPool(); | 66 web::WebThread::GetBlockingPool(); |
65 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 67 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
66 sequenced_worker_pool->GetSequencedTaskRunner( | 68 sequenced_worker_pool->GetSequencedTaskRunner( |
67 sequenced_worker_pool->GetSequenceToken()); | 69 sequenced_worker_pool->GetSequenceToken()); |
68 | 70 |
69 ios::ChromeBrowserState* browser_state = | 71 ios::ChromeBrowserState* browser_state = |
70 ios::ChromeBrowserState::FromBrowserState(context); | 72 ios::ChromeBrowserState::FromBrowserState(context); |
71 SigninManager* signin_manager = | 73 SigninManager* signin_manager = |
72 ios::SigninManagerFactory::GetForBrowserState(browser_state); | 74 ios::SigninManagerFactory::GetForBrowserState(browser_state); |
73 ProfileOAuth2TokenService* token_service = | 75 ProfileOAuth2TokenService* token_service = |
74 OAuth2TokenServiceFactory::GetForBrowserState(browser_state); | 76 OAuth2TokenServiceFactory::GetForBrowserState(browser_state); |
75 ProfileSyncService* sync_service = | 77 ProfileSyncService* sync_service = |
76 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state); | 78 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state); |
77 base::FilePath database_dir( | 79 base::FilePath database_dir( |
78 browser_state->GetStatePath().Append(kThumbnailDirectory)); | 80 browser_state->GetStatePath().Append(kThumbnailDirectory)); |
79 scoped_ptr<SuggestionsStore> suggestions_store( | 81 std::unique_ptr<SuggestionsStore> suggestions_store( |
80 new SuggestionsStore(browser_state->GetPrefs())); | 82 new SuggestionsStore(browser_state->GetPrefs())); |
81 scoped_ptr<BlacklistStore> blacklist_store( | 83 std::unique_ptr<BlacklistStore> blacklist_store( |
82 new BlacklistStore(browser_state->GetPrefs())); | 84 new BlacklistStore(browser_state->GetPrefs())); |
83 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ImageData>> db( | 85 std::unique_ptr<leveldb_proto::ProtoDatabaseImpl<ImageData>> db( |
84 new leveldb_proto::ProtoDatabaseImpl<ImageData>(background_task_runner)); | 86 new leveldb_proto::ProtoDatabaseImpl<ImageData>(background_task_runner)); |
85 scoped_ptr<ImageFetcher> image_fetcher(new ImageFetcherImpl( | 87 std::unique_ptr<ImageFetcher> image_fetcher(new ImageFetcherImpl( |
86 browser_state->GetRequestContext(), sequenced_worker_pool)); | 88 browser_state->GetRequestContext(), sequenced_worker_pool)); |
87 scoped_ptr<ImageManager> thumbnail_manager(new ImageManager( | 89 std::unique_ptr<ImageManager> thumbnail_manager(new ImageManager( |
88 std::move(image_fetcher), std::move(db), database_dir, | 90 std::move(image_fetcher), std::move(db), database_dir, |
89 web::WebThread::GetTaskRunnerForThread(web::WebThread::DB))); | 91 web::WebThread::GetTaskRunnerForThread(web::WebThread::DB))); |
90 return make_scoped_ptr(new SuggestionsService( | 92 return base::WrapUnique(new SuggestionsService( |
91 signin_manager, token_service, sync_service, | 93 signin_manager, token_service, sync_service, |
92 browser_state->GetRequestContext(), std::move(suggestions_store), | 94 browser_state->GetRequestContext(), std::move(suggestions_store), |
93 std::move(thumbnail_manager), std::move(blacklist_store))); | 95 std::move(thumbnail_manager), std::move(blacklist_store))); |
94 } | 96 } |
95 | 97 |
96 void SuggestionsServiceFactory::RegisterBrowserStatePrefs( | 98 void SuggestionsServiceFactory::RegisterBrowserStatePrefs( |
97 user_prefs::PrefRegistrySyncable* registry) { | 99 user_prefs::PrefRegistrySyncable* registry) { |
98 SuggestionsService::RegisterProfilePrefs(registry); | 100 SuggestionsService::RegisterProfilePrefs(registry); |
99 } | 101 } |
100 | 102 |
101 } // namespace suggestions | 103 } // namespace suggestions |
OLD | NEW |