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

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

Issue 2851303003: Add the download component and initial setup (Closed)
Patch Set: Build break Created 3 years, 7 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
(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_DOWNLOAD_PARAMS_H_
6 #define COMPONENTS_DOWNLOAD_PUBLIC_DOWNLOAD_PARAMS_H_
7
8 #include "base/callback.h"
9 #include "base/time/time.h"
10 #include "components/download/public/clients.h"
11 #include "net/http/http_request_headers.h"
12 #include "url/gurl.h"
13
14 namespace download {
15
16 // The parameters describing when to run a download. This allows the caller to
17 // specify restrictions on what impact this download will have on the device
18 // (battery, network conditions, priority, etc.).
19 struct SchedulingParams {
20 public:
21 enum class NetworkRequirements {
22 // The download can occur under all network conditions.
23 NONE = 0,
24
25 // The download should occur when the network isn't metered. However if the
26 // device does not provide that opportunity over a long period of time, the
27 // DownloadService may start allowing these downloads to run on metered
28 // networks as well.
29 OPTIMISTIC = 1,
30
31 // The download can occur only if the network isn't metered.
32 UNMETERED = 2,
33 };
34
35 enum class BatteryRequirements {
36 // The download can occur under all battery scenarios. Note that the
37 // DownloadService may still not run this download under extremely low
38 // battery conditions.
39 BATTERY_INSENSITIVE = 0,
40
41 // The download can only occur when charging or in optimal battery
42 // conditions.
43 BATTERY_SENSITIVE = 1,
44 };
45
46 enum class Priority {
47 // The lowest priority. Requires that the device is idle or Chrome is
48 // running.
49 LOW = 0,
50
51 // The normal priority. Requires that the device is idle or Chrome is
52 // running.
53 NORMAL = 1,
54
55 // The highest background priority. Does not require the device to be idle.
56 HIGH = 2,
57
58 // The highest priority. This will act (scheduling requirements aside) as a
59 // user-initiated download.
60 UI = 3,
61
62 // The default priority for all tasks unless overridden.
63 DEFAULT = NORMAL,
64 };
65
66 SchedulingParams();
67 SchedulingParams(const SchedulingParams& other) = default;
68 ~SchedulingParams() = default;
69
70 // Cancel the download after this delay. Will cancel in-progress downloads.
71 base::TimeDelta cancel_after;
72
73 // The suggested priority. Non-UI priorities may not be honored by the
74 // DownloadService based on internal criteria and settings.
75 Priority priority;
76 NetworkRequirements network_requirements;
77 BatteryRequirements battery_requirements;
78 };
79
80 // The parameters describing how to build the request when starting a download.
81 struct RequestParams {
82 public:
83 RequestParams();
84 RequestParams(const RequestParams& other) = default;
85 ~RequestParams() = default;
86
87 GURL url;
88
89 // The request method ("GET" is the default value).
90 std::string method;
91 net::HttpRequestHeaders request_headers;
92 };
93
94 // The parameters that describe a download request made to the
95 // BackgroundDownloadService. The |client| needs to be properly created and
96 // registered for this service for the download to be accepted.
97 struct DownloadParams {
98 enum StartResult {
99 // The download is accepted and persisted.
100 ACCEPTED,
101
102 // The DownloadService has too many downloads. Backoff and retry.
103 BACKOFF,
104
105 // Failed to create the download. Invalid input parameters.
106 BAD_PARAMETERS,
107
108 // TODO(dtrainor): Add more error codes.
109 };
110
111 DownloadParams();
112 DownloadParams(const DownloadParams& other);
113 ~DownloadParams();
114
115 // The feature that is requesting this download.
116 DownloadClient client;
117
118 // A unique GUID that represents this download. See |base::GenerateGUID()|.
119 std::string guid;
120
121 // A callback that will be notified if this download has been accepted and
122 // persisted by the DownloadService.
123 base::Callback<void(const DownloadParams&, StartResult)> callback;
124
125 // The parameters that determine under what device conditions this download
126 // will occur.
127 SchedulingParams scheduling_params;
128
129 // The parameters that define the actual download request to make.
130 RequestParams request_params;
131 };
132
133 } // namespace download
134
135 #endif // COMPONENTS_DOWNLOAD_PUBLIC_DOWNLOAD_PARAMS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698