| 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" |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
| 18 #include "content/browser/download/download_net_log_parameters.h" | 18 #include "content/browser/download/download_net_log_parameters.h" |
| 19 #include "content/browser/download/download_request_handle.h" | 19 #include "content/browser/download/download_request_handle.h" |
| 20 #include "content/browser/loader/global_routing_id.h" |
| 20 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
| 21 #include "content/public/browser/download_destination_observer.h" | 22 #include "content/public/browser/download_destination_observer.h" |
| 23 #include "content/public/browser/download_interrupt_reasons.h" |
| 22 #include "content/public/browser/download_item.h" | 24 #include "content/public/browser/download_item.h" |
| 23 #include "net/base/net_errors.h" | |
| 24 #include "net/base/net_log.h" | 25 #include "net/base/net_log.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 namespace content { | 28 namespace content { |
| 28 class DownloadFile; | 29 class DownloadFile; |
| 29 class DownloadItemImplDelegate; | 30 class DownloadItemImplDelegate; |
| 30 | 31 |
| 31 // See download_item.h for usage. | 32 // See download_item.h for usage. |
| 32 class CONTENT_EXPORT DownloadItemImpl | 33 class CONTENT_EXPORT DownloadItemImpl |
| 33 : public DownloadItem, | 34 : public DownloadItem, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 bool opened, | 69 bool opened, |
| 69 const net::BoundNetLog& bound_net_log); | 70 const net::BoundNetLog& bound_net_log); |
| 70 | 71 |
| 71 // Constructing for a regular download. | 72 // Constructing for a regular download. |
| 72 // |bound_net_log| is constructed externally for our use. | 73 // |bound_net_log| is constructed externally for our use. |
| 73 DownloadItemImpl(DownloadItemImplDelegate* delegate, | 74 DownloadItemImpl(DownloadItemImplDelegate* delegate, |
| 74 uint32 id, | 75 uint32 id, |
| 75 const DownloadCreateInfo& info, | 76 const DownloadCreateInfo& info, |
| 76 const net::BoundNetLog& bound_net_log); | 77 const net::BoundNetLog& bound_net_log); |
| 77 | 78 |
| 78 // Constructing for the "Save Page As..." feature: | |
| 79 // |bound_net_log| is constructed externally for our use. | |
| 80 DownloadItemImpl(DownloadItemImplDelegate* delegate, | |
| 81 uint32 id, | |
| 82 const base::FilePath& path, | |
| 83 const GURL& url, | |
| 84 const std::string& mime_type, | |
| 85 scoped_ptr<DownloadRequestHandleInterface> request_handle, | |
| 86 const net::BoundNetLog& bound_net_log); | |
| 87 | |
| 88 virtual ~DownloadItemImpl(); | 79 virtual ~DownloadItemImpl(); |
| 89 | 80 |
| 90 // DownloadItem | 81 // DownloadItem |
| 91 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; | 82 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; |
| 92 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; | 83 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; |
| 93 virtual void UpdateObservers() OVERRIDE; | 84 virtual void UpdateObservers() OVERRIDE; |
| 94 virtual void ValidateDangerousDownload() OVERRIDE; | 85 virtual void ValidateDangerousDownload() OVERRIDE; |
| 95 virtual void StealDangerousDownload(const AcquireFileCallback& callback) | 86 virtual void StealDangerousDownload(const AcquireFileCallback& callback) |
| 96 OVERRIDE; | 87 OVERRIDE; |
| 97 virtual void Pause() OVERRIDE; | 88 virtual void Pause() OVERRIDE; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 virtual std::string DebugString(bool verbose) const OVERRIDE; | 147 virtual std::string DebugString(bool verbose) const OVERRIDE; |
| 157 | 148 |
| 158 // All remaining public interfaces virtual to allow for DownloadItemImpl | 149 // All remaining public interfaces virtual to allow for DownloadItemImpl |
| 159 // mocks. | 150 // mocks. |
| 160 | 151 |
| 161 // Determines the resume mode for an interrupted download. Requires | 152 // Determines the resume mode for an interrupted download. Requires |
| 162 // last_reason_ to be set, but doesn't require the download to be in | 153 // last_reason_ to be set, but doesn't require the download to be in |
| 163 // INTERRUPTED state. | 154 // INTERRUPTED state. |
| 164 virtual ResumeMode GetResumeMode() const; | 155 virtual ResumeMode GetResumeMode() const; |
| 165 | 156 |
| 157 // Notify the download item that new origin information is available due to a |
| 158 // resumption request receiving a response. |
| 159 virtual void MergeOriginInfoOnResume( |
| 160 const DownloadCreateInfo& new_create_info); |
| 161 |
| 166 // State transition operations on regular downloads -------------------------- | 162 // State transition operations on regular downloads -------------------------- |
| 167 | 163 |
| 168 // Start the download. | 164 // Start the download. |
| 169 // |download_file| is the associated file on the storage medium. | 165 // |download_file| is the associated file on the storage medium. |
| 170 // |req_handle| is the new request handle associated with the download. | 166 // |req_handle| is the new request handle associated with the download. |
| 171 virtual void Start(scoped_ptr<DownloadFile> download_file, | 167 virtual void Start(scoped_ptr<DownloadFile> download_file, |
| 172 scoped_ptr<DownloadRequestHandleInterface> req_handle); | 168 scoped_ptr<DownloadRequestHandle> req_handle); |
| 173 | 169 |
| 174 // Needed because of intertwining with DownloadManagerImpl ------------------- | 170 // Needed because of intertwining with DownloadManagerImpl ------------------- |
| 175 | 171 |
| 176 // TODO(rdsmith): Unwind DownloadManagerImpl and DownloadItemImpl, | 172 // TODO(rdsmith): Unwind DownloadManagerImpl and DownloadItemImpl, |
| 177 // removing these from the public interface. | 173 // removing these from the public interface. |
| 178 | 174 |
| 179 // Notify observers that this item is being removed by the user. | 175 // Notify observers that this item is being removed by the user. |
| 180 virtual void NotifyRemoved(); | 176 virtual void NotifyRemoved(); |
| 181 | 177 |
| 182 virtual void OnDownloadedFileRemoved(); | 178 virtual void OnDownloadedFileRemoved(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 324 |
| 329 // Called if the embedder took over opening a download, to indicate that | 325 // Called if the embedder took over opening a download, to indicate that |
| 330 // the download has been opened. | 326 // the download has been opened. |
| 331 void DelayedDownloadOpened(bool auto_opened); | 327 void DelayedDownloadOpened(bool auto_opened); |
| 332 | 328 |
| 333 // Called when the entire download operation (including renaming etc) | 329 // Called when the entire download operation (including renaming etc) |
| 334 // is completed. | 330 // is completed. |
| 335 void Completed(); | 331 void Completed(); |
| 336 | 332 |
| 337 // Callback invoked when the URLRequest for a download resumption has started. | 333 // Callback invoked when the URLRequest for a download resumption has started. |
| 338 void OnResumeRequestStarted(DownloadItem* item, net::Error error); | 334 void OnResumeRequestStarted(DownloadItem* item, |
| 335 DownloadInterruptReason interrupt_reason); |
| 339 | 336 |
| 340 // Helper routines ----------------------------------------------------------- | 337 // Helper routines ----------------------------------------------------------- |
| 341 | 338 |
| 342 // Indicate that an error has occurred on the download. | 339 // Indicate that an error has occurred on the download. |
| 343 void Interrupt(DownloadInterruptReason reason); | 340 void Interrupt(DownloadInterruptReason reason); |
| 344 | 341 |
| 345 // Destroy the DownloadFile object. If |destroy_file| is true, the file is | 342 // Destroy the DownloadFile object. If |destroy_file| is true, the file is |
| 346 // destroyed with it. Otherwise, DownloadFile::Detach() is called before | 343 // destroyed with it. Otherwise, DownloadFile::Detach() is called before |
| 347 // object destruction to prevent file destruction. Destroying the file also | 344 // object destruction to prevent file destruction. Destroying the file also |
| 348 // resets |current_path_|. | 345 // resets |current_path_|. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 376 // Debugging routines -------------------------------------------------------- | 373 // Debugging routines -------------------------------------------------------- |
| 377 static const char* DebugDownloadStateString(DownloadInternalState state); | 374 static const char* DebugDownloadStateString(DownloadInternalState state); |
| 378 static const char* DebugResumeModeString(ResumeMode mode); | 375 static const char* DebugResumeModeString(ResumeMode mode); |
| 379 | 376 |
| 380 // Will be false for save package downloads retrieved from the history. | 377 // Will be false for save package downloads retrieved from the history. |
| 381 // TODO(rdsmith): Replace with a generalized enum for "download source". | 378 // TODO(rdsmith): Replace with a generalized enum for "download source". |
| 382 const bool is_save_package_download_; | 379 const bool is_save_package_download_; |
| 383 | 380 |
| 384 // The handle to the request information. Used for operations outside the | 381 // The handle to the request information. Used for operations outside the |
| 385 // download system. | 382 // download system. |
| 386 scoped_ptr<DownloadRequestHandleInterface> request_handle_; | 383 scoped_ptr<DownloadRequestHandle> request_handle_; |
| 387 | 384 |
| 388 uint32 download_id_; | 385 uint32 download_id_; |
| 389 | 386 |
| 390 // Display name for the download. If this is empty, then the display name is | 387 // Display name for the download. If this is empty, then the display name is |
| 391 // considered to be |target_path_.BaseName()|. | 388 // considered to be |target_path_.BaseName()|. |
| 392 base::FilePath display_name_; | 389 base::FilePath display_name_; |
| 393 | 390 |
| 394 // Full path to the downloaded or downloading file. This is the path to the | 391 // Full path to the downloaded or downloading file. This is the path to the |
| 395 // physical file, if one exists. The final target path is specified by | 392 // physical file, if one exists. The final target path is specified by |
| 396 // |target_path_|. |current_path_| can be empty if the in-progress path hasn't | 393 // |target_path_|. |current_path_| can be empty if the in-progress path hasn't |
| (...skipping 22 matching lines...) Expand all Loading... |
| 419 // If non-empty, contains an externally supplied path that should be used as | 416 // If non-empty, contains an externally supplied path that should be used as |
| 420 // the target path. | 417 // the target path. |
| 421 base::FilePath forced_file_path_; | 418 base::FilePath forced_file_path_; |
| 422 | 419 |
| 423 // Page transition that triggerred the download. | 420 // Page transition that triggerred the download. |
| 424 PageTransition transition_type_; | 421 PageTransition transition_type_; |
| 425 | 422 |
| 426 // Whether the download was triggered with a user gesture. | 423 // Whether the download was triggered with a user gesture. |
| 427 bool has_user_gesture_; | 424 bool has_user_gesture_; |
| 428 | 425 |
| 426 // Route associated with this download. |
| 427 GlobalRoutingID route_id_; |
| 428 |
| 429 // Information from the request. | 429 // Information from the request. |
| 430 // Content-disposition field from the header. | 430 // Content-disposition field from the header. |
| 431 std::string content_disposition_; | 431 std::string content_disposition_; |
| 432 | 432 |
| 433 // Mime-type from the header. Subject to change. | 433 // Mime-type from the header. Subject to change. |
| 434 std::string mime_type_; | 434 std::string mime_type_; |
| 435 | 435 |
| 436 // The value of the content type header sent with the downloaded item. It | 436 // The value of the content type header sent with the downloaded item. It |
| 437 // may be different from |mime_type_|, which may be set based on heuristics | 437 // may be different from |mime_type_|, which may be set based on heuristics |
| 438 // which may look at the file extension and first few bytes of the file. | 438 // which may look at the file extension and first few bytes of the file. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 const net::BoundNetLog bound_net_log_; | 537 const net::BoundNetLog bound_net_log_; |
| 538 | 538 |
| 539 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; | 539 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; |
| 540 | 540 |
| 541 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 541 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
| 542 }; | 542 }; |
| 543 | 543 |
| 544 } // namespace content | 544 } // namespace content |
| 545 | 545 |
| 546 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 546 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
| OLD | NEW |