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

Side by Side Diff: components/download/public/download_service.h

Issue 2895953004: Add initial Controller to DownloadService (Closed)
Patch Set: Moved stats out Created 3 years, 6 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_DOWNLOAD_PUBLIC_DOWNLOAD_SERVICE_H_ 5 #ifndef COMPONENTS_DOWNLOAD_PUBLIC_DOWNLOAD_SERVICE_H_
6 #define COMPONENTS_DOWNLOAD_PUBLIC_DOWNLOAD_SERVICE_H_ 6 #define COMPONENTS_DOWNLOAD_PUBLIC_DOWNLOAD_SERVICE_H_
7 7
8 #include <memory>
8 #include <string> 9 #include <string>
9 10
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/sequenced_task_runner.h" 15 #include "base/sequenced_task_runner.h"
16 #include "components/download/public/clients.h"
15 #include "components/keyed_service/core/keyed_service.h" 17 #include "components/keyed_service/core/keyed_service.h"
16 18
17 namespace download { 19 namespace download {
18 20
21 class Client;
19 struct DownloadParams; 22 struct DownloadParams;
20 struct SchedulingParams; 23 struct SchedulingParams;
21 24
22 // A service responsible for helping facilitate the scheduling and downloading 25 // A service responsible for helping facilitate the scheduling and downloading
23 // of file content from the web. See |DownloadParams| for more details on the 26 // of file content from the web. See |DownloadParams| for more details on the
24 // types of scheduling that can be achieved and the required input parameters 27 // types of scheduling that can be achieved and the required input parameters
25 // for starting a download. Note that DownloadServices with a valid storage 28 // for starting a download. Note that DownloadServices with a valid storage
26 // directory will persist the requests across restarts. This means that any 29 // directory will persist the requests across restarts. This means that any
27 // feature requesting a download will have to implement a download::Client 30 // feature requesting a download will have to implement a download::Client
28 // interface so this class knows who to contact when a download completes after 31 // interface so this class knows who to contact when a download completes after
29 // a process restart. 32 // a process restart.
30 class DownloadService : public KeyedService { 33 class DownloadService : public KeyedService {
31 public: 34 public:
35 // The current status of the Service.
36 enum class ServiceStatus {
37 // The service is in the process of initializing and should not be used yet.
38 // All registered Clients will be notified via
39 // Client::OnServiceInitialized() once the service is ready.
40 STARTING_UP = 0,
41
42 // The service is ready and available for use.
43 READY = 1,
44
45 // The service is unavailable. This is typically due to an unrecoverable
46 // error on some internal component like the persistence layer.
47 UNAVAILABLE = 2,
48 };
49
50 // |clients| is a map of DownloadClient -> std::unique_ptr<Client>. This
51 // represents all of the clients that are allowed to have requests made on
52 // their behalf. This cannot be changed after startup. Any existing requests
53 // no longer associated with a client will be cancelled.
32 // |storage_dir| is a path to where all the local storage will be. This will 54 // |storage_dir| is a path to where all the local storage will be. This will
33 // hold the internal database as well as any temporary files on disk. If this 55 // hold the internal database as well as any temporary files on disk. If this
34 // is an empty path, the service will not persist any information to disk and 56 // is an empty path, the service will not persist any information to disk and
35 // will act as an in-memory only service (this means no auto-retries after 57 // will act as an in-memory only service (this means no auto-retries after
36 // restarts, no files written on completion, etc.). 58 // restarts, no files written on completion, etc.).
37 // |background_task_runner| will be used for all disk reads and writes. 59 // |background_task_runner| will be used for all disk reads and writes.
38 static DownloadService* Create( 60 static DownloadService* Create(
61 std::unique_ptr<DownloadClientMap> clients,
39 const base::FilePath& storage_dir, 62 const base::FilePath& storage_dir,
40 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner); 63 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner);
41 64
65 // Whether or not the DownloadService is currently available, initialized
66 // successfully, and ready to be used.
67 virtual ServiceStatus GetStatus() = 0;
68
42 // Sends the download to the service. A callback to 69 // Sends the download to the service. A callback to
43 // |DownloadParams::callback| will be triggered once the download has been 70 // |DownloadParams::callback| will be triggered once the download has been
44 // persisted and saved in the service 71 // persisted and saved in the service
45 virtual void StartDownload(const DownloadParams& download_params) = 0; 72 virtual void StartDownload(const DownloadParams& download_params) = 0;
46 73
47 // Allows any feature to pause or resume downloads at will. Paused downloads 74 // Allows any feature to pause or resume downloads at will. Paused downloads
48 // will not start or stop based on scheduling criteria. They will be 75 // will not start or stop based on scheduling criteria. They will be
49 // effectively frozen. 76 // effectively frozen.
50 virtual void PauseDownload(const std::string& guid) = 0; 77 virtual void PauseDownload(const std::string& guid) = 0;
51 virtual void ResumeDownload(const std::string& guid) = 0; 78 virtual void ResumeDownload(const std::string& guid) = 0;
(...skipping 11 matching lines...) Expand all
63 protected: 90 protected:
64 DownloadService() = default; 91 DownloadService() = default;
65 92
66 private: 93 private:
67 DISALLOW_COPY_AND_ASSIGN(DownloadService); 94 DISALLOW_COPY_AND_ASSIGN(DownloadService);
68 }; 95 };
69 96
70 } // namespace download 97 } // namespace download
71 98
72 #endif // COMPONENTS_DOWNLOAD_PUBLIC_DOWNLOAD_SERVICE_H_ 99 #endif // COMPONENTS_DOWNLOAD_PUBLIC_DOWNLOAD_SERVICE_H_
OLDNEW
« components/download/internal/startup_status.h ('K') | « components/download/public/download_params.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698