| 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 int64 total_bytes() const { return total_bytes_; } | 251 int64 total_bytes() const { return total_bytes_; } |
| 251 void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; } | 252 void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; } |
| 252 int64 received_bytes() const { return received_bytes_; } | 253 int64 received_bytes() const { return received_bytes_; } |
| 253 int32 id() const { return id_; } | 254 int32 id() const { return id_; } |
| 254 base::Time start_time() const { return start_time_; } | 255 base::Time start_time() const { return start_time_; } |
| 255 void set_db_handle(int64 handle) { db_handle_ = handle; } | 256 void set_db_handle(int64 handle) { db_handle_ = handle; } |
| 256 int64 db_handle() const { return db_handle_; } | 257 int64 db_handle() const { return db_handle_; } |
| 257 bool is_paused() const { return is_paused_; } | 258 bool is_paused() const { return is_paused_; } |
| 258 bool open_when_complete() const { return open_when_complete_; } | 259 bool open_when_complete() const { return open_when_complete_; } |
| 259 void set_open_when_complete(bool open) { open_when_complete_ = open; } | 260 void set_open_when_complete(bool open) { open_when_complete_ = open; } |
| 260 int render_process_id() const { return render_process_id_; } | |
| 261 int request_id() const { return request_id_; } | |
| 262 SafetyState safety_state() const { return safety_state_; } | 261 SafetyState safety_state() const { return safety_state_; } |
| 263 void set_safety_state(SafetyState safety_state) { | 262 void set_safety_state(SafetyState safety_state) { |
| 264 safety_state_ = safety_state; | 263 safety_state_ = safety_state; |
| 265 } | 264 } |
| 266 DangerType danger_type() { return danger_type_;} | 265 DangerType danger_type() { return danger_type_;} |
| 267 bool auto_opened() { return auto_opened_; } | 266 bool auto_opened() { return auto_opened_; } |
| 268 FilePath target_name() const { return target_name_; } | 267 FilePath target_name() const { return target_name_; } |
| 269 bool save_as() const { return save_as_; } | 268 bool save_as() const { return save_as_; } |
| 270 bool is_otr() const { return is_otr_; } | 269 bool is_otr() const { return is_otr_; } |
| 271 bool is_extension_install() const { return is_extension_install_; } | 270 bool is_extension_install() const { return is_extension_install_; } |
| 272 bool is_temporary() const { return is_temporary_; } | 271 bool is_temporary() const { return is_temporary_; } |
| 273 void set_opened(bool opened) { opened_ = opened; } | 272 void set_opened(bool opened) { opened_ = opened; } |
| 274 bool opened() const { return opened_; } | 273 bool opened() const { return opened_; } |
| 275 | 274 |
| 275 const DownloadProcessHandle& process_handle() const { |
| 276 return process_handle_; |
| 277 } |
| 278 |
| 276 // Returns the final target file path for the download. | 279 // Returns the final target file path for the download. |
| 277 FilePath GetTargetFilePath() const; | 280 FilePath GetTargetFilePath() const; |
| 278 | 281 |
| 279 // Returns the file-name that should be reported to the user, which is | 282 // Returns the file-name that should be reported to the user, which is |
| 280 // target_name_ possibly with the uniquifier number. | 283 // target_name_ possibly with the uniquifier number. |
| 281 FilePath GetFileNameToReportUser() const; | 284 FilePath GetFileNameToReportUser() const; |
| 282 | 285 |
| 283 // Returns the user-verified target file path for the download. | 286 // Returns the user-verified target file path for the download. |
| 284 // This returns the same path as GetTargetFilePath() for safe downloads | 287 // This returns the same path as GetTargetFilePath() for safe downloads |
| 285 // but does not for dangerous downloads until the name is verified. | 288 // but does not for dangerous downloads until the name is verified. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // Whether the download was auto-opened. We set this rather than using | 378 // Whether the download was auto-opened. We set this rather than using |
| 376 // an observer as it's frequently possible for the download to be auto opened | 379 // an observer as it's frequently possible for the download to be auto opened |
| 377 // before the observer is added. | 380 // before the observer is added. |
| 378 bool auto_opened_; | 381 bool auto_opened_; |
| 379 | 382 |
| 380 // Dangerous downloads or ongoing downloads are given temporary names until | 383 // Dangerous downloads or ongoing downloads are given temporary names until |
| 381 // the user approves them or the downloads finish. | 384 // the user approves them or the downloads finish. |
| 382 // This stores their final target name. | 385 // This stores their final target name. |
| 383 FilePath target_name_; | 386 FilePath target_name_; |
| 384 | 387 |
| 385 // For canceling or pausing requests. | 388 // The handle to the process information. Used for operations outside the |
| 386 int render_process_id_; | 389 // download system. |
| 387 int request_id_; | 390 DownloadProcessHandle process_handle_; |
| 388 | 391 |
| 389 // True if the item was downloaded as a result of 'save as...' | 392 // True if the item was downloaded as a result of 'save as...' |
| 390 bool save_as_; | 393 bool save_as_; |
| 391 | 394 |
| 392 // True if the download was initiated in an incognito window. | 395 // True if the download was initiated in an incognito window. |
| 393 bool is_otr_; | 396 bool is_otr_; |
| 394 | 397 |
| 395 // True if the item was downloaded for an extension installation. | 398 // True if the item was downloaded for an extension installation. |
| 396 bool is_extension_install_; | 399 bool is_extension_install_; |
| 397 | 400 |
| 398 // True if the item was downloaded temporarily. | 401 // True if the item was downloaded temporarily. |
| 399 bool is_temporary_; | 402 bool is_temporary_; |
| 400 | 403 |
| 401 // True if we've saved all the data for the download. | 404 // True if we've saved all the data for the download. |
| 402 bool all_data_saved_; | 405 bool all_data_saved_; |
| 403 | 406 |
| 404 // Did the user open the item either directly or indirectly (such as by | 407 // Did the user open the item either directly or indirectly (such as by |
| 405 // setting always open files of this type)? The shelf also sets this field | 408 // setting always open files of this type)? The shelf also sets this field |
| 406 // when the user closes the shelf before the item has been opened but should | 409 // when the user closes the shelf before the item has been opened but should |
| 407 // be treated as though the user opened it. | 410 // be treated as though the user opened it. |
| 408 bool opened_; | 411 bool opened_; |
| 409 | 412 |
| 410 DISALLOW_COPY_AND_ASSIGN(DownloadItem); | 413 DISALLOW_COPY_AND_ASSIGN(DownloadItem); |
| 411 }; | 414 }; |
| 412 | 415 |
| 413 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ | 416 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_H_ |
| OLD | NEW |