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