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

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

Issue 11028131: Shift passage of FileStream in downloads system to be by scoped_ptr<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated Al's comments. 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_BASE_FILE_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_
6 #define CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 17 matching lines...) Expand all
28 // File being downloaded and saved to disk. This is a base class 28 // File being downloaded and saved to disk. This is a base class
29 // for DownloadFile and SaveFile, which keep more state information. 29 // for DownloadFile and SaveFile, which keep more state information.
30 class CONTENT_EXPORT BaseFile { 30 class CONTENT_EXPORT BaseFile {
31 public: 31 public:
32 BaseFile(const FilePath& full_path, 32 BaseFile(const FilePath& full_path,
33 const GURL& source_url, 33 const GURL& source_url,
34 const GURL& referrer_url, 34 const GURL& referrer_url,
35 int64 received_bytes, 35 int64 received_bytes,
36 bool calculate_hash, 36 bool calculate_hash,
37 const std::string& hash_state, 37 const std::string& hash_state,
38 const linked_ptr<net::FileStream>& file_stream, 38 scoped_ptr<net::FileStream> file_stream,
39 const net::BoundNetLog& bound_net_log); 39 const net::BoundNetLog& bound_net_log);
40 virtual ~BaseFile(); 40 virtual ~BaseFile();
41 41
42 // Returns net::OK on success, or a network error code on failure. 42 // Returns net::OK on success, or a network error code on failure.
43 // |default_directory| specifies the directory to create the temporary file in 43 // |default_directory| specifies the directory to create the temporary file in
44 // if |full_path()| is empty. If |default_directory| and |full_path()| are 44 // if |full_path()| is empty. If |default_directory| and |full_path()| are
45 // empty, then a temporary file will be created in the default download 45 // empty, then a temporary file will be created in the default download
46 // location as determined by ContentBrowserClient. 46 // location as determined by ContentBrowserClient.
47 net::Error Initialize(const FilePath& default_directory); 47 net::Error Initialize(const FilePath& default_directory);
48 48
(...skipping 15 matching lines...) Expand all
64 // Indicate that the download has finished. No new data will be received. 64 // Indicate that the download has finished. No new data will be received.
65 void Finish(); 65 void Finish();
66 66
67 // Informs the OS that this file came from the internet. 67 // Informs the OS that this file came from the internet.
68 void AnnotateWithSourceInformation(); 68 void AnnotateWithSourceInformation();
69 69
70 // Calculate and return the current speed in bytes per second. 70 // Calculate and return the current speed in bytes per second.
71 int64 CurrentSpeed() const; 71 int64 CurrentSpeed() const;
72 72
73 FilePath full_path() const { return full_path_; } 73 FilePath full_path() const { return full_path_; }
74 bool in_progress() const { return file_stream_ != NULL; } 74 bool in_progress() const { return file_stream_.get() != NULL; }
75 int64 bytes_so_far() const { return bytes_so_far_; } 75 int64 bytes_so_far() const { return bytes_so_far_; }
76 76
77 // Fills |hash| with the hash digest for the file. 77 // Fills |hash| with the hash digest for the file.
78 // Returns true if digest is successfully calculated. 78 // Returns true if digest is successfully calculated.
79 virtual bool GetHash(std::string* hash); 79 virtual bool GetHash(std::string* hash);
80 80
81 // Returns the current (intermediate) state of the hash as a byte string. 81 // Returns the current (intermediate) state of the hash as a byte string.
82 virtual std::string GetHashState(); 82 virtual std::string GetHashState();
83 83
84 // Returns true if the given hash is considered empty. An empty hash is 84 // Returns true if the given hash is considered empty. An empty hash is
(...skipping 27 matching lines...) Expand all
112 static const size_t kSha256HashLen = 32; 112 static const size_t kSha256HashLen = 32;
113 static const unsigned char kEmptySha256Hash[kSha256HashLen]; 113 static const unsigned char kEmptySha256Hash[kSha256HashLen];
114 114
115 // Source URL for the file being downloaded. 115 // Source URL for the file being downloaded.
116 GURL source_url_; 116 GURL source_url_;
117 117
118 // The URL where the download was initiated. 118 // The URL where the download was initiated.
119 GURL referrer_url_; 119 GURL referrer_url_;
120 120
121 // OS file stream for writing 121 // OS file stream for writing
122 linked_ptr<net::FileStream> file_stream_; 122 scoped_ptr<net::FileStream> file_stream_;
123 123
124 // Amount of data received up so far, in bytes. 124 // Amount of data received up so far, in bytes.
125 int64 bytes_so_far_; 125 int64 bytes_so_far_;
126 126
127 // Start time for calculating speed. 127 // Start time for calculating speed.
128 base::TimeTicks start_tick_; 128 base::TimeTicks start_tick_;
129 129
130 // Indicates if hash should be calculated for the file. 130 // Indicates if hash should be calculated for the file.
131 bool calculate_hash_; 131 bool calculate_hash_;
132 132
133 // Used to calculate hash for the file when calculate_hash_ 133 // Used to calculate hash for the file when calculate_hash_
134 // is set. 134 // is set.
135 scoped_ptr<crypto::SecureHash> secure_hash_; 135 scoped_ptr<crypto::SecureHash> secure_hash_;
136 136
137 unsigned char sha256_hash_[kSha256HashLen]; 137 unsigned char sha256_hash_[kSha256HashLen];
138 138
139 // Indicates that this class no longer owns the associated file, and so 139 // Indicates that this class no longer owns the associated file, and so
140 // won't delete it on destruction. 140 // won't delete it on destruction.
141 bool detached_; 141 bool detached_;
142 142
143 net::BoundNetLog bound_net_log_; 143 net::BoundNetLog bound_net_log_;
144 144
145 DISALLOW_COPY_AND_ASSIGN(BaseFile); 145 DISALLOW_COPY_AND_ASSIGN(BaseFile);
146 }; 146 };
147 147
148 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ 148 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu.cc ('k') | content/browser/download/base_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698