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); |
+} |