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

Side by Side 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, 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/background_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/background_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 BackgroundDownloadServiceFactory*
19 BackgroundDownloadServiceFactory::GetInstance() {
20 return base::Singleton<BackgroundDownloadServiceFactory>::get();
21 }
22
23 // static
24 download::BackgroundDownloadService*
25 BackgroundDownloadServiceFactory::GetForBrowserContext(
26 content::BrowserContext* context) {
27 return static_cast<download::BackgroundDownloadService*>(
28 GetInstance()->GetServiceForBrowserContext(context, true));
29 }
30
31 BackgroundDownloadServiceFactory::BackgroundDownloadServiceFactory()
32 : BrowserContextKeyedServiceFactory(
33 "download::BackgroundDownloadService",
34 BrowserContextDependencyManager::GetInstance()) {}
35
36 BackgroundDownloadServiceFactory::~BackgroundDownloadServiceFactory() = default;
37
38 KeyedService* BackgroundDownloadServiceFactory::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::TaskTraits().MayBlock().WithPriority(
45 base::TaskPriority::BACKGROUND));
46
47 base::FilePath storage_dir;
48 if (!profile->IsOffTheRecord() && !profile->GetPath().empty()) {
49 storage_dir =
50 profile->GetPath().Append(chrome::kDownloadServiceStorageDirname);
51 }
52
53 download::BackgroundDownloadService* service =
54 download::BackgroundDownloadService::Create(storage_dir,
55 background_task_runner);
56
57 // TODO(dtrainor): Register all clients here.
58 return service;
59 }
60
61 content::BrowserContext*
62 BackgroundDownloadServiceFactory::GetBrowserContextToUse(
63 content::BrowserContext* context) const {
64 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698