Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_HTTP_WEBSOCKET_STREAM_BASE_H_ | |
| 6 #define NET_HTTP_WEBSOCKET_STREAM_BASE_H_ | |
| 7 | |
| 8 // This file is placed on net/http because net/http classes depends it. | |
| 9 // Since net/http can be built without linking net/websockets code, | |
| 10 // you should not introduce dependency to net/websockets in this file. | |
| 11 | |
| 12 #include <base/basictypes.h> | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 class ClientSocketHandle; | |
| 17 class SpdySession; | |
| 18 | |
| 19 // WebSocketStreamBase is the base class of WebSocketStream. | |
| 20 // net/http code uses this interface to handle WebSocketStream. | |
| 21 // When net/websockets code gets a WebSocketStreamBase, it should downcast | |
| 22 // the object into a derived class depending on the object's type() property. | |
|
mmenke
2013/05/30 19:27:12
Why will higher level code care about the type?
yhirano
2013/05/31 08:36:45
WebSocketStreamBase is not in "natural" design. Mo
Adam Rice
2013/05/31 16:46:42
How about a virtual AsWebSocketStream method that
yhirano
2013/05/31 18:40:06
Cool! I will do that. Thank you!
yhirano
2013/06/03 04:49:58
Done.
| |
| 23 class WebSocketStreamBase { | |
| 24 public: | |
| 25 // The enum describing the stream type. | |
| 26 // Each type corresponds to a WebSocketStream derived class. | |
| 27 enum StreamType { | |
| 28 // Corresponds to WebSocketBasicStream. | |
| 29 kStreamTypeBasic, | |
| 30 // Corresponds to WebSockeSpdyStream. | |
| 31 kStreamTypeSpdy | |
| 32 }; | |
| 33 | |
| 34 class Factory { | |
| 35 public: | |
| 36 virtual ~Factory() {} | |
| 37 | |
| 38 // Create a WebSocketBasicStream. | |
| 39 // This function (or the returned object) takes the ownership | |
| 40 // of |connection|. | |
| 41 virtual WebSocketStreamBase* CreateBasicStream( | |
| 42 ClientSocketHandle* connection, | |
| 43 bool using_proxy) = 0; | |
| 44 | |
| 45 // Create a WebSocketSpdyStream. | |
| 46 virtual WebSocketStreamBase* CreateSpdyStream( | |
| 47 SpdySession* session, | |
| 48 bool use_relative_url) = 0; | |
| 49 }; | |
| 50 | |
| 51 virtual ~WebSocketStreamBase() {} | |
| 52 | |
| 53 StreamType type() const { | |
| 54 return type_; | |
| 55 } | |
| 56 | |
| 57 protected: | |
| 58 explicit WebSocketStreamBase(StreamType type); | |
| 59 | |
| 60 private: | |
| 61 const StreamType type_; | |
| 62 DISALLOW_COPY_AND_ASSIGN(WebSocketStreamBase); | |
| 63 }; | |
| 64 | |
| 65 } // namespace net | |
| 66 | |
| 67 #endif // NET_HTTP_WEBSOCKET_STREAM_BASE_H_ | |
| OLD | NEW |