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

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

Issue 6613027: Adds memory cache logging, and updates disk cache logging (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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
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"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/disk_cache/backend_impl.h" 15 #include "net/disk_cache/backend_impl.h"
16 #include "net/disk_cache/entry_impl.h" 16 #include "net/disk_cache/entry_impl.h"
17 #include "net/disk_cache/file.h" 17 #include "net/disk_cache/file.h"
18 #include "net/disk_cache/net_log_parameters.h"
18 19
19 using base::Time; 20 using base::Time;
20 21
21 namespace { 22 namespace {
22 23
23 // Stream of the sparse data index. 24 // Stream of the sparse data index.
24 const int kSparseIndex = 2; 25 const int kSparseIndex = 2;
25 26
26 // Stream of the sparse data. 27 // Stream of the sparse data.
27 const int kSparseData = 1; 28 const int kSparseData = 1;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 132 }
132 std::string child_name = GenerateChildName(name_, signature_, child_id); 133 std::string child_name = GenerateChildName(name_, signature_, child_id);
133 backend_->SyncDoomEntry(child_name); 134 backend_->SyncDoomEntry(child_name);
134 children_map_.Set(child_id, false); 135 children_map_.Set(child_id, false);
135 136
136 // Post a task to delete the next child. 137 // Post a task to delete the next child.
137 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 138 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
138 this, &ChildrenDeleter::DeleteChildren)); 139 this, &ChildrenDeleter::DeleteChildren));
139 } 140 }
140 141
141 // Logs the end event for |operation|, if all events are being logged. 142 // Returns the NetLog event type corresponding to a SparseOperation.
142 void LogOperationEnd(const net::BoundNetLog& net_log, 143 net::NetLog::EventType GetSparseEventType(
143 disk_cache::SparseControl::SparseOperation operation, 144 disk_cache::SparseControl::SparseOperation operation) {
144 int result) { 145 switch (operation) {
146 case disk_cache::SparseControl::kReadOperation:
147 return net::NetLog::TYPE_SPARSE_READ;
148 case disk_cache::SparseControl::kWriteOperation:
149 return net::NetLog::TYPE_SPARSE_WRITE;
150 case disk_cache::SparseControl::kGetRangeOperation:
151 return net::NetLog::TYPE_SPARSE_GET_RANGE;
152 default:
153 NOTREACHED();
154 return net::NetLog::TYPE_CANCELLED;
155 }
156 }
157
158 // Logs the end event for |operation| on a child entry. Range operations log
159 // no events for each child they search through.
160 void LogChildOperationEnd(const net::BoundNetLog& net_log,
161 disk_cache::SparseControl::SparseOperation operation,
162 int result) {
145 if (net_log.IsLoggingAllEvents()) { 163 if (net_log.IsLoggingAllEvents()) {
146 net::NetLog::EventType event_type; 164 net::NetLog::EventType event_type;
147 switch (operation) { 165 switch (operation) {
148 case disk_cache::SparseControl::kReadOperation: 166 case disk_cache::SparseControl::kReadOperation:
149 event_type = net::NetLog::TYPE_SPARSE_CONTROL_READ; 167 event_type = net::NetLog::TYPE_SPARSE_READ_CHILD_DATA;
150 break; 168 break;
151 case disk_cache::SparseControl::kWriteOperation: 169 case disk_cache::SparseControl::kWriteOperation:
152 event_type = net::NetLog::TYPE_SPARSE_CONTROL_WRITE; 170 event_type = net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA;
153 break; 171 break;
154 case disk_cache::SparseControl::kGetRangeOperation: 172 case disk_cache::SparseControl::kGetRangeOperation:
155 event_type = net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE; 173 return;
156 break;
157 default: 174 default:
158 NOTREACHED(); 175 NOTREACHED();
159 return; 176 return;
160 } 177 }
161 net_log.EndEventWithNetErrorCode(event_type, result); 178 net_log.EndEventWithNetErrorCode(event_type, result);
162 } 179 }
163 } 180 }
164 181
165 } // namespace. 182 } // namespace.
166 183
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 offset_ = offset; 257 offset_ = offset;
241 user_buf_ = buf ? new net::DrainableIOBuffer(buf, buf_len) : NULL; 258 user_buf_ = buf ? new net::DrainableIOBuffer(buf, buf_len) : NULL;
242 buf_len_ = buf_len; 259 buf_len_ = buf_len;
243 user_callback_ = callback; 260 user_callback_ = callback;
244 261
245 result_ = 0; 262 result_ = 0;
246 pending_ = false; 263 pending_ = false;
247 finished_ = false; 264 finished_ = false;
248 abort_ = false; 265 abort_ = false;
249 266
250 entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); 267 if (entry_->net_log().IsLoggingAllEvents()) {
268 entry_->net_log().BeginEvent(
269 GetSparseEventType(operation_),
270 make_scoped_refptr(new SparseOperationParameters(offset_, buf_len_)));
271 }
251 DoChildrenIO(); 272 DoChildrenIO();
252 273
253 if (!pending_) { 274 if (!pending_) {
254 // Everything was done synchronously. 275 // Everything was done synchronously.
255 operation_ = kNoOperation; 276 operation_ = kNoOperation;
256 user_buf_ = NULL; 277 user_buf_ = NULL;
257 user_callback_ = NULL; 278 user_callback_ = NULL;
258 return result_; 279 return result_;
259 } 280 }
260 281
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 int map_len = data_len - sizeof(SparseHeader); 331 int map_len = data_len - sizeof(SparseHeader);
311 if (map_len > kMaxMapSize || map_len % 4) 332 if (map_len > kMaxMapSize || map_len % 4)
312 return; 333 return;
313 334
314 char* buffer; 335 char* buffer;
315 Addr address; 336 Addr address;
316 entry->GetData(kSparseIndex, &buffer, &address); 337 entry->GetData(kSparseIndex, &buffer, &address);
317 if (!buffer && !address.is_initialized()) 338 if (!buffer && !address.is_initialized())
318 return; 339 return;
319 340
341 entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN, NULL);
342
320 ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_, 343 ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_,
321 entry->GetKey()); 344 entry->GetKey());
322 // The object will self destruct when finished. 345 // The object will self destruct when finished.
323 deleter->AddRef(); 346 deleter->AddRef();
324 347
325 if (buffer) { 348 if (buffer) {
326 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 349 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
327 deleter, &ChildrenDeleter::Start, buffer, data_len)); 350 deleter, &ChildrenDeleter::Start, buffer, data_len));
328 } else { 351 } else {
329 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 352 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 NULL, false); 652 NULL, false);
630 if (rv != sizeof(child_data_)) 653 if (rv != sizeof(child_data_))
631 DLOG(ERROR) << "Failed to save child data"; 654 DLOG(ERROR) << "Failed to save child data";
632 SetChildBit(true); 655 SetChildBit(true);
633 } 656 }
634 657
635 void SparseControl::DoChildrenIO() { 658 void SparseControl::DoChildrenIO() {
636 while (DoChildIO()) continue; 659 while (DoChildIO()) continue;
637 660
638 if (finished_) { 661 if (finished_) {
639 entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); 662 if (entry_->net_log().IsLoggingAllEvents()) {
663 if (operation_ != kGetRangeOperation) {
664 entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL);
665 } else {
666 entry_->net_log().EndEvent(
667 net::NetLog::TYPE_SPARSE_GET_RANGE,
668 make_scoped_refptr(
669 new GetAvailableRangeResultParameters(offset_, result_)));
670 }
671 }
640 if (pending_) 672 if (pending_)
641 DoUserCallback(); 673 DoUserCallback();
642 } 674 }
643 } 675 }
644 676
645 bool SparseControl::DoChildIO() { 677 bool SparseControl::DoChildIO() {
646 finished_ = true; 678 finished_ = true;
647 if (!buf_len_ || result_ < 0) 679 if (!buf_len_ || result_ < 0)
648 return false; 680 return false;
649 681
650 if (!OpenChild()) 682 if (!OpenChild())
651 return false; 683 return false;
652 684
653 if (!VerifyRange()) 685 if (!VerifyRange())
654 return false; 686 return false;
655 687
656 // We have more work to do. Let's not trigger a callback to the caller. 688 // We have more work to do. Let's not trigger a callback to the caller.
657 finished_ = false; 689 finished_ = false;
658 net::CompletionCallback* callback = user_callback_ ? &child_callback_ : NULL; 690 net::CompletionCallback* callback = user_callback_ ? &child_callback_ : NULL;
659 691
660 int rv = 0; 692 int rv = 0;
661 switch (operation_) { 693 switch (operation_) {
662 case kReadOperation: 694 case kReadOperation:
663 if (entry_->net_log().IsLoggingAllEvents()) { 695 if (entry_->net_log().IsLoggingAllEvents()) {
664 entry_->net_log().BeginEvent( 696 entry_->net_log().BeginEvent(
665 net::NetLog::TYPE_SPARSE_CONTROL_READ, 697 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA,
666 make_scoped_refptr(new net::NetLogSourceParameter( 698 make_scoped_refptr(new SparseReadWriteParameters(
667 "source_dependency", 699 child_->net_log().source(),
668 child_->net_log().source()))); 700 child_len_)));
669 } 701 }
670 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_, 702 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_,
671 child_len_, callback); 703 child_len_, callback);
672 break; 704 break;
673 case kWriteOperation: 705 case kWriteOperation:
674 if (entry_->net_log().IsLoggingAllEvents()) { 706 if (entry_->net_log().IsLoggingAllEvents()) {
675 entry_->net_log().BeginEvent( 707 entry_->net_log().BeginEvent(
676 net::NetLog::TYPE_SPARSE_CONTROL_WRITE, 708 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA,
677 make_scoped_refptr(new net::NetLogSourceParameter( 709 make_scoped_refptr(new SparseReadWriteParameters(
678 "source_dependency", 710 child_->net_log().source(),
679 child_->net_log().source()))); 711 child_len_)));
680 } 712 }
681 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_, 713 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_,
682 child_len_, callback, false); 714 child_len_, callback, false);
683 break; 715 break;
684 case kGetRangeOperation: 716 case kGetRangeOperation:
685 if (entry_->net_log().IsLoggingAllEvents()) {
686 entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE,
687 NULL);
688 }
689 rv = DoGetAvailableRange(); 717 rv = DoGetAvailableRange();
690 break; 718 break;
691 default: 719 default:
692 NOTREACHED(); 720 NOTREACHED();
693 } 721 }
694 722
695 if (rv == net::ERR_IO_PENDING) { 723 if (rv == net::ERR_IO_PENDING) {
696 if (!pending_) { 724 if (!pending_) {
697 pending_ = true; 725 pending_ = true;
698 // The child will protect himself against closing the entry while IO is in 726 // 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
751 // Only update offset_ when this query found zeros at the start. 779 // Only update offset_ when this query found zeros at the start.
752 if (empty_start) 780 if (empty_start)
753 offset_ += empty_start; 781 offset_ += empty_start;
754 782
755 // This will actually break the loop. 783 // This will actually break the loop.
756 buf_len_ = 0; 784 buf_len_ = 0;
757 return 0; 785 return 0;
758 } 786 }
759 787
760 void SparseControl::DoChildIOCompleted(int result) { 788 void SparseControl::DoChildIOCompleted(int result) {
761 LogOperationEnd(entry_->net_log(), operation_, result); 789 LogChildOperationEnd(entry_->net_log(), operation_, result);
762 if (result < 0) { 790 if (result < 0) {
763 // We fail the whole operation if we encounter an error. 791 // We fail the whole operation if we encounter an error.
764 result_ = result; 792 result_ = result;
765 return; 793 return;
766 } 794 }
767 795
768 UpdateRange(result); 796 UpdateRange(result);
769 797
770 result_ += result; 798 result_ += result;
771 offset_ += result; 799 offset_ += result;
772 buf_len_ -= result; 800 buf_len_ -= result;
773 801
774 // We'll be reusing the user provided buffer for the next chunk. 802 // We'll be reusing the user provided buffer for the next chunk.
775 if (buf_len_ && user_buf_) 803 if (buf_len_ && user_buf_)
776 user_buf_->DidConsume(result); 804 user_buf_->DidConsume(result);
777 } 805 }
778 806
779 void SparseControl::OnChildIOCompleted(int result) { 807 void SparseControl::OnChildIOCompleted(int result) {
780 DCHECK_NE(net::ERR_IO_PENDING, result); 808 DCHECK_NE(net::ERR_IO_PENDING, result);
781 DoChildIOCompleted(result); 809 DoChildIOCompleted(result);
782 810
783 if (abort_) { 811 if (abort_) {
784 // We'll return the current result of the operation, which may be less than 812 // We'll return the current result of the operation, which may be less than
785 // the bytes to read or write, but the user cancelled the operation. 813 // the bytes to read or write, but the user cancelled the operation.
786 abort_ = false; 814 abort_ = false;
787 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL); 815 if (entry_->net_log().IsLoggingAllEvents()) {
788 entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); 816 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL);
817 entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL);
818 }
789 DoUserCallback(); 819 DoUserCallback();
790 return DoAbortCallbacks(); 820 return DoAbortCallbacks();
791 } 821 }
792 822
793 // We are running a callback from the message loop. It's time to restart what 823 // We are running a callback from the message loop. It's time to restart what
794 // we were doing before. 824 // we were doing before.
795 DoChildrenIO(); 825 DoChildrenIO();
796 } 826 }
797 827
798 void SparseControl::DoUserCallback() { 828 void SparseControl::DoUserCallback() {
(...skipping 14 matching lines...) Expand all
813 net::CompletionCallback* c = abort_callbacks_[i]; 843 net::CompletionCallback* c = abort_callbacks_[i];
814 if (i == abort_callbacks_.size() - 1) 844 if (i == abort_callbacks_.size() - 1)
815 abort_callbacks_.clear(); 845 abort_callbacks_.clear();
816 846
817 entry_->Release(); // Don't touch object after this line. 847 entry_->Release(); // Don't touch object after this line.
818 c->Run(net::OK); 848 c->Run(net::OK);
819 } 849 }
820 } 850 }
821 851
822 } // namespace disk_cache 852 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698