Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: content/browser/download/download_file_impl.h

Issue 10912173: Replace the DownloadFileManager with direct ownership of DownloadFileImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to LKGR (r162700) Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 7
8 #include "content/browser/download/download_file.h" 8 #include "content/browser/download/download_file.h"
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "base/timer.h" 14 #include "base/timer.h"
15 #include "content/browser/download/base_file.h" 15 #include "content/browser/download/base_file.h"
16 #include "content/browser/download/byte_stream.h" 16 #include "content/browser/download/byte_stream.h"
17 #include "content/browser/download/download_request_handle.h" 17 #include "content/public/browser/download_save_info.h"
18 #include "net/base/net_log.h" 18 #include "net/base/net_log.h"
19 19
20 struct DownloadCreateInfo; 20 struct DownloadCreateInfo;
21 21
22 namespace content { 22 namespace content {
23 class ByteStreamReader; 23 class ByteStreamReader;
24 class DownloadDestinationObserver;
24 class DownloadManager; 25 class DownloadManager;
25 class PowerSaveBlocker; 26 class PowerSaveBlocker;
26 } 27 }
27 28
28 class CONTENT_EXPORT DownloadFileImpl : virtual public content::DownloadFile { 29 class CONTENT_EXPORT DownloadFileImpl : virtual public content::DownloadFile {
29 public: 30 public:
30 // Takes ownership of the object pointed to by |request_handle|. 31 // Takes ownership of the object pointed to by |request_handle|.
31 // |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.
32 DownloadFileImpl(scoped_ptr<DownloadCreateInfo> info, 33 // May be constructed on any thread. All methods besides the constructor
33 scoped_ptr<content::ByteStreamReader> stream, 34 // (including destruction) must occur on the FILE thread.
34 scoped_ptr<DownloadRequestHandleInterface> request_handle, 35 //
35 scoped_refptr<content::DownloadManager> download_manager, 36 // Note that the DownloadFileImpl automatically reads from the passed in
36 bool calculate_hash, 37 // stream, and sends updates and status of those reads to the
37 scoped_ptr<content::PowerSaveBlocker> power_save_blocker, 38 // DownloadDestinationObserver.
38 const net::BoundNetLog& bound_net_log); 39 DownloadFileImpl(
40 scoped_ptr<content::DownloadSaveInfo> save_info,
41 const FilePath& default_downloads_directory,
42 const GURL& url,
43 const GURL& referrer_url,
44 int64 received_bytes,
45 bool calculate_hash,
46 scoped_ptr<content::ByteStreamReader> stream,
47 const net::BoundNetLog& bound_net_log,
48 scoped_ptr<content::PowerSaveBlocker> power_save_blocker,
49 base::WeakPtr<content::DownloadDestinationObserver> observer);
50
39 virtual ~DownloadFileImpl(); 51 virtual ~DownloadFileImpl();
40 52
41 // DownloadFile functions. 53 // DownloadFile functions.
42 virtual content::DownloadInterruptReason Initialize() OVERRIDE; 54 virtual void Initialize(const InitializeCallback& callback) OVERRIDE;
43 virtual void Rename(const FilePath& full_path, 55 virtual void Rename(const FilePath& full_path,
44 bool overwrite_existing_file, 56 bool overwrite_existing_file,
45 const RenameCompletionCallback& callback) OVERRIDE; 57 const RenameCompletionCallback& callback) OVERRIDE;
46 virtual void Detach(base::Closure callback) OVERRIDE; 58 virtual void Detach(base::Closure callback) OVERRIDE;
47 virtual void Cancel() OVERRIDE; 59 virtual void Cancel() OVERRIDE;
48 virtual void AnnotateWithSourceInformation() OVERRIDE; 60 virtual void AnnotateWithSourceInformation() OVERRIDE;
49 virtual FilePath FullPath() const OVERRIDE; 61 virtual FilePath FullPath() const OVERRIDE;
50 virtual bool InProgress() const OVERRIDE; 62 virtual bool InProgress() const OVERRIDE;
51 virtual int64 BytesSoFar() const OVERRIDE; 63 virtual int64 BytesSoFar() const OVERRIDE;
52 virtual int64 CurrentSpeed() const OVERRIDE; 64 virtual int64 CurrentSpeed() const OVERRIDE;
53 virtual bool GetHash(std::string* hash) OVERRIDE; 65 virtual bool GetHash(std::string* hash) OVERRIDE;
54 virtual std::string GetHashState() OVERRIDE; 66 virtual std::string GetHashState() OVERRIDE;
55 virtual void CancelDownloadRequest() OVERRIDE;
56 virtual int Id() const OVERRIDE;
57 virtual content::DownloadManager* GetDownloadManager() OVERRIDE;
58 virtual const content::DownloadId& GlobalId() const OVERRIDE;
59 virtual std::string DebugString() const OVERRIDE;
60 67
61 protected: 68 protected:
62 // For test class overrides. 69 // For test class overrides.
63 virtual content::DownloadInterruptReason AppendDataToFile( 70 virtual content::DownloadInterruptReason AppendDataToFile(
64 const char* data, size_t data_len); 71 const char* data, size_t data_len);
65 72
66 private: 73 private:
67 // Send an update on our progress. 74 // Send an update on our progress.
68 void SendUpdate(); 75 void SendUpdate();
69 76
70 // Called when there's some activity on stream_reader_ that needs to be 77 // Called when there's some activity on stream_reader_ that needs to be
71 // handled. 78 // handled.
72 void StreamActive(); 79 void StreamActive();
73 80
74 // The base file instance. 81 // The base file instance.
75 BaseFile file_; 82 BaseFile file_;
76 83
84 // The default directory for creating the download file.
85 FilePath default_download_directory_;
86
77 // The stream through which data comes. 87 // The stream through which data comes.
78 // TODO(rdsmith): Move this into BaseFile; requires using the same 88 // TODO(rdsmith): Move this into BaseFile; requires using the same
79 // stream semantics in SavePackage. Alternatively, replace SaveFile 89 // stream semantics in SavePackage. Alternatively, replace SaveFile
80 // with DownloadFile and get rid of BaseFile. 90 // with DownloadFile and get rid of BaseFile.
81 scoped_ptr<content::ByteStreamReader> stream_reader_; 91 scoped_ptr<content::ByteStreamReader> stream_reader_;
82 92
83 // The unique identifier for this download, assigned at creation by
84 // the DownloadFileManager for its internal record keeping.
85 content::DownloadId id_;
86
87 // The default directory for creating the download file.
88 FilePath default_download_directory_;
89
90 // Used to trigger progress updates. 93 // Used to trigger progress updates.
91 scoped_ptr<base::RepeatingTimer<DownloadFileImpl> > update_timer_; 94 scoped_ptr<base::RepeatingTimer<DownloadFileImpl> > update_timer_;
92 95
93 // The handle to the request information. Used for operations outside the
94 // download system, specifically canceling a download.
95 scoped_ptr<DownloadRequestHandleInterface> request_handle_;
96
97 // DownloadManager this download belongs to.
98 scoped_refptr<content::DownloadManager> download_manager_;
99
100 // Statistics 96 // Statistics
101 size_t bytes_seen_; 97 size_t bytes_seen_;
102 base::TimeDelta disk_writes_time_; 98 base::TimeDelta disk_writes_time_;
103 base::TimeTicks download_start_; 99 base::TimeTicks download_start_;
104 100
105 net::BoundNetLog bound_net_log_; 101 net::BoundNetLog bound_net_log_;
106 102
103 base::WeakPtr<content::DownloadDestinationObserver> observer_;
104
107 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; 105 base::WeakPtrFactory<DownloadFileImpl> weak_factory_;
108 106
109 // RAII handle to keep the system from sleeping while we're downloading. 107 // RAII handle to keep the system from sleeping while we're downloading.
110 scoped_ptr<content::PowerSaveBlocker> power_save_blocker_; 108 scoped_ptr<content::PowerSaveBlocker> power_save_blocker_;
111 109
112 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); 110 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl);
113 }; 111 };
114 112
115 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ 113 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_file_factory.cc ('k') | content/browser/download/download_file_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698