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

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: Remove pointless plumbing that forced matching begin/end events 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
« no previous file with comments | « net/disk_cache/sparse_control.h ('k') | net/net.gyp » ('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"
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 11 matching lines...) Expand all
39 // parent and the child_id. 40 // parent and the child_id.
40 // If the entry is called entry_name, child entries will be named something 41 // If the entry is called entry_name, child entries will be named something
41 // like Range_entry_name:XXX:YYY where XXX is the entry signature and YYY is the 42 // like Range_entry_name:XXX:YYY where XXX is the entry signature and YYY is the
42 // number of the particular child. 43 // number of the particular child.
43 std::string GenerateChildName(const std::string& base_name, int64 signature, 44 std::string GenerateChildName(const std::string& base_name, int64 signature,
44 int64 child_id) { 45 int64 child_id) {
45 return base::StringPrintf("Range_%s:%" PRIx64 ":%" PRIx64, base_name.c_str(), 46 return base::StringPrintf("Range_%s:%" PRIx64 ":%" PRIx64, base_name.c_str(),
46 signature, child_id); 47 signature, child_id);
47 } 48 }
48 49
50 // Returns the NetLog event type corresponding to a SparseOperation.
51 net::NetLog::EventType GetSparseEventType(
52 disk_cache::SparseControl::SparseOperation operation) {
53 switch (operation) {
54 case disk_cache::SparseControl::kReadOperation:
55 return net::NetLog::TYPE_SPARSE_READ;
56 case disk_cache::SparseControl::kWriteOperation:
57 return net::NetLog::TYPE_SPARSE_WRITE;
58 case disk_cache::SparseControl::kGetRangeOperation:
59 return net::NetLog::TYPE_SPARSE_GET_RANGE;
60 default:
61 NOTREACHED();
62 return net::NetLog::TYPE_CANCELLED;
63 }
64 }
65
49 // This class deletes the children of a sparse entry. 66 // This class deletes the children of a sparse entry.
50 class ChildrenDeleter 67 class ChildrenDeleter
51 : public base::RefCounted<ChildrenDeleter>, 68 : public base::RefCounted<ChildrenDeleter>,
52 public disk_cache::FileIOCallback { 69 public disk_cache::FileIOCallback {
53 public: 70 public:
54 ChildrenDeleter(disk_cache::BackendImpl* backend, const std::string& name) 71 ChildrenDeleter(disk_cache::BackendImpl* backend, const std::string& name)
55 : backend_(backend->GetWeakPtr()), name_(name), signature_(0) {} 72 : backend_(backend->GetWeakPtr()), name_(name), signature_(0) {}
56 73
57 virtual void OnFileIOComplete(int bytes_copied); 74 virtual void OnFileIOComplete(int bytes_copied);
58 75
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 148 }
132 std::string child_name = GenerateChildName(name_, signature_, child_id); 149 std::string child_name = GenerateChildName(name_, signature_, child_id);
133 backend_->SyncDoomEntry(child_name); 150 backend_->SyncDoomEntry(child_name);
134 children_map_.Set(child_id, false); 151 children_map_.Set(child_id, false);
135 152
136 // Post a task to delete the next child. 153 // Post a task to delete the next child.
137 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 154 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
138 this, &ChildrenDeleter::DeleteChildren)); 155 this, &ChildrenDeleter::DeleteChildren));
139 } 156 }
140 157
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
165 } // namespace. 158 } // namespace.
166 159
167 namespace disk_cache { 160 namespace disk_cache {
168 161
169 SparseControl::SparseControl(EntryImpl* entry) 162 SparseControl::SparseControl(EntryImpl* entry)
170 : entry_(entry), 163 : entry_(entry),
171 child_(NULL), 164 child_(NULL),
172 operation_(kNoOperation), 165 operation_(kNoOperation),
173 init_(false), 166 init_(false),
174 child_map_(child_data_.bitmap, kNumSparseBits, kNumSparseBits / 32), 167 child_map_(child_data_.bitmap, kNumSparseBits, kNumSparseBits / 32),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 offset_ = offset; 233 offset_ = offset;
241 user_buf_ = buf ? new net::DrainableIOBuffer(buf, buf_len) : NULL; 234 user_buf_ = buf ? new net::DrainableIOBuffer(buf, buf_len) : NULL;
242 buf_len_ = buf_len; 235 buf_len_ = buf_len;
243 user_callback_ = callback; 236 user_callback_ = callback;
244 237
245 result_ = 0; 238 result_ = 0;
246 pending_ = false; 239 pending_ = false;
247 finished_ = false; 240 finished_ = false;
248 abort_ = false; 241 abort_ = false;
249 242
250 entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); 243 if (entry_->net_log().IsLoggingAllEvents()) {
244 entry_->net_log().BeginEvent(
245 GetSparseEventType(operation_),
246 make_scoped_refptr(new SparseOperationParameters(offset_, buf_len_)));
247 }
251 DoChildrenIO(); 248 DoChildrenIO();
252 249
253 if (!pending_) { 250 if (!pending_) {
254 // Everything was done synchronously. 251 // Everything was done synchronously.
255 operation_ = kNoOperation; 252 operation_ = kNoOperation;
256 user_buf_ = NULL; 253 user_buf_ = NULL;
257 user_callback_ = NULL; 254 user_callback_ = NULL;
258 return result_; 255 return result_;
259 } 256 }
260 257
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 int map_len = data_len - sizeof(SparseHeader); 307 int map_len = data_len - sizeof(SparseHeader);
311 if (map_len > kMaxMapSize || map_len % 4) 308 if (map_len > kMaxMapSize || map_len % 4)
312 return; 309 return;
313 310
314 char* buffer; 311 char* buffer;
315 Addr address; 312 Addr address;
316 entry->GetData(kSparseIndex, &buffer, &address); 313 entry->GetData(kSparseIndex, &buffer, &address);
317 if (!buffer && !address.is_initialized()) 314 if (!buffer && !address.is_initialized())
318 return; 315 return;
319 316
317 entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN, NULL);
318
320 ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_, 319 ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_,
321 entry->GetKey()); 320 entry->GetKey());
322 // The object will self destruct when finished. 321 // The object will self destruct when finished.
323 deleter->AddRef(); 322 deleter->AddRef();
324 323
325 if (buffer) { 324 if (buffer) {
326 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 325 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
327 deleter, &ChildrenDeleter::Start, buffer, data_len)); 326 deleter, &ChildrenDeleter::Start, buffer, data_len));
328 } else { 327 } else {
329 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 328 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 NULL, false); 628 NULL, false);
630 if (rv != sizeof(child_data_)) 629 if (rv != sizeof(child_data_))
631 DLOG(ERROR) << "Failed to save child data"; 630 DLOG(ERROR) << "Failed to save child data";
632 SetChildBit(true); 631 SetChildBit(true);
633 } 632 }
634 633
635 void SparseControl::DoChildrenIO() { 634 void SparseControl::DoChildrenIO() {
636 while (DoChildIO()) continue; 635 while (DoChildIO()) continue;
637 636
638 if (finished_) { 637 if (finished_) {
639 entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); 638 if (entry_->net_log().IsLoggingAllEvents()) {
639 if (operation_ != kGetRangeOperation) {
rvargas (doing something else) 2011/03/04 21:39:16 nit: reverse this if
rvargas (doing something else) 2011/03/07 22:13:51 I guess you missed this one.
mmenke 2011/03/07 22:19:25 Yea, I did. Thanks for catching it. Done.
640 entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL);
641 } else {
642 entry_->net_log().EndEvent(
643 net::NetLog::TYPE_SPARSE_GET_RANGE,
644 make_scoped_refptr(
645 new GetAvailableRangeResultParameters(offset_, result_)));
646 }
647 }
640 if (pending_) 648 if (pending_)
641 DoUserCallback(); 649 DoUserCallback();
642 } 650 }
643 } 651 }
644 652
645 bool SparseControl::DoChildIO() { 653 bool SparseControl::DoChildIO() {
646 finished_ = true; 654 finished_ = true;
647 if (!buf_len_ || result_ < 0) 655 if (!buf_len_ || result_ < 0)
648 return false; 656 return false;
649 657
650 if (!OpenChild()) 658 if (!OpenChild())
651 return false; 659 return false;
652 660
653 if (!VerifyRange()) 661 if (!VerifyRange())
654 return false; 662 return false;
655 663
656 // We have more work to do. Let's not trigger a callback to the caller. 664 // We have more work to do. Let's not trigger a callback to the caller.
657 finished_ = false; 665 finished_ = false;
658 net::CompletionCallback* callback = user_callback_ ? &child_callback_ : NULL; 666 net::CompletionCallback* callback = user_callback_ ? &child_callback_ : NULL;
659 667
660 int rv = 0; 668 int rv = 0;
661 switch (operation_) { 669 switch (operation_) {
662 case kReadOperation: 670 case kReadOperation:
663 if (entry_->net_log().IsLoggingAllEvents()) { 671 if (entry_->net_log().IsLoggingAllEvents()) {
664 entry_->net_log().BeginEvent( 672 entry_->net_log().BeginEvent(
665 net::NetLog::TYPE_SPARSE_CONTROL_READ, 673 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA,
666 make_scoped_refptr(new net::NetLogSourceParameter( 674 make_scoped_refptr(new SparseReadWriteParameters(
667 "source_dependency", 675 child_->net_log().source(),
668 child_->net_log().source()))); 676 child_len_)));
669 } 677 }
670 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_, 678 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_,
671 child_len_, callback); 679 child_len_, callback);
672 break; 680 break;
673 case kWriteOperation: 681 case kWriteOperation:
674 if (entry_->net_log().IsLoggingAllEvents()) { 682 if (entry_->net_log().IsLoggingAllEvents()) {
675 entry_->net_log().BeginEvent( 683 entry_->net_log().BeginEvent(
676 net::NetLog::TYPE_SPARSE_CONTROL_WRITE, 684 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA,
677 make_scoped_refptr(new net::NetLogSourceParameter( 685 make_scoped_refptr(new SparseReadWriteParameters(
678 "source_dependency", 686 child_->net_log().source(),
679 child_->net_log().source()))); 687 child_len_)));
680 } 688 }
681 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_, 689 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_,
682 child_len_, callback, false); 690 child_len_, callback, false);
683 break; 691 break;
684 case kGetRangeOperation: 692 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(); 693 rv = DoGetAvailableRange();
690 break; 694 break;
691 default: 695 default:
692 NOTREACHED(); 696 NOTREACHED();
693 } 697 }
694 698
695 if (rv == net::ERR_IO_PENDING) { 699 if (rv == net::ERR_IO_PENDING) {
696 if (!pending_) { 700 if (!pending_) {
697 pending_ = true; 701 pending_ = true;
698 // The child will protect himself against closing the entry while IO is in 702 // 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. 755 // Only update offset_ when this query found zeros at the start.
752 if (empty_start) 756 if (empty_start)
753 offset_ += empty_start; 757 offset_ += empty_start;
754 758
755 // This will actually break the loop. 759 // This will actually break the loop.
756 buf_len_ = 0; 760 buf_len_ = 0;
757 return 0; 761 return 0;
758 } 762 }
759 763
760 void SparseControl::DoChildIOCompleted(int result) { 764 void SparseControl::DoChildIOCompleted(int result) {
761 LogOperationEnd(entry_->net_log(), operation_, result); 765 if (entry_->net_log().IsLoggingAllEvents())
766 LogChildOperationEnd(result);
762 if (result < 0) { 767 if (result < 0) {
763 // We fail the whole operation if we encounter an error. 768 // We fail the whole operation if we encounter an error.
764 result_ = result; 769 result_ = result;
765 return; 770 return;
766 } 771 }
767 772
768 UpdateRange(result); 773 UpdateRange(result);
769 774
770 result_ += result; 775 result_ += result;
771 offset_ += result; 776 offset_ += result;
772 buf_len_ -= result; 777 buf_len_ -= result;
773 778
774 // We'll be reusing the user provided buffer for the next chunk. 779 // We'll be reusing the user provided buffer for the next chunk.
775 if (buf_len_ && user_buf_) 780 if (buf_len_ && user_buf_)
776 user_buf_->DidConsume(result); 781 user_buf_->DidConsume(result);
777 } 782 }
778 783
779 void SparseControl::OnChildIOCompleted(int result) { 784 void SparseControl::OnChildIOCompleted(int result) {
780 DCHECK_NE(net::ERR_IO_PENDING, result); 785 DCHECK_NE(net::ERR_IO_PENDING, result);
781 DoChildIOCompleted(result); 786 DoChildIOCompleted(result);
782 787
783 if (abort_) { 788 if (abort_) {
784 // We'll return the current result of the operation, which may be less than 789 // 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. 790 // the bytes to read or write, but the user cancelled the operation.
786 abort_ = false; 791 abort_ = false;
787 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL); 792 if (entry_->net_log().IsLoggingAllEvents()) {
788 entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); 793 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL);
794 entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL);
795 }
789 DoUserCallback(); 796 DoUserCallback();
790 return DoAbortCallbacks(); 797 return DoAbortCallbacks();
791 } 798 }
792 799
793 // We are running a callback from the message loop. It's time to restart what 800 // We are running a callback from the message loop. It's time to restart what
794 // we were doing before. 801 // we were doing before.
795 DoChildrenIO(); 802 DoChildrenIO();
796 } 803 }
797 804
798 void SparseControl::DoUserCallback() { 805 void SparseControl::DoUserCallback() {
(...skipping 13 matching lines...) Expand all
812 // object so we should not be touching it after the last Release(). 819 // object so we should not be touching it after the last Release().
813 net::CompletionCallback* c = abort_callbacks_[i]; 820 net::CompletionCallback* c = abort_callbacks_[i];
814 if (i == abort_callbacks_.size() - 1) 821 if (i == abort_callbacks_.size() - 1)
815 abort_callbacks_.clear(); 822 abort_callbacks_.clear();
816 823
817 entry_->Release(); // Don't touch object after this line. 824 entry_->Release(); // Don't touch object after this line.
818 c->Run(net::OK); 825 c->Run(net::OK);
819 } 826 }
820 } 827 }
821 828
829 void SparseControl::LogChildOperationEnd(int result) {
830 net::NetLog::EventType event_type;
831 switch (operation_) {
832 case disk_cache::SparseControl::kReadOperation:
833 event_type = net::NetLog::TYPE_SPARSE_READ_CHILD_DATA;
834 break;
835 case disk_cache::SparseControl::kWriteOperation:
836 event_type = net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA;
837 break;
838 case disk_cache::SparseControl::kGetRangeOperation:
839 return;
840 default:
841 NOTREACHED();
842 return;
843 }
844 entry_->net_log().EndEventWithNetErrorCode(event_type, result);
845 }
846
822 } // namespace disk_cache 847 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/sparse_control.h ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698