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

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

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