Revert of Re-enabling webrtc Telemetry tests. (patchset #1 id:1 of https://codereview...
[chromium-blink-merge.git] / net / base / upload_disk_cache_entry_element_reader.h
blob1885b2e907412d5238d0ee4b205a61c4f7a7964e
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.
5 #ifndef NET_BASE_UPLOAD_DISK_CACHE_ENTRY_ELEMENT_READER_H_
6 #define NET_BASE_UPLOAD_DISK_CACHE_ENTRY_ELEMENT_READER_H_
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"
15 namespace disk_cache {
16 class Entry;
19 namespace net {
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;
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_;
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;
54 private:
55 void OnReadCompleted(const CompletionCallback& callback, int result);
57 disk_cache::Entry* const disk_cache_entry_;
58 const int disk_cache_stream_index_;
60 const int range_begin_offset_;
61 const int range_end_offset_;
63 int current_read_offset_;
65 base::WeakPtrFactory<UploadDiskCacheEntryElementReader> weak_factory_;
67 DISALLOW_COPY_AND_ASSIGN(UploadDiskCacheEntryElementReader);
70 } // namespace net
72 #endif // NET_BASE_UPLOAD_DISK_CACHE_ENTRY_ELEMENT_READER_H_