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

Side by Side Diff: net/disk_cache/memory/mem_entry_impl.cc

Issue 1059843002: Refactor NetLog::LogLevel --> NetLogCaptureMode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase again to fix a merge conflict Created 5 years, 8 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
« no previous file with comments | « net/disk_cache/blockfile/sparse_control_v3.cc ('k') | net/disk_cache/net_log_parameters.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) 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/memory/mem_entry_impl.h" 5 #include "net/disk_cache/memory/mem_entry_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 30 matching lines...) Expand all
41 // like Range_entry_name:YYY where YYY is the number of the particular child. 41 // like Range_entry_name:YYY where YYY is the number of the particular child.
42 std::string GenerateChildName(const std::string& base_name, int child_id) { 42 std::string GenerateChildName(const std::string& base_name, int child_id) {
43 return base::StringPrintf("Range_%s:%i", base_name.c_str(), child_id); 43 return base::StringPrintf("Range_%s:%i", base_name.c_str(), child_id);
44 } 44 }
45 45
46 // Returns NetLog parameters for the creation of a child MemEntryImpl. Separate 46 // Returns NetLog parameters for the creation of a child MemEntryImpl. Separate
47 // function needed because child entries don't suppport GetKey(). 47 // function needed because child entries don't suppport GetKey().
48 base::Value* NetLogChildEntryCreationCallback( 48 base::Value* NetLogChildEntryCreationCallback(
49 const disk_cache::MemEntryImpl* parent, 49 const disk_cache::MemEntryImpl* parent,
50 int child_id, 50 int child_id,
51 net::NetLog::LogLevel /* log_level */) { 51 net::NetLogCaptureMode /* capture_mode */) {
52 base::DictionaryValue* dict = new base::DictionaryValue(); 52 base::DictionaryValue* dict = new base::DictionaryValue();
53 dict->SetString("key", GenerateChildName(parent->GetKey(), child_id)); 53 dict->SetString("key", GenerateChildName(parent->GetKey(), child_id));
54 dict->SetBoolean("created", true); 54 dict->SetBoolean("created", true);
55 return dict; 55 return dict;
56 } 56 }
57 57
58 } // namespace 58 } // namespace
59 59
60 namespace disk_cache { 60 namespace disk_cache {
61 61
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 179
180 int32 MemEntryImpl::GetDataSize(int index) const { 180 int32 MemEntryImpl::GetDataSize(int index) const {
181 if (index < 0 || index >= NUM_STREAMS) 181 if (index < 0 || index >= NUM_STREAMS)
182 return 0; 182 return 0;
183 return data_size_[index]; 183 return data_size_[index];
184 } 184 }
185 185
186 int MemEntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, 186 int MemEntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len,
187 const CompletionCallback& callback) { 187 const CompletionCallback& callback) {
188 if (net_log_.IsLogging()) { 188 if (net_log_.GetCaptureMode().enabled()) {
189 net_log_.BeginEvent( 189 net_log_.BeginEvent(
190 net::NetLog::TYPE_ENTRY_READ_DATA, 190 net::NetLog::TYPE_ENTRY_READ_DATA,
191 CreateNetLogReadWriteDataCallback(index, offset, buf_len, false)); 191 CreateNetLogReadWriteDataCallback(index, offset, buf_len, false));
192 } 192 }
193 193
194 int result = InternalReadData(index, offset, buf, buf_len); 194 int result = InternalReadData(index, offset, buf, buf_len);
195 195
196 if (net_log_.IsLogging()) { 196 if (net_log_.GetCaptureMode().enabled()) {
197 net_log_.EndEvent( 197 net_log_.EndEvent(
198 net::NetLog::TYPE_ENTRY_READ_DATA, 198 net::NetLog::TYPE_ENTRY_READ_DATA,
199 CreateNetLogReadWriteCompleteCallback(result)); 199 CreateNetLogReadWriteCompleteCallback(result));
200 } 200 }
201 return result; 201 return result;
202 } 202 }
203 203
204 int MemEntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, 204 int MemEntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len,
205 const CompletionCallback& callback, bool truncate) { 205 const CompletionCallback& callback, bool truncate) {
206 if (net_log_.IsLogging()) { 206 if (net_log_.GetCaptureMode().enabled()) {
207 net_log_.BeginEvent( 207 net_log_.BeginEvent(
208 net::NetLog::TYPE_ENTRY_WRITE_DATA, 208 net::NetLog::TYPE_ENTRY_WRITE_DATA,
209 CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); 209 CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate));
210 } 210 }
211 211
212 int result = InternalWriteData(index, offset, buf, buf_len, truncate); 212 int result = InternalWriteData(index, offset, buf, buf_len, truncate);
213 213
214 if (net_log_.IsLogging()) { 214 if (net_log_.GetCaptureMode().enabled()) {
215 net_log_.EndEvent( 215 net_log_.EndEvent(
216 net::NetLog::TYPE_ENTRY_WRITE_DATA, 216 net::NetLog::TYPE_ENTRY_WRITE_DATA,
217 CreateNetLogReadWriteCompleteCallback(result)); 217 CreateNetLogReadWriteCompleteCallback(result));
218 } 218 }
219 return result; 219 return result;
220 } 220 }
221 221
222 int MemEntryImpl::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, 222 int MemEntryImpl::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len,
223 const CompletionCallback& callback) { 223 const CompletionCallback& callback) {
224 if (net_log_.IsLogging()) { 224 if (net_log_.GetCaptureMode().enabled()) {
225 net_log_.BeginEvent( 225 net_log_.BeginEvent(
226 net::NetLog::TYPE_SPARSE_READ, 226 net::NetLog::TYPE_SPARSE_READ,
227 CreateNetLogSparseOperationCallback(offset, buf_len)); 227 CreateNetLogSparseOperationCallback(offset, buf_len));
228 } 228 }
229 int result = InternalReadSparseData(offset, buf, buf_len); 229 int result = InternalReadSparseData(offset, buf, buf_len);
230 if (net_log_.IsLogging()) 230 if (net_log_.GetCaptureMode().enabled())
231 net_log_.EndEvent(net::NetLog::TYPE_SPARSE_READ); 231 net_log_.EndEvent(net::NetLog::TYPE_SPARSE_READ);
232 return result; 232 return result;
233 } 233 }
234 234
235 int MemEntryImpl::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, 235 int MemEntryImpl::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len,
236 const CompletionCallback& callback) { 236 const CompletionCallback& callback) {
237 if (net_log_.IsLogging()) { 237 if (net_log_.GetCaptureMode().enabled()) {
238 net_log_.BeginEvent( 238 net_log_.BeginEvent(
239 net::NetLog::TYPE_SPARSE_WRITE, 239 net::NetLog::TYPE_SPARSE_WRITE,
240 CreateNetLogSparseOperationCallback(offset, buf_len)); 240 CreateNetLogSparseOperationCallback(offset, buf_len));
241 } 241 }
242 int result = InternalWriteSparseData(offset, buf, buf_len); 242 int result = InternalWriteSparseData(offset, buf, buf_len);
243 if (net_log_.IsLogging()) 243 if (net_log_.GetCaptureMode().enabled())
244 net_log_.EndEvent(net::NetLog::TYPE_SPARSE_WRITE); 244 net_log_.EndEvent(net::NetLog::TYPE_SPARSE_WRITE);
245 return result; 245 return result;
246 } 246 }
247 247
248 int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start, 248 int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
249 const CompletionCallback& callback) { 249 const CompletionCallback& callback) {
250 if (net_log_.IsLogging()) { 250 if (net_log_.GetCaptureMode().enabled()) {
251 net_log_.BeginEvent( 251 net_log_.BeginEvent(
252 net::NetLog::TYPE_SPARSE_GET_RANGE, 252 net::NetLog::TYPE_SPARSE_GET_RANGE,
253 CreateNetLogSparseOperationCallback(offset, len)); 253 CreateNetLogSparseOperationCallback(offset, len));
254 } 254 }
255 int result = GetAvailableRange(offset, len, start); 255 int result = GetAvailableRange(offset, len, start);
256 if (net_log_.IsLogging()) { 256 if (net_log_.GetCaptureMode().enabled()) {
257 net_log_.EndEvent( 257 net_log_.EndEvent(
258 net::NetLog::TYPE_SPARSE_GET_RANGE, 258 net::NetLog::TYPE_SPARSE_GET_RANGE,
259 CreateNetLogGetAvailableRangeResultCallback(*start, result)); 259 CreateNetLogGetAvailableRangeResultCallback(*start, result));
260 } 260 }
261 return result; 261 return result;
262 } 262 }
263 263
264 bool MemEntryImpl::CouldBeSparse() const { 264 bool MemEntryImpl::CouldBeSparse() const {
265 DCHECK_EQ(kParentEntry, type()); 265 DCHECK_EQ(kParentEntry, type());
266 return (children_.get() != NULL); 266 return (children_.get() != NULL);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 if (!child) 366 if (!child)
367 break; 367 break;
368 368
369 // We then need to prepare the child offset and len. 369 // We then need to prepare the child offset and len.
370 int child_offset = ToChildOffset(offset + io_buf->BytesConsumed()); 370 int child_offset = ToChildOffset(offset + io_buf->BytesConsumed());
371 371
372 // If we are trying to read from a position that the child entry has no data 372 // If we are trying to read from a position that the child entry has no data
373 // we should stop. 373 // we should stop.
374 if (child_offset < child->child_first_pos_) 374 if (child_offset < child->child_first_pos_)
375 break; 375 break;
376 if (net_log_.IsLogging()) { 376 if (net_log_.GetCaptureMode().enabled()) {
377 net_log_.BeginEvent( 377 net_log_.BeginEvent(
378 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, 378 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA,
379 CreateNetLogSparseReadWriteCallback(child->net_log().source(), 379 CreateNetLogSparseReadWriteCallback(child->net_log().source(),
380 io_buf->BytesRemaining())); 380 io_buf->BytesRemaining()));
381 } 381 }
382 int ret = child->ReadData(kSparseData, child_offset, io_buf.get(), 382 int ret = child->ReadData(kSparseData, child_offset, io_buf.get(),
383 io_buf->BytesRemaining(), CompletionCallback()); 383 io_buf->BytesRemaining(), CompletionCallback());
384 if (net_log_.IsLogging()) { 384 if (net_log_.GetCaptureMode().enabled()) {
385 net_log_.EndEventWithNetErrorCode( 385 net_log_.EndEventWithNetErrorCode(
386 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, ret); 386 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, ret);
387 } 387 }
388 388
389 // If we encounter an error in one entry, return immediately. 389 // If we encounter an error in one entry, return immediately.
390 if (ret < 0) 390 if (ret < 0)
391 return ret; 391 return ret;
392 else if (ret == 0) 392 else if (ret == 0)
393 break; 393 break;
394 394
(...skipping 28 matching lines...) Expand all
423 int child_offset = ToChildOffset(offset + io_buf->BytesConsumed()); 423 int child_offset = ToChildOffset(offset + io_buf->BytesConsumed());
424 424
425 // Find the right amount to write, this evaluates the remaining bytes to 425 // Find the right amount to write, this evaluates the remaining bytes to
426 // write and remaining capacity of this child entry. 426 // write and remaining capacity of this child entry.
427 int write_len = std::min(static_cast<int>(io_buf->BytesRemaining()), 427 int write_len = std::min(static_cast<int>(io_buf->BytesRemaining()),
428 kMaxSparseEntrySize - child_offset); 428 kMaxSparseEntrySize - child_offset);
429 429
430 // Keep a record of the last byte position (exclusive) in the child. 430 // Keep a record of the last byte position (exclusive) in the child.
431 int data_size = child->GetDataSize(kSparseData); 431 int data_size = child->GetDataSize(kSparseData);
432 432
433 if (net_log_.IsLogging()) { 433 if (net_log_.GetCaptureMode().enabled()) {
434 net_log_.BeginEvent( 434 net_log_.BeginEvent(
435 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, 435 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA,
436 CreateNetLogSparseReadWriteCallback(child->net_log().source(), 436 CreateNetLogSparseReadWriteCallback(child->net_log().source(),
437 write_len)); 437 write_len));
438 } 438 }
439 439
440 // Always writes to the child entry. This operation may overwrite data 440 // Always writes to the child entry. This operation may overwrite data
441 // previously written. 441 // previously written.
442 // TODO(hclam): if there is data in the entry and this write is not 442 // TODO(hclam): if there is data in the entry and this write is not
443 // continuous we may want to discard this write. 443 // continuous we may want to discard this write.
444 int ret = child->WriteData(kSparseData, child_offset, io_buf.get(), 444 int ret = child->WriteData(kSparseData, child_offset, io_buf.get(),
445 write_len, CompletionCallback(), true); 445 write_len, CompletionCallback(), true);
446 if (net_log_.IsLogging()) { 446 if (net_log_.GetCaptureMode().enabled()) {
447 net_log_.EndEventWithNetErrorCode( 447 net_log_.EndEventWithNetErrorCode(
448 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, ret); 448 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, ret);
449 } 449 }
450 if (ret < 0) 450 if (ret < 0)
451 return ret; 451 return ret;
452 else if (ret == 0) 452 else if (ret == 0)
453 break; 453 break;
454 454
455 // Keep a record of the first byte position in the child if the write was 455 // Keep a record of the first byte position in the child if the write was
456 // not aligned nor continuous. This is to enable witting to the middle 456 // not aligned nor continuous. This is to enable witting to the middle
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 scanned_len += kMaxSparseEntrySize - current_child_offset; 622 scanned_len += kMaxSparseEntrySize - current_child_offset;
623 } 623 }
624 return scanned_len; 624 return scanned_len;
625 } 625 }
626 626
627 void MemEntryImpl::DetachChild(int child_id) { 627 void MemEntryImpl::DetachChild(int child_id) {
628 children_->erase(child_id); 628 children_->erase(child_id);
629 } 629 }
630 630
631 } // namespace disk_cache 631 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/blockfile/sparse_control_v3.cc ('k') | net/disk_cache/net_log_parameters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698