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

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: Fix some code styles issue Created 7 years, 8 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"
tyoshino (SeeGerritForStatus) 2013/04/17 08:15:49 include base/string16.h
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebSocketStreamErro r.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebSocketStreamHand leClient.h" 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebSocketStreamHand leClient.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.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;
24 using WebKit::WebSocketStreamError;
23 using WebKit::WebSocketStreamHandle; 25 using WebKit::WebSocketStreamHandle;
24 using WebKit::WebSocketStreamHandleClient; 26 using WebKit::WebSocketStreamHandleClient;
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>,
(...skipping 14 matching lines...) Expand all
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) OVERRIDE; 53 virtual void DidOpenStream(WebSocketStreamHandle*, int) OVERRIDE;
52 virtual void DidSendData(WebSocketStreamHandle*, int) OVERRIDE; 54 virtual void DidSendData(WebSocketStreamHandle*, int) OVERRIDE;
53 virtual void DidReceiveData(WebSocketStreamHandle*, 55 virtual void DidReceiveData(WebSocketStreamHandle*,
54 const char*, 56 const char*,
55 int) OVERRIDE; 57 int) OVERRIDE;
56 virtual void DidClose(WebSocketStreamHandle*) OVERRIDE; 58 virtual void DidClose(WebSocketStreamHandle*) OVERRIDE;
59 virtual void DidFail(WebSocketStreamHandle*, int, const string16&);
57 60
58 private: 61 private:
59 friend class base::RefCounted<Context>; 62 friend class base::RefCounted<Context>;
60 virtual ~Context() { 63 virtual ~Context() {
61 DCHECK(!handle_); 64 DCHECK(!handle_);
62 DCHECK(!client_); 65 DCHECK(!client_);
63 DCHECK(!bridge_); 66 DCHECK(!bridge_);
64 } 67 }
65 68
66 WebSocketStreamHandleImpl* handle_; 69 WebSocketStreamHandleImpl* handle_;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 WebSocketStreamHandleImpl* handle = handle_; 141 WebSocketStreamHandleImpl* handle = handle_;
139 handle_ = NULL; 142 handle_ = NULL;
140 if (client_) { 143 if (client_) {
141 WebSocketStreamHandleClient* client = client_; 144 WebSocketStreamHandleClient* client = client_;
142 client_ = NULL; 145 client_ = NULL;
143 client->didClose(handle); 146 client->didClose(handle);
144 } 147 }
145 Release(); 148 Release();
146 } 149 }
147 150
151 void WebSocketStreamHandleImpl::Context::DidFail(
152 WebSocketStreamHandle* web_handle,
153 int error_code,
154 const string16& error_msg) {
155 VLOG(1) << "DidFail";
156 if (client_) {
157 client_->didFail(
158 handle_,
159 WebSocketStreamError(error_code, error_msg));
160 }
161 }
162
148 // WebSocketStreamHandleImpl ------------------------------------------------ 163 // WebSocketStreamHandleImpl ------------------------------------------------
149 164
150 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl( 165 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl(
151 WebKitPlatformSupportImpl* platform) 166 WebKitPlatformSupportImpl* platform)
152 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))), 167 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))),
153 platform_(platform) { 168 platform_(platform) {
154 } 169 }
155 170
156 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() { 171 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() {
157 // We won't receive any events from |context_|. 172 // We won't receive any events from |context_|.
(...skipping 13 matching lines...) Expand all
171 186
172 bool WebSocketStreamHandleImpl::send(const WebData& data) { 187 bool WebSocketStreamHandleImpl::send(const WebData& data) {
173 return context_->Send(data); 188 return context_->Send(data);
174 } 189 }
175 190
176 void WebSocketStreamHandleImpl::close() { 191 void WebSocketStreamHandleImpl::close() {
177 context_->Close(); 192 context_->Close();
178 } 193 }
179 194
180 } // namespace webkit_glue 195 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698