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

Side by Side Diff: net/disk_cache/sparse_control.cc

Issue 10543114: NetLogEventParameter to Callback refactoring 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Update comment in response to comment Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/net_log_parameters.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "net/disk_cache/sparse_control.h" 5 #include "net/disk_cache/sparse_control.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.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/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 user_callback_ = callback; 258 user_callback_ = callback;
259 259
260 result_ = 0; 260 result_ = 0;
261 pending_ = false; 261 pending_ = false;
262 finished_ = false; 262 finished_ = false;
263 abort_ = false; 263 abort_ = false;
264 264
265 if (entry_->net_log().IsLoggingAllEvents()) { 265 if (entry_->net_log().IsLoggingAllEvents()) {
266 entry_->net_log().BeginEvent( 266 entry_->net_log().BeginEvent(
267 GetSparseEventType(operation_), 267 GetSparseEventType(operation_),
268 make_scoped_refptr(new SparseOperationParameters(offset_, buf_len_))); 268 CreateNetLogSparseOperationCallback(offset_, buf_len_));
269 } 269 }
270 DoChildrenIO(); 270 DoChildrenIO();
271 271
272 if (!pending_) { 272 if (!pending_) {
273 // Everything was done synchronously. 273 // Everything was done synchronously.
274 operation_ = kNoOperation; 274 operation_ = kNoOperation;
275 user_buf_ = NULL; 275 user_buf_ = NULL;
276 user_callback_.Reset(); 276 user_callback_.Reset();
277 return result_; 277 return result_;
278 } 278 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 int map_len = data_len - sizeof(SparseHeader); 330 int map_len = data_len - sizeof(SparseHeader);
331 if (map_len > kMaxMapSize || map_len % 4) 331 if (map_len > kMaxMapSize || map_len % 4)
332 return; 332 return;
333 333
334 char* buffer; 334 char* buffer;
335 Addr address; 335 Addr address;
336 entry->GetData(kSparseIndex, &buffer, &address); 336 entry->GetData(kSparseIndex, &buffer, &address);
337 if (!buffer && !address.is_initialized()) 337 if (!buffer && !address.is_initialized())
338 return; 338 return;
339 339
340 entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN, NULL); 340 entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN);
341 341
342 DCHECK(entry && entry->backend_); 342 DCHECK(entry && entry->backend_);
343 ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_, 343 ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_,
344 entry->GetKey()); 344 entry->GetKey());
345 // The object will self destruct when finished. 345 // The object will self destruct when finished.
346 deleter->AddRef(); 346 deleter->AddRef();
347 347
348 if (buffer) { 348 if (buffer) {
349 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 349 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
350 &ChildrenDeleter::Start, deleter, buffer, data_len)); 350 &ChildrenDeleter::Start, deleter, buffer, data_len));
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 667
668 void SparseControl::DoChildrenIO() { 668 void SparseControl::DoChildrenIO() {
669 while (DoChildIO()) continue; 669 while (DoChildIO()) continue;
670 670
671 // Range operations are finished synchronously, often without setting 671 // Range operations are finished synchronously, often without setting
672 // |finished_| to true. 672 // |finished_| to true.
673 if (kGetRangeOperation == operation_ && 673 if (kGetRangeOperation == operation_ &&
674 entry_->net_log().IsLoggingAllEvents()) { 674 entry_->net_log().IsLoggingAllEvents()) {
675 entry_->net_log().EndEvent( 675 entry_->net_log().EndEvent(
676 net::NetLog::TYPE_SPARSE_GET_RANGE, 676 net::NetLog::TYPE_SPARSE_GET_RANGE,
677 make_scoped_refptr( 677 CreateNetLogGetAvailableRangeResultCallback(offset_, result_));
678 new GetAvailableRangeResultParameters(offset_, result_)));
679 } 678 }
680 if (finished_) { 679 if (finished_) {
681 if (kGetRangeOperation != operation_ && 680 if (kGetRangeOperation != operation_ &&
682 entry_->net_log().IsLoggingAllEvents()) { 681 entry_->net_log().IsLoggingAllEvents()) {
683 entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL); 682 entry_->net_log().EndEvent(GetSparseEventType(operation_));
684 } 683 }
685 if (pending_) 684 if (pending_)
686 DoUserCallback(); // Don't touch this object after this point. 685 DoUserCallback(); // Don't touch this object after this point.
687 } 686 }
688 } 687 }
689 688
690 bool SparseControl::DoChildIO() { 689 bool SparseControl::DoChildIO() {
691 finished_ = true; 690 finished_ = true;
692 if (!buf_len_ || result_ < 0) 691 if (!buf_len_ || result_ < 0)
693 return false; 692 return false;
(...skipping 11 matching lines...) Expand all
705 callback = 704 callback =
706 base::Bind(&SparseControl::OnChildIOCompleted, base::Unretained(this)); 705 base::Bind(&SparseControl::OnChildIOCompleted, base::Unretained(this));
707 } 706 }
708 707
709 int rv = 0; 708 int rv = 0;
710 switch (operation_) { 709 switch (operation_) {
711 case kReadOperation: 710 case kReadOperation:
712 if (entry_->net_log().IsLoggingAllEvents()) { 711 if (entry_->net_log().IsLoggingAllEvents()) {
713 entry_->net_log().BeginEvent( 712 entry_->net_log().BeginEvent(
714 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, 713 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA,
715 make_scoped_refptr(new SparseReadWriteParameters( 714 CreateNetLogSparseReadWriteCallback(child_->net_log().source(),
716 child_->net_log().source(), 715 child_len_));
717 child_len_)));
718 } 716 }
719 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_, 717 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_,
720 child_len_, callback); 718 child_len_, callback);
721 break; 719 break;
722 case kWriteOperation: 720 case kWriteOperation:
723 if (entry_->net_log().IsLoggingAllEvents()) { 721 if (entry_->net_log().IsLoggingAllEvents()) {
724 entry_->net_log().BeginEvent( 722 entry_->net_log().BeginEvent(
725 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, 723 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA,
726 make_scoped_refptr(new SparseReadWriteParameters( 724 CreateNetLogSparseReadWriteCallback(child_->net_log().source(),
727 child_->net_log().source(), 725 child_len_));
728 child_len_)));
729 } 726 }
730 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_, 727 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_,
731 child_len_, callback, false); 728 child_len_, callback, false);
732 break; 729 break;
733 case kGetRangeOperation: 730 case kGetRangeOperation:
734 rv = DoGetAvailableRange(); 731 rv = DoGetAvailableRange();
735 break; 732 break;
736 default: 733 default:
737 NOTREACHED(); 734 NOTREACHED();
738 } 735 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 820
824 void SparseControl::OnChildIOCompleted(int result) { 821 void SparseControl::OnChildIOCompleted(int result) {
825 DCHECK_NE(net::ERR_IO_PENDING, result); 822 DCHECK_NE(net::ERR_IO_PENDING, result);
826 DoChildIOCompleted(result); 823 DoChildIOCompleted(result);
827 824
828 if (abort_) { 825 if (abort_) {
829 // We'll return the current result of the operation, which may be less than 826 // We'll return the current result of the operation, which may be less than
830 // the bytes to read or write, but the user cancelled the operation. 827 // the bytes to read or write, but the user cancelled the operation.
831 abort_ = false; 828 abort_ = false;
832 if (entry_->net_log().IsLoggingAllEvents()) { 829 if (entry_->net_log().IsLoggingAllEvents()) {
833 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL); 830 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED);
834 entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL); 831 entry_->net_log().EndEvent(GetSparseEventType(operation_));
835 } 832 }
836 // We have an indirect reference to this object for every callback so if 833 // We have an indirect reference to this object for every callback so if
837 // there is only one callback, we may delete this object before reaching 834 // there is only one callback, we may delete this object before reaching
838 // DoAbortCallbacks. 835 // DoAbortCallbacks.
839 bool has_abort_callbacks = !abort_callbacks_.empty(); 836 bool has_abort_callbacks = !abort_callbacks_.empty();
840 DoUserCallback(); 837 DoUserCallback();
841 if (has_abort_callbacks) 838 if (has_abort_callbacks)
842 DoAbortCallbacks(); 839 DoAbortCallbacks();
843 return; 840 return;
844 } 841 }
(...skipping 22 matching lines...) Expand all
867 CompletionCallback cb = abort_callbacks_[i]; 864 CompletionCallback cb = abort_callbacks_[i];
868 if (i == abort_callbacks_.size() - 1) 865 if (i == abort_callbacks_.size() - 1)
869 abort_callbacks_.clear(); 866 abort_callbacks_.clear();
870 867
871 entry_->Release(); // Don't touch object after this line. 868 entry_->Release(); // Don't touch object after this line.
872 cb.Run(net::OK); 869 cb.Run(net::OK);
873 } 870 }
874 } 871 }
875 872
876 } // namespace disk_cache 873 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/net_log_parameters.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698