OLD | NEW |
(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 #ifndef COMPONENTS_DOWNLOAD_PUBLIC_CLIENT_H_ |
| 6 #define COMPONENTS_DOWNLOAD_PUBLIC_CLIENT_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/files/file_path.h" |
| 12 #include "net/http/http_response_headers.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 namespace download { |
| 16 |
| 17 // The Client interface required by any feature that wants to start a download |
| 18 // through the DownloadService. Should be registered immediately at startup |
| 19 // when the DownloadService is created (see the factory). |
| 20 class Client { |
| 21 public: |
| 22 // Used by OnDownloadStarted to determine whether or not the DownloadService |
| 23 // should continue downloading the file or abort the attempt. |
| 24 enum class ShouldDownload { |
| 25 CONTINUE, |
| 26 ABORT, |
| 27 }; |
| 28 |
| 29 virtual ~Client() = default; |
| 30 |
| 31 // Called when the DownloadService is initialized and ready to be interacted |
| 32 // with. |outstanding_download_guids| is a list of all downloads the |
| 33 // DownloadService is aware of that are associated with this Client. |
| 34 virtual void OnServiceInitialized( |
| 35 const std::vector<std::string>& outstanding_download_guids) = 0; |
| 36 |
| 37 // Return whether or not the download should be aborted (potentially in |
| 38 // response to |headers|). The download will be downloading at the time this |
| 39 // call is made. |
| 40 virtual ShouldDownload OnDownloadStarted( |
| 41 const std::string& guid, |
| 42 const std::vector<GURL>& url_chain, |
| 43 const scoped_refptr<const net::HttpResponseHeaders>& headers) = 0; |
| 44 |
| 45 // Will be called when there is an update to the current progress state of the |
| 46 // underlying download. Note that |bytes_downloaded| may go backwards if the |
| 47 // download had to be started over from the beginning due to an interruption. |
| 48 // This will be called frequently if the download is actively downloading, |
| 49 // with byte updates coming in as they are processed by the internal download |
| 50 // driver. |
| 51 virtual void OnDownloadUpdated(const std::string& guid, |
| 52 uint64_t bytes_downloaded) = 0; |
| 53 |
| 54 // TODO(dtrainor): Expose a useful error message with the failed download. |
| 55 virtual void OnDownloadFailed(const std::string& guid) = 0; |
| 56 |
| 57 // Called when the download was not completed before the |
| 58 // DownloadParams::cancel_after timeout. |
| 59 virtual void OnDownloadTimedOut(const std::string& guid) = 0; |
| 60 |
| 61 // Called when the download has been aborted after reaching a treshold where |
| 62 // we decide it is not worth attempting to start again. This could be either |
| 63 // due to a specific number of failed retry attempts or a specific number of |
| 64 // wasted bytes due to the download restarting. |
| 65 virtual void OnDownloadAborted(const std::string& guid) = 0; |
| 66 |
| 67 // Called when a download has been successfully completed. After this call |
| 68 // the download entry will be purged from the database. The file will be |
| 69 // automatically removed if it is not renamed or deleted after a window of |
| 70 // time (12 hours, but finch configurable). The timeout is meant to be a |
| 71 // failsafe to ensure that we clean up properly. |
| 72 // TODO(dtrainor): Investigate alternate output formats. |
| 73 // TODO(dtrainor): Point to finch configurable timeout when it is added. |
| 74 virtual void OnDownloadSucceeded(const std::string& guid, |
| 75 const base::FilePath& path, |
| 76 uint64_t size) = 0; |
| 77 }; |
| 78 |
| 79 } // namespace download |
| 80 |
| 81 #endif // COMPONENTS_DOWNLOAD_PUBLIC_CLIENT_H_ |
OLD | NEW |