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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
192 DCHECK(!detached_); | 192 DCHECK(!detached_); |
193 | 193 |
194 bound_net_log_.AddEvent(net::NetLog::TYPE_CANCELLED); | 194 bound_net_log_.AddEvent(net::NetLog::TYPE_CANCELLED); |
195 | 195 |
196 Close(); | 196 Close(); |
197 | 197 |
198 if (!full_path_.empty()) { | 198 if (!full_path_.empty()) { |
199 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_DELETED); | 199 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_DELETED); |
200 | 200 |
201 file_util::Delete(full_path_, false); | 201 bool deleted = file_util::Delete(full_path_, false); |
202 DCHECK(deleted); | |
sky
2012/11/05 16:12:52
Why the DCHECK? We know delete can fail for variou
| |
202 } | 203 } |
203 } | 204 } |
204 | 205 |
205 void BaseFile::Finish() { | 206 void BaseFile::Finish() { |
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
207 | 208 |
208 if (calculate_hash_) | 209 if (calculate_hash_) |
209 secure_hash_->Finish(sha256_hash_, kSha256HashLen); | 210 secure_hash_->Finish(sha256_hash_, kSha256HashLen); |
210 | 211 |
211 Close(); | 212 Close(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
304 | 305 |
305 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_CLOSED); | 306 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_CLOSED); |
306 | 307 |
307 if (file_stream_.get()) { | 308 if (file_stream_.get()) { |
308 #if defined(OS_CHROMEOS) | 309 #if defined(OS_CHROMEOS) |
309 // Currently we don't really care about the return value, since if it fails | 310 // Currently we don't really care about the return value, since if it fails |
310 // theres not much we can do. But we might in the future. | 311 // theres not much we can do. But we might in the future. |
311 file_stream_->FlushSync(); | 312 file_stream_->FlushSync(); |
312 #endif | 313 #endif |
313 file_stream_->CloseSync(); | |
314 ClearStream(); | 314 ClearStream(); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 void BaseFile::ClearStream() { | 318 void BaseFile::ClearStream() { |
319 // This should only be called when we have a stream. | 319 // This should only be called when we have a stream. |
320 DCHECK(file_stream_.get() != NULL); | 320 DCHECK(file_stream_.get() != NULL); |
321 file_stream_.reset(); | 321 file_stream_.reset(); |
322 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_OPENED); | 322 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_OPENED); |
323 } | 323 } |
(...skipping 28 matching lines...) Expand all Loading... | |
352 const char* operation, | 352 const char* operation, |
353 int os_error, | 353 int os_error, |
354 DownloadInterruptReason reason) { | 354 DownloadInterruptReason reason) { |
355 bound_net_log_.AddEvent( | 355 bound_net_log_.AddEvent( |
356 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, | 356 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, |
357 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); | 357 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); |
358 return reason; | 358 return reason; |
359 } | 359 } |
360 | 360 |
361 } // namespace content | 361 } // namespace content |
OLD | NEW |