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

Side by Side Diff: net/filter/mock_stream_source.cc

Issue 1662763002: [ON HOLD] Implement pull-based design for content decoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
(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/filter/mock_stream_source.h"
6
7 namespace net {
8
9 MockStreamSource::MockStreamSource()
10 : awaiting_completion_(false),
11 dest_buffer_(nullptr),
12 dest_buffer_size_(0),
13 total_bytes_output_(0) {}
14
15 MockStreamSource::~MockStreamSource() {}
16
17 MockStreamSource::QueuedResult::QueuedResult(const char* data,
18 size_t len,
19 Error error,
20 bool sync)
21 : data(data), len(len), error(error), sync(sync) {}
22
23 void MockStreamSource::AddReadResult(const char* data,
24 size_t len,
25 Error error,
26 bool sync) {
27 QueuedResult result(data, len, error, sync);
28 results_.push(result);
29 }
30
31 void MockStreamSource::CompleteNextRead() {
32 DCHECK(awaiting_completion_);
33 awaiting_completion_ = false;
34 QueuedResult r = results_.front();
35 DCHECK(!r.sync);
36 results_.pop();
37 DCHECK_GE(dest_buffer_size_, r.len);
38 memcpy(dest_buffer_->data(), r.data, r.len);
39 if (r.error == OK)
40 total_bytes_output_ += r.len;
41 callback_.Run(r.error, r.len);
42 }
43
44 net::Error MockStreamSource::Read(IOBuffer* dest_buffer,
45 size_t buffer_size,
46 size_t* bytes_read,
47 const OnReadCompleteCallback& callback) {
48 DCHECK(!awaiting_completion_);
49 if (results_.empty()) {
50 *bytes_read = 0;
51 return OK;
52 }
53
54 QueuedResult r = results_.front();
55 if (!r.sync) {
56 awaiting_completion_ = true;
57 dest_buffer_ = dest_buffer;
58 dest_buffer_size_ = buffer_size;
59 callback_ = callback;
60 return ERR_IO_PENDING;
61 }
62
63 results_.pop();
64 DCHECK_GE(buffer_size, r.len);
65 memcpy(dest_buffer->data(), r.data, r.len);
66 *bytes_read = r.len;
67 total_bytes_output_ += r.len;
68 return r.error;
69 }
70
71 size_t MockStreamSource::GetBytesOutput() const {
72 return total_bytes_output_;
73 }
74
75 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698