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

Side by Side Diff: chrome/browser/download/download_service_factory.cc

Issue 2851303003: Add the download component and initial setup (Closed)
Patch Set: Renamed the service 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
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/sequenced_task_runner.h"
9 #include "base/task_scheduler/post_task.h"
10 #include "chrome/browser/profiles/incognito_helpers.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/chrome_constants.h"
13 #include "components/download/public/download_service.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #include "content/public/browser/browser_context.h"
16
17 // static
18 DownloadServiceFactory* DownloadServiceFactory::GetInstance() {
19 return base::Singleton<DownloadServiceFactory>::get();
20 }
21
22 // static
23 download::DownloadService* DownloadServiceFactory::GetForBrowserContext(
24 content::BrowserContext* context) {
25 return static_cast<download::DownloadService*>(
26 GetInstance()->GetServiceForBrowserContext(context, true));
27 }
28
29 DownloadServiceFactory::DownloadServiceFactory()
30 : BrowserContextKeyedServiceFactory(
31 "download::DownloadService",
32 BrowserContextDependencyManager::GetInstance()) {}
33
34 DownloadServiceFactory::~DownloadServiceFactory() = default;
35
36 KeyedService* DownloadServiceFactory::BuildServiceInstanceFor(
37 content::BrowserContext* context) const {
38 Profile* profile = Profile::FromBrowserContext(context);
39
40 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
41 base::CreateSequencedTaskRunnerWithTraits(
42 base::TaskTraits().MayBlock().WithPriority(
43 base::TaskPriority::BACKGROUND));
dcheng 2017/05/04 00:19:26 Based on CLs like https://codereview.chromium.org/
David Trainor- moved to gerrit 2017/05/04 16:15:48 Done.
44
45 base::FilePath storage_dir;
46 if (!profile->IsOffTheRecord() && !profile->GetPath().empty()) {
47 storage_dir =
48 profile->GetPath().Append(chrome::kDownloadServiceStorageDirname);
49 }
50
51 download::DownloadService* service =
52 download::DownloadService::Create(storage_dir, background_task_runner);
53
54 // TODO(dtrainor): Register all clients here.
55 return service;
56 }
57
58 content::BrowserContext* DownloadServiceFactory::GetBrowserContextToUse(
59 content::BrowserContext* context) const {
60 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698