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

Side by Side Diff: webkit/glue/websocketstreamhandle_impl.cc

Issue 10668018: Websocket should fire 'error' event if no server available (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: For reland (tyoshino) Created 7 years, 7 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
OLDNEW
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 // An implementation of WebSocketStreamHandle. 5 // An implementation of WebSocketStreamHandle.
6 6
7 #include "webkit/glue/websocketstreamhandle_impl.h" 7 #include "webkit/glue/websocketstreamhandle_impl.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/string16.h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebSocketStreamErro r.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebSocketStreamHand leClient.h" 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebSocketStreamHand leClient.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
18 #include "webkit/glue/webkitplatformsupport_impl.h" 20 #include "webkit/glue/webkitplatformsupport_impl.h"
19 #include "webkit/glue/websocketstreamhandle_bridge.h" 21 #include "webkit/glue/websocketstreamhandle_bridge.h"
20 #include "webkit/glue/websocketstreamhandle_delegate.h" 22 #include "webkit/glue/websocketstreamhandle_delegate.h"
21 23
22 using WebKit::WebData; 24 using WebKit::WebData;
25 using WebKit::WebSocketStreamError;
23 using WebKit::WebSocketStreamHandle; 26 using WebKit::WebSocketStreamHandle;
24 using WebKit::WebSocketStreamHandleClient; 27 using WebKit::WebSocketStreamHandleClient;
25 using WebKit::WebURL; 28 using WebKit::WebURL;
26 29
27 namespace webkit_glue { 30 namespace webkit_glue {
28 31
29 // WebSocketStreamHandleImpl::Context ----------------------------------------- 32 // WebSocketStreamHandleImpl::Context -----------------------------------------
30 33
31 class WebSocketStreamHandleImpl::Context 34 class WebSocketStreamHandleImpl::Context
32 : public base::RefCounted<Context>, 35 : public base::RefCounted<Context>,
(...skipping 14 matching lines...) Expand all
47 // Once detached, it never calls |client_| back. 50 // Once detached, it never calls |client_| back.
48 void Detach(); 51 void Detach();
49 52
50 // WebSocketStreamHandleDelegate methods: 53 // WebSocketStreamHandleDelegate methods:
51 virtual void DidOpenStream(WebSocketStreamHandle*, int) OVERRIDE; 54 virtual void DidOpenStream(WebSocketStreamHandle*, int) OVERRIDE;
52 virtual void DidSendData(WebSocketStreamHandle*, int) OVERRIDE; 55 virtual void DidSendData(WebSocketStreamHandle*, int) OVERRIDE;
53 virtual void DidReceiveData(WebSocketStreamHandle*, 56 virtual void DidReceiveData(WebSocketStreamHandle*,
54 const char*, 57 const char*,
55 int) OVERRIDE; 58 int) OVERRIDE;
56 virtual void DidClose(WebSocketStreamHandle*) OVERRIDE; 59 virtual void DidClose(WebSocketStreamHandle*) OVERRIDE;
60 virtual void DidFail(WebSocketStreamHandle*, int, const string16&);
57 61
58 private: 62 private:
59 friend class base::RefCounted<Context>; 63 friend class base::RefCounted<Context>;
60 virtual ~Context() { 64 virtual ~Context() {
61 DCHECK(!handle_); 65 DCHECK(!handle_);
62 DCHECK(!client_); 66 DCHECK(!client_);
63 DCHECK(!bridge_); 67 DCHECK(!bridge_);
64 } 68 }
65 69
66 WebSocketStreamHandleImpl* handle_; 70 WebSocketStreamHandleImpl* handle_;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 WebSocketStreamHandleImpl* handle = handle_; 142 WebSocketStreamHandleImpl* handle = handle_;
139 handle_ = NULL; 143 handle_ = NULL;
140 if (client_) { 144 if (client_) {
141 WebSocketStreamHandleClient* client = client_; 145 WebSocketStreamHandleClient* client = client_;
142 client_ = NULL; 146 client_ = NULL;
143 client->didClose(handle); 147 client->didClose(handle);
144 } 148 }
145 Release(); 149 Release();
146 } 150 }
147 151
152 void WebSocketStreamHandleImpl::Context::DidFail(
153 WebSocketStreamHandle* web_handle,
154 int error_code,
155 const string16& error_msg) {
156 VLOG(1) << "DidFail";
157 if (client_) {
158 client_->didFail(
159 handle_,
160 WebSocketStreamError(error_code, error_msg));
161 }
162 }
163
148 // WebSocketStreamHandleImpl ------------------------------------------------ 164 // WebSocketStreamHandleImpl ------------------------------------------------
149 165
150 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl( 166 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl(
151 WebKitPlatformSupportImpl* platform) 167 WebKitPlatformSupportImpl* platform)
152 : context_(new Context(this)), 168 : context_(new Context(this)),
153 platform_(platform) { 169 platform_(platform) {
154 } 170 }
155 171
156 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() { 172 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() {
157 // We won't receive any events from |context_|. 173 // We won't receive any events from |context_|.
(...skipping 13 matching lines...) Expand all
171 187
172 bool WebSocketStreamHandleImpl::send(const WebData& data) { 188 bool WebSocketStreamHandleImpl::send(const WebData& data) {
173 return context_->Send(data); 189 return context_->Send(data);
174 } 190 }
175 191
176 void WebSocketStreamHandleImpl::close() { 192 void WebSocketStreamHandleImpl::close() {
177 context_->Close(); 193 context_->Close();
178 } 194 }
179 195
180 } // namespace webkit_glue 196 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/websocketstreamhandle_delegate.h ('k') | webkit/tools/test_shell/simple_socket_stream_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698