Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Each download is represented by a DownloadItem, and all DownloadItems | 5 // Each download is represented by a DownloadItem, and all DownloadItems |
| 6 // are owned by the DownloadManager which maintains a global list of all | 6 // are owned by the DownloadManager which maintains a global list of all |
| 7 // downloads. DownloadItems are created when a user initiates a download, | 7 // downloads. DownloadItems are created when a user initiates a download, |
| 8 // and exist for the duration of the browser life time. | 8 // and exist for the duration of the browser life time. |
| 9 // | 9 // |
| 10 // Download observers: | 10 // Download observers: |
| 11 // DownloadItem::Observer: | 11 // DownloadItem::Observer: |
| 12 // - allows observers to receive notifications about one download from start | 12 // - allows observers to receive notifications about one download from start |
| 13 // to completion | 13 // to completion |
| 14 // Use AddObserver() / RemoveObserver() on the appropriate download object to | 14 // Use AddObserver() / RemoveObserver() on the appropriate download object to |
| 15 // receive state updates. | 15 // receive state updates. |
| 16 | 16 |
| 17 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 17 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| 18 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 18 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| 19 #pragma once | 19 #pragma once |
| 20 | 20 |
| 21 #include <string> | 21 #include <string> |
| 22 | 22 |
| 23 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
| 24 #include "base/file_path.h" | 24 #include "base/file_path.h" |
| 25 #include "base/observer_list.h" | 25 #include "base/observer_list.h" |
| 26 #include "base/time.h" | 26 #include "base/time.h" |
| 27 #include "base/timer.h" | 27 #include "base/timer.h" |
| 28 #include "chrome/browser/download/download_process_handle.h" | |
| 28 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 29 | 30 |
| 30 class DownloadFileManager; | 31 class DownloadFileManager; |
| 31 class DownloadManager; | 32 class DownloadManager; |
| 32 struct DownloadCreateInfo; | 33 struct DownloadCreateInfo; |
| 33 | 34 |
| 34 // One DownloadItem per download. This is the model class that stores all the | 35 // One DownloadItem per download. This is the model class that stores all the |
| 35 // state for a download. Multiple views, such as a tab's download shelf and the | 36 // state for a download. Multiple views, such as a tab's download shelf and the |
| 36 // Destination tab's download view, may refer to a given DownloadItem. | 37 // Destination tab's download view, may refer to a given DownloadItem. |
| 37 // | 38 // |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 int64 total_bytes() const { return total_bytes_; } | 254 int64 total_bytes() const { return total_bytes_; } |
| 254 void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; } | 255 void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; } |
| 255 int64 received_bytes() const { return received_bytes_; } | 256 int64 received_bytes() const { return received_bytes_; } |
| 256 int32 id() const { return id_; } | 257 int32 id() const { return id_; } |
| 257 base::Time start_time() const { return start_time_; } | 258 base::Time start_time() const { return start_time_; } |
| 258 void set_db_handle(int64 handle) { db_handle_ = handle; } | 259 void set_db_handle(int64 handle) { db_handle_ = handle; } |
| 259 int64 db_handle() const { return db_handle_; } | 260 int64 db_handle() const { return db_handle_; } |
| 260 bool is_paused() const { return is_paused_; } | 261 bool is_paused() const { return is_paused_; } |
| 261 bool open_when_complete() const { return open_when_complete_; } | 262 bool open_when_complete() const { return open_when_complete_; } |
| 262 void set_open_when_complete(bool open) { open_when_complete_ = open; } | 263 void set_open_when_complete(bool open) { open_when_complete_ = open; } |
| 263 int render_process_id() const { return render_process_id_; } | 264 int render_process_id() const { return process_handle_.child_id(); } |
|
Paweł Hajdan Jr.
2011/05/05 20:13:51
Just wondering, can we remove those accessors comp
ahendrickson
2011/05/06 16:16:50
Done.
| |
| 264 int request_id() const { return request_id_; } | 265 int request_id() const { return process_handle_.request_id(); } |
| 265 SafetyState safety_state() const { return safety_state_; } | 266 SafetyState safety_state() const { return safety_state_; } |
| 266 void set_safety_state(SafetyState safety_state) { | 267 void set_safety_state(SafetyState safety_state) { |
| 267 safety_state_ = safety_state; | 268 safety_state_ = safety_state; |
| 268 } | 269 } |
| 269 DangerType danger_type() { return danger_type_;} | 270 DangerType danger_type() { return danger_type_;} |
| 270 bool auto_opened() { return auto_opened_; } | 271 bool auto_opened() { return auto_opened_; } |
| 271 FilePath target_name() const { return target_name_; } | 272 FilePath target_name() const { return target_name_; } |
| 272 bool save_as() const { return save_as_; } | 273 bool save_as() const { return save_as_; } |
| 273 bool is_otr() const { return is_otr_; } | 274 bool is_otr() const { return is_otr_; } |
| 274 bool is_extension_install() const { return is_extension_install_; } | 275 bool is_extension_install() const { return is_extension_install_; } |
| 275 bool name_finalized() const { return name_finalized_; } | 276 bool name_finalized() const { return name_finalized_; } |
| 276 bool is_temporary() const { return is_temporary_; } | 277 bool is_temporary() const { return is_temporary_; } |
| 277 void set_opened(bool opened) { opened_ = opened; } | 278 void set_opened(bool opened) { opened_ = opened; } |
| 278 bool opened() const { return opened_; } | 279 bool opened() const { return opened_; } |
| 279 | 280 |
| 281 const DownloadProcessHandle& process_handle() const { | |
| 282 return process_handle_; | |
| 283 } | |
| 284 | |
| 280 // Returns the final target file path for the download. | 285 // Returns the final target file path for the download. |
| 281 FilePath GetTargetFilePath() const; | 286 FilePath GetTargetFilePath() const; |
| 282 | 287 |
| 283 // Returns the file-name that should be reported to the user, which is | 288 // Returns the file-name that should be reported to the user, which is |
| 284 // target_name_ possibly with the uniquifier number. | 289 // target_name_ possibly with the uniquifier number. |
| 285 FilePath GetFileNameToReportUser() const; | 290 FilePath GetFileNameToReportUser() const; |
| 286 | 291 |
| 287 // Returns the user-verified target file path for the download. | 292 // Returns the user-verified target file path for the download. |
| 288 // This returns the same path as GetTargetFilePath() for safe downloads | 293 // This returns the same path as GetTargetFilePath() for safe downloads |
| 289 // but does not for dangerous downloads until the name is verified. | 294 // but does not for dangerous downloads until the name is verified. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 | 336 |
| 332 // The value of the content type header received when downloading | 337 // The value of the content type header received when downloading |
| 333 // this item. |mime_type_| may be different because of type sniffing. | 338 // this item. |mime_type_| may be different because of type sniffing. |
| 334 std::string original_mime_type_; | 339 std::string original_mime_type_; |
| 335 | 340 |
| 336 // Total bytes expected | 341 // Total bytes expected |
| 337 int64 total_bytes_; | 342 int64 total_bytes_; |
| 338 | 343 |
| 339 // Current received bytes | 344 // Current received bytes |
| 340 int64 received_bytes_; | 345 int64 received_bytes_; |
| 346 DownloadProcessHandle process_handle_; | |
|
Paweł Hajdan Jr.
2011/05/05 20:13:51
nit: There should be an empty line above an a comm
ahendrickson
2011/05/06 16:16:50
Done.
| |
| 341 | 347 |
| 342 // Last error. | 348 // Last error. |
| 343 int last_os_error_; | 349 int last_os_error_; |
| 344 | 350 |
| 345 // Start time for calculating remaining time | 351 // Start time for calculating remaining time |
| 346 base::TimeTicks start_tick_; | 352 base::TimeTicks start_tick_; |
| 347 | 353 |
| 348 // The current state of this download | 354 // The current state of this download |
| 349 DownloadState state_; | 355 DownloadState state_; |
| 350 | 356 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 379 // Whether the download was auto-opened. We set this rather than using | 385 // Whether the download was auto-opened. We set this rather than using |
| 380 // an observer as it's frequently possible for the download to be auto opened | 386 // an observer as it's frequently possible for the download to be auto opened |
| 381 // before the observer is added. | 387 // before the observer is added. |
| 382 bool auto_opened_; | 388 bool auto_opened_; |
| 383 | 389 |
| 384 // Dangerous downloads or ongoing downloads are given temporary names until | 390 // Dangerous downloads or ongoing downloads are given temporary names until |
| 385 // the user approves them or the downloads finish. | 391 // the user approves them or the downloads finish. |
| 386 // This stores their final target name. | 392 // This stores their final target name. |
| 387 FilePath target_name_; | 393 FilePath target_name_; |
| 388 | 394 |
| 389 // For canceling or pausing requests. | |
| 390 int render_process_id_; | |
| 391 int request_id_; | |
| 392 | |
| 393 // True if the item was downloaded as a result of 'save as...' | 395 // True if the item was downloaded as a result of 'save as...' |
| 394 bool save_as_; | 396 bool save_as_; |
| 395 | 397 |
| 396 // True if the download was initiated in an incognito window. | 398 // True if the download was initiated in an incognito window. |
| 397 bool is_otr_; | 399 bool is_otr_; |
| 398 | 400 |
| 399 // True if the item was downloaded for an extension installation. | 401 // True if the item was downloaded for an extension installation. |
| 400 bool is_extension_install_; | 402 bool is_extension_install_; |
| 401 | 403 |
| 402 // True if the filename is finalized. | 404 // True if the filename is finalized. |
| 403 bool name_finalized_; | 405 bool name_finalized_; |
| 404 | 406 |
| 405 // True if the item was downloaded temporarily. | 407 // True if the item was downloaded temporarily. |
| 406 bool is_temporary_; | 408 bool is_temporary_; |
| 407 | 409 |
| 408 // True if we've saved all the data for the download. | 410 // True if we've saved all the data for the download. |
| 409 bool all_data_saved_; | 411 bool all_data_saved_; |
| 410 | 412 |
| 411 // Did the user open the item either directly or indirectly (such as by | 413 // Did the user open the item either directly or indirectly (such as by |
| 412 // setting always open files of this type)? The shelf also sets this field | 414 // setting always open files of this type)? The shelf also sets this field |
| 413 // when the user closes the shelf before the item has been opened but should | 415 // when the user closes the shelf before the item has been opened but should |
| 414 // be treated as though the user opened it. | 416 // be treated as though the user opened it. |
| 415 bool opened_; | 417 bool opened_; |
| 416 | 418 |
| 417 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | 419 DISALLOW_COPY_AND_ASSIGN(DownloadItem); |
| 418 }; | 420 }; |
| 419 | 421 |
| 420 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 422 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| OLD | NEW |