| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 win_util::SetInternetZoneIdentifier(full_path_, | 196 win_util::SetInternetZoneIdentifier(full_path_, |
| 197 UTF8ToWide(source_url_.spec())); | 197 UTF8ToWide(source_url_.spec())); |
| 198 #elif defined(OS_MACOSX) | 198 #elif defined(OS_MACOSX) |
| 199 file_metadata::AddQuarantineMetadataToFile(full_path_, source_url_, | 199 file_metadata::AddQuarantineMetadataToFile(full_path_, source_url_, |
| 200 referrer_url_); | 200 referrer_url_); |
| 201 file_metadata::AddOriginMetadataToFile(full_path_, source_url_, | 201 file_metadata::AddOriginMetadataToFile(full_path_, source_url_, |
| 202 referrer_url_); | 202 referrer_url_); |
| 203 #endif | 203 #endif |
| 204 } | 204 } |
| 205 | 205 |
| 206 void BaseFile::CreateFileStream() { |
| 207 file_stream_.reset(new net::FileStream); |
| 208 } |
| 209 |
| 206 bool BaseFile::Open() { | 210 bool BaseFile::Open() { |
| 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 208 DCHECK(!detached_); | 212 DCHECK(!detached_); |
| 209 DCHECK(!full_path_.empty()); | 213 DCHECK(!full_path_.empty()); |
| 210 | 214 |
| 211 // Create a new file stream if it is not provided. | 215 // Create a new file stream if it is not provided. |
| 212 if (!file_stream_.get()) { | 216 if (!file_stream_.get()) { |
| 213 file_stream_.reset(new net::FileStream); | 217 CreateFileStream(); |
| 214 if (file_stream_->Open(full_path_, | 218 if (file_stream_->Open(full_path_, |
| 215 base::PLATFORM_FILE_OPEN_ALWAYS | | 219 base::PLATFORM_FILE_OPEN_ALWAYS | |
| 216 base::PLATFORM_FILE_WRITE) != net::OK) { | 220 base::PLATFORM_FILE_WRITE) != net::OK) { |
| 217 file_stream_.reset(); | 221 file_stream_.reset(); |
| 218 return false; | 222 return false; |
| 219 } | 223 } |
| 220 | 224 |
| 221 // We may be re-opening the file after rename. Always make sure we're | 225 // We may be re-opening the file after rename. Always make sure we're |
| 222 // writing at the end of the file. | 226 // writing at the end of the file. |
| 223 if (file_stream_->Seek(net::FROM_END, 0) < 0) { | 227 if (file_stream_->Seek(net::FROM_END, 0) < 0) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 247 | 251 |
| 248 std::string BaseFile::DebugString() const { | 252 std::string BaseFile::DebugString() const { |
| 249 return base::StringPrintf("{ source_url_ = \"%s\"" | 253 return base::StringPrintf("{ source_url_ = \"%s\"" |
| 250 " full_path_ = \"%" PRFilePath "\"" | 254 " full_path_ = \"%" PRFilePath "\"" |
| 251 " bytes_so_far_ = %" PRId64 " detached_ = %c }", | 255 " bytes_so_far_ = %" PRId64 " detached_ = %c }", |
| 252 source_url_.spec().c_str(), | 256 source_url_.spec().c_str(), |
| 253 full_path_.value().c_str(), | 257 full_path_.value().c_str(), |
| 254 bytes_so_far_, | 258 bytes_so_far_, |
| 255 detached_ ? 'T' : 'F'); | 259 detached_ ? 'T' : 'F'); |
| 256 } | 260 } |
| OLD | NEW |