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

Unified Diff: chrome/browser/download/download_service_factory.cc

Issue 2851303003: Add the download component and initial setup (Closed)
Patch Set: Renamed the service Created 3 years, 8 months 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
Index: chrome/browser/download/download_service_factory.cc
diff --git a/chrome/browser/download/download_service_factory.cc b/chrome/browser/download/download_service_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1ba2a0fcb71368fad465aa010e937d37612c45b0
--- /dev/null
+++ b/chrome/browser/download/download_service_factory.cc
@@ -0,0 +1,61 @@
+// Copyright 2017 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 "chrome/browser/download/download_service_factory.h"
+
+#include "base/files/file_path.h"
+#include "base/sequenced_task_runner.h"
+#include "base/task_scheduler/post_task.h"
+#include "chrome/browser/profiles/incognito_helpers.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_constants.h"
+#include "components/download/public/download_service.h"
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#include "content/public/browser/browser_context.h"
+
+// static
+DownloadServiceFactory* DownloadServiceFactory::GetInstance() {
+ return base::Singleton<DownloadServiceFactory>::get();
+}
+
+// static
+download::DownloadService* DownloadServiceFactory::GetForBrowserContext(
+ content::BrowserContext* context) {
+ return static_cast<download::DownloadService*>(
+ GetInstance()->GetServiceForBrowserContext(context, true));
+}
+
+DownloadServiceFactory::DownloadServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "download::DownloadService",
+ BrowserContextDependencyManager::GetInstance()) {}
+
+DownloadServiceFactory::~DownloadServiceFactory() = default;
+
+KeyedService* DownloadServiceFactory::BuildServiceInstanceFor(
+ content::BrowserContext* context) const {
+ Profile* profile = Profile::FromBrowserContext(context);
+
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner =
+ base::CreateSequencedTaskRunnerWithTraits(
+ base::TaskTraits().MayBlock().WithPriority(
+ base::TaskPriority::BACKGROUND));
dcheng 2017/05/04 00:19:26 Based on CLs like https://codereview.chromium.org/
David Trainor- moved to gerrit 2017/05/04 16:15:48 Done.
+
+ base::FilePath storage_dir;
+ if (!profile->IsOffTheRecord() && !profile->GetPath().empty()) {
+ storage_dir =
+ profile->GetPath().Append(chrome::kDownloadServiceStorageDirname);
+ }
+
+ download::DownloadService* service =
+ download::DownloadService::Create(storage_dir, background_task_runner);
+
+ // TODO(dtrainor): Register all clients here.
+ return service;
+}
+
+content::BrowserContext* DownloadServiceFactory::GetBrowserContextToUse(
+ content::BrowserContext* context) const {
+ return chrome::GetBrowserContextOwnInstanceInIncognito(context);
+}

Powered by Google App Engine
This is Rietveld 408576698