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

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

Issue 2851303003: Add the download component and initial setup (Closed)
Patch Set: Removed accidental rename 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 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,
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!
30
31 // The download can occur only if the network isn't metered.
32 UNMETERED = 2,
33 };
34
35 enum BatteryRequirements {
36 // The download can only occur when charging or in optimal battery
37 // conditions.
38 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.
39
40 // The download can occur under all battery scenarios. Note that the
41 // DownloadService may still not run this download under extremely low
42 // battery conditions.
43 BATTERY_INSENSITIVE = 1,
44 };
45
46 enum 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() = default;
68
69 // Cancel the download after this delay. Will cancel in-progress downloads.
70 base::TimeDelta cancel_after;
71
72 // The suggested priority. Non-UI priorities may not be honored by the
73 // DownloadService based on internal criteria and settings.
74 Priority priority;
75 NetworkRequirements network_requirements;
76 BatteryRequirements battery_requirements;
77 };
78
79 // The parameters describing how to build the request when starting a download.
80 struct RequestParams {
81 public:
82 RequestParams();
83 ~RequestParams() = default;
84
85 GURL url;
86
87 // The request method ("GET" is the default value).
88 std::string method;
89 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
90 };
91
92 // The parameters that describe a download request made to the
93 // BackgroundDownloadService. The |client| needs to be properly created and
94 // registered for this service for the download to be accepted.
95 struct DownloadParams {
96 enum StartResult {
97 // The download is accepted and persisted.
98 ACCEPTED,
99
100 // The DownloadService has too many downloads. Backoff and retry.
101 BACKOFF,
102
103 // Failed to create the download. Invalid input parameters.
104 BAD_PARAMETERS,
105
106 // TODO(dtrainor): Add more error codes.
107 };
108
109 DownloadParams();
110 ~DownloadParams();
111
112 // The feature that is requesting this download.
113 DownloadClient client;
114
115 // A unique GUID that represents this download. See |base::GenerateGUID()|.
116 std::string guid;
117
118 // A callback that will be notified if this download has been accepted and
119 // persisted by the DownloadService.
120 base::Callback<void(const DownloadParams&, StartResult)> callback;
121
122 // The parameters that determine under what device conditions this download
123 // will occur.
124 SchedulingParams scheduling_params;
125
126 // The parameters that define the actual download request to make.
127 RequestParams request_params;
128 };
129
130 } // namespace download
131
132 #endif // COMPONENTS_DOWNLOAD_PUBLIC_DOWNLOAD_PARAMS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698