Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/download/base_file.h" | 5 #include "chrome/browser/download/base_file.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "net/base/file_stream.h" | 9 #include "net/base/file_stream.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool BaseFile::Initialize() { | 42 bool BaseFile::Initialize() { |
| 43 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 43 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 44 if (!full_path_.empty() || | 44 if (!full_path_.empty() || |
| 45 download_util::CreateTemporaryFileForDownload(&full_path_)) | 45 download_util::CreateTemporaryFileForDownload(&full_path_)) |
| 46 return Open(); | 46 return Open(); |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool BaseFile::ReOpen() { | |
| 51 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | |
| 52 bool opened = Open(); | |
|
Paweł Hajdan Jr.
2010/10/01 09:03:55
I think it would be cleaner to just expose Open th
| |
| 53 return opened; | |
| 54 } | |
| 55 | |
| 50 bool BaseFile::AppendDataToFile(const char* data, size_t data_len) { | 56 bool BaseFile::AppendDataToFile(const char* data, size_t data_len) { |
| 51 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 57 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 52 | 58 |
| 53 if (!file_stream_.get()) | 59 if (!file_stream_.get()) |
| 54 return false; | 60 return false; |
| 55 | 61 |
| 56 // TODO(phajdan.jr): get rid of this check. | 62 // TODO(phajdan.jr): get rid of this check. |
| 57 if (data_len == 0) | 63 if (data_len == 0) |
| 58 return true; | 64 return true; |
| 59 | 65 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 // We ignore the return value because a failure is not fatal. | 153 // We ignore the return value because a failure is not fatal. |
| 148 win_util::SetInternetZoneIdentifier(full_path_); | 154 win_util::SetInternetZoneIdentifier(full_path_); |
| 149 #elif defined(OS_MACOSX) | 155 #elif defined(OS_MACOSX) |
| 150 file_metadata::AddQuarantineMetadataToFile(full_path_, source_url_, | 156 file_metadata::AddQuarantineMetadataToFile(full_path_, source_url_, |
| 151 referrer_url_); | 157 referrer_url_); |
| 152 file_metadata::AddOriginMetadataToFile(full_path_, source_url_, | 158 file_metadata::AddOriginMetadataToFile(full_path_, source_url_, |
| 153 referrer_url_); | 159 referrer_url_); |
| 154 #endif | 160 #endif |
| 155 } | 161 } |
| 156 | 162 |
| 163 bool BaseFile::MatchesUrlAndPath(const GURL& url, const FilePath& path) const { | |
| 164 return (url == source_url_) && (path == full_path_); | |
| 165 } | |
| 166 | |
| 157 bool BaseFile::Open() { | 167 bool BaseFile::Open() { |
| 158 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 168 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 159 DCHECK(!full_path_.empty()); | 169 DCHECK(!full_path_.empty()); |
| 160 | 170 |
| 161 // Create a new file steram if it is not provided. | 171 // Create a new file steram if it is not provided. |
| 162 if (!file_stream_.get()) { | 172 if (!file_stream_.get()) { |
| 163 file_stream_.reset(new net::FileStream); | 173 file_stream_.reset(new net::FileStream); |
| 164 if (file_stream_->Open(full_path_, | 174 if (file_stream_->Open(full_path_, |
| 165 base::PLATFORM_FILE_OPEN_ALWAYS | | 175 base::PLATFORM_FILE_OPEN_ALWAYS | |
| 166 base::PLATFORM_FILE_WRITE) != net::OK) { | 176 base::PLATFORM_FILE_WRITE) != net::OK) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 187 if (file_stream_.get()) { | 197 if (file_stream_.get()) { |
| 188 #if defined(OS_CHROMEOS) | 198 #if defined(OS_CHROMEOS) |
| 189 // Currently we don't really care about the return value, since if it fails | 199 // Currently we don't really care about the return value, since if it fails |
| 190 // theres not much we can do. But we might in the future. | 200 // theres not much we can do. But we might in the future. |
| 191 file_stream_->Flush(); | 201 file_stream_->Flush(); |
| 192 #endif | 202 #endif |
| 193 file_stream_->Close(); | 203 file_stream_->Close(); |
| 194 file_stream_.reset(); | 204 file_stream_.reset(); |
| 195 } | 205 } |
| 196 } | 206 } |
| OLD | NEW |