| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 : full_path_(full_path), | 29 : full_path_(full_path), |
| 30 source_url_(source_url), | 30 source_url_(source_url), |
| 31 referrer_url_(referrer_url), | 31 referrer_url_(referrer_url), |
| 32 file_stream_(file_stream), | 32 file_stream_(file_stream), |
| 33 bytes_so_far_(received_bytes), | 33 bytes_so_far_(received_bytes), |
| 34 power_save_blocker_(true), | 34 power_save_blocker_(true), |
| 35 calculate_hash_(false), | 35 calculate_hash_(false), |
| 36 detached_(false) { | 36 detached_(false) { |
| 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 38 memset(sha256_hash_, 0, sizeof(sha256_hash_)); | 38 memset(sha256_hash_, 0, sizeof(sha256_hash_)); |
| 39 if (file_stream_.get()) |
| 40 file_stream_->EnableErrorStatistics(); |
| 39 } | 41 } |
| 40 | 42 |
| 41 BaseFile::~BaseFile() { | 43 BaseFile::~BaseFile() { |
| 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 43 if (detached_) | 45 if (detached_) |
| 44 Close(); | 46 Close(); |
| 45 else | 47 else |
| 46 Cancel(); // Will delete the file. | 48 Cancel(); // Will delete the file. |
| 47 } | 49 } |
| 48 | 50 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 198 } |
| 197 | 199 |
| 198 bool BaseFile::Open() { | 200 bool BaseFile::Open() { |
| 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 200 DCHECK(!detached_); | 202 DCHECK(!detached_); |
| 201 DCHECK(!full_path_.empty()); | 203 DCHECK(!full_path_.empty()); |
| 202 | 204 |
| 203 // Create a new file stream if it is not provided. | 205 // Create a new file stream if it is not provided. |
| 204 if (!file_stream_.get()) { | 206 if (!file_stream_.get()) { |
| 205 file_stream_.reset(new net::FileStream); | 207 file_stream_.reset(new net::FileStream); |
| 208 file_stream_->EnableErrorStatistics(); |
| 206 if (file_stream_->Open(full_path_, | 209 if (file_stream_->Open(full_path_, |
| 207 base::PLATFORM_FILE_OPEN_ALWAYS | | 210 base::PLATFORM_FILE_OPEN_ALWAYS | |
| 208 base::PLATFORM_FILE_WRITE) != net::OK) { | 211 base::PLATFORM_FILE_WRITE) != net::OK) { |
| 209 file_stream_.reset(); | 212 file_stream_.reset(); |
| 210 return false; | 213 return false; |
| 211 } | 214 } |
| 212 | 215 |
| 213 // We may be re-opening the file after rename. Always make sure we're | 216 // We may be re-opening the file after rename. Always make sure we're |
| 214 // writing at the end of the file. | 217 // writing at the end of the file. |
| 215 if (file_stream_->Seek(net::FROM_END, 0) < 0) { | 218 if (file_stream_->Seek(net::FROM_END, 0) < 0) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 239 | 242 |
| 240 std::string BaseFile::DebugString() const { | 243 std::string BaseFile::DebugString() const { |
| 241 return base::StringPrintf("{ source_url_ = \"%s\"" | 244 return base::StringPrintf("{ source_url_ = \"%s\"" |
| 242 " full_path_ = \"%" PRFilePath "\"" | 245 " full_path_ = \"%" PRFilePath "\"" |
| 243 " bytes_so_far_ = %" PRId64 " detached_ = %c }", | 246 " bytes_so_far_ = %" PRId64 " detached_ = %c }", |
| 244 source_url_.spec().c_str(), | 247 source_url_.spec().c_str(), |
| 245 full_path_.value().c_str(), | 248 full_path_.value().c_str(), |
| 246 bytes_so_far_, | 249 bytes_so_far_, |
| 247 detached_ ? 'T' : 'F'); | 250 detached_ ? 'T' : 'F'); |
| 248 } | 251 } |
| OLD | NEW |