| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 208 } | 210 } | 
| 209 | 211 | 
| 210 bool BaseFile::Open() { | 212 bool BaseFile::Open() { | 
| 211   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 213   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 
| 212   DCHECK(!detached_); | 214   DCHECK(!detached_); | 
| 213   DCHECK(!full_path_.empty()); | 215   DCHECK(!full_path_.empty()); | 
| 214 | 216 | 
| 215   // Create a new file stream if it is not provided. | 217   // Create a new file stream if it is not provided. | 
| 216   if (!file_stream_.get()) { | 218   if (!file_stream_.get()) { | 
| 217     CreateFileStream(); | 219     CreateFileStream(); | 
|  | 220     file_stream_->EnableErrorStatistics(); | 
| 218     if (file_stream_->Open(full_path_, | 221     if (file_stream_->Open(full_path_, | 
| 219                            base::PLATFORM_FILE_OPEN_ALWAYS | | 222                            base::PLATFORM_FILE_OPEN_ALWAYS | | 
| 220                                base::PLATFORM_FILE_WRITE) != net::OK) { | 223                                base::PLATFORM_FILE_WRITE) != net::OK) { | 
| 221       file_stream_.reset(); | 224       file_stream_.reset(); | 
| 222       return false; | 225       return false; | 
| 223     } | 226     } | 
| 224 | 227 | 
| 225     // We may be re-opening the file after rename. Always make sure we're | 228     // We may be re-opening the file after rename. Always make sure we're | 
| 226     // writing at the end of the file. | 229     // writing at the end of the file. | 
| 227     if (file_stream_->Seek(net::FROM_END, 0) < 0) { | 230     if (file_stream_->Seek(net::FROM_END, 0) < 0) { | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 251 | 254 | 
| 252 std::string BaseFile::DebugString() const { | 255 std::string BaseFile::DebugString() const { | 
| 253   return base::StringPrintf("{ source_url_ = \"%s\"" | 256   return base::StringPrintf("{ source_url_ = \"%s\"" | 
| 254                             " full_path_ = \"%" PRFilePath "\"" | 257                             " full_path_ = \"%" PRFilePath "\"" | 
| 255                             " bytes_so_far_ = %" PRId64 " detached_ = %c }", | 258                             " bytes_so_far_ = %" PRId64 " detached_ = %c }", | 
| 256                             source_url_.spec().c_str(), | 259                             source_url_.spec().c_str(), | 
| 257                             full_path_.value().c_str(), | 260                             full_path_.value().c_str(), | 
| 258                             bytes_so_far_, | 261                             bytes_so_far_, | 
| 259                             detached_ ? 'T' : 'F'); | 262                             detached_ ? 'T' : 'F'); | 
| 260 } | 263 } | 
| OLD | NEW | 
|---|