Index: components/download/public/download_params.h |
diff --git a/components/download/public/download_params.h b/components/download/public/download_params.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9805feebf88a8027fb85407292f03af7514875a8 |
--- /dev/null |
+++ b/components/download/public/download_params.h |
@@ -0,0 +1,135 @@ |
+// 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_DOWNLOAD_PARAMS_H_ |
+#define COMPONENTS_DOWNLOAD_PUBLIC_DOWNLOAD_PARAMS_H_ |
+ |
+#include "base/callback.h" |
+#include "base/time/time.h" |
+#include "components/download/public/clients.h" |
+#include "net/http/http_request_headers.h" |
+#include "url/gurl.h" |
+ |
+namespace download { |
+ |
+// The parameters describing when to run a download. This allows the caller to |
+// specify restrictions on what impact this download will have on the device |
+// (battery, network conditions, priority, etc.). |
+struct SchedulingParams { |
+ public: |
+ enum class NetworkRequirements { |
+ // The download can occur under all network conditions. |
+ NONE = 0, |
+ |
+ // The download should occur when the network isn't metered. However if the |
+ // device does not provide that opportunity over a long period of time, the |
+ // DownloadService may start allowing these downloads to run on metered |
+ // networks as well. |
+ OPTIMISTIC = 1, |
+ |
+ // The download can occur only if the network isn't metered. |
+ UNMETERED = 2, |
+ }; |
+ |
+ enum class BatteryRequirements { |
+ // The download can occur under all battery scenarios. Note that the |
+ // DownloadService may still not run this download under extremely low |
+ // battery conditions. |
+ BATTERY_INSENSITIVE = 0, |
+ |
+ // The download can only occur when charging or in optimal battery |
+ // conditions. |
+ BATTERY_SENSITIVE = 1, |
+ }; |
+ |
+ enum class Priority { |
+ // The lowest priority. Requires that the device is idle or Chrome is |
+ // running. |
+ LOW = 0, |
+ |
+ // The normal priority. Requires that the device is idle or Chrome is |
+ // running. |
+ NORMAL = 1, |
+ |
+ // The highest background priority. Does not require the device to be idle. |
+ HIGH = 2, |
+ |
+ // The highest priority. This will act (scheduling requirements aside) as a |
+ // user-initiated download. |
+ UI = 3, |
+ |
+ // The default priority for all tasks unless overridden. |
+ DEFAULT = NORMAL, |
+ }; |
+ |
+ SchedulingParams(); |
+ SchedulingParams(const SchedulingParams& other) = default; |
+ ~SchedulingParams() = default; |
+ |
+ // Cancel the download after this delay. Will cancel in-progress downloads. |
+ base::TimeDelta cancel_after; |
+ |
+ // The suggested priority. Non-UI priorities may not be honored by the |
+ // DownloadService based on internal criteria and settings. |
+ Priority priority; |
+ NetworkRequirements network_requirements; |
+ BatteryRequirements battery_requirements; |
+}; |
+ |
+// The parameters describing how to build the request when starting a download. |
+struct RequestParams { |
+ public: |
+ RequestParams(); |
+ RequestParams(const RequestParams& other) = default; |
+ ~RequestParams() = default; |
+ |
+ GURL url; |
+ |
+ // The request method ("GET" is the default value). |
+ std::string method; |
+ net::HttpRequestHeaders request_headers; |
+}; |
+ |
+// The parameters that describe a download request made to the |
+// BackgroundDownloadService. The |client| needs to be properly created and |
+// registered for this service for the download to be accepted. |
+struct DownloadParams { |
+ enum StartResult { |
+ // The download is accepted and persisted. |
+ ACCEPTED, |
+ |
+ // The DownloadService has too many downloads. Backoff and retry. |
+ BACKOFF, |
+ |
+ // Failed to create the download. Invalid input parameters. |
+ BAD_PARAMETERS, |
+ |
+ // TODO(dtrainor): Add more error codes. |
+ }; |
+ |
+ DownloadParams(); |
+ DownloadParams(const DownloadParams& other); |
+ ~DownloadParams(); |
+ |
+ // The feature that is requesting this download. |
+ DownloadClient client; |
+ |
+ // A unique GUID that represents this download. See |base::GenerateGUID()|. |
+ std::string guid; |
+ |
+ // A callback that will be notified if this download has been accepted and |
+ // persisted by the DownloadService. |
+ base::Callback<void(const DownloadParams&, StartResult)> callback; |
+ |
+ // The parameters that determine under what device conditions this download |
+ // will occur. |
+ SchedulingParams scheduling_params; |
+ |
+ // The parameters that define the actual download request to make. |
+ RequestParams request_params; |
+}; |
+ |
+} // namespace download |
+ |
+#endif // COMPONENTS_DOWNLOAD_PUBLIC_DOWNLOAD_PARAMS_H_ |