| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SPDY_SPDY_SESSION_H_ | 5 #ifndef NET_SPDY_SPDY_SESSION_H_ |
| 6 #define NET_SPDY_SPDY_SESSION_H_ | 6 #define NET_SPDY_SPDY_SESSION_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // Cancels any pending stream creation request. May be called | 184 // Cancels any pending stream creation request. May be called |
| 185 // repeatedly. | 185 // repeatedly. |
| 186 void CancelRequest(); | 186 void CancelRequest(); |
| 187 | 187 |
| 188 // Transfers the created stream (guaranteed to not be NULL) to the | 188 // Transfers the created stream (guaranteed to not be NULL) to the |
| 189 // caller. Must be called at most once after StartRequest() returns | 189 // caller. Must be called at most once after StartRequest() returns |
| 190 // OK or |callback| is called with OK. The caller must immediately | 190 // OK or |callback| is called with OK. The caller must immediately |
| 191 // set a delegate for the returned stream (except for test code). | 191 // set a delegate for the returned stream (except for test code). |
| 192 base::WeakPtr<SpdyStream> ReleaseStream(); | 192 base::WeakPtr<SpdyStream> ReleaseStream(); |
| 193 | 193 |
| 194 // Returns the estimate of dynamically allocated memory in bytes. |
| 195 size_t EstimateMemoryUsage() const; |
| 196 |
| 194 private: | 197 private: |
| 195 friend class SpdySession; | 198 friend class SpdySession; |
| 196 | 199 |
| 197 // Called by |session_| when the stream attempt has finished | 200 // Called by |session_| when the stream attempt has finished |
| 198 // successfully. | 201 // successfully. |
| 199 void OnRequestCompleteSuccess(const base::WeakPtr<SpdyStream>& stream); | 202 void OnRequestCompleteSuccess(const base::WeakPtr<SpdyStream>& stream); |
| 200 | 203 |
| 201 // Called by |session_| when the stream attempt has finished with an | 204 // Called by |session_| when the stream attempt has finished with an |
| 202 // error. Also called with ERR_ABORTED if |session_| is destroyed | 205 // error. Also called with ERR_ABORTED if |session_| is destroyed |
| 203 // while the stream attempt is still pending. | 206 // while the stream attempt is still pending. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // Container class for unclaimed pushed streams on a SpdySession. Guarantees | 238 // Container class for unclaimed pushed streams on a SpdySession. Guarantees |
| 236 // that |spdy_session_.pool_| gets notified every time a stream is pushed or | 239 // that |spdy_session_.pool_| gets notified every time a stream is pushed or |
| 237 // an unclaimed pushed stream is claimed. | 240 // an unclaimed pushed stream is claimed. |
| 238 class UnclaimedPushedStreamContainer { | 241 class UnclaimedPushedStreamContainer { |
| 239 public: | 242 public: |
| 240 struct PushedStreamInfo { | 243 struct PushedStreamInfo { |
| 241 PushedStreamInfo() : stream_id(0) {} | 244 PushedStreamInfo() : stream_id(0) {} |
| 242 PushedStreamInfo(SpdyStreamId stream_id, base::TimeTicks creation_time) | 245 PushedStreamInfo(SpdyStreamId stream_id, base::TimeTicks creation_time) |
| 243 : stream_id(stream_id), creation_time(creation_time) {} | 246 : stream_id(stream_id), creation_time(creation_time) {} |
| 244 ~PushedStreamInfo() {} | 247 ~PushedStreamInfo() {} |
| 248 size_t EstimateMemoryUsage() const { return 0; } |
| 245 | 249 |
| 246 SpdyStreamId stream_id; | 250 SpdyStreamId stream_id; |
| 247 base::TimeTicks creation_time; | 251 base::TimeTicks creation_time; |
| 248 }; | 252 }; |
| 249 using PushedStreamMap = std::map<GURL, PushedStreamInfo>; | 253 using PushedStreamMap = std::map<GURL, PushedStreamInfo>; |
| 250 using iterator = PushedStreamMap::iterator; | 254 using iterator = PushedStreamMap::iterator; |
| 251 using const_iterator = PushedStreamMap::const_iterator; | 255 using const_iterator = PushedStreamMap::const_iterator; |
| 252 | 256 |
| 253 UnclaimedPushedStreamContainer() = delete; | 257 UnclaimedPushedStreamContainer() = delete; |
| 254 explicit UnclaimedPushedStreamContainer(SpdySession* spdy_session); | 258 explicit UnclaimedPushedStreamContainer(SpdySession* spdy_session); |
| 255 ~UnclaimedPushedStreamContainer(); | 259 ~UnclaimedPushedStreamContainer(); |
| 256 | 260 |
| 257 bool empty() const { return streams_.empty(); } | 261 bool empty() const { return streams_.empty(); } |
| 258 size_t size() const { return streams_.size(); } | 262 size_t size() const { return streams_.size(); } |
| 259 const_iterator begin() const { return streams_.begin(); } | 263 const_iterator begin() const { return streams_.begin(); } |
| 260 const_iterator end() const { return streams_.end(); } | 264 const_iterator end() const { return streams_.end(); } |
| 261 const_iterator find(const GURL& url) const { return streams_.find(url); } | 265 const_iterator find(const GURL& url) const { return streams_.find(url); } |
| 262 size_t count(const GURL& url) const { return streams_.count(url); } | 266 size_t count(const GURL& url) const { return streams_.count(url); } |
| 263 const_iterator lower_bound(const GURL& url) const { | 267 const_iterator lower_bound(const GURL& url) const { |
| 264 return streams_.lower_bound(url); | 268 return streams_.lower_bound(url); |
| 265 } | 269 } |
| 266 | 270 |
| 267 size_t erase(const GURL& url); | 271 size_t erase(const GURL& url); |
| 268 iterator erase(const_iterator it); | 272 iterator erase(const_iterator it); |
| 269 iterator insert(const_iterator position, | 273 iterator insert(const_iterator position, |
| 270 const GURL& url, | 274 const GURL& url, |
| 271 SpdyStreamId stream_id, | 275 SpdyStreamId stream_id, |
| 272 const base::TimeTicks& creation_time); | 276 const base::TimeTicks& creation_time); |
| 273 | 277 |
| 278 size_t EstimateMemoryUsage() const; |
| 279 |
| 274 private: | 280 private: |
| 275 SpdySession* spdy_session_; | 281 SpdySession* spdy_session_; |
| 276 | 282 |
| 277 // (Bijective) map from the URL to the ID of the streams that have | 283 // (Bijective) map from the URL to the ID of the streams that have |
| 278 // already started to be pushed by the server, but do not have | 284 // already started to be pushed by the server, but do not have |
| 279 // consumers yet. Contains a subset of |active_streams_|. | 285 // consumers yet. Contains a subset of |active_streams_|. |
| 280 PushedStreamMap streams_; | 286 PushedStreamMap streams_; |
| 281 }; | 287 }; |
| 282 | 288 |
| 283 // Returns true if |new_hostname| can be pooled into an existing connection to | 289 // Returns true if |new_hostname| can be pooled into an existing connection to |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 // Must be used only by |pool_|. | 564 // Must be used only by |pool_|. |
| 559 base::WeakPtr<SpdySession> GetWeakPtr(); | 565 base::WeakPtr<SpdySession> GetWeakPtr(); |
| 560 | 566 |
| 561 // HigherLayeredPool implementation: | 567 // HigherLayeredPool implementation: |
| 562 bool CloseOneIdleConnection() override; | 568 bool CloseOneIdleConnection() override; |
| 563 | 569 |
| 564 // Dumps memory allocation stats to |stats|. Sets |*is_session_active| to | 570 // Dumps memory allocation stats to |stats|. Sets |*is_session_active| to |
| 565 // indicate whether session is active. | 571 // indicate whether session is active. |
| 566 // |stats| can be assumed as being default initialized upon entry. | 572 // |stats| can be assumed as being default initialized upon entry. |
| 567 // Implementation overrides fields in |stats|. | 573 // Implementation overrides fields in |stats|. |
| 568 void DumpMemoryStats(StreamSocket::SocketMemoryStats* stats, | 574 // Returns the estimate of dynamically allocated memory in bytes, which |
| 569 bool* is_session_active) const; | 575 // includes the size attributed to the underlying socket. |
| 576 size_t DumpMemoryStats(StreamSocket::SocketMemoryStats* stats, |
| 577 bool* is_session_active) const; |
| 570 | 578 |
| 571 private: | 579 private: |
| 572 friend class test::SpdyStreamTest; | 580 friend class test::SpdyStreamTest; |
| 573 friend class base::RefCounted<SpdySession>; | 581 friend class base::RefCounted<SpdySession>; |
| 574 friend class HttpNetworkTransactionTest; | 582 friend class HttpNetworkTransactionTest; |
| 575 friend class HttpProxyClientSocketPoolTest; | 583 friend class HttpProxyClientSocketPoolTest; |
| 576 friend class SpdyHttpStreamTest; | 584 friend class SpdyHttpStreamTest; |
| 577 friend class SpdyNetworkTransactionTest; | 585 friend class SpdyNetworkTransactionTest; |
| 578 friend class SpdyProxyClientSocketTest; | 586 friend class SpdyProxyClientSocketTest; |
| 579 friend class SpdySessionTest; | 587 friend class SpdySessionTest; |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 // Used for posting asynchronous IO tasks. We use this even though | 1219 // Used for posting asynchronous IO tasks. We use this even though |
| 1212 // SpdySession is refcounted because we don't need to keep the SpdySession | 1220 // SpdySession is refcounted because we don't need to keep the SpdySession |
| 1213 // alive if the last reference is within a RunnableMethod. Just revoke the | 1221 // alive if the last reference is within a RunnableMethod. Just revoke the |
| 1214 // method. | 1222 // method. |
| 1215 base::WeakPtrFactory<SpdySession> weak_factory_; | 1223 base::WeakPtrFactory<SpdySession> weak_factory_; |
| 1216 }; | 1224 }; |
| 1217 | 1225 |
| 1218 } // namespace net | 1226 } // namespace net |
| 1219 | 1227 |
| 1220 #endif // NET_SPDY_SPDY_SESSION_H_ | 1228 #endif // NET_SPDY_SPDY_SESSION_H_ |
| OLD | NEW |