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

Side by Side Diff: net/flip/flip_session.h

Issue 342088: Update the FLIP session to use the FlipIOBuffer.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_FLIP_FLIP_SESSION_H_ 5 #ifndef NET_FLIP_FLIP_SESSION_H_
6 #define NET_FLIP_FLIP_SESSION_H_ 6 #define NET_FLIP_FLIP_SESSION_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
11 #include <queue> 11 #include <queue>
12 #include <string> 12 #include <string>
13 13
14 #include "base/ref_counted.h" 14 #include "base/ref_counted.h"
15 #include "net/base/io_buffer.h" 15 #include "net/base/io_buffer.h"
16 #include "net/base/load_states.h" 16 #include "net/base/load_states.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/base/ssl_config_service.h" 18 #include "net/base/ssl_config_service.h"
19 #include "net/base/upload_data_stream.h" 19 #include "net/base/upload_data_stream.h"
20 #include "net/flip/flip_framer.h" 20 #include "net/flip/flip_framer.h"
21 #include "net/flip/flip_io_buffer.h"
21 #include "net/flip/flip_protocol.h" 22 #include "net/flip/flip_protocol.h"
22 #include "net/flip/flip_session_pool.h" 23 #include "net/flip/flip_session_pool.h"
23 #include "net/socket/client_socket.h" 24 #include "net/socket/client_socket.h"
24 #include "net/socket/client_socket_handle.h" 25 #include "net/socket/client_socket_handle.h"
25 #include "testing/platform_test.h" 26 #include "testing/platform_test.h"
26 27
27 namespace net { 28 namespace net {
28 29
29 class FlipStream; 30 class FlipStream;
30 class HttpNetworkSession; 31 class HttpNetworkSession;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 virtual void OnDataReceived(const char* buffer, int bytes) = 0; 80 virtual void OnDataReceived(const char* buffer, int bytes) = 0;
80 81
81 // Called by the FlipSession when the request is finished. This callback 82 // Called by the FlipSession when the request is finished. This callback
82 // will always be called at the end of the request and signals to the 83 // will always be called at the end of the request and signals to the
83 // delegate that the delegate can be torn down. No further callbacks to the 84 // delegate that the delegate can be torn down. No further callbacks to the
84 // delegate will be made after this call. 85 // delegate will be made after this call.
85 // |status| is an error code or OK. 86 // |status| is an error code or OK.
86 virtual void OnClose(int status) = 0; 87 virtual void OnClose(int status) = 0;
87 }; 88 };
88 89
89 class PrioritizedIOBuffer {
90 public:
91 PrioritizedIOBuffer() : buffer_(0), priority_(0) {}
92 PrioritizedIOBuffer(IOBufferWithSize* buffer, int priority)
93 : buffer_(buffer),
94 priority_(priority),
95 position_(++order_) {
96 }
97
98 IOBuffer* buffer() const { return buffer_; }
99
100 size_t size() const { return buffer_->size(); }
101
102 void release() { buffer_ = NULL; }
103
104 int priority() { return priority_; }
105
106 // Supports sorting.
107 bool operator<(const PrioritizedIOBuffer& other) const {
108 if (priority_ != other.priority_)
109 return priority_ > other.priority_;
110 return position_ >= other.position_;
111 }
112
113 private:
114 scoped_refptr<IOBufferWithSize> buffer_;
115 int priority_;
116 int position_;
117 static int order_; // Maintains a FIFO order for equal priorities.
118 };
119
120 class FlipSession : public base::RefCounted<FlipSession>, 90 class FlipSession : public base::RefCounted<FlipSession>,
121 public flip::FlipFramerVisitorInterface { 91 public flip::FlipFramerVisitorInterface {
122 public: 92 public:
123 // Factory for finding open sessions. 93 // Factory for finding open sessions.
124 // TODO(mbelshe): Break this out into a connection pool class? 94 // TODO(mbelshe): Break this out into a connection pool class?
125 static FlipSession* GetFlipSession(const HostResolver::RequestInfo&, 95 static FlipSession* GetFlipSession(const HostResolver::RequestInfo&,
126 HttpNetworkSession* session); 96 HttpNetworkSession* session);
127 virtual ~FlipSession(); 97 virtual ~FlipSession();
128 98
129 // Get the domain for this FlipSession. 99 // Get the domain for this FlipSession.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 typedef std::map<int, FlipStream*> ActiveStreamMap; 212 typedef std::map<int, FlipStream*> ActiveStreamMap;
243 typedef std::list<FlipStream*> ActiveStreamList; 213 typedef std::list<FlipStream*> ActiveStreamList;
244 ActiveStreamMap active_streams_; 214 ActiveStreamMap active_streams_;
245 215
246 ActiveStreamList pushed_streams_; 216 ActiveStreamList pushed_streams_;
247 // List of streams declared in X-Associated-Content headers. 217 // List of streams declared in X-Associated-Content headers.
248 // The key is a string representing the path of the URI being pushed. 218 // The key is a string representing the path of the URI being pushed.
249 std::map<std::string, FlipDelegate*> pending_streams_; 219 std::map<std::string, FlipDelegate*> pending_streams_;
250 220
251 // As we gather data to be sent, we put it into the output queue. 221 // As we gather data to be sent, we put it into the output queue.
252 typedef std::priority_queue<PrioritizedIOBuffer> OutputQueue; 222 typedef std::priority_queue<FlipIOBuffer> OutputQueue;
253 OutputQueue queue_; 223 OutputQueue queue_;
254 224
255 // TODO(mbelshe): this is ugly!! 225 // TODO(mbelshe): this is ugly!!
256 // The packet we are currently sending. 226 // The packet we are currently sending.
257 PrioritizedIOBuffer in_flight_write_; 227 FlipIOBuffer in_flight_write_;
258 bool delayed_write_pending_; 228 bool delayed_write_pending_;
259 bool write_pending_; 229 bool write_pending_;
260 230
261 // Flip Frame state. 231 // Flip Frame state.
262 flip::FlipFramer flip_framer_; 232 flip::FlipFramer flip_framer_;
263 233
264 // This is our weak session pool - one session per domain. 234 // This is our weak session pool - one session per domain.
265 static scoped_ptr<FlipSessionPool> session_pool_; 235 static scoped_ptr<FlipSessionPool> session_pool_;
266 static bool use_ssl_; 236 static bool use_ssl_;
267 }; 237 };
268 238
269 } // namespace net 239 } // namespace net
270 240
271 #endif // NET_FLIP_FLIP_SESSION_H_ 241 #endif // NET_FLIP_FLIP_SESSION_H_
272 242
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698