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

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: fix compile on mac Created 4 years, 5 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 #include "net/base/io_buffer.h"
8
9 namespace net {
10
11 MockStreamSource::MockStreamSource()
12 : StreamSource(StreamSource::TYPE_NONE),
13 awaiting_completion_(false),
14 dest_buffer_(nullptr),
15 dest_buffer_size_(0) {}
16
17 MockStreamSource::~MockStreamSource() {}
18
19 int MockStreamSource::Read(IOBuffer* dest_buffer,
20 size_t buffer_size,
21 const CompletionCallback& callback) {
22 DCHECK(!awaiting_completion_);
23 if (results_.empty()) {
24 return OK;
25 }
26
27 QueuedResult r = results_.front();
28 if (!r.sync) {
29 awaiting_completion_ = true;
30 dest_buffer_ = dest_buffer;
31 dest_buffer_size_ = buffer_size;
32 callback_ = callback;
33 return ERR_IO_PENDING;
34 }
35
36 results_.pop();
37 DCHECK_GE(buffer_size, r.len);
38 memcpy(dest_buffer->data(), r.data, r.len);
39 return r.len;
40 }
41
42 MockStreamSource::QueuedResult::QueuedResult(const char* data,
43 size_t len,
44 Error error,
45 bool sync)
46 : data(data), len(len), error(error), sync(sync) {}
47
48 void MockStreamSource::AddReadResult(const char* data,
49 size_t len,
50 Error error,
51 bool sync) {
52 QueuedResult result(data, len, error, sync);
53 results_.push(result);
54 }
55
56 void MockStreamSource::CompleteNextRead() {
57 DCHECK(awaiting_completion_);
58 awaiting_completion_ = false;
59 QueuedResult r = results_.front();
60 DCHECK(!r.sync);
61 results_.pop();
62 DCHECK_GE(dest_buffer_size_, r.len);
63 memcpy(dest_buffer_->data(), r.data, r.len);
64 callback_.Run(r.len);
65 }
66
67 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698