Index: components/download/public/client.h |
diff --git a/components/download/public/client.h b/components/download/public/client.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..081873f5130f94e853a6e5638381571f0f8d328c |
--- /dev/null |
+++ b/components/download/public/client.h |
@@ -0,0 +1,69 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_DOWNLOAD_PUBLIC_CLIENT_H_ |
+#define COMPONENTS_DOWNLOAD_PUBLIC_CLIENT_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/files/file_path.h" |
+#include "net/http/http_response_headers.h" |
+#include "url/gurl.h" |
+ |
+namespace download { |
+ |
+// The Client interface required by any feature that wants to start a download |
+// through the BackgroundDownloadService. Should be registered immediately at |
+// startup when the BackgroundDownloadService is created (see the factory). |
+class Client { |
+ public: |
+ // Used by OnDownloadStarted to determine whether or not the DownloadService |
+ // should continue downloading the file or abort the attempt. |
+ enum ShouldDownload { |
+ CONTINUE, |
+ ABORT, |
+ }; |
+ |
+ // Called when the DownloadService is initialized and ready to be interacted |
+ // with. |outstanding_download_guids| is a list of all downloads the |
+ // DownloadService is aware of that are associated with this Client. |
+ void OnServiceInitialized( |
Peter Beverloo
2017/05/02 16:12:21
Are the `virtual` keywords missing everywhere?
David Trainor- moved to gerrit
2017/05/03 06:02:58
O_o
|
+ const std::vector<std::string>& outstanding_download_guids); |
Peter Beverloo
2017/05/02 16:12:21
= 0?
It'd be good to have either everything be pu
David Trainor- moved to gerrit
2017/05/03 06:02:58
Done.
|
+ |
+ // Return whether or not the download should be aborted (potentially in |
+ // response to |headers|). The download will be downloading at the time this |
+ // call is made. |
+ ShouldDownload OnDownloadStarted( |
+ const std::string& guid, |
+ const GURL& final_url, |
Peter Beverloo
2017/05/02 16:12:21
Why not an std::vector<GURL> with the entire URL c
David Trainor- moved to gerrit
2017/05/03 06:02:58
Done.
|
+ const scoped_refptr<const net::HttpResponseHeaders> headers) = 0; |
Peter Beverloo
2017/05/02 16:12:21
const&?
David Trainor- moved to gerrit
2017/05/03 06:02:58
Done.
|
+ |
+ void OnDownloadUpdated(const std::string& guid, |
Peter Beverloo
2017/05/02 16:12:21
docs? Especially the frequency would be interestin
David Trainor- moved to gerrit
2017/05/03 06:02:58
Done.
|
+ uint64_t bytes_downloaded) = 0; |
+ |
+ // TODO(dtrainor): Expose a useful error message with the failed download. |
+ void OnDownloadFailed(const std::string& guid) = 0; |
+ |
+ // Called when the download was not completed before the |
+ // DownloadParams::cancel_after timeout. |
+ void OnDownloadTimedOut(const std::string& guid) = 0; |
+ |
+ // Called when the download has been aborted due to a specific number of |
+ // retries or a specific number of bytes wasted. |
Peter Beverloo
2017/05/02 16:12:21
"or a specific number of bytes wasted" what does t
David Trainor- moved to gerrit
2017/05/03 06:02:58
Failing only based on retry count is probably not
|
+ void OnDownloadAborted(const std::string& guid) = 0; |
+ |
+ // Called when a download has been successfully completed. After this call |
+ // the download entry will be purged from the database. The file will be |
+ // automatically removed if it is not renamed or deleted after a window of |
+ // time (hours). |
Peter Beverloo
2017/05/02 16:12:21
define "time (hours)"
David Trainor- moved to gerrit
2017/05/03 06:02:58
Done.
|
+ // TODO(dtrainor): Investigate alternate output formats. |
+ void OnDownloadSucceeded(const std::string& guid, |
+ const base::FilePath& path, |
+ uint64_t size) = 0; |
+}; |
Peter Beverloo
2017/05/02 16:12:21
+virtual dtor
David Trainor- moved to gerrit
2017/05/03 06:02:58
Done.
|
+ |
+} // namespace download |
+ |
+#endif // COMPONENTS_DOWNLOAD_PUBLIC_CLIENT_H_ |