OLD | NEW |
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/blockfile/sparse_control.h" | 5 #include "net/disk_cache/blockfile/sparse_control.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "net/disk_cache/blockfile/backend_impl.h" | 21 #include "net/disk_cache/blockfile/backend_impl.h" |
22 #include "net/disk_cache/blockfile/entry_impl.h" | 22 #include "net/disk_cache/blockfile/entry_impl.h" |
23 #include "net/disk_cache/blockfile/file.h" | 23 #include "net/disk_cache/blockfile/file.h" |
24 #include "net/disk_cache/net_log_parameters.h" | 24 #include "net/disk_cache/net_log_parameters.h" |
| 25 #include "net/log/net_log_event_type.h" |
25 | 26 |
26 using base::Time; | 27 using base::Time; |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 // Stream of the sparse data index. | 31 // Stream of the sparse data index. |
31 const int kSparseIndex = 2; | 32 const int kSparseIndex = 2; |
32 | 33 |
33 // Stream of the sparse data. | 34 // Stream of the sparse data. |
34 const int kSparseData = 1; | 35 const int kSparseData = 1; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 std::string child_name = GenerateChildName(name_, signature_, child_id); | 141 std::string child_name = GenerateChildName(name_, signature_, child_id); |
141 backend_->SyncDoomEntry(child_name); | 142 backend_->SyncDoomEntry(child_name); |
142 children_map_.Set(child_id, false); | 143 children_map_.Set(child_id, false); |
143 | 144 |
144 // Post a task to delete the next child. | 145 // Post a task to delete the next child. |
145 base::ThreadTaskRunnerHandle::Get()->PostTask( | 146 base::ThreadTaskRunnerHandle::Get()->PostTask( |
146 FROM_HERE, base::Bind(&ChildrenDeleter::DeleteChildren, this)); | 147 FROM_HERE, base::Bind(&ChildrenDeleter::DeleteChildren, this)); |
147 } | 148 } |
148 | 149 |
149 // Returns the NetLog event type corresponding to a SparseOperation. | 150 // Returns the NetLog event type corresponding to a SparseOperation. |
150 net::NetLog::EventType GetSparseEventType( | 151 net::NetLogEventType GetSparseEventType( |
151 disk_cache::SparseControl::SparseOperation operation) { | 152 disk_cache::SparseControl::SparseOperation operation) { |
152 switch (operation) { | 153 switch (operation) { |
153 case disk_cache::SparseControl::kReadOperation: | 154 case disk_cache::SparseControl::kReadOperation: |
154 return net::NetLog::TYPE_SPARSE_READ; | 155 return net::NetLogEventType::SPARSE_READ; |
155 case disk_cache::SparseControl::kWriteOperation: | 156 case disk_cache::SparseControl::kWriteOperation: |
156 return net::NetLog::TYPE_SPARSE_WRITE; | 157 return net::NetLogEventType::SPARSE_WRITE; |
157 case disk_cache::SparseControl::kGetRangeOperation: | 158 case disk_cache::SparseControl::kGetRangeOperation: |
158 return net::NetLog::TYPE_SPARSE_GET_RANGE; | 159 return net::NetLogEventType::SPARSE_GET_RANGE; |
159 default: | 160 default: |
160 NOTREACHED(); | 161 NOTREACHED(); |
161 return net::NetLog::TYPE_CANCELLED; | 162 return net::NetLogEventType::CANCELLED; |
162 } | 163 } |
163 } | 164 } |
164 | 165 |
165 // Logs the end event for |operation| on a child entry. Range operations log | 166 // Logs the end event for |operation| on a child entry. Range operations log |
166 // no events for each child they search through. | 167 // no events for each child they search through. |
167 void LogChildOperationEnd(const net::BoundNetLog& net_log, | 168 void LogChildOperationEnd(const net::BoundNetLog& net_log, |
168 disk_cache::SparseControl::SparseOperation operation, | 169 disk_cache::SparseControl::SparseOperation operation, |
169 int result) { | 170 int result) { |
170 if (net_log.IsCapturing()) { | 171 if (net_log.IsCapturing()) { |
171 net::NetLog::EventType event_type; | 172 net::NetLogEventType event_type; |
172 switch (operation) { | 173 switch (operation) { |
173 case disk_cache::SparseControl::kReadOperation: | 174 case disk_cache::SparseControl::kReadOperation: |
174 event_type = net::NetLog::TYPE_SPARSE_READ_CHILD_DATA; | 175 event_type = net::NetLogEventType::SPARSE_READ_CHILD_DATA; |
175 break; | 176 break; |
176 case disk_cache::SparseControl::kWriteOperation: | 177 case disk_cache::SparseControl::kWriteOperation: |
177 event_type = net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA; | 178 event_type = net::NetLogEventType::SPARSE_WRITE_CHILD_DATA; |
178 break; | 179 break; |
179 case disk_cache::SparseControl::kGetRangeOperation: | 180 case disk_cache::SparseControl::kGetRangeOperation: |
180 return; | 181 return; |
181 default: | 182 default: |
182 NOTREACHED(); | 183 NOTREACHED(); |
183 return; | 184 return; |
184 } | 185 } |
185 net_log.EndEventWithNetErrorCode(event_type, result); | 186 net_log.EndEventWithNetErrorCode(event_type, result); |
186 } | 187 } |
187 } | 188 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 int map_len = data_len - sizeof(SparseHeader); | 353 int map_len = data_len - sizeof(SparseHeader); |
353 if (map_len > kMaxMapSize || map_len % 4) | 354 if (map_len > kMaxMapSize || map_len % 4) |
354 return; | 355 return; |
355 | 356 |
356 char* buffer; | 357 char* buffer; |
357 Addr address; | 358 Addr address; |
358 entry->GetData(kSparseIndex, &buffer, &address); | 359 entry->GetData(kSparseIndex, &buffer, &address); |
359 if (!buffer && !address.is_initialized()) | 360 if (!buffer && !address.is_initialized()) |
360 return; | 361 return; |
361 | 362 |
362 entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN); | 363 entry->net_log().AddEvent(net::NetLogEventType::SPARSE_DELETE_CHILDREN); |
363 | 364 |
364 DCHECK(entry->backend_.get()); | 365 DCHECK(entry->backend_.get()); |
365 ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_.get(), | 366 ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_.get(), |
366 entry->GetKey()); | 367 entry->GetKey()); |
367 // The object will self destruct when finished. | 368 // The object will self destruct when finished. |
368 deleter->AddRef(); | 369 deleter->AddRef(); |
369 | 370 |
370 if (buffer) { | 371 if (buffer) { |
371 base::ThreadTaskRunnerHandle::Get()->PostTask( | 372 base::ThreadTaskRunnerHandle::Get()->PostTask( |
372 FROM_HERE, | 373 FROM_HERE, |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 SetChildBit(true); | 683 SetChildBit(true); |
683 } | 684 } |
684 | 685 |
685 void SparseControl::DoChildrenIO() { | 686 void SparseControl::DoChildrenIO() { |
686 while (DoChildIO()) continue; | 687 while (DoChildIO()) continue; |
687 | 688 |
688 // Range operations are finished synchronously, often without setting | 689 // Range operations are finished synchronously, often without setting |
689 // |finished_| to true. | 690 // |finished_| to true. |
690 if (kGetRangeOperation == operation_ && entry_->net_log().IsCapturing()) { | 691 if (kGetRangeOperation == operation_ && entry_->net_log().IsCapturing()) { |
691 entry_->net_log().EndEvent( | 692 entry_->net_log().EndEvent( |
692 net::NetLog::TYPE_SPARSE_GET_RANGE, | 693 net::NetLogEventType::SPARSE_GET_RANGE, |
693 CreateNetLogGetAvailableRangeResultCallback(offset_, result_)); | 694 CreateNetLogGetAvailableRangeResultCallback(offset_, result_)); |
694 } | 695 } |
695 if (finished_) { | 696 if (finished_) { |
696 if (kGetRangeOperation != operation_ && entry_->net_log().IsCapturing()) { | 697 if (kGetRangeOperation != operation_ && entry_->net_log().IsCapturing()) { |
697 entry_->net_log().EndEvent(GetSparseEventType(operation_)); | 698 entry_->net_log().EndEvent(GetSparseEventType(operation_)); |
698 } | 699 } |
699 if (pending_) | 700 if (pending_) |
700 DoUserCallback(); // Don't touch this object after this point. | 701 DoUserCallback(); // Don't touch this object after this point. |
701 } | 702 } |
702 } | 703 } |
(...skipping 15 matching lines...) Expand all Loading... |
718 if (!user_callback_.is_null()) { | 719 if (!user_callback_.is_null()) { |
719 callback = | 720 callback = |
720 base::Bind(&SparseControl::OnChildIOCompleted, base::Unretained(this)); | 721 base::Bind(&SparseControl::OnChildIOCompleted, base::Unretained(this)); |
721 } | 722 } |
722 | 723 |
723 int rv = 0; | 724 int rv = 0; |
724 switch (operation_) { | 725 switch (operation_) { |
725 case kReadOperation: | 726 case kReadOperation: |
726 if (entry_->net_log().IsCapturing()) { | 727 if (entry_->net_log().IsCapturing()) { |
727 entry_->net_log().BeginEvent( | 728 entry_->net_log().BeginEvent( |
728 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, | 729 net::NetLogEventType::SPARSE_READ_CHILD_DATA, |
729 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), | 730 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), |
730 child_len_)); | 731 child_len_)); |
731 } | 732 } |
732 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_.get(), | 733 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_.get(), |
733 child_len_, callback); | 734 child_len_, callback); |
734 break; | 735 break; |
735 case kWriteOperation: | 736 case kWriteOperation: |
736 if (entry_->net_log().IsCapturing()) { | 737 if (entry_->net_log().IsCapturing()) { |
737 entry_->net_log().BeginEvent( | 738 entry_->net_log().BeginEvent( |
738 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, | 739 net::NetLogEventType::SPARSE_WRITE_CHILD_DATA, |
739 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), | 740 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), |
740 child_len_)); | 741 child_len_)); |
741 } | 742 } |
742 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_.get(), | 743 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_.get(), |
743 child_len_, callback, false); | 744 child_len_, callback, false); |
744 break; | 745 break; |
745 case kGetRangeOperation: | 746 case kGetRangeOperation: |
746 rv = DoGetAvailableRange(); | 747 rv = DoGetAvailableRange(); |
747 break; | 748 break; |
748 default: | 749 default: |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 | 858 |
858 void SparseControl::OnChildIOCompleted(int result) { | 859 void SparseControl::OnChildIOCompleted(int result) { |
859 DCHECK_NE(net::ERR_IO_PENDING, result); | 860 DCHECK_NE(net::ERR_IO_PENDING, result); |
860 DoChildIOCompleted(result); | 861 DoChildIOCompleted(result); |
861 | 862 |
862 if (abort_) { | 863 if (abort_) { |
863 // We'll return the current result of the operation, which may be less than | 864 // We'll return the current result of the operation, which may be less than |
864 // the bytes to read or write, but the user cancelled the operation. | 865 // the bytes to read or write, but the user cancelled the operation. |
865 abort_ = false; | 866 abort_ = false; |
866 if (entry_->net_log().IsCapturing()) { | 867 if (entry_->net_log().IsCapturing()) { |
867 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED); | 868 entry_->net_log().AddEvent(net::NetLogEventType::CANCELLED); |
868 entry_->net_log().EndEvent(GetSparseEventType(operation_)); | 869 entry_->net_log().EndEvent(GetSparseEventType(operation_)); |
869 } | 870 } |
870 // We have an indirect reference to this object for every callback so if | 871 // We have an indirect reference to this object for every callback so if |
871 // there is only one callback, we may delete this object before reaching | 872 // there is only one callback, we may delete this object before reaching |
872 // DoAbortCallbacks. | 873 // DoAbortCallbacks. |
873 bool has_abort_callbacks = !abort_callbacks_.empty(); | 874 bool has_abort_callbacks = !abort_callbacks_.empty(); |
874 DoUserCallback(); | 875 DoUserCallback(); |
875 if (has_abort_callbacks) | 876 if (has_abort_callbacks) |
876 DoAbortCallbacks(); | 877 DoAbortCallbacks(); |
877 return; | 878 return; |
(...skipping 23 matching lines...) Expand all Loading... |
901 CompletionCallback cb = abort_callbacks_[i]; | 902 CompletionCallback cb = abort_callbacks_[i]; |
902 if (i == abort_callbacks_.size() - 1) | 903 if (i == abort_callbacks_.size() - 1) |
903 abort_callbacks_.clear(); | 904 abort_callbacks_.clear(); |
904 | 905 |
905 entry_->Release(); // Don't touch object after this line. | 906 entry_->Release(); // Don't touch object after this line. |
906 cb.Run(net::OK); | 907 cb.Run(net::OK); |
907 } | 908 } |
908 } | 909 } |
909 | 910 |
910 } // namespace disk_cache | 911 } // namespace disk_cache |
OLD | NEW |