Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/base/upload_disk_cache_entry_element_reader.h" | |
| 6 | |
| 7 #include "net/base/io_buffer.h" | |
| 8 #include "net/base/net_errors.h" | |
| 9 #include "net/disk_cache/disk_cache.h" | |
| 10 | |
| 11 namespace net { | |
| 12 | |
| 13 UploadDiskCacheEntryElementReader::UploadDiskCacheEntryElementReader( | |
| 14 disk_cache::Entry* disk_cache_entry, | |
| 15 int disk_cache_stream_index, | |
| 16 int range_offset, | |
| 17 int range_length) | |
| 18 : disk_cache_entry_(disk_cache_entry), | |
| 19 disk_cache_stream_index_(disk_cache_stream_index), | |
| 20 range_offset_(range_offset), | |
| 21 range_length_(range_length), | |
| 22 offset_(range_offset_), | |
| 23 weak_factory_(this) { | |
| 24 DCHECK_LE(range_offset_ + range_length, | |
|
mmenke
2015/06/16 18:51:18
Should we also DCHECK both of these are >= 0?
gavinp
2015/06/16 22:28:01
Done.
| |
| 25 disk_cache_entry_->GetDataSize(disk_cache_stream_index_)); | |
|
mmenke
2015/06/16 18:51:18
nit: include base/logging.h
gavinp
2015/06/16 22:28:01
Done.
| |
| 26 } | |
| 27 | |
| 28 UploadDiskCacheEntryElementReader::~UploadDiskCacheEntryElementReader() { | |
| 29 } | |
| 30 | |
| 31 const UploadDiskCacheEntryElementReader* | |
| 32 UploadDiskCacheEntryElementReader::AsDiskCacheEntryReader() const { | |
| 33 return this; | |
| 34 } | |
| 35 | |
| 36 int UploadDiskCacheEntryElementReader::Init( | |
| 37 const CompletionCallback& callback) { | |
|
mmenke
2015/06/16 18:51:18
If there's a pending read from entry, it's fine if
gavinp
2015/06/16 22:28:01
Yes.
The behaviour that we will not call the call
| |
| 38 weak_factory_.InvalidateWeakPtrs(); | |
| 39 offset_ = range_offset_; | |
| 40 return OK; | |
| 41 } | |
| 42 | |
| 43 uint64_t UploadDiskCacheEntryElementReader::GetContentLength() const { | |
| 44 return range_length_; | |
| 45 } | |
| 46 | |
| 47 uint64_t UploadDiskCacheEntryElementReader::BytesRemaining() const { | |
| 48 const int amount_read = offset_ - range_offset_; | |
|
mmenke
2015/06/16 18:51:18
nit: Basically no code in chrome or net consts st
michaeln
2015/06/16 21:52:54
i don't think that's true and i think its helpful
mmenke
2015/06/16 22:22:47
Per style guide, kSomething is only for compile-ti
gavinp
2015/06/16 22:28:01
In this case, it's moot, because this line doesn't
gavinp
2015/06/16 22:28:01
Done.
gavinp
2015/06/16 23:08:04
I have gone ahead and removed most const from auto
michaeln
2015/06/17 00:57:36
ok, if you say so :)
mmenke
2015/06/17 01:24:35
Note that if net/ globally follows a convention, t
| |
| 49 return range_length_ - amount_read; | |
| 50 } | |
| 51 | |
| 52 bool UploadDiskCacheEntryElementReader::IsInMemory() const { | |
| 53 return false; | |
| 54 } | |
| 55 | |
| 56 int UploadDiskCacheEntryElementReader::Read( | |
| 57 IOBuffer* buf, | |
| 58 int buf_length, | |
| 59 const CompletionCallback& callback) { | |
|
mmenke
2015/06/16 18:51:18
DCHECK(!callback.is_null())?
gavinp
2015/06/16 22:28:01
Done.
| |
| 60 const int bytes_to_read = | |
| 61 std::min(buf_length, static_cast<int>(BytesRemaining())); | |
|
mmenke
2015/06/16 18:51:18
need to include the header for min (algorithm?)
gavinp
2015/06/16 22:28:01
Done. It's algorithm.
| |
| 62 | |
| 63 CompletionCallback new_callback = | |
| 64 base::Bind(&UploadDiskCacheEntryElementReader::OnReadCompleted, | |
| 65 weak_factory_.GetWeakPtr(), callback); | |
|
mmenke
2015/06/16 18:51:18
include base/bind.h
mmenke
2015/06/16 18:51:18
Suggest making this callback a class member variab
gavinp
2015/06/16 22:28:01
I'm leaving this as is, absent further reviewer in
gavinp
2015/06/16 22:28:01
Done.
| |
| 66 | |
| 67 const int result = disk_cache_entry_->ReadData( | |
| 68 disk_cache_stream_index_, offset_, buf, bytes_to_read, new_callback); | |
| 69 if (result == ERR_IO_PENDING) | |
| 70 return ERR_IO_PENDING; | |
| 71 if (result > 0) | |
| 72 offset_ += result; | |
| 73 return result; | |
| 74 } | |
| 75 | |
| 76 void UploadDiskCacheEntryElementReader::OnReadCompleted( | |
| 77 const CompletionCallback& callback, | |
| 78 int result) { | |
| 79 if (result > 0) | |
| 80 offset_ += result; | |
| 81 callback.Run(result); | |
| 82 } | |
| 83 | |
| 84 } // namespace net | |
| OLD | NEW |