Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: ios/chrome/browser/suggestions/suggestions_service_factory.mm

Issue 790773003: Upstream iOS SuggestionsServiceFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@436897.1
Patch Set: Rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/suggestions/suggestions_service_factory.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/suggestions/suggestions_service_factory.mm
diff --git a/ios/chrome/browser/suggestions/suggestions_service_factory.mm b/ios/chrome/browser/suggestions/suggestions_service_factory.mm
new file mode 100644
index 0000000000000000000000000000000000000000..efd35e5ba21a1fa0b28e348d769a2af585877fd7
--- /dev/null
+++ b/ios/chrome/browser/suggestions/suggestions_service_factory.mm
@@ -0,0 +1,83 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/chrome/browser/suggestions/suggestions_service_factory.h"
+
+#include "base/files/file_path.h"
+#include "base/memory/singleton.h"
+#include "base/sequenced_task_runner.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "components/keyed_service/ios/browser_state_dependency_manager.h"
+#include "components/leveldb_proto/proto_database_impl.h"
+#include "components/suggestions/blacklist_store.h"
+#include "components/suggestions/image_fetcher.h"
+#include "components/suggestions/image_manager.h"
+#include "components/suggestions/suggestions_service.h"
+#include "components/suggestions/suggestions_store.h"
+#include "ios/chrome/browser/suggestions/image_fetcher_impl.h"
+#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
+#include "ios/web/public/browser_state.h"
+#include "ios/web/public/web_thread.h"
+
+namespace suggestions {
+namespace {
+const base::FilePath::CharType kThumbnailDirectory[] =
+ FILE_PATH_LITERAL("Thumbnail");
+}
+
+// static
+SuggestionsServiceFactory* SuggestionsServiceFactory::GetInstance() {
+ return Singleton<SuggestionsServiceFactory>::get();
+}
+
+// static
+SuggestionsService* SuggestionsServiceFactory::GetForBrowserState(
+ web::BrowserState* browser_state) {
+ return static_cast<SuggestionsService*>(
+ GetInstance()->GetServiceForBrowserState(browser_state, true));
+}
+
+SuggestionsServiceFactory::SuggestionsServiceFactory()
+ : BrowserStateKeyedServiceFactory(
+ "SuggestionsService",
+ BrowserStateDependencyManager::GetInstance()) {
+ // No dependencies.
+}
+
+SuggestionsServiceFactory::~SuggestionsServiceFactory() {
+}
+
+KeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor(
+ web::BrowserState* browser_state) const {
+ base::SequencedWorkerPool* sequenced_worker_pool =
+ web::WebThread::GetBlockingPool();
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner =
+ sequenced_worker_pool->GetSequencedTaskRunner(
+ sequenced_worker_pool->GetSequenceToken());
+
+ ios::ChromeBrowserState* chrome_browser_state =
+ ios::ChromeBrowserState::FromBrowserState(browser_state);
+ base::FilePath database_dir(
+ chrome_browser_state->GetPath().Append(kThumbnailDirectory));
+ scoped_ptr<SuggestionsStore> suggestions_store(
+ new SuggestionsStore(chrome_browser_state->GetPrefs()));
+ scoped_ptr<BlacklistStore> blacklist_store(
+ new BlacklistStore(chrome_browser_state->GetPrefs()));
+ scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ImageData>> db(
+ new leveldb_proto::ProtoDatabaseImpl<ImageData>(background_task_runner));
+ scoped_ptr<ImageFetcher> image_fetcher(new ImageFetcherImpl(
+ browser_state->GetRequestContext(), sequenced_worker_pool));
+ scoped_ptr<ImageManager> thumbnail_manager(
+ new ImageManager(image_fetcher.Pass(), db.Pass(), database_dir));
+ return new SuggestionsService(
+ browser_state->GetRequestContext(), suggestions_store.Pass(),
+ thumbnail_manager.Pass(), blacklist_store.Pass());
+}
+
+void SuggestionsServiceFactory::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ SuggestionsService::RegisterProfilePrefs(registry);
+}
+
+} // namespace suggestions
« no previous file with comments | « ios/chrome/browser/suggestions/suggestions_service_factory.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698