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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/download/download_service_factory.h"
6
7 #include "base/files/file_path.h"
8 #include "base/memory/singleton.h"
9 #include "base/sequenced_task_runner.h"
10 #include "base/task_scheduler/post_task.h"
11 #include "base/task_scheduler/task_traits.h"
12 #include "chrome/browser/profiles/incognito_helpers.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/chrome_constants.h"
15 #include "components/download/public/download_service.h"
16 #include "components/keyed_service/content/browser_context_dependency_manager.h"
17 #include "content/public/browser/browser_context.h"
18
19 // static
20 DownloadServiceFactory* DownloadServiceFactory::GetInstance() {
21 return base::Singleton<DownloadServiceFactory>::get();
22 }
23
24 // static
25 download::DownloadService* DownloadServiceFactory::GetForBrowserContext(
26 content::BrowserContext* context) {
27 return static_cast<download::DownloadService*>(
28 GetInstance()->GetServiceForBrowserContext(context, true));
29 }
30
31 DownloadServiceFactory::DownloadServiceFactory()
32 : BrowserContextKeyedServiceFactory(
33 "download::DownloadService",
34 BrowserContextDependencyManager::GetInstance()) {}
35
36 DownloadServiceFactory::~DownloadServiceFactory() = default;
37
38 KeyedService* DownloadServiceFactory::BuildServiceInstanceFor(
39 content::BrowserContext* context) const {
40 Profile* profile = Profile::FromBrowserContext(context);
41
42 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
43 base::CreateSequencedTaskRunnerWithTraits(
44 {base::MayBlock(), base::TaskPriority::BACKGROUND});
45
46 base::FilePath storage_dir;
47 if (!profile->IsOffTheRecord() && !profile->GetPath().empty()) {
48 storage_dir =
49 profile->GetPath().Append(chrome::kDownloadServiceStorageDirname);
50 }
51
52 download::DownloadService* service =
53 download::DownloadService::Create(storage_dir, background_task_runner);
54
55 // TODO(dtrainor): Register all clients here.
56 return service;
57 }
58
59 content::BrowserContext* DownloadServiceFactory::GetBrowserContextToUse(
60 content::BrowserContext* context) const {
61 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
62 }
OLDNEW
« 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