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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadInfo.java

Issue 2771803004: Glue OfflineContentProvider to the download service (Closed)
Patch Set: Fixing test failure Created 3 years, 8 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.download; 5 package org.chromium.chrome.browser.download;
6 6
7 import org.chromium.base.annotations.CalledByNative; 7 import org.chromium.base.annotations.CalledByNative;
8 import org.chromium.components.offline_items_collection.ContentId; 8 import org.chromium.components.offline_items_collection.ContentId;
9 import org.chromium.components.offline_items_collection.LegacyHelpers; 9 import org.chromium.components.offline_items_collection.LegacyHelpers;
10 import org.chromium.components.offline_items_collection.OfflineItem;
11 import org.chromium.components.offline_items_collection.OfflineItemState;
10 import org.chromium.content_public.browser.DownloadState; 12 import org.chromium.content_public.browser.DownloadState;
11 13
12 /** 14 /**
13 * Class representing the state of a single download. 15 * Class representing the state of a single download.
14 */ 16 */
15 public final class DownloadInfo { 17 public final class DownloadInfo {
16 private final String mUrl; 18 private final String mUrl;
17 private final String mUserAgent; 19 private final String mUserAgent;
18 private final String mMimeType; 20 private final String mMimeType;
19 private final String mCookie; 21 private final String mCookie;
20 private final String mFileName; 22 private final String mFileName;
21 private final String mDescription; 23 private final String mDescription;
22 private final String mFilePath; 24 private final String mFilePath;
23 private final String mReferrer; 25 private final String mReferrer;
24 private final String mOriginalUrl; 26 private final String mOriginalUrl;
25 private final long mBytesReceived; 27 private final long mBytesReceived;
26 private final String mDownloadGuid; 28 private final String mDownloadGuid;
27 private final boolean mHasUserGesture; 29 private final boolean mHasUserGesture;
28 private final String mContentDisposition; 30 private final String mContentDisposition;
29 private final boolean mIsGETRequest; 31 private final boolean mIsGETRequest;
30 private final int mPercentCompleted; 32 private final int mPercentCompleted;
31 private final long mTimeRemainingInMillis; 33 private final long mTimeRemainingInMillis;
32 private final boolean mIsResumable; 34 private final boolean mIsResumable;
33 private final boolean mIsPaused; 35 private final boolean mIsPaused;
34 private final boolean mIsOffTheRecord; 36 private final boolean mIsOffTheRecord;
35 private final boolean mIsOfflinePage; 37 private final boolean mIsOfflinePage;
36 private final int mState; 38 private final int mState;
37 private final long mLastAccessTime; 39 private final long mLastAccessTime;
40
41 // New variables to assist with the migration to OfflineItems.
38 private final ContentId mContentId; 42 private final ContentId mContentId;
43 private final boolean mIsOpenable;
44 private final boolean mIsTransient;
39 45
40 private DownloadInfo(Builder builder) { 46 private DownloadInfo(Builder builder) {
41 mUrl = builder.mUrl; 47 mUrl = builder.mUrl;
42 mUserAgent = builder.mUserAgent; 48 mUserAgent = builder.mUserAgent;
43 mMimeType = builder.mMimeType; 49 mMimeType = builder.mMimeType;
44 mCookie = builder.mCookie; 50 mCookie = builder.mCookie;
45 mFileName = builder.mFileName; 51 mFileName = builder.mFileName;
46 mDescription = builder.mDescription; 52 mDescription = builder.mDescription;
47 mFilePath = builder.mFilePath; 53 mFilePath = builder.mFilePath;
48 mReferrer = builder.mReferrer; 54 mReferrer = builder.mReferrer;
49 mOriginalUrl = builder.mOriginalUrl; 55 mOriginalUrl = builder.mOriginalUrl;
50 mBytesReceived = builder.mBytesReceived; 56 mBytesReceived = builder.mBytesReceived;
51 mDownloadGuid = builder.mDownloadGuid; 57 mDownloadGuid = builder.mDownloadGuid;
52 mHasUserGesture = builder.mHasUserGesture; 58 mHasUserGesture = builder.mHasUserGesture;
53 mIsGETRequest = builder.mIsGETRequest; 59 mIsGETRequest = builder.mIsGETRequest;
54 mContentDisposition = builder.mContentDisposition; 60 mContentDisposition = builder.mContentDisposition;
55 mPercentCompleted = builder.mPercentCompleted; 61 mPercentCompleted = builder.mPercentCompleted;
56 mTimeRemainingInMillis = builder.mTimeRemainingInMillis; 62 mTimeRemainingInMillis = builder.mTimeRemainingInMillis;
57 mIsResumable = builder.mIsResumable; 63 mIsResumable = builder.mIsResumable;
58 mIsPaused = builder.mIsPaused; 64 mIsPaused = builder.mIsPaused;
59 mIsOffTheRecord = builder.mIsOffTheRecord; 65 mIsOffTheRecord = builder.mIsOffTheRecord;
60 mIsOfflinePage = builder.mIsOfflinePage; 66 mIsOfflinePage = builder.mIsOfflinePage;
61 mState = builder.mState; 67 mState = builder.mState;
62 mLastAccessTime = builder.mLastAccessTime; 68 mLastAccessTime = builder.mLastAccessTime;
69
63 if (builder.mContentId != null) { 70 if (builder.mContentId != null) {
64 mContentId = builder.mContentId; 71 mContentId = builder.mContentId;
65 } else { 72 } else {
66 mContentId = LegacyHelpers.buildLegacyContentId(mIsOfflinePage, mDow nloadGuid); 73 mContentId = LegacyHelpers.buildLegacyContentId(mIsOfflinePage, mDow nloadGuid);
67 } 74 }
75 mIsOpenable = builder.mIsOpenable;
76 mIsTransient = builder.mIsTransient;
68 } 77 }
69 78
70 public String getUrl() { 79 public String getUrl() {
71 return mUrl; 80 return mUrl;
72 } 81 }
73 82
74 public String getUserAgent() { 83 public String getUserAgent() {
75 return mUserAgent; 84 return mUserAgent;
76 } 85 }
77 86
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 167 }
159 168
160 public long getLastAccessTime() { 169 public long getLastAccessTime() {
161 return mLastAccessTime; 170 return mLastAccessTime;
162 } 171 }
163 172
164 public ContentId getContentId() { 173 public ContentId getContentId() {
165 return mContentId; 174 return mContentId;
166 } 175 }
167 176
177 public boolean getIsOpenable() {
178 return mIsOpenable;
179 }
180
181 public boolean getIsTransient() {
182 return mIsTransient;
183 }
184
185 /**
186 * Helper method to build a {@link DownloadInfo} from an {@link OfflineItem} .
187 * @param item The {@link OfflineItem} to mimic.
188 * @return A {@link DownloadInfo} containing the relevant fields from {@ code item}.
189 */
190 public static DownloadInfo fromOfflineItem(OfflineItem item) {
191 int state;
192 switch (item.state) {
193 case OfflineItemState.COMPLETE:
194 state = DownloadState.COMPLETE;
195 break;
196 case OfflineItemState.CANCELLED:
197 state = DownloadState.CANCELLED;
198 break;
199 case OfflineItemState.INTERRUPTED:
200 state = DownloadState.INTERRUPTED;
201 break;
202 case OfflineItemState.FAILED:
203 state = DownloadState.INTERRUPTED; // TODO(dtrainor): Validate w hat this state is.
204 break;
205 case OfflineItemState.PENDING: // TODO(dtrainor): Validate what this state is.
206 case OfflineItemState.IN_PROGRESS:
207 case OfflineItemState.PAUSED: // TODO(dtrainor): Validate what this state is.
208 default:
209 state = DownloadState.IN_PROGRESS;
210 break;
211 }
212
213 return new DownloadInfo.Builder()
214 .setContentId(item.id)
215 .setFileName(item.title)
216 .setDescription(item.description)
217 .setIsTransient(item.isTransient)
218 .setLastAccessTime(item.lastAccessedTimeMs)
219 .setIsOpenable(item.isOpenable)
220 .setOriginalUrl(item.originalUrl)
221 .setIsOffTheRecord(item.isOffTheRecord)
222 .setState(state)
223 .setIsPaused(item.state == OfflineItemState.PAUSED)
224 .setIsResumable(item.isResumable)
225 .setBytesReceived(item.receivedBytes)
226 .setPercentCompleted(item.percentCompleted)
227 .setTimeRemainingInMillis(item.timeRemainingMs)
228 .build();
229 }
230
168 /** 231 /**
169 * Helper class for building the DownloadInfo object. 232 * Helper class for building the DownloadInfo object.
170 */ 233 */
171 public static class Builder { 234 public static class Builder {
172 private String mUrl; 235 private String mUrl;
173 private String mUserAgent; 236 private String mUserAgent;
174 private String mMimeType; 237 private String mMimeType;
175 private String mCookie; 238 private String mCookie;
176 private String mFileName; 239 private String mFileName;
177 private String mDescription; 240 private String mDescription;
178 private String mFilePath; 241 private String mFilePath;
179 private String mReferrer; 242 private String mReferrer;
180 private String mOriginalUrl; 243 private String mOriginalUrl;
181 private long mBytesReceived; 244 private long mBytesReceived;
182 private boolean mIsGETRequest; 245 private boolean mIsGETRequest;
183 private String mDownloadGuid; 246 private String mDownloadGuid;
184 private boolean mHasUserGesture; 247 private boolean mHasUserGesture;
185 private String mContentDisposition; 248 private String mContentDisposition;
186 private int mPercentCompleted = -1; 249 private int mPercentCompleted = -1;
187 private long mTimeRemainingInMillis; 250 private long mTimeRemainingInMillis;
188 private boolean mIsResumable = true; 251 private boolean mIsResumable = true;
189 private boolean mIsPaused; 252 private boolean mIsPaused;
190 private boolean mIsOffTheRecord; 253 private boolean mIsOffTheRecord;
191 private boolean mIsOfflinePage; 254 private boolean mIsOfflinePage;
192 private int mState = DownloadState.IN_PROGRESS; 255 private int mState = DownloadState.IN_PROGRESS;
193 private long mLastAccessTime; 256 private long mLastAccessTime;
194 private ContentId mContentId; 257 private ContentId mContentId;
258 private boolean mIsOpenable = true;
259 private boolean mIsTransient;
195 260
196 public Builder setUrl(String url) { 261 public Builder setUrl(String url) {
197 mUrl = url; 262 mUrl = url;
198 return this; 263 return this;
199 } 264 }
200 265
201 public Builder setUserAgent(String userAgent) { 266 public Builder setUserAgent(String userAgent) {
202 mUserAgent = userAgent; 267 mUserAgent = userAgent;
203 return this; 268 return this;
204 } 269 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 public Builder setLastAccessTime(long lastAccessTime) { 367 public Builder setLastAccessTime(long lastAccessTime) {
303 mLastAccessTime = lastAccessTime; 368 mLastAccessTime = lastAccessTime;
304 return this; 369 return this;
305 } 370 }
306 371
307 public Builder setContentId(ContentId contentId) { 372 public Builder setContentId(ContentId contentId) {
308 mContentId = contentId; 373 mContentId = contentId;
309 return this; 374 return this;
310 } 375 }
311 376
377 public Builder setIsOpenable(boolean isOpenable) {
378 mIsOpenable = isOpenable;
379 return this;
380 }
381
382 public Builder setIsTransient(boolean isTransient) {
383 mIsTransient = isTransient;
384 return this;
385 }
386
312 public DownloadInfo build() { 387 public DownloadInfo build() {
313 return new DownloadInfo(this); 388 return new DownloadInfo(this);
314 } 389 }
315 390
316 /** 391 /**
317 * Create a builder from the DownloadInfo object. 392 * Create a builder from the DownloadInfo object.
318 * @param downloadInfo DownloadInfo object from which builder fields are populated. 393 * @param downloadInfo DownloadInfo object from which builder fields are populated.
319 * @return A builder initialized with fields from downloadInfo object. 394 * @return A builder initialized with fields from downloadInfo object.
320 */ 395 */
321 public static Builder fromDownloadInfo(final DownloadInfo downloadInfo) { 396 public static Builder fromDownloadInfo(final DownloadInfo downloadInfo) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 .setOriginalUrl(originalUrl) 443 .setOriginalUrl(originalUrl)
369 .setPercentCompleted(percentCompleted) 444 .setPercentCompleted(percentCompleted)
370 .setReferrer(referrerUrl) 445 .setReferrer(referrerUrl)
371 .setState(state) 446 .setState(state)
372 .setTimeRemainingInMillis(timeRemainingInMs) 447 .setTimeRemainingInMillis(timeRemainingInMs)
373 .setLastAccessTime(lastAccessTime) 448 .setLastAccessTime(lastAccessTime)
374 .setUrl(url) 449 .setUrl(url)
375 .build(); 450 .build();
376 } 451 }
377 } 452 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698