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 #ifndef COMPONENTS_DOWNLOAD_CONTENT_FACTORY_DOWNLOAD_SERVICE_FACTORY_HELPER_H_
6 #define COMPONENTS_DOWNLOAD_CONTENT_FACTORY_DOWNLOAD_SERVICE_FACTORY_HELPER_H_
7 
8 #include <memory>
9 
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/sequenced_task_runner.h"
13 #include "base/single_thread_task_runner.h"
14 #include "components/download/public/background_service/blob_context_getter_factory.h"
15 #include "components/download/public/background_service/clients.h"
16 
17 class SimpleFactoryKey;
18 
19 namespace network {
20 class NetworkConnectionTracker;
21 class SharedURLLoaderFactory;
22 }  // namespace network
23 
24 namespace leveldb_proto {
25 class ProtoDatabaseProvider;
26 }  // namespace leveldb_proto
27 
28 namespace download {
29 
30 class DownloadService;
31 class SimpleDownloadManagerCoordinator;
32 class TaskScheduler;
33 
34 // |clients| is a map of DownloadClient -> std::unique_ptr<Client>.  This
35 // represents all of the clients that are allowed to have requests made on
36 // their behalf.  This cannot be changed after startup.  Any existing requests
37 // no longer associated with a client will be cancelled.
38 // |storage_dir| is a path to where all the local storage will be.  This will
39 // hold the internal database as well as any temporary files on disk.  If this
40 // is an empty path, the service will not persist any information to disk and
41 // will act as an in-memory only service (this means no auto-retries after
42 // restarts, no files written on completion, etc.).
43 // |background_task_runner| will be used for all disk reads and writes.
44 std::unique_ptr<DownloadService> BuildDownloadService(
45     SimpleFactoryKey* simple_factory_key,
46     std::unique_ptr<DownloadClientMap> clients,
47     network::NetworkConnectionTracker* network_connection_tracker,
48     const base::FilePath& storage_dir,
49     SimpleDownloadManagerCoordinator* download_manager_coordinator,
50     leveldb_proto::ProtoDatabaseProvider* proto_db_provider,
51     const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
52     std::unique_ptr<TaskScheduler> task_scheduler);
53 
54 // Create download service used in incognito mode, without any database or
55 // download file IO.
56 std::unique_ptr<DownloadService> BuildInMemoryDownloadService(
57     SimpleFactoryKey* simple_factory_key,
58     std::unique_ptr<DownloadClientMap> clients,
59     network::NetworkConnectionTracker* network_connection_tracker,
60     const base::FilePath& storage_dir,
61     BlobContextGetterFactoryPtr blob_context_getter_factory,
62     scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
63     scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
64 
65 }  // namespace download
66 
67 #endif  // COMPONENTS_DOWNLOAD_CONTENT_FACTORY_DOWNLOAD_SERVICE_FACTORY_HELPER_H_
68