summaryrefslogtreecommitdiffstats
path: root/net/flip/flip_session.h
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-22 00:43:00 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-22 00:43:00 +0000
commita677f2b546d2034b459d40e6d0f24977e9b9ade3 (patch)
tree899e1150d0518fe318309301b215bc4ccc7690df /net/flip/flip_session.h
parent967dd54183a539e2c178fed766c48a61f407f8ff (diff)
downloadchromium_src-a677f2b546d2034b459d40e6d0f24977e9b9ade3.zip
chromium_src-a677f2b546d2034b459d40e6d0f24977e9b9ade3.tar.gz
chromium_src-a677f2b546d2034b459d40e6d0f24977e9b9ade3.tar.bz2
Flip: Merge FlipStreamParser and FlipStream. Eliminate FlipDelegate.
FlipStream now conceptually contains everything associated with a single Flip stream. This primarily consists of 2 things: (1) FlipStream as a consumer of network events from FlipSession (2) FlipStream as a network provider to consumers (such as FlipNetworkTransaction). Conceptually, FlipStream also should be agnostic of wire level protocol framing details, only dealing with HTTP style headers and responses. Anything wire level has been moved out of FlipStream into FlipSession. FlipStream is now reference counted since it is referenced by both the FlipSession and the consumer (only FlipNetworkTransaction currently). FlipNetworkTransaction can be cancelled prior to all network events finishing up, therefore the code needs to handle this gracefully. FlipStream supports a Cancel() function for this reason. FlipStream now communicates with consumers via CompletionCallbacks rather than using FlipDelegates. Review URL: http://codereview.chromium.org/410006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32765 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/flip/flip_session.h')
-rw-r--r--net/flip/flip_session.h93
1 files changed, 29 insertions, 64 deletions
diff --git a/net/flip/flip_session.h b/net/flip/flip_session.h
index fdefb6e..3ebd6d2 100644
--- a/net/flip/flip_session.h
+++ b/net/flip/flip_session.h
@@ -32,55 +32,6 @@ class HttpNetworkSession;
class HttpRequestInfo;
class HttpResponseInfo;
-// The FlipDelegate interface is an interface so that the FlipSession
-// can interact with the provider of a given Flip stream.
-class FlipDelegate : public base::RefCounted<FlipDelegate> {
- public:
- // Accessors from the delegate.
-
- // The delegate provides access to the HttpRequestInfo for use by the flip
- // session.
- virtual const HttpRequestInfo* request() const = 0;
-
- // The delegate provides access to an UploadDataStream for use by the
- // flip session. If the delegate is not uploading content, this call
- // must return NULL.
- virtual const UploadDataStream* data() const = 0;
-
- // Callbacks.
-
- // Called by the FlipSession when a response (e.g. a SYN_REPLY) has been
- // received for this request. This callback will never be called prior
- // to the OnRequestSent() callback.
- virtual void OnResponseReceived(HttpResponseInfo* response) = 0;
-
- // Called by the FlipSession when response data has been received for this
- // request. This callback may be called multiple times as data arrives
- // from the network, and will never be called prior to OnResponseReceived.
- // |buffer| contains the data received. The delegate must copy any data
- // from this buffer before returning from this callback.
- // |bytes| is the number of bytes received or an error.
- // A zero-length count does not indicate end-of-stream.
- virtual void OnDataReceived(const char* buffer, int bytes) = 0;
-
- // Called by the FlipSession when a write has completed. This callback
- // will be called multiple times for each write which completes. Writes
- // include the SYN_STREAM write and also DATA frame writes.
- // |result| is the number of bytes written or a net error code.
- virtual void OnWriteComplete(int result) = 0;
-
- // Called by the FlipSession when the request is finished. This callback
- // will always be called at the end of the request and signals to the
- // delegate that the delegate can be torn down. No further callbacks to the
- // delegate will be made after this call.
- // |status| is an error code or OK.
- virtual void OnClose(int status) = 0;
-
- protected:
- friend class base::RefCounted<FlipDelegate>;
- virtual ~FlipDelegate() {}
-};
-
class FlipSession : public base::RefCounted<FlipSession>,
public flip::FlipFramerVisitorInterface {
public:
@@ -94,12 +45,14 @@ class FlipSession : public base::RefCounted<FlipSession>,
net::Error Connect(const std::string& group_name,
const HostResolver::RequestInfo& host, int priority);
- // Create a new stream.
- // FlipDelegate must remain valid until the stream is either cancelled by the
- // creator via CancelStream or the FlipDelegate OnClose or OnCancel callbacks
- // have been made.
- // Once the stream is created, the delegate should wait for a callback.
- int CreateStream(FlipDelegate* delegate);
+ // Get a stream for a given |request|. In the typical case, this will involve
+ // the creation of a new stream (and will send the SYN frame). If the server
+ // initiates a stream, it might already exist for a given path. The server
+ // might also not have initiated the stream yet, but indicated it will via
+ // X-Associated-Content.
+ // Returns the new or existing stream. Never returns NULL.
+ scoped_refptr<FlipStream> GetOrCreateStream(
+ const HttpRequestInfo& request, const UploadDataStream* upload_data);
// Write a data frame to the stream.
// Used to create and queue a data frame for the given stream.
@@ -134,6 +87,12 @@ class FlipSession : public base::RefCounted<FlipSession>,
private:
friend class base::RefCounted<FlipSession>;
+
+ typedef std::map<int, scoped_refptr<FlipStream> > ActiveStreamMap;
+ typedef std::list<scoped_refptr<FlipStream> > ActiveStreamList;
+ typedef std::map<std::string, scoped_refptr<FlipStream> > PendingStreamMap;
+ typedef std::priority_queue<FlipIOBuffer> OutputQueue;
+
virtual ~FlipSession();
// FlipFramerVisitorInterface
@@ -167,13 +126,13 @@ class FlipSession : public base::RefCounted<FlipSession>,
int GetNewStreamId();
// Track active streams in the active stream list.
- FlipStream* ActivateStream(flip::FlipStreamId id, FlipDelegate* delegate);
+ void ActivateStream(FlipStream* stream);
void DeactivateStream(flip::FlipStreamId id);
// Check if we have a pending pushed-stream for this url
// Returns the stream if found (and returns it from the pending
// list), returns NULL otherwise.
- FlipStream* GetPushStream(const std::string& url);
+ scoped_refptr<FlipStream> GetPushStream(const std::string& url);
// Callbacks for the Flip session.
CompletionCallbackImpl<FlipSession> connect_callback_;
@@ -194,7 +153,6 @@ class FlipSession : public base::RefCounted<FlipSession>,
bool connection_ready_; // Is the connection ready for use.
// The read buffer used to read data from the socket.
- enum { kReadBufferSize = (4 * 1024) };
scoped_refptr<IOBuffer> read_buffer_;
bool read_pending_;
@@ -203,18 +161,25 @@ class FlipSession : public base::RefCounted<FlipSession>,
// TODO(mbelshe): We need to track these stream lists better.
// I suspect it is possible to remove a stream from
// one list, but not the other.
- typedef std::map<int, FlipStream*> ActiveStreamMap;
- typedef std::list<FlipStream*> ActiveStreamList;
- ActiveStreamMap active_streams_;
+ // Map from stream id to all active streams. Streams are active in the sense
+ // that they have a consumer (typically FlipNetworkTransaction and regardless
+ // of whether or not there is currently any ongoing IO [might be waiting for
+ // the server to start pushing the stream]) or there are still network events
+ // incoming even though the consumer has already gone away (cancellation).
+ // TODO(willchan): Perhaps we should separate out cancelled streams and move
+ // them into a separate ActiveStreamMap, and not deliver network events to
+ // them?
+ ActiveStreamMap active_streams_;
+ // List of all the streams that have already started to be pushed by the
+ // server, but do not have consumers yet.
ActiveStreamList pushed_streams_;
- // List of streams declared in X-Associated-Content headers.
+ // List of streams declared in X-Associated-Content headers, but do not have
+ // consumers yet.
// The key is a string representing the path of the URI being pushed.
- typedef std::map<std::string, scoped_refptr<FlipDelegate> > PendingStreamMap;
PendingStreamMap pending_streams_;
// As we gather data to be sent, we put it into the output queue.
- typedef std::priority_queue<FlipIOBuffer> OutputQueue;
OutputQueue queue_;
// TODO(mbelshe): this is ugly!!