| 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..190b90b2dbe9d364e652767ce480871b3d84c6ca
|
| --- /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::kDownloadServicePersistedStorageDirname);
|
| + }
|
| +
|
| + 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);
|
| +}
|
|
|