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

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

Issue 6125001: Fixed first pass at adding http/backend cache events to the NetLog. ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix Created 9 years, 11 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/entry_impl.cc ('k') | net/disk_cache/stress_cache.cc » ('j') | 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) 2009-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009-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 "net/disk_cache/sparse_control.h" 5 #include "net/disk_cache/sparse_control.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 std::string child_name = GenerateChildName(name_, signature_, child_id); 132 std::string child_name = GenerateChildName(name_, signature_, child_id);
133 backend_->SyncDoomEntry(child_name); 133 backend_->SyncDoomEntry(child_name);
134 children_map_.Set(child_id, false); 134 children_map_.Set(child_id, false);
135 135
136 // Post a task to delete the next child. 136 // Post a task to delete the next child.
137 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 137 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
138 this, &ChildrenDeleter::DeleteChildren)); 138 this, &ChildrenDeleter::DeleteChildren));
139 } 139 }
140 140
141 // Logs the end event for |operation|, if all events are being logged.
142 void LogOperationEnd(const net::BoundNetLog& net_log,
143 disk_cache::SparseControl::SparseOperation operation,
144 int result) {
145 if (net_log.IsLoggingAllEvents()) {
146 net::NetLog::EventType event_type;
147 switch (operation) {
148 case disk_cache::SparseControl::kReadOperation:
149 event_type = net::NetLog::TYPE_SPARSE_CONTROL_READ;
150 break;
151 case disk_cache::SparseControl::kWriteOperation:
152 event_type = net::NetLog::TYPE_SPARSE_CONTROL_WRITE;
153 break;
154 case disk_cache::SparseControl::kGetRangeOperation:
155 event_type = net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE;
156 break;
157 default:
158 NOTREACHED();
159 return;
160 }
161 net_log.EndEventWithNetErrorCode(event_type, result);
162 }
163 }
164
141 } // namespace. 165 } // namespace.
142 166
143 namespace disk_cache { 167 namespace disk_cache {
144 168
145 SparseControl::SparseControl(EntryImpl* entry) 169 SparseControl::SparseControl(EntryImpl* entry)
146 : entry_(entry), 170 : entry_(entry),
147 child_(NULL), 171 child_(NULL),
148 operation_(kNoOperation), 172 operation_(kNoOperation),
149 init_(false), 173 init_(false),
150 child_map_(child_data_.bitmap, kNumSparseBits, kNumSparseBits / 32), 174 child_map_(child_data_.bitmap, kNumSparseBits, kNumSparseBits / 32),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 offset_ = offset; 240 offset_ = offset;
217 user_buf_ = buf ? new net::DrainableIOBuffer(buf, buf_len) : NULL; 241 user_buf_ = buf ? new net::DrainableIOBuffer(buf, buf_len) : NULL;
218 buf_len_ = buf_len; 242 buf_len_ = buf_len;
219 user_callback_ = callback; 243 user_callback_ = callback;
220 244
221 result_ = 0; 245 result_ = 0;
222 pending_ = false; 246 pending_ = false;
223 finished_ = false; 247 finished_ = false;
224 abort_ = false; 248 abort_ = false;
225 249
250 entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL);
226 DoChildrenIO(); 251 DoChildrenIO();
227 252
228 if (!pending_) { 253 if (!pending_) {
229 // Everything was done synchronously. 254 // Everything was done synchronously.
230 operation_ = kNoOperation; 255 operation_ = kNoOperation;
231 user_buf_ = NULL; 256 user_buf_ = NULL;
232 user_callback_ = NULL; 257 user_callback_ = NULL;
233 return result_; 258 return result_;
234 } 259 }
235 260
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 int rv = child_->WriteData(kSparseIndex, 0, buf, sizeof(child_data_), 628 int rv = child_->WriteData(kSparseIndex, 0, buf, sizeof(child_data_),
604 NULL, false); 629 NULL, false);
605 if (rv != sizeof(child_data_)) 630 if (rv != sizeof(child_data_))
606 DLOG(ERROR) << "Failed to save child data"; 631 DLOG(ERROR) << "Failed to save child data";
607 SetChildBit(true); 632 SetChildBit(true);
608 } 633 }
609 634
610 void SparseControl::DoChildrenIO() { 635 void SparseControl::DoChildrenIO() {
611 while (DoChildIO()) continue; 636 while (DoChildIO()) continue;
612 637
613 if (pending_ && finished_) 638 if (finished_) {
614 DoUserCallback(); 639 entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL);
640 if (pending_)
641 DoUserCallback();
642 }
615 } 643 }
616 644
617 bool SparseControl::DoChildIO() { 645 bool SparseControl::DoChildIO() {
618 finished_ = true; 646 finished_ = true;
619 if (!buf_len_ || result_ < 0) 647 if (!buf_len_ || result_ < 0)
620 return false; 648 return false;
621 649
622 if (!OpenChild()) 650 if (!OpenChild())
623 return false; 651 return false;
624 652
625 if (!VerifyRange()) 653 if (!VerifyRange())
626 return false; 654 return false;
627 655
628 // We have more work to do. Let's not trigger a callback to the caller. 656 // We have more work to do. Let's not trigger a callback to the caller.
629 finished_ = false; 657 finished_ = false;
630 net::CompletionCallback* callback = user_callback_ ? &child_callback_ : NULL; 658 net::CompletionCallback* callback = user_callback_ ? &child_callback_ : NULL;
631 659
632 int rv = 0; 660 int rv = 0;
633 switch (operation_) { 661 switch (operation_) {
634 case kReadOperation: 662 case kReadOperation:
663 if (entry_->net_log().IsLoggingAllEvents()) {
664 entry_->net_log().BeginEvent(
665 net::NetLog::TYPE_SPARSE_CONTROL_READ,
666 make_scoped_refptr(new net::NetLogSourceParameter(
667 "source_dependency",
668 child_->net_log().source())));
669 }
635 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_, 670 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_,
636 child_len_, callback); 671 child_len_, callback);
637 break; 672 break;
638 case kWriteOperation: 673 case kWriteOperation:
674 if (entry_->net_log().IsLoggingAllEvents()) {
675 entry_->net_log().BeginEvent(
676 net::NetLog::TYPE_SPARSE_CONTROL_WRITE,
677 make_scoped_refptr(new net::NetLogSourceParameter(
678 "source_dependency",
679 child_->net_log().source())));
680 }
639 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_, 681 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_,
640 child_len_, callback, false); 682 child_len_, callback, false);
641 break; 683 break;
642 case kGetRangeOperation: 684 case kGetRangeOperation:
685 if (entry_->net_log().IsLoggingAllEvents()) {
686 entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE,
687 NULL);
688 }
643 rv = DoGetAvailableRange(); 689 rv = DoGetAvailableRange();
644 break; 690 break;
645 default: 691 default:
646 NOTREACHED(); 692 NOTREACHED();
647 } 693 }
648 694
649 if (rv == net::ERR_IO_PENDING) { 695 if (rv == net::ERR_IO_PENDING) {
650 if (!pending_) { 696 if (!pending_) {
651 pending_ = true; 697 pending_ = true;
652 // The child will protect himself against closing the entry while IO is in 698 // The child will protect himself against closing the entry while IO is in
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 // Only update offset_ when this query found zeros at the start. 751 // Only update offset_ when this query found zeros at the start.
706 if (empty_start) 752 if (empty_start)
707 offset_ += empty_start; 753 offset_ += empty_start;
708 754
709 // This will actually break the loop. 755 // This will actually break the loop.
710 buf_len_ = 0; 756 buf_len_ = 0;
711 return 0; 757 return 0;
712 } 758 }
713 759
714 void SparseControl::DoChildIOCompleted(int result) { 760 void SparseControl::DoChildIOCompleted(int result) {
761 LogOperationEnd(entry_->net_log(), operation_, result);
715 if (result < 0) { 762 if (result < 0) {
716 // We fail the whole operation if we encounter an error. 763 // We fail the whole operation if we encounter an error.
717 result_ = result; 764 result_ = result;
718 return; 765 return;
719 } 766 }
720 767
721 UpdateRange(result); 768 UpdateRange(result);
722 769
723 result_ += result; 770 result_ += result;
724 offset_ += result; 771 offset_ += result;
725 buf_len_ -= result; 772 buf_len_ -= result;
726 773
727 // We'll be reusing the user provided buffer for the next chunk. 774 // We'll be reusing the user provided buffer for the next chunk.
728 if (buf_len_ && user_buf_) 775 if (buf_len_ && user_buf_)
729 user_buf_->DidConsume(result); 776 user_buf_->DidConsume(result);
730 } 777 }
731 778
732 void SparseControl::OnChildIOCompleted(int result) { 779 void SparseControl::OnChildIOCompleted(int result) {
733 DCHECK_NE(net::ERR_IO_PENDING, result); 780 DCHECK_NE(net::ERR_IO_PENDING, result);
734 DoChildIOCompleted(result); 781 DoChildIOCompleted(result);
735 782
736 if (abort_) { 783 if (abort_) {
737 // We'll return the current result of the operation, which may be less than 784 // We'll return the current result of the operation, which may be less than
738 // the bytes to read or write, but the user cancelled the operation. 785 // the bytes to read or write, but the user cancelled the operation.
739 abort_ = false; 786 abort_ = false;
787 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL);
788 entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL);
740 DoUserCallback(); 789 DoUserCallback();
741 return DoAbortCallbacks(); 790 return DoAbortCallbacks();
742 } 791 }
743 792
744 // We are running a callback from the message loop. It's time to restart what 793 // We are running a callback from the message loop. It's time to restart what
745 // we were doing before. 794 // we were doing before.
746 DoChildrenIO(); 795 DoChildrenIO();
747 } 796 }
748 797
749 void SparseControl::DoUserCallback() { 798 void SparseControl::DoUserCallback() {
(...skipping 14 matching lines...) Expand all
764 net::CompletionCallback* c = abort_callbacks_[i]; 813 net::CompletionCallback* c = abort_callbacks_[i];
765 if (i == abort_callbacks_.size() - 1) 814 if (i == abort_callbacks_.size() - 1)
766 abort_callbacks_.clear(); 815 abort_callbacks_.clear();
767 816
768 entry_->Release(); // Don't touch object after this line. 817 entry_->Release(); // Don't touch object after this line.
769 c->Run(net::OK); 818 c->Run(net::OK);
770 } 819 }
771 } 820 }
772 821
773 } // namespace disk_cache 822 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/entry_impl.cc ('k') | net/disk_cache/stress_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698