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

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

Issue 10392111: Use ByteStream in downloads system to decouple source and sink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to LKGR. Created 8 years, 6 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 #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:
62 // For test class overrides.
63 virtual net::Error AppendDataToFile(const char* data,
64 size_t data_len);
65
58 private: 66 private:
67 // Called when there's some activity on stream_reader_ that needs to be
68 // handled.
69 void StreamActive();
70
59 // Send updates on our progress. 71 // Send updates on our progress.
60 void SendUpdate(); 72 void SendUpdate();
61 73
62 // The base file instance. 74 // The base file instance.
63 BaseFile file_; 75 BaseFile file_;
64 76
77 // The stream through which data comes.
78 // TODO(rdsmith): Move this into BaseFile; requires using the same
79 // stream semantics in SavePackage. Alternatively, replace SaveFile
80 // with DownloadFile and get rid of BaseFile.
81 scoped_ptr<content::ByteStreamReader> stream_reader_;
82
65 // The unique identifier for this download, assigned at creation by 83 // The unique identifier for this download, assigned at creation by
66 // the DownloadFileManager for its internal record keeping. 84 // the DownloadFileManager for its internal record keeping.
67 content::DownloadId id_; 85 content::DownloadId id_;
68 86
69 // Used to trigger progress updates. 87 // Used to trigger progress updates.
70 scoped_ptr<base::RepeatingTimer<DownloadFileImpl> > update_timer_; 88 scoped_ptr<base::RepeatingTimer<DownloadFileImpl> > update_timer_;
71 89
72 // The handle to the request information. Used for operations outside the 90 // The handle to the request information. Used for operations outside the
73 // download system, specifically canceling a download. 91 // download system, specifically canceling a download.
74 scoped_ptr<DownloadRequestHandleInterface> request_handle_; 92 scoped_ptr<DownloadRequestHandleInterface> request_handle_;
75 93
76 // DownloadManager this download belongs to. 94 // DownloadManager this download belongs to.
77 scoped_refptr<content::DownloadManager> download_manager_; 95 scoped_refptr<content::DownloadManager> download_manager_;
78 96
97 // Statistics
98 size_t bytes_seen_;
99 base::TimeDelta disk_writes_time_;
100 base::TimeTicks download_start_;
101
102 net::BoundNetLog bound_net_log_;
103
104 base::WeakPtrFactory<DownloadFileImpl> weak_factory_;
105
79 // RAII handle to keep the system from sleeping while we're downloading. 106 // RAII handle to keep the system from sleeping while we're downloading.
80 scoped_ptr<PowerSaveBlocker> power_save_blocker_; 107 scoped_ptr<PowerSaveBlocker> power_save_blocker_;
81 108
82 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); 109 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl);
83 }; 110 };
84 111
85 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ 112 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_file.h ('k') | content/browser/download/download_file_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698