Chromium Code Reviews| 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_FILE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "content/browser/download/download_file.h" | 9 #include "content/browser/download/download_file.h" |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/time.h" | |
| 13 #include "base/timer.h" | 15 #include "base/timer.h" |
| 14 #include "content/browser/download/base_file.h" | 16 #include "content/browser/download/base_file.h" |
| 17 #include "content/browser/download/byte_stream.h" | |
| 15 #include "content/browser/download/download_request_handle.h" | 18 #include "content/browser/download/download_request_handle.h" |
| 19 #include "net/base/net_log.h" | |
| 16 | 20 |
| 17 class PowerSaveBlocker; | 21 class PowerSaveBlocker; |
| 18 | 22 |
| 19 struct DownloadCreateInfo; | 23 struct DownloadCreateInfo; |
| 20 | 24 |
| 21 namespace content { | 25 namespace content { |
| 26 class ByteStreamReader; | |
| 22 class DownloadManager; | 27 class DownloadManager; |
| 23 } | 28 } |
| 24 | 29 |
| 25 class CONTENT_EXPORT DownloadFileImpl : virtual public content::DownloadFile { | 30 class CONTENT_EXPORT DownloadFileImpl : virtual public content::DownloadFile { |
| 26 public: | 31 public: |
| 27 // Takes ownership of the object pointed to by |request_handle|. | 32 // Takes ownership of the object pointed to by |request_handle|. |
| 28 // |bound_net_log| will be used for logging the download file's events. | 33 // |bound_net_log| will be used for logging the download file's events. |
| 29 DownloadFileImpl(const DownloadCreateInfo* info, | 34 DownloadFileImpl(const DownloadCreateInfo* info, |
| 35 scoped_ptr<content::ByteStreamReader> stream, | |
| 30 DownloadRequestHandleInterface* request_handle, | 36 DownloadRequestHandleInterface* request_handle, |
| 31 content::DownloadManager* download_manager, | 37 content::DownloadManager* download_manager, |
| 32 bool calculate_hash, | 38 bool calculate_hash, |
| 33 scoped_ptr<PowerSaveBlocker> power_save_blocker, | 39 scoped_ptr<PowerSaveBlocker> power_save_blocker, |
| 34 const net::BoundNetLog& bound_net_log); | 40 const net::BoundNetLog& bound_net_log); |
| 35 virtual ~DownloadFileImpl(); | 41 virtual ~DownloadFileImpl(); |
| 36 | 42 |
| 37 // DownloadFile functions. | 43 // DownloadFile functions. |
| 38 virtual net::Error Initialize() OVERRIDE; | 44 virtual net::Error Initialize() OVERRIDE; |
| 39 virtual net::Error AppendDataToFile(const char* data, | |
| 40 size_t data_len) OVERRIDE; | |
| 41 virtual net::Error Rename(const FilePath& full_path) OVERRIDE; | 45 virtual net::Error Rename(const FilePath& full_path) OVERRIDE; |
| 42 virtual void Detach() OVERRIDE; | 46 virtual void Detach() OVERRIDE; |
| 43 virtual void Cancel() OVERRIDE; | 47 virtual void Cancel() OVERRIDE; |
| 44 virtual void Finish() OVERRIDE; | |
| 45 virtual void AnnotateWithSourceInformation() OVERRIDE; | 48 virtual void AnnotateWithSourceInformation() OVERRIDE; |
| 46 virtual FilePath FullPath() const OVERRIDE; | 49 virtual FilePath FullPath() const OVERRIDE; |
| 47 virtual bool InProgress() const OVERRIDE; | 50 virtual bool InProgress() const OVERRIDE; |
| 48 virtual int64 BytesSoFar() const OVERRIDE; | 51 virtual int64 BytesSoFar() const OVERRIDE; |
| 49 virtual int64 CurrentSpeed() const OVERRIDE; | 52 virtual int64 CurrentSpeed() const OVERRIDE; |
| 50 virtual bool GetHash(std::string* hash) OVERRIDE; | 53 virtual bool GetHash(std::string* hash) OVERRIDE; |
| 51 virtual std::string GetHashState() OVERRIDE; | 54 virtual std::string GetHashState() OVERRIDE; |
| 52 virtual void CancelDownloadRequest() OVERRIDE; | 55 virtual void CancelDownloadRequest() OVERRIDE; |
| 53 virtual int Id() const OVERRIDE; | 56 virtual int Id() const OVERRIDE; |
| 54 virtual content::DownloadManager* GetDownloadManager() OVERRIDE; | 57 virtual content::DownloadManager* GetDownloadManager() OVERRIDE; |
| 55 virtual const content::DownloadId& GlobalId() const OVERRIDE; | 58 virtual const content::DownloadId& GlobalId() const OVERRIDE; |
| 56 virtual std::string DebugString() const OVERRIDE; | 59 virtual std::string DebugString() const OVERRIDE; |
| 57 | 60 |
| 61 protected: // For test class overrides. | |
|
benjhayden
2012/05/29 17:40:37
Please put the comment on the next line.
Randy Smith (Not in Mondays)
2012/05/30 00:22:32
Done.
| |
| 62 virtual net::Error AppendDataToFile(const char* data, | |
| 63 size_t data_len); | |
| 64 | |
| 58 private: | 65 private: |
| 66 // Called when there's some activity on stream_reader_ that needs to be | |
| 67 // handled. | |
| 68 void StreamActive(); | |
| 69 | |
| 59 // Send updates on our progress. | 70 // Send updates on our progress. |
| 60 void SendUpdate(); | 71 void SendUpdate(); |
| 61 | 72 |
| 62 // The base file instance. | 73 // The base file instance. |
| 63 BaseFile file_; | 74 BaseFile file_; |
| 64 | 75 |
| 76 // The stream through which data comes. | |
| 77 // TODO(rdsmith): Move this into BaseFile; requires using the same | |
| 78 // stream semantics in SavePackage. Alternatively, replace SaveFile | |
| 79 // with DownloadFile and get rid of BaseFile. | |
| 80 scoped_ptr<content::ByteStreamReader> stream_reader_; | |
| 81 | |
| 65 // The unique identifier for this download, assigned at creation by | 82 // The unique identifier for this download, assigned at creation by |
| 66 // the DownloadFileManager for its internal record keeping. | 83 // the DownloadFileManager for its internal record keeping. |
| 67 content::DownloadId id_; | 84 content::DownloadId id_; |
| 68 | 85 |
| 69 // Used to trigger progress updates. | 86 // Used to trigger progress updates. |
| 70 scoped_ptr<base::RepeatingTimer<DownloadFileImpl> > update_timer_; | 87 scoped_ptr<base::RepeatingTimer<DownloadFileImpl> > update_timer_; |
| 71 | 88 |
| 72 // The handle to the request information. Used for operations outside the | 89 // The handle to the request information. Used for operations outside the |
| 73 // download system, specifically canceling a download. | 90 // download system, specifically canceling a download. |
| 74 scoped_ptr<DownloadRequestHandleInterface> request_handle_; | 91 scoped_ptr<DownloadRequestHandleInterface> request_handle_; |
| 75 | 92 |
| 76 // DownloadManager this download belongs to. | 93 // DownloadManager this download belongs to. |
| 77 scoped_refptr<content::DownloadManager> download_manager_; | 94 scoped_refptr<content::DownloadManager> download_manager_; |
| 78 | 95 |
| 96 // Statistics | |
| 97 size_t bytes_seen_; | |
| 98 base::TimeDelta disk_writes_time_; | |
| 99 base::TimeTicks download_start_; | |
| 100 | |
| 101 net::BoundNetLog bound_net_log_; | |
| 102 | |
| 103 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; | |
| 104 | |
| 79 // RAII handle to keep the system from sleeping while we're downloading. | 105 // RAII handle to keep the system from sleeping while we're downloading. |
| 80 scoped_ptr<PowerSaveBlocker> power_save_blocker_; | 106 scoped_ptr<PowerSaveBlocker> power_save_blocker_; |
| 81 | 107 |
| 82 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); | 108 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); |
| 83 }; | 109 }; |
| 84 | 110 |
| 85 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ | 111 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ |
| OLD | NEW |