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

Side by Side Diff: Source/web/WebSocketChannelClientProxy.h

Issue 419973007: Decouple WebSocketChannelClient from WebSocketImpl (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 months 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
« no previous file with comments | « no previous file | Source/web/WebSocketImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
yhirano 2014/08/04 03:13:00 Please use the new license.
haraken 2014/08/04 05:54:33 Done.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef WebSocketImpl_h 31 #ifndef WebSocketChannelClientProxy_h
32 #define WebSocketImpl_h 32 #define WebSocketChannelClientProxy_h
33 33
34 #include "modules/websockets/WebSocketChannelClient.h" 34 #include "modules/websockets/WebSocketChannelClient.h"
35 #include "platform/heap/Handle.h" 35 #include "platform/heap/Handle.h"
36 #include "public/platform/WebCommon.h" 36 #include "web/WebSocketImpl.h"
37 #include "public/platform/WebString.h" 37 #include "wtf/PassOwnPtr.h"
38 #include "public/web/WebSocket.h" 38 #include "wtf/Vector.h"
39 #include "public/web/WebSocketClient.h" 39 #include "wtf/text/WTFString.h"
40 #include "wtf/OwnPtr.h"
41 #include "wtf/RefPtr.h"
42 40
43 namespace blink { class WebSocketChannel; } 41 namespace blink { class WebSocketChannel; }
tyoshino (SeeGerritForStatus) 2014/08/04 03:36:07 remove
haraken 2014/08/04 05:54:33 Done.
44 42
45 namespace blink { 43 namespace blink {
46 44
47 class WebDocument; 45 // Ideally we want to simply make WebSocketImpl inherit from
48 class WebURL; 46 // WebSocketChannelClient, but we cannot do that because WebSocketChannelClient
47 // needs to be on Oilpan's heap whereas WebSocketImpl cannot be on Oilpan's
48 // heap. Thus we need to introduce a proxy class to decouple WebSocketImpl
49 // from WebSocketChannelClient.
50 class WebSocketChannelClientProxy FINAL : public NoBaseWillBeGarbageCollectedFin alized<WebSocketChannelClientProxy>, public blink::WebSocketChannelClient {
51 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WebSocketChannelClientProxy)
52 public:
53 static PassOwnPtrWillBeRawPtr<WebSocketChannelClientProxy> create(WebSocketI mpl* impl)
54 {
55 return adoptPtrWillBeNoop(new WebSocketChannelClientProxy(impl));
56 }
49 57
50 class WebSocketImpl FINAL : public NoBaseWillBeGarbageCollectedFinalized<WebSock etImpl>, public WebSocket, public blink::WebSocketChannelClient { 58 virtual void didConnect(const String& subprotocol, const String& extensions) OVERRIDE
51 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WebSocketImpl) 59 {
52 public: 60 m_impl->didConnect(subprotocol, extensions);
53 WebSocketImpl(const WebDocument&, WebSocketClient*); 61 }
54 virtual ~WebSocketImpl(); 62 virtual void didReceiveMessage(const String& message) OVERRIDE
55 63 {
56 bool isNull() const { return !m_private; } 64 m_impl->didReceiveMessage(message);
57 65 }
58 virtual BinaryType binaryType() const OVERRIDE; 66 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) OVER RIDE
59 virtual bool setBinaryType(BinaryType) OVERRIDE; 67 {
60 virtual void connect(const WebURL&, const WebString& protocol) OVERRIDE; 68 m_impl->didReceiveBinaryData(binaryData);
61 virtual WebString subprotocol() OVERRIDE; 69 }
62 virtual WebString extensions() OVERRIDE; 70 virtual void didReceiveMessageError() OVERRIDE
63 virtual bool sendText(const WebString&) OVERRIDE; 71 {
64 virtual bool sendArrayBuffer(const WebArrayBuffer&) OVERRIDE; 72 m_impl->didReceiveMessageError();
65 virtual unsigned long bufferedAmount() const OVERRIDE; 73 }
66 virtual void close(int code, const WebString& reason) OVERRIDE; 74 virtual void didConsumeBufferedAmount(unsigned long consumed) OVERRIDE
67 virtual void fail(const WebString& reason) OVERRIDE; 75 {
68 virtual void disconnect() OVERRIDE; 76 m_impl->didConsumeBufferedAmount(consumed);
69 77 }
70 // WebSocketChannelClient 78 virtual void didStartClosingHandshake() OVERRIDE
71 virtual void didConnect(const String& subprotocol, const String& extensions) OVERRIDE; 79 {
72 virtual void didReceiveMessage(const String& message) OVERRIDE; 80 m_impl->didStartClosingHandshake();
73 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) OVER RIDE; 81 }
74 virtual void didReceiveMessageError() OVERRIDE; 82 virtual void didClose(ClosingHandshakeCompletionStatus status, unsigned shor t code, const String& reason) OVERRIDE
75 virtual void didConsumeBufferedAmount(unsigned long consumed) OVERRIDE; 83 {
76 virtual void didStartClosingHandshake() OVERRIDE; 84 WebSocketImpl* impl = m_impl;
77 virtual void didClose(ClosingHandshakeCompletionStatus, unsigned short code, const String& reason) OVERRIDE; 85 m_impl = nullptr;
78 86 impl->didClose(status, code, reason);
79 virtual void trace(blink::Visitor*) OVERRIDE; 87 }
80 88
81 private: 89 private:
82 RefPtrWillBeMember<blink::WebSocketChannel> m_private; 90 explicit WebSocketChannelClientProxy(WebSocketImpl* impl)
83 WebSocketClient* m_client; 91 : m_impl(impl)
84 BinaryType m_binaryType; 92 {
85 WebString m_subprotocol; 93 }
86 WebString m_extensions; 94
87 bool m_isClosingOrClosed; 95 WebSocketImpl* m_impl;
88 // m_bufferedAmount includes m_bufferedAmountAfterClose.
89 unsigned long m_bufferedAmount;
90 unsigned long m_bufferedAmountAfterClose;
91 }; 96 };
92 97
93 } // namespace blink 98 } // namespace blink
94 99
95 #endif // WebWebSocketChannelImpl_h 100 #endif // WebSocketChannelClientProxy_h
OLDNEW
« no previous file with comments | « no previous file | Source/web/WebSocketImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698