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

Unified Diff: net/spdy/bidirectional_stream_spdy_job.h

Issue 1326503003: Added a net::BidirectionalStream to expose a bidirectional streaming interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bug and added a test Created 5 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/spdy/bidirectional_stream_spdy_job.h
diff --git a/net/spdy/bidirectional_stream_spdy_job.h b/net/spdy/bidirectional_stream_spdy_job.h
new file mode 100644
index 0000000000000000000000000000000000000000..96ef7c82a4f5c490950ea136e20c933d85d8e7e8
--- /dev/null
+++ b/net/spdy/bidirectional_stream_spdy_job.h
@@ -0,0 +1,96 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_SPDY_BIDIRECTIONAL_STREAM_SPDY_JOB_H_
+#define NET_SPDY_BIDIRECTIONAL_STREAM_SPDY_JOB_H_
+
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "net/http/bidirectional_stream_job.h"
+#include "net/http/http_request_info.h"
+#include "net/spdy/spdy_read_queue.h"
+#include "net/spdy/spdy_session.h"
+#include "net/spdy/spdy_stream.h"
+
+namespace base {
+class Timer;
+} // namespace base
+
+namespace net {
+
+class BoundNetLog;
+class IOBuffer;
+class SpdyHeaderBlock;
+
+class NET_EXPORT_PRIVATE BidirectionalStreamSpdyJob
+ : public BidirectionalStreamJob,
+ public SpdyStream::Delegate {
+ public:
+ BidirectionalStreamSpdyJob(const base::WeakPtr<SpdySession>& spdy_session);
+
+ // Constructor that accepts a Timer. This is used in tests.
+ BidirectionalStreamSpdyJob(const base::WeakPtr<SpdySession>& spdy_session,
+ scoped_ptr<base::Timer> timer);
+ ~BidirectionalStreamSpdyJob() override;
+
+ // BidirectionalStreamSpdyJob implementation:
+
+ void Start(const HttpRequestInfo& request_info,
+ RequestPriority priority,
+ const BoundNetLog& net_log,
+ BidirectionalStreamJob::Delegate* delegate) override;
+
+ int ReadData(IOBuffer* buf, int buf_len) override;
+
+ void SendData(IOBuffer* data, int length, bool end_stream) override;
+
+ void Cancel() override;
+
+ // SpdyStream::Delegate implementation:
+
+ void OnRequestHeadersSent() override;
+
+ SpdyResponseHeadersStatus OnResponseHeadersUpdated(
+ const SpdyHeaderBlock& response_headers) override;
+
+ void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) override;
+
+ void OnDataSent() override;
+
+ void OnTrailers(const SpdyHeaderBlock& trailers) override;
+
+ void OnClose(int status) override;
+
+ private:
+ void SendRequestHeaders();
+ void OnStreamInitialized(int rv);
+ void ScheduleBufferedRead();
+ void DoBufferedRead();
+ bool ShouldWaitForMoreBufferedData() const;
+
+ const base::WeakPtr<SpdySession> spdy_session_;
+ scoped_ptr<base::Timer> timer_;
+ bool stream_closed_;
+ int closed_stream_status_;
+ bool more_read_data_pending_;
+
+ HttpRequestInfo request_info_;
+ // Buffers the data as it arrives asynchronously from the stream.
+ SpdyReadQueue data_queue_;
+ // User provided buffer for ReadData() response.
+ scoped_refptr<IOBuffer> user_buffer_;
+ int user_buffer_len_;
+
+ BidirectionalStreamJob::Delegate* delegate_;
+ SpdyStreamRequest stream_request_;
+ base::WeakPtr<SpdyStream> stream_;
+
+ base::WeakPtrFactory<BidirectionalStreamSpdyJob> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamSpdyJob);
+};
+
+} // namespace net
+
+#endif // NET_SPDY_BIDIRECTIONAL_STREAM_SPDY_JOB_H_

Powered by Google App Engine
This is Rietveld 408576698