Chromium Code Reviews| Index: components/grpc_support/bidirectional_stream.h |
| diff --git a/components/cronet/ios/cronet_bidirectional_stream.h b/components/grpc_support/bidirectional_stream.h |
| similarity index 87% |
| rename from components/cronet/ios/cronet_bidirectional_stream.h |
| rename to components/grpc_support/bidirectional_stream.h |
| index 9df7de1766f55db7bca49b8e06a6a9b31c442d80..d57cd87f4b87aba25dc5a121f27deae6d0f126ab 100644 |
| --- a/components/cronet/ios/cronet_bidirectional_stream.h |
| +++ b/components/grpc_support/bidirectional_stream.h |
| @@ -2,8 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef COMPONENTS_CRONET_IOS_CRONET_BIDIRECTIONAL_STREAM_H_ |
| -#define COMPONENTS_CRONET_IOS_CRONET_BIDIRECTIONAL_STREAM_H_ |
| +#ifndef COMPONENTS_GRPC_SUPPORT_BIDIRECTIONAL_STREAM_H_ |
| +#define COMPONENTS_GRPC_SUPPORT_BIDIRECTIONAL_STREAM_H_ |
| #include <memory> |
| #include <vector> |
| @@ -13,15 +13,14 @@ |
| #include "base/memory/weak_ptr.h" |
| #include "base/synchronization/lock.h" |
| #include "net/http/bidirectional_stream.h" |
| +#include "net/url_request/url_request_context_getter.h" |
| namespace net { |
| class HttpRequestHeaders; |
| class WrappedIOBuffer; |
| } // namespace net |
| -namespace cronet { |
| - |
| -class CronetEnvironment; |
| +namespace grpc_support { |
| // An adapter to net::BidirectionalStream. |
| // Created and configured from any thread. Start, ReadData, WriteData and |
| @@ -31,7 +30,7 @@ class CronetEnvironment; |
| // callbacks into the Delegate are done on the network thread. |
| // The app is expected to initiate the next step like ReadData or Destroy. |
| // Public methods can be called on any thread. |
| -class CronetBidirectionalStream : public net::BidirectionalStream::Delegate { |
| +class BidirectionalStream : public net::BidirectionalStream::Delegate { |
| public: |
| class Delegate { |
| public: |
| @@ -53,8 +52,9 @@ class CronetBidirectionalStream : public net::BidirectionalStream::Delegate { |
| virtual void OnCanceled() = 0; |
| }; |
| - CronetBidirectionalStream(CronetEnvironment* environment, Delegate* delegate); |
| - ~CronetBidirectionalStream() override; |
| + BidirectionalStream(net::URLRequestContextGetter* request_context_getter, |
| + Delegate* delegate); |
| + ~BidirectionalStream() override; |
| // Disables automatic flushing of each buffer passed to WriteData(). |
| void disable_auto_flush(bool disable_auto_flush) { |
| @@ -119,7 +119,7 @@ class CronetBidirectionalStream : public net::BidirectionalStream::Delegate { |
| // Stream is canceled. |
| CANCELED, |
| // Error has occured, stream is closed. |
| - ERROR, |
| + ERR, |
|
Garrett Casto
2016/10/24 18:34:25
Note: This was changed because the Window compiler
mef
2016/10/26 22:19:45
Acknowledged.
|
| // Reading and writing are done, and the stream is closed successfully. |
| SUCCESS, |
| // Waiting for Flush() to be called. |
| @@ -187,17 +187,21 @@ class CronetBidirectionalStream : public net::BidirectionalStream::Delegate { |
| void CancelOnNetworkThread(); |
| void DestroyOnNetworkThread(); |
| + bool IsOnNetworkThread(); |
| + void PostToNetworkThread(const tracked_objects::Location& from_here, |
| + const base::Closure& task); |
| + |
| // Read state is tracking reading flow. Only accessed on network thread. |
| - // / <--- READING <--- \ |
| + // | <--- READING <--- | |
|
Garrett Casto
2016/10/24 18:34:26
Note: Android compiler didn't like the "/ <" char
mef
2016/10/26 22:19:45
Acknowledged.
|
| + // | | |
| // | | |
| - // \ / |
| // NOT_STARTED -> STARTED --> WAITING_FOR_READ -> READING_DONE -> SUCCESS |
| State read_state_; |
| // Write state is tracking writing flow. Only accessed on network thread. |
| - // / <--- WRITING <--- \ |
| + // | <--- WRITING <--- | |
| + // | | |
| // | | |
| - // \ / |
| // NOT_STARTED -> STARTED --> WAITING_FOR_FLUSH -> WRITING_DONE -> SUCCESS |
| State write_state_; |
| @@ -207,7 +211,7 @@ class CronetBidirectionalStream : public net::BidirectionalStream::Delegate { |
| bool disable_auto_flush_; |
| bool delay_headers_until_flush_; |
| - CronetEnvironment* const environment_; |
| + net::URLRequestContextGetter* const request_context_getter_; |
| scoped_refptr<net::WrappedIOBuffer> read_buffer_; |
| @@ -221,12 +225,12 @@ class CronetBidirectionalStream : public net::BidirectionalStream::Delegate { |
| std::unique_ptr<net::BidirectionalStream> bidi_stream_; |
| Delegate* delegate_; |
| - base::WeakPtr<CronetBidirectionalStream> weak_this_; |
| - base::WeakPtrFactory<CronetBidirectionalStream> weak_factory_; |
| + base::WeakPtr<BidirectionalStream> weak_this_; |
| + base::WeakPtrFactory<BidirectionalStream> weak_factory_; |
| - DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStream); |
| + DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); |
| }; |
| -} // namespace cronet |
| +} // namespace grpc_support |
| -#endif // COMPONENTS_CRONET_IOS_CRONET_BIDIRECTIONAL_STREAM_H_ |
| +#endif // COMPONENTS_GRPC_SUPPORT_BIDIRECTIONAL_STREAM_H_ |