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

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

Issue 2851303003: Add the download component and initial setup (Closed)
Patch Set: Build break 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/background_download_service_factory.cc
diff --git a/chrome/browser/download/background_download_service_factory.cc b/chrome/browser/download/background_download_service_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a56930ba5e57af28e301946bd0e41212edbd474b
--- /dev/null
+++ b/chrome/browser/download/background_download_service_factory.cc
@@ -0,0 +1,65 @@
+// 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/background_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/background_download_service.h"
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#include "content/public/browser/browser_context.h"
+
+// static
+BackgroundDownloadServiceFactory*
+BackgroundDownloadServiceFactory::GetInstance() {
+ return base::Singleton<BackgroundDownloadServiceFactory>::get();
+}
+
+// static
+download::BackgroundDownloadService*
+BackgroundDownloadServiceFactory::GetForBrowserContext(
+ content::BrowserContext* context) {
+ return static_cast<download::BackgroundDownloadService*>(
+ GetInstance()->GetServiceForBrowserContext(context, true));
+}
+
+BackgroundDownloadServiceFactory::BackgroundDownloadServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "download::BackgroundDownloadService",
+ BrowserContextDependencyManager::GetInstance()) {}
+
+BackgroundDownloadServiceFactory::~BackgroundDownloadServiceFactory() = default;
+
+KeyedService* BackgroundDownloadServiceFactory::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));
+
+ base::FilePath storage_dir;
+ if (!profile->IsOffTheRecord() && !profile->GetPath().empty()) {
+ storage_dir =
+ profile->GetPath().Append(chrome::kDownloadServiceStorageDirname);
+ }
+
+ download::BackgroundDownloadService* service =
+ download::BackgroundDownloadService::Create(storage_dir,
+ background_task_runner);
+
+ // TODO(dtrainor): Register all clients here.
+ return service;
+}
+
+content::BrowserContext*
+BackgroundDownloadServiceFactory::GetBrowserContextToUse(
+ content::BrowserContext* context) const {
+ return chrome::GetBrowserContextOwnInstanceInIncognito(context);
+}

Powered by Google App Engine
This is Rietveld 408576698