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

Unified Diff: net/spdy/chromium/spdy_test_util_common.cc

Issue 2936663002: Simplify CombineFrames() interface. (Closed)
Patch Set: Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: net/spdy/chromium/spdy_test_util_common.cc
diff --git a/net/spdy/chromium/spdy_test_util_common.cc b/net/spdy/chromium/spdy_test_util_common.cc
index 28c42764ed1edab136d361b7cf6e31e66bf58996..766af213f8c6a0682bdc3963bb9e87d909fd4721 100644
--- a/net/spdy/chromium/spdy_test_util_common.cc
+++ b/net/spdy/chromium/spdy_test_util_common.cc
@@ -163,22 +163,20 @@ MockRead CreateMockRead(const SpdySerializedFrame& resp, int seq, IoMode mode) {
// Combines the given SpdyFrames into the given char array and returns
// the total length.
Zhongyi Shi 2017/06/12 19:34:12 ditto.
Bence 2017/06/12 19:49:13 Done.
-int CombineFrames(const SpdySerializedFrame** frames,
- int num_frames,
- char* buf,
- int buf_len) {
- int total_len = 0;
- for (int i = 0; i < num_frames; ++i) {
- total_len += frames[i]->size();
+SpdySerializedFrame CombineFrames(
+ std::vector<const SpdySerializedFrame*> frames) {
+ int total_size = 0;
+ for (const auto* frame : frames) {
+ total_size += frame->size();
}
- DCHECK_LE(total_len, buf_len);
- char* ptr = buf;
- for (int i = 0; i < num_frames; ++i) {
- int len = frames[i]->size();
- memcpy(ptr, frames[i]->data(), len);
- ptr += len;
+ auto data = base::MakeUnique<char[]>(total_size);
+ char* ptr = data.get();
+ for (const auto* frame : frames) {
+ memcpy(ptr, frame->data(), frame->size());
+ ptr += frame->size();
}
- return total_len;
+ return SpdySerializedFrame(data.release(), total_size,
+ /* owns_buffer = */ true);
}
namespace {
@@ -898,15 +896,7 @@ SpdySerializedFrame SpdyTestUtil::ConstructSpdyPush(
SpdySerializedFrame headers_frame(
response_spdy_framer_.SerializeFrame(headers));
- int joint_data_size = push_promise_frame.size() + headers_frame.size();
- auto data = base::MakeUnique<char[]>(joint_data_size);
- const SpdySerializedFrame* frames[2] = {
- &push_promise_frame, &headers_frame,
- };
- int combined_size =
- CombineFrames(frames, arraysize(frames), data.get(), joint_data_size);
- DCHECK_EQ(combined_size, joint_data_size);
- return SpdySerializedFrame(data.release(), joint_data_size, true);
+ return CombineFrames({&push_promise_frame, &headers_frame});
}
SpdySerializedFrame SpdyTestUtil::ConstructSpdyPush(
@@ -933,15 +923,7 @@ SpdySerializedFrame SpdyTestUtil::ConstructSpdyPush(
SpdySerializedFrame headers_frame(
response_spdy_framer_.SerializeFrame(headers));
- int joint_data_size = push_promise_frame.size() + headers_frame.size();
- auto data = base::MakeUnique<char[]>(joint_data_size);
- const SpdySerializedFrame* frames[2] = {
- &push_promise_frame, &headers_frame,
- };
- int combined_size =
- CombineFrames(frames, arraysize(frames), data.get(), joint_data_size);
- DCHECK_EQ(combined_size, joint_data_size);
- return SpdySerializedFrame(data.release(), joint_data_size, true);
+ return CombineFrames({&push_promise_frame, &headers_frame});
}
SpdySerializedFrame SpdyTestUtil::ConstructInitialSpdyPushFrame(
« net/spdy/chromium/spdy_test_util_common.h ('K') | « net/spdy/chromium/spdy_test_util_common.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698