Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: content/browser/download/base_file.cc

Issue 10701050: net: Implement canceling of all async operations in FileStream. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Update after http://crrev.com/159454 Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
411 DCHECK(!detached_); 411 DCHECK(!detached_);
412 412
413 bound_net_log_.AddEvent(net::NetLog::TYPE_CANCELLED); 413 bound_net_log_.AddEvent(net::NetLog::TYPE_CANCELLED);
414 414
415 Close(); 415 Close();
416 416
417 if (!full_path_.empty()) { 417 if (!full_path_.empty()) {
418 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_DELETED); 418 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_DELETED);
419 419
420 file_util::Delete(full_path_, false); 420 bool deleted = file_util::Delete(full_path_, false);
421 DCHECK(deleted);
421 } 422 }
422 } 423 }
423 424
424 void BaseFile::Finish() { 425 void BaseFile::Finish() {
425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
426 427
427 if (calculate_hash_) 428 if (calculate_hash_)
428 secure_hash_->Finish(sha256_hash_, kSha256HashLen); 429 secure_hash_->Finish(sha256_hash_, kSha256HashLen);
429 430
430 Close(); 431 Close();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
523 524
524 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_CLOSED); 525 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_CLOSED);
525 526
526 if (file_stream_.get()) { 527 if (file_stream_.get()) {
527 #if defined(OS_CHROMEOS) 528 #if defined(OS_CHROMEOS)
528 // Currently we don't really care about the return value, since if it fails 529 // Currently we don't really care about the return value, since if it fails
529 // theres not much we can do. But we might in the future. 530 // theres not much we can do. But we might in the future.
530 file_stream_->FlushSync(); 531 file_stream_->FlushSync();
531 #endif 532 #endif
532 file_stream_->CloseSync();
533 ClearStream(net::OK); 533 ClearStream(net::OK);
534 } 534 }
535 } 535 }
536 536
537 net::Error BaseFile::ClearStream(net::Error net_error) { 537 net::Error BaseFile::ClearStream(net::Error net_error) {
538 // This should only be called when we have a stream. 538 // This should only be called when we have a stream.
539 DCHECK(file_stream_.get() != NULL); 539 DCHECK(file_stream_.get() != NULL);
540 file_stream_.reset(); 540 file_stream_.reset();
541 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_OPENED); 541 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_OPENED);
542 return net_error; 542 return net_error;
(...skipping 13 matching lines...) Expand all
556 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const { 556 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const {
557 base::TimeDelta diff = current_time - start_tick_; 557 base::TimeDelta diff = current_time - start_tick_;
558 int64 diff_ms = diff.InMilliseconds(); 558 int64 diff_ms = diff.InMilliseconds();
559 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms; 559 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms;
560 } 560 }
561 561
562 int64 BaseFile::CurrentSpeed() const { 562 int64 BaseFile::CurrentSpeed() const {
563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
564 return CurrentSpeedAtTime(base::TimeTicks::Now()); 564 return CurrentSpeedAtTime(base::TimeTicks::Now());
565 } 565 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698