| OLD | NEW |
| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // should be considered complete. | 200 // should be considered complete. |
| 201 virtual void MarkAsComplete(); | 201 virtual void MarkAsComplete(); |
| 202 | 202 |
| 203 // Interactions with persistence system -------------------------------------- | 203 // Interactions with persistence system -------------------------------------- |
| 204 | 204 |
| 205 // TODO(benjhayden): Remove when DownloadHistory becomes an observer. | 205 // TODO(benjhayden): Remove when DownloadHistory becomes an observer. |
| 206 virtual void SetIsPersisted(); | 206 virtual void SetIsPersisted(); |
| 207 virtual void SetDbHandle(int64 handle); | 207 virtual void SetDbHandle(int64 handle); |
| 208 | 208 |
| 209 private: | 209 private: |
| 210 // Fine grained states of a download. |
| 211 enum DownloadInternalState { |
| 212 // Unless otherwise specified, state transitions are linear forward |
| 213 // in this list. |
| 214 |
| 215 // Includes both before and after file name determination. |
| 216 // TODO(rdsmith): Put in state variable for file name determination. |
| 217 IN_PROGRESS_INTERNAL, |
| 218 |
| 219 // Between commit point (dispatch of download file release) and |
| 220 // completed. Embedder may be opening the file in this state. |
| 221 COMPLETING_INTERNAL, |
| 222 |
| 223 // After embedder has had a chance to auto-open. User may now open |
| 224 // or auto-open based on extension. |
| 225 COMPLETE_INTERNAL, |
| 226 |
| 227 // User has cancelled the download. |
| 228 // Only incoming transition IN_PROGRESS-> |
| 229 CANCELLED_INTERNAL, |
| 230 |
| 231 // An error has interrupted the download. |
| 232 // Only incoming transition IN_PROGRESS-> |
| 233 INTERRUPTED_INTERNAL, |
| 234 |
| 235 MAX_DOWNLOAD_INTERNAL_STATE, |
| 236 }; |
| 237 |
| 238 // Map from DownloadInternalState -> DownloadState. |
| 239 static const DownloadState kInternalStateMap[]; |
| 240 |
| 241 // Map from DownloadState -> DownloadInternalState (for external |
| 242 // initialization). |
| 243 static const DownloadInternalState kExternalStateMap[]; |
| 244 |
| 210 // Normal progression of a download ------------------------------------------ | 245 // Normal progression of a download ------------------------------------------ |
| 211 | 246 |
| 212 // These are listed in approximately chronological order. There are also | 247 // These are listed in approximately chronological order. There are also |
| 213 // public methods involved in normal download progression; see | 248 // public methods involved in normal download progression; see |
| 214 // the implementation ordering in download_item_impl.cc. | 249 // the implementation ordering in download_item_impl.cc. |
| 215 | 250 |
| 216 // Construction common to all constructors. |active| should be true for new | 251 // Construction common to all constructors. |active| should be true for new |
| 217 // downloads and false for downloads from the history. | 252 // downloads and false for downloads from the history. |
| 218 // |download_type| indicates to the net log system what kind of download | 253 // |download_type| indicates to the net log system what kind of download |
| 219 // this is. | 254 // this is. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 242 // GetTargetFilePath(). | 277 // GetTargetFilePath(). |
| 243 bool NeedsRename() const; | 278 bool NeedsRename() const; |
| 244 | 279 |
| 245 // Internal helper for maintaining consistent received and total sizes, and | 280 // Internal helper for maintaining consistent received and total sizes, and |
| 246 // setting the final hash. | 281 // setting the final hash. |
| 247 // Should only be called from |OnAllDataSaved|. | 282 // Should only be called from |OnAllDataSaved|. |
| 248 void ProgressComplete(int64 bytes_so_far, | 283 void ProgressComplete(int64 bytes_so_far, |
| 249 const std::string& final_hash); | 284 const std::string& final_hash); |
| 250 | 285 |
| 251 // Call to transition state; all state transitions should go through this. | 286 // Call to transition state; all state transitions should go through this. |
| 252 void TransitionTo(DownloadState new_state); | 287 void TransitionTo(DownloadInternalState new_state); |
| 253 | 288 |
| 254 // Set the |danger_type_| and invoke obserers if necessary. | 289 // Set the |danger_type_| and invoke obserers if necessary. |
| 255 void SetDangerType(content::DownloadDangerType danger_type); | 290 void SetDangerType(content::DownloadDangerType danger_type); |
| 256 | 291 |
| 257 void SetFullPath(const FilePath& new_path); | 292 void SetFullPath(const FilePath& new_path); |
| 258 | 293 |
| 294 // Debugging routines -------------------------------------------------------- |
| 295 static const char* DebugDownloadStateString(DownloadInternalState state); |
| 296 |
| 259 // The handle to the request information. Used for operations outside the | 297 // The handle to the request information. Used for operations outside the |
| 260 // download system. | 298 // download system. |
| 261 scoped_ptr<DownloadRequestHandleInterface> request_handle_; | 299 scoped_ptr<DownloadRequestHandleInterface> request_handle_; |
| 262 | 300 |
| 263 // Download ID assigned by DownloadResourceHandler. | 301 // Download ID assigned by DownloadResourceHandler. |
| 264 content::DownloadId download_id_; | 302 content::DownloadId download_id_; |
| 265 | 303 |
| 266 // Display name for the download. If this is empty, then the display name is | 304 // Display name for the download. If this is empty, then the display name is |
| 267 // considered to be |target_path_.BaseName()|. | 305 // considered to be |target_path_.BaseName()|. |
| 268 FilePath display_name_; | 306 FilePath display_name_; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 // Server's ETAG for the file. | 384 // Server's ETAG for the file. |
| 347 std::string etag_; | 385 std::string etag_; |
| 348 | 386 |
| 349 // Last reason. | 387 // Last reason. |
| 350 content::DownloadInterruptReason last_reason_; | 388 content::DownloadInterruptReason last_reason_; |
| 351 | 389 |
| 352 // Start time for recording statistics. | 390 // Start time for recording statistics. |
| 353 base::TimeTicks start_tick_; | 391 base::TimeTicks start_tick_; |
| 354 | 392 |
| 355 // The current state of this download. | 393 // The current state of this download. |
| 356 DownloadState state_; | 394 DownloadInternalState state_; |
| 357 | 395 |
| 358 // Current danger type for the download. | 396 // Current danger type for the download. |
| 359 content::DownloadDangerType danger_type_; | 397 content::DownloadDangerType danger_type_; |
| 360 | 398 |
| 361 // The views of this item in the download shelf and download contents. | 399 // The views of this item in the download shelf and download contents. |
| 362 ObserverList<Observer> observers_; | 400 ObserverList<Observer> observers_; |
| 363 | 401 |
| 364 // Time the download was started. | 402 // Time the download was started. |
| 365 base::Time start_time_; | 403 base::Time start_time_; |
| 366 | 404 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 451 |
| 414 // Net log to use for this download. | 452 // Net log to use for this download. |
| 415 const net::BoundNetLog bound_net_log_; | 453 const net::BoundNetLog bound_net_log_; |
| 416 | 454 |
| 417 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 455 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 418 | 456 |
| 419 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 457 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 420 }; | 458 }; |
| 421 | 459 |
| 422 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 460 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |