| 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 #ifndef NET_BASE_UPLOAD_DISK_CACHE_ENTRY_ELEMENT_READER_H_ | |
| 6 #define NET_BASE_UPLOAD_DISK_CACHE_ENTRY_ELEMENT_READER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "net/base/completion_callback.h" | |
| 12 #include "net/base/net_export.h" | |
| 13 #include "net/base/upload_element_reader.h" | |
| 14 | |
| 15 namespace disk_cache { | |
| 16 class Entry; | |
| 17 } | |
| 18 | |
| 19 namespace net { | |
| 20 | |
| 21 // An UploadElementReader implementation for disk_cache::Entry objects. The | |
| 22 // caller keeps ownership of |disk_cache_entry|, and is responsible for ensuring | |
| 23 // it outlives the UploadDiskCacheEntryElementReader. | |
| 24 class NET_EXPORT UploadDiskCacheEntryElementReader | |
| 25 : public UploadElementReader { | |
| 26 public: | |
| 27 // Construct a new UploadDiskCacheEntryElementReader which reads from the disk | |
| 28 // cache entry |disk_cache_entry| with stream index |disk_cache_stream_index|. | |
| 29 // The new upload reader object will read |range_length| bytes, starting from | |
| 30 // |range_offset|. To read an whole cache entry give a 0 as |range_offset| and | |
| 31 // provide the length of the entry's stream as |range_length|. | |
| 32 UploadDiskCacheEntryElementReader(disk_cache::Entry* disk_cache_entry, | |
| 33 int disk_cache_stream_index, | |
| 34 int range_offset, | |
| 35 int range_length); | |
| 36 ~UploadDiskCacheEntryElementReader() override; | |
| 37 | |
| 38 int range_offset_for_tests() const { return range_begin_offset_; } | |
| 39 int range_length_for_tests() const { | |
| 40 return range_end_offset_ - range_begin_offset_; | |
| 41 } | |
| 42 | |
| 43 // UploadElementReader overrides: | |
| 44 const UploadDiskCacheEntryElementReader* AsDiskCacheEntryReaderForTests() | |
| 45 const override; | |
| 46 int Init(const CompletionCallback& callback) override; | |
| 47 uint64_t GetContentLength() const override; | |
| 48 uint64_t BytesRemaining() const override; | |
| 49 bool IsInMemory() const override; | |
| 50 int Read(IOBuffer* buf, | |
| 51 int buf_length, | |
| 52 const CompletionCallback& callback) override; | |
| 53 | |
| 54 private: | |
| 55 void OnReadCompleted(const CompletionCallback& callback, int result); | |
| 56 | |
| 57 disk_cache::Entry* const disk_cache_entry_; | |
| 58 const int disk_cache_stream_index_; | |
| 59 | |
| 60 const int range_begin_offset_; | |
| 61 const int range_end_offset_; | |
| 62 | |
| 63 int current_read_offset_; | |
| 64 | |
| 65 base::WeakPtrFactory<UploadDiskCacheEntryElementReader> weak_factory_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(UploadDiskCacheEntryElementReader); | |
| 68 }; | |
| 69 | |
| 70 } // namespace net | |
| 71 | |
| 72 #endif // NET_BASE_UPLOAD_DISK_CACHE_ENTRY_ELEMENT_READER_H_ | |
| OLD | NEW |