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 #include "content/browser/download/base_file.h" | 5 #include "content/browser/download/base_file.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 | 202 |
203 // This will initialize the entire array to zero. | 203 // This will initialize the entire array to zero. |
204 const unsigned char BaseFile::kEmptySha256Hash[] = { 0 }; | 204 const unsigned char BaseFile::kEmptySha256Hash[] = { 0 }; |
205 | 205 |
206 BaseFile::BaseFile(const FilePath& full_path, | 206 BaseFile::BaseFile(const FilePath& full_path, |
207 const GURL& source_url, | 207 const GURL& source_url, |
208 const GURL& referrer_url, | 208 const GURL& referrer_url, |
209 int64 received_bytes, | 209 int64 received_bytes, |
210 bool calculate_hash, | 210 bool calculate_hash, |
211 const std::string& hash_state, | 211 const std::string& hash_state, |
212 const linked_ptr<net::FileStream>& file_stream, | 212 const linked_ptr<net::FileStream>& file_stream, |
asanka
2012/10/10 16:04:40
linked_ptr<> isn't thread safe. Can a note be adde
| |
213 const net::BoundNetLog& bound_net_log) | 213 const net::BoundNetLog& bound_net_log) |
214 : full_path_(full_path), | 214 : full_path_(full_path), |
215 source_url_(source_url), | 215 source_url_(source_url), |
216 referrer_url_(referrer_url), | 216 referrer_url_(referrer_url), |
217 file_stream_(file_stream), | 217 file_stream_(file_stream), |
218 bytes_so_far_(received_bytes), | 218 bytes_so_far_(received_bytes), |
219 start_tick_(base::TimeTicks::Now()), | 219 start_tick_(base::TimeTicks::Now()), |
220 calculate_hash_(calculate_hash), | 220 calculate_hash_(calculate_hash), |
221 detached_(false), | 221 detached_(false), |
222 bound_net_log_(bound_net_log) { | 222 bound_net_log_(bound_net_log) { |
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
224 memcpy(sha256_hash_, kEmptySha256Hash, kSha256HashLen); | 223 memcpy(sha256_hash_, kEmptySha256Hash, kSha256HashLen); |
225 if (file_stream_.get()) { | 224 if (file_stream_.get()) { |
asanka
2012/10/10 16:04:40
Suggestion: If the constructor can be called from
Randy Smith (Not in Mondays)
2012/10/16 18:30:29
Done.
| |
226 file_stream_->SetBoundNetLogSource(bound_net_log_); | 225 file_stream_->SetBoundNetLogSource(bound_net_log_); |
227 file_stream_->EnableErrorStatistics(); | 226 file_stream_->EnableErrorStatistics(); |
228 } | 227 } |
229 | 228 |
230 if (calculate_hash_) { | 229 if (calculate_hash_) { |
231 secure_hash_.reset(crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | 230 secure_hash_.reset(crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
232 if ((bytes_so_far_ > 0) && // Not starting at the beginning. | 231 if ((bytes_so_far_ > 0) && // Not starting at the beginning. |
233 (hash_state != "") && // Reasonably sure we have a hash state. | 232 (hash_state != "") && // Reasonably sure we have a hash state. |
234 (!IsEmptyHash(hash_state))) { | 233 (!IsEmptyHash(hash_state))) { |
235 SetHashState(hash_state); | 234 SetHashState(hash_state); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const { | 555 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const { |
557 base::TimeDelta diff = current_time - start_tick_; | 556 base::TimeDelta diff = current_time - start_tick_; |
558 int64 diff_ms = diff.InMilliseconds(); | 557 int64 diff_ms = diff.InMilliseconds(); |
559 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms; | 558 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms; |
560 } | 559 } |
561 | 560 |
562 int64 BaseFile::CurrentSpeed() const { | 561 int64 BaseFile::CurrentSpeed() const { |
563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
564 return CurrentSpeedAtTime(base::TimeTicks::Now()); | 563 return CurrentSpeedAtTime(base::TimeTicks::Now()); |
565 } | 564 } |
OLD | NEW |