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

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

Issue 2936663002: Simplify CombineFrames() interface. (Closed)
Patch Set: Re: #7. 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
« no previous file with comments | « net/spdy/chromium/spdy_test_util_common.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..288f341079e42b3fb47c379494de7acafb11e286 100644
--- a/net/spdy/chromium/spdy_test_util_common.cc
+++ b/net/spdy/chromium/spdy_test_util_common.cc
@@ -161,24 +161,21 @@ MockRead CreateMockRead(const SpdySerializedFrame& resp, int seq, IoMode mode) {
return MockRead(mode, resp.data(), resp.size(), seq);
}
-// Combines the given SpdyFrames into the given char array and returns
-// the total length.
-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();
+// Combines the given vector of SpdySerializedFrame into a single frame.
+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 +895,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 +922,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(
« no previous file with comments | « 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