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

Side by Side Diff: content/browser/download/download_item_impl.h

Issue 1691543002: [Downloads] Enforce state transition integrity and state invariants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clarify comments. Created 4 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 virtual void MarkAsComplete(); 210 virtual void MarkAsComplete();
211 211
212 // DownloadDestinationObserver 212 // DownloadDestinationObserver
213 void DestinationUpdate(int64_t bytes_so_far, 213 void DestinationUpdate(int64_t bytes_so_far,
214 int64_t bytes_per_sec, 214 int64_t bytes_per_sec,
215 const std::string& hash_state) override; 215 const std::string& hash_state) override;
216 void DestinationError(DownloadInterruptReason reason) override; 216 void DestinationError(DownloadInterruptReason reason) override;
217 void DestinationCompleted(const std::string& final_hash) override; 217 void DestinationCompleted(const std::string& final_hash) override;
218 218
219 private: 219 private:
220 // Fine grained states of a download. Note that active downloads are created 220 // Fine grained states of a download.
221 // in IN_PROGRESS_INTERNAL state. However, downloads creates via history can 221 //
222 // be created in COMPLETE_INTERNAL, CANCELLED_INTERNAL and 222 // New downloads can be created in the following states:
223 // INTERRUPTED_INTERNAL. 223 //
224 // INITIAL_INTERNAL: All active new downloads.
225 //
226 // COMPLETE_INTERNAL: Downloads restored from persisted state.
227 // CANCELLED_INTERNAL: - do -
228 // INTERRUPTED_INTERNAL: - do -
229 //
230 // IN_PROGRESS_INTERNAL: SavePackage downloads.
231 //
232 // On debug builds, state transitions can be verified via
233 // IsValidStateTransition() and IsValidSavePackageStateTransition(). Allowed
234 // state transitions are described below, both for normal downloads and
235 // SavePackage downloads.
236 enum DownloadInternalState {
237 // Initial state. Regular downloads are created in this state until the
238 // Start() call is received.
239 //
240 // Transitions to (regular):
241 // TARGET_PENDING_INTERNAL: After a successful Start() call.
242 // INTERRUPTED_INTERNAL: Afater a failed Start() call.
243 //
244 // Transitions to (SavePackage):
245 // <n/a> SavePackage downloads never reach this state.
246 INITIAL_INTERNAL,
224 247
225 enum DownloadInternalState { 248 // Embedder is in the process of determining the target of the download.
226 // Includes both before and after file name determination, and paused 249 // Since the embedder is sensitive to state transitions during this time,
227 // downloads. 250 // any DestinationError/DestinationCompleted events are deferred until
228 // TODO(rdsmith): Put in state variable for file name determination. 251 // TARGET_RESOLVED_INTERNAL.
229 // Transitions from: 252 //
230 // <Initial creation> Active downloads are created in this state. 253 // Transitions to (regular):
231 // RESUMING_INTERNAL 254 // TARGET_RESOLVED_INTERNAL: Once the embedder invokes the callback.
232 // Transitions to: 255 // CANCELLED_INTERNAL: Cancelled.
233 // COMPLETING_INTERNAL On final rename completion. 256 //
234 // CANCELLED_INTERNAL On cancel. 257 // Transitions to (SavePackage):
235 // INTERRUPTED_INTERNAL On interrupt. 258 // <n/a> SavePackage downloads never reach this state.
236 // COMPLETE_INTERNAL On SavePackage download completion. 259 TARGET_PENDING_INTERNAL,
260
261 // Embedder has completed target determination. It is now safe to resolve
262 // the download target as well as process deferred DestinationError events.
263 // This state is differs from TARGET_PENDING_INTERNAL due to it being
264 // allowed to transition to INTERRUPTED_INTERNAL, and it's different from
265 // IN_PROGRESS_INTERNAL in that entering this state doesn't require having
266 // a valid target.
267 //
268 // Transitions to (regular):
269 // IN_PROGRESS_INTERNAL: Target successfully determined. The incoming
270 // data stream can now be written to the target.
271 // INTERRUPTED_INTERNAL: Either the target determination or one of the
272 // deferred signals indicated that the download
273 // should be interrupted.
274 // CANCELLED_INTERNAL: User cancelled the download or there was a
275 // deferred Cancel() call.
276 //
277 // Transitions to (SavePackage):
278 // <n/a> SavePackage downloads never reach this state.
279 TARGET_RESOLVED_INTERNAL,
Randy Smith (Not in Mondays) 2016/02/12 00:03:11 I said it on the other CL, but I think it's more a
asanka 2016/02/12 05:04:26 I believe the need for this state was established.
Randy Smith (Not in Mondays) 2016/02/12 17:37:02 Acknowledged.
280
281 // Download target is known and the data can be transferred from our source
282 // to our sink.
283 //
284 // Transitions to (regular):
285 // COMPLETING_INTERNAL: On final rename completion.
286 // CANCELLED_INTERNAL: On cancel.
287 // INTERRUPTED_INTERNAL: On interrupt.
288 //
289 // Transitions to (SavePackage):
290 // COMPLETE_INTERNAL: On completion.
291 // CANCELLED_INTERNAL: On cancel.
237 IN_PROGRESS_INTERNAL, 292 IN_PROGRESS_INTERNAL,
238 293
239 // Between commit point (dispatch of download file release) and completed. 294 // Between commit point (dispatch of download file release) and completed.
240 // Embedder may be opening the file in this state. 295 // Embedder may be opening the file in this state.
241 // Transitions from: 296 //
242 // IN_PROGRESS_INTERNAL 297 // Transitions to (regular):
243 // Transitions to: 298 // COMPLETE_INTERNAL: On successful completion.
244 // COMPLETE_INTERNAL On successful completion. 299 //
300 // Transitions to (SavePackage):
301 // <n/a> SavePackage downloads never reach this state.
245 COMPLETING_INTERNAL, 302 COMPLETING_INTERNAL,
246 303
247 // After embedder has had a chance to auto-open. User may now open 304 // After embedder has had a chance to auto-open. User may now open
248 // or auto-open based on extension. 305 // or auto-open based on extension.
249 // Transitions from: 306 //
250 // COMPLETING_INTERNAL 307 // Transitions to (regular):
251 // IN_PROGRESS_INTERNAL SavePackage only. 308 // <none> Terminal state.
252 // <Initial creation> Completed persisted downloads. 309 //
253 // Transitions to: 310 // Transitions to (SavePackage):
254 // <none> Terminal state. 311 // <none> Terminal state.
255 COMPLETE_INTERNAL, 312 COMPLETE_INTERNAL,
256 313
257 // User has cancelled the download.
258 // Transitions from:
259 // IN_PROGRESS_INTERNAL
260 // INTERRUPTED_INTERNAL
261 // RESUMING_INTERNAL
262 // <Initial creation> Canceleld persisted downloads.
263 // Transitions to:
264 // <none> Terminal state.
265 CANCELLED_INTERNAL,
266
267 // An error has interrupted the download. 314 // An error has interrupted the download.
268 // Transitions from: 315 //
269 // IN_PROGRESS_INTERNAL 316 // Transitions to (regular):
270 // RESUMING_INTERNAL 317 // RESUMING_INTERNAL: On resumption.
271 // <Initial creation> Interrupted persisted downloads. 318 // CANCELLED_INTERNAL: On cancel.
272 // Transitions to: 319 //
273 // RESUMING_INTERNAL On resumption. 320 // Transitions to (SavePackage):
321 // <n/a> SavePackage downloads never reach this state.
274 INTERRUPTED_INTERNAL, 322 INTERRUPTED_INTERNAL,
275 323
276 // A request to resume this interrupted download is in progress. 324 // A request to resume this interrupted download is in progress.
277 // Transitions from: 325 //
278 // INTERRUPTED_INTERNAL 326 // Transitions to (regular):
279 // Transitions to: 327 // TARGET_PENDING_INTERNAL: Once a server response is received from a
280 // IN_PROGRESS_INTERNAL Once a server response is received from a 328 // resumption.
281 // resumption. 329 // CANCELLED_INTERNAL: On cancel.
282 // INTERRUPTED_INTERNAL If the resumption request fails. 330 //
283 // CANCELLED_INTERNAL On cancel. 331 // Transitions to (SavePackage):
332 // <n/a> SavePackage downloads never reach this state.
284 RESUMING_INTERNAL, 333 RESUMING_INTERNAL,
285 334
335 // User has cancelled the download.
336 // TODO(asanka): Merge interrupted and cancelled states.
337 //
338 // Transitions to (regular):
339 // <none> Terminal state.
340 //
341 // Transitions to (SavePackage):
342 // <none> Terminal state.
343 CANCELLED_INTERNAL,
344
286 MAX_DOWNLOAD_INTERNAL_STATE, 345 MAX_DOWNLOAD_INTERNAL_STATE,
287 }; 346 };
288 347
289 // Used with TransitionTo() to indicate whether or not to call 348 // Used with TransitionTo() to indicate whether or not to call
290 // UpdateObservers() after the state transition. 349 // UpdateObservers() after the state transition.
291 enum ShouldUpdateObservers { 350 enum ShouldUpdateObservers {
292 UPDATE_OBSERVERS, 351 UPDATE_OBSERVERS,
293 DONT_UPDATE_OBSERVERS 352 DONT_UPDATE_OBSERVERS
294 }; 353 };
295 354
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 void ResumeInterruptedDownload(); 438 void ResumeInterruptedDownload();
380 439
381 static DownloadState InternalToExternalState( 440 static DownloadState InternalToExternalState(
382 DownloadInternalState internal_state); 441 DownloadInternalState internal_state);
383 static DownloadInternalState ExternalToInternalState( 442 static DownloadInternalState ExternalToInternalState(
384 DownloadState external_state); 443 DownloadState external_state);
385 444
386 // Debugging routines -------------------------------------------------------- 445 // Debugging routines --------------------------------------------------------
387 static const char* DebugDownloadStateString(DownloadInternalState state); 446 static const char* DebugDownloadStateString(DownloadInternalState state);
388 static const char* DebugResumeModeString(ResumeMode mode); 447 static const char* DebugResumeModeString(ResumeMode mode);
448 static bool IsValidSavePackageStateTransition(DownloadInternalState from,
449 DownloadInternalState to);
450 static bool IsValidStateTransition(DownloadInternalState from,
451 DownloadInternalState to);
389 452
390 // Will be false for save package downloads retrieved from the history. 453 // Will be false for save package downloads retrieved from the history.
391 // TODO(rdsmith): Replace with a generalized enum for "download source". 454 // TODO(rdsmith): Replace with a generalized enum for "download source".
392 const bool is_save_package_download_; 455 const bool is_save_package_download_;
393 456
394 // The handle to the request information. Used for operations outside the 457 // The handle to the request information. Used for operations outside the
395 // download system. 458 // download system.
396 scoped_ptr<DownloadRequestHandleInterface> request_handle_; 459 scoped_ptr<DownloadRequestHandleInterface> request_handle_;
397 460
398 uint32_t download_id_; 461 uint32_t download_id_;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 const net::BoundNetLog bound_net_log_; 616 const net::BoundNetLog bound_net_log_;
554 617
555 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; 618 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_;
556 619
557 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 620 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
558 }; 621 };
559 622
560 } // namespace content 623 } // namespace content
561 624
562 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 625 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_item_impl.cc » ('j') | content/browser/download/download_item_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698