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

Unified Diff: net/spdy/spdy_protocol.h

Issue 1852423004: Implement SpdySerializedFrame move semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/spdy_network_transaction_unittest.cc ('k') | net/spdy/spdy_proxy_client_socket_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/spdy_protocol.h
diff --git a/net/spdy/spdy_protocol.h b/net/spdy/spdy_protocol.h
index 2f2d06de880c5751ac59aca6d40a57c484f4699e..e22f89c026009779fdea38a843d3b13f8408c654 100644
--- a/net/spdy/spdy_protocol.h
+++ b/net/spdy/spdy_protocol.h
@@ -522,14 +522,9 @@ class NET_EXPORT_PRIVATE SpdyConstants {
static std::string GetVersionString(SpdyMajorVersion version);
};
-class SpdyFrame;
-typedef SpdyFrame SpdySerializedFrame;
-
class SpdyFrameVisitor;
// Intermediate representation for SPDY frames.
-// TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is
-// gone.
class NET_EXPORT_PRIVATE SpdyFrameIR {
public:
virtual ~SpdyFrameIR() {}
@@ -987,35 +982,50 @@ class NET_EXPORT_PRIVATE SpdyPriorityIR : public SpdyFrameWithStreamIdIR {
DISALLOW_COPY_AND_ASSIGN(SpdyPriorityIR);
};
-// -------------------------------------------------------------------------
-// Wrapper classes for various SPDY frames.
-
-// All Spdy Frame types derive from this SpdyFrame class.
-class SpdyFrame {
+class SpdySerializedFrame {
public:
- // Create a SpdyFrame using a pre-created buffer.
- // If |owns_buffer| is true, this class takes ownership of the buffer
- // and will delete it on cleanup. The buffer must have been created using
- // new char[].
+ SpdySerializedFrame()
+ : frame_(const_cast<char*>("")), size_(0), owns_buffer_(false) {}
+
+ // Create a valid SpdySerializedFrame using a pre-created buffer.
+ // If |owns_buffer| is true, this class takes ownership of the buffer and will
+ // delete it on cleanup. The buffer must have been created using new char[].
// If |owns_buffer| is false, the caller retains ownership of the buffer and
// is responsible for making sure the buffer outlives this frame. In other
// words, this class does NOT create a copy of the buffer.
- SpdyFrame(char* data, size_t size, bool owns_buffer)
- : frame_(data),
- size_(size),
- owns_buffer_(owns_buffer) {
- DCHECK(frame_);
+ SpdySerializedFrame(char* data, size_t size, bool owns_buffer)
+ : frame_(data), size_(size), owns_buffer_(owns_buffer) {}
+
+ SpdySerializedFrame(SpdySerializedFrame&& other)
+ : frame_(other.frame_),
+ size_(other.size_),
+ owns_buffer_(other.owns_buffer_) {
+ // |other| is no longer responsible for the buffer.
+ other.owns_buffer_ = false;
+ }
+
+ SpdySerializedFrame& operator=(SpdySerializedFrame&& other) {
+ // Free buffer if necessary.
+ if (owns_buffer_) {
+ delete[] frame_;
+ }
+ // Take over |other|.
+ frame_ = other.frame_;
+ size_ = other.size_;
+ owns_buffer_ = other.owns_buffer_;
+ // |other| is no longer responsible for the buffer.
+ other.owns_buffer_ = false;
+ return *this;
}
- ~SpdyFrame() {
+ ~SpdySerializedFrame() {
if (owns_buffer_) {
- delete [] frame_;
+ delete[] frame_;
}
- frame_ = NULL;
}
- // Provides access to the frame bytes, which is a buffer containing
- // the frame packed as expected for sending over the wire.
+ // Provides access to the frame bytes, which is a buffer containing the frame
+ // packed as expected for sending over the wire.
char* data() const { return frame_; }
// Returns the actual size of the underlying buffer.
@@ -1027,7 +1037,7 @@ class SpdyFrame {
private:
size_t size_;
bool owns_buffer_;
- DISALLOW_COPY_AND_ASSIGN(SpdyFrame);
+ DISALLOW_COPY_AND_ASSIGN(SpdySerializedFrame);
};
// This interface is for classes that want to process SpdyFrameIRs without
« no previous file with comments | « net/spdy/spdy_network_transaction_unittest.cc ('k') | net/spdy/spdy_proxy_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698