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

Unified Diff: net/http2/hpack/decoder/hpack_string_decoder_test.cc

Issue 2572343002: Use std::function instead of base::Callback in net/http2/. (Closed)
Patch Set: Remove unreachable return statements. Created 4 years 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/http2/hpack/decoder/hpack_string_decoder_test.cc
diff --git a/net/http2/hpack/decoder/hpack_string_decoder_test.cc b/net/http2/hpack/decoder/hpack_string_decoder_test.cc
index e4afc61e4e74bb3a02c34877e6cd534e435a5c85..614fa0d5980bbb0edef18d34195f223791050ac4 100644
--- a/net/http2/hpack/decoder/hpack_string_decoder_test.cc
+++ b/net/http2/hpack/decoder/hpack_string_decoder_test.cc
@@ -6,8 +6,6 @@
// Tests of HpackStringDecoder.
-#include "base/bind.h"
-#include "base/bind_helpers.h"
#include "base/strings/string_piece.h"
#include "net/http2/hpack/decoder/hpack_string_collector.h"
#include "net/http2/hpack/decoder/hpack_string_decoder_listener.h"
@@ -74,32 +72,27 @@ class HpackStringDecoderTest
return collector_.Collected(s, huffman_encoded);
}
- // Note that base::Bind() makes a copy of |expected_str| even though it is
- // taken as a constant reference, so even if MakeValidator is called with a
- // C-style string that is cast to a temporary std::string that gets destroyed
- // after the call to MakeValidator, |expected_str| is still valid later when
- // the Validator is run.
- AssertionResult StringValidator(const string& expected_str,
- bool expected_huffman,
- const DecodeBuffer& input,
- DecodeStatus status) {
- AssertionResult result = Collected(expected_str, expected_huffman);
- if (result) {
- VERIFY_EQ(collector_,
- HpackStringCollector(expected_str, expected_huffman));
- } else {
- VERIFY_NE(collector_,
- HpackStringCollector(expected_str, expected_huffman));
- }
- VLOG(2) << collector_.ToString();
- collector_.Clear();
- VLOG(2) << collector_;
- return result;
- }
+ // expected_str is a string rather than a const string& or StringPiece so that
+ // the lambda makes a copy of the string, and thus the string to be passed to
+ // Collected outlives the call to MakeValidator.
Validator MakeValidator(const string& expected_str, bool expected_huffman) {
- return base::Bind(&HpackStringDecoderTest::StringValidator,
- base::Unretained(this), expected_str, expected_huffman);
+ return
+ [expected_str, expected_huffman, this](
+ const DecodeBuffer& input, DecodeStatus status) -> AssertionResult {
+ AssertionResult result = Collected(expected_str, expected_huffman);
+ if (result) {
+ VERIFY_EQ(collector_,
+ HpackStringCollector(expected_str, expected_huffman));
+ } else {
+ VERIFY_NE(collector_,
+ HpackStringCollector(expected_str, expected_huffman));
+ }
+ VLOG(2) << collector_.ToString();
+ collector_.Clear();
+ VLOG(2) << collector_;
+ return result;
+ };
}
const StartMethod start_method_;

Powered by Google App Engine
This is Rietveld 408576698