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

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

Issue 10458057: Websocket should fire 'error' event if no server available (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years, 6 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 "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStr eamHandleClient.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStr eamHandleClient.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSocketStr eamError.h"
18 #include "webkit/glue/webkitplatformsupport_impl.h" 19 #include "webkit/glue/webkitplatformsupport_impl.h"
19 #include "webkit/glue/websocketstreamhandle_bridge.h" 20 #include "webkit/glue/websocketstreamhandle_bridge.h"
20 #include "webkit/glue/websocketstreamhandle_delegate.h" 21 #include "webkit/glue/websocketstreamhandle_delegate.h"
21 22
22 using WebKit::WebData; 23 using WebKit::WebData;
23 using WebKit::WebSocketStreamHandle; 24 using WebKit::WebSocketStreamHandle;
24 using WebKit::WebSocketStreamHandleClient; 25 using WebKit::WebSocketStreamHandleClient;
26 using WebKit::WebSocketStreamError;
25 using WebKit::WebURL; 27 using WebKit::WebURL;
26 28
27 namespace webkit_glue { 29 namespace webkit_glue {
28 30
29 // WebSocketStreamHandleImpl::Context ----------------------------------------- 31 // WebSocketStreamHandleImpl::Context -----------------------------------------
30 32
31 class WebSocketStreamHandleImpl::Context 33 class WebSocketStreamHandleImpl::Context
32 : public base::RefCounted<Context>, 34 : public base::RefCounted<Context>,
33 public WebSocketStreamHandleDelegate { 35 public WebSocketStreamHandleDelegate {
34 public: 36 public:
(...skipping 10 matching lines...) Expand all
45 47
46 // Must be called before |handle_| or |client_| is deleted. 48 // Must be called before |handle_| or |client_| is deleted.
47 // Once detached, it never calls |client_| back. 49 // Once detached, it never calls |client_| back.
48 void Detach(); 50 void Detach();
49 51
50 // WebSocketStreamHandleDelegate methods: 52 // WebSocketStreamHandleDelegate methods:
51 virtual void DidOpenStream(WebSocketStreamHandle*, int); 53 virtual void DidOpenStream(WebSocketStreamHandle*, int);
52 virtual void DidSendData(WebSocketStreamHandle*, int); 54 virtual void DidSendData(WebSocketStreamHandle*, int);
53 virtual void DidReceiveData(WebSocketStreamHandle*, const char*, int); 55 virtual void DidReceiveData(WebSocketStreamHandle*, const char*, int);
54 virtual void DidClose(WebSocketStreamHandle*); 56 virtual void DidClose(WebSocketStreamHandle*);
57 virtual void DidFail(WebSocketStreamHandle*, int);
55 58
56 private: 59 private:
57 friend class base::RefCounted<Context>; 60 friend class base::RefCounted<Context>;
58 ~Context() { 61 ~Context() {
59 DCHECK(!handle_); 62 DCHECK(!handle_);
60 DCHECK(!client_); 63 DCHECK(!client_);
61 DCHECK(!bridge_); 64 DCHECK(!bridge_);
62 } 65 }
63 66
64 WebSocketStreamHandleImpl* handle_; 67 WebSocketStreamHandleImpl* handle_;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 WebSocketStreamHandleImpl* handle = handle_; 139 WebSocketStreamHandleImpl* handle = handle_;
137 handle_ = NULL; 140 handle_ = NULL;
138 if (client_) { 141 if (client_) {
139 WebSocketStreamHandleClient* client = client_; 142 WebSocketStreamHandleClient* client = client_;
140 client_ = NULL; 143 client_ = NULL;
141 client->didClose(handle); 144 client->didClose(handle);
142 } 145 }
143 Release(); 146 Release();
144 } 147 }
145 148
149 void WebSocketStreamHandleImpl::Context::DidFail(
150 WebSocketStreamHandle* web_handle, int error_code) {
Yuta Kitamura 2012/06/11 08:24:16 Wrap line between arguments.
151 VLOG(1) << "DidFail";
152 if (client_) {
153 // FIXME: transfer error_code.
154 client_->didFail(handle_, WebSocketStreamError());
155 }
156 }
146 // WebSocketStreamHandleImpl ------------------------------------------------ 157 // WebSocketStreamHandleImpl ------------------------------------------------
147 158
148 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl( 159 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl(
149 WebKitPlatformSupportImpl* platform) 160 WebKitPlatformSupportImpl* platform)
150 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))), 161 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))),
151 platform_(platform) { 162 platform_(platform) {
152 } 163 }
153 164
154 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() { 165 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() {
155 // We won't receive any events from |context_|. 166 // We won't receive any events from |context_|.
(...skipping 13 matching lines...) Expand all
169 180
170 bool WebSocketStreamHandleImpl::send(const WebData& data) { 181 bool WebSocketStreamHandleImpl::send(const WebData& data) {
171 return context_->Send(data); 182 return context_->Send(data);
172 } 183 }
173 184
174 void WebSocketStreamHandleImpl::close() { 185 void WebSocketStreamHandleImpl::close() {
175 context_->Close(); 186 context_->Close();
176 } 187 }
177 188
178 } // namespace webkit_glue 189 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698