Chromium Code Reviews| 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..7a94dc39e61c1716a998c7250e2cd1dc9556bb6a |
| --- /dev/null |
| +++ b/components/download/public/download_params.h |
| @@ -0,0 +1,132 @@ |
| +// 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 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, |
|
Peter Beverloo
2017/05/02 16:12:21
nit: the user would use this value as SchedulingPa
David Trainor- moved to gerrit
2017/05/03 06:02:59
ah enum class is nice thanks!
|
| + |
| + // The download can occur only if the network isn't metered. |
| + UNMETERED = 2, |
| + }; |
| + |
| + enum BatteryRequirements { |
| + // The download can only occur when charging or in optimal battery |
| + // conditions. |
| + BATTERY_SENSITIVE = 0, |
|
xingliu
2017/05/01 23:56:54
nit: Can we put BATTERY_INSENSITIVE before BATTERY
David Trainor- moved to gerrit
2017/05/03 06:02:59
Done.
|
| + |
| + // 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 = 1, |
| + }; |
| + |
| + enum 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() = 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() = default; |
| + |
| + GURL url; |
| + |
| + // The request method ("GET" is the default value). |
| + std::string method; |
| + net::HttpRequestHeaders request_headers; |
|
xingliu
2017/05/01 23:56:54
nit: Not necessary in this patch, but shall we avo
David Trainor- moved to gerrit
2017/05/03 06:02:59
Will that cause an issue? I did add copy construc
|
| +}; |
| + |
| +// 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(); |
| + |
| + // 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_ |