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

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

Issue 2851303003: Add the download component and initial setup (Closed)
Patch Set: Addressed comments Created 3 years, 7 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
« no previous file with comments | « chrome/browser/download/download_service_factory.h ('k') | chrome/common/chrome_constants.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..aae4341033639e7f7d60cd9733ae252aafe8548e
--- /dev/null
+++ b/chrome/browser/download/download_service_factory.cc
@@ -0,0 +1,62 @@
+// 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/memory/singleton.h"
+#include "base/sequenced_task_runner.h"
+#include "base/task_scheduler/post_task.h"
+#include "base/task_scheduler/task_traits.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::MayBlock(), base::TaskPriority::BACKGROUND});
+
+ 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);
+}
« no previous file with comments | « chrome/browser/download/download_service_factory.h ('k') | chrome/common/chrome_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698