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

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

Issue 316008: Make WebSocketStreamHandleBridge RefCountedThreadSafe. (Closed)
Patch Set: Created 11 years, 2 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 ~Context() { 54 ~Context() {
55 DCHECK(!handle_); 55 DCHECK(!handle_);
56 DCHECK(!client_); 56 DCHECK(!client_);
57 DCHECK(!bridge_); 57 DCHECK(!bridge_);
58 } 58 }
59 59
60 WebSocketStreamHandleImpl* handle_; 60 WebSocketStreamHandleImpl* handle_;
61 WebKit::WebSocketStreamHandleClient* client_; 61 WebKit::WebSocketStreamHandleClient* client_;
62 // |bridge_| is alive from Connect to DidClose, so Context must be alive 62 // |bridge_| is alive from Connect to DidClose, so Context must be alive
63 // in the time period. 63 // in the time period.
64 WebSocketStreamHandleBridge* bridge_; 64 scoped_refptr<WebSocketStreamHandleBridge> bridge_;
65 65
66 DISALLOW_COPY_AND_ASSIGN(Context); 66 DISALLOW_COPY_AND_ASSIGN(Context);
67 }; 67 };
68 68
69 WebSocketStreamHandleImpl::Context::Context(WebSocketStreamHandleImpl* handle) 69 WebSocketStreamHandleImpl::Context::Context(WebSocketStreamHandleImpl* handle)
70 : handle_(handle), 70 : handle_(handle),
71 client_(NULL), 71 client_(NULL),
72 bridge_(NULL) { 72 bridge_(NULL) {
73 } 73 }
74 74
(...skipping 15 matching lines...) Expand all
90 void WebSocketStreamHandleImpl::Context::Close() { 90 void WebSocketStreamHandleImpl::Context::Close() {
91 LOG(INFO) << "Close"; 91 LOG(INFO) << "Close";
92 if (bridge_) 92 if (bridge_)
93 bridge_->Close(); 93 bridge_->Close();
94 } 94 }
95 95
96 void WebSocketStreamHandleImpl::Context::Detach() { 96 void WebSocketStreamHandleImpl::Context::Detach() {
97 handle_ = NULL; 97 handle_ = NULL;
98 client_ = NULL; 98 client_ = NULL;
99 // If Connect was called, |bridge_| is not NULL, so that this Context closes 99 // If Connect was called, |bridge_| is not NULL, so that this Context closes
100 // the |bridge_| here. Then |bridge_| will call back DidClose, in which 100 // the |bridge_| here. Then |bridge_| will call back DidClose, and will
101 // this Context will delete the |bridge_|. 101 // be released by itself.
102 // Otherwise, |bridge_| is NULL. 102 // Otherwise, |bridge_| is NULL.
103 if (bridge_) 103 if (bridge_)
104 bridge_->Close(); 104 bridge_->Close();
105 } 105 }
106 106
107 void WebSocketStreamHandleImpl::Context::WillOpenStream( 107 void WebSocketStreamHandleImpl::Context::WillOpenStream(
108 WebKit::WebSocketStreamHandle* web_handle, const GURL& url) { 108 WebKit::WebSocketStreamHandle* web_handle, const GURL& url) {
109 LOG(INFO) << "WillOpenStream url=" << url; 109 LOG(INFO) << "WillOpenStream url=" << url;
110 if (client_) 110 if (client_)
111 client_->willOpenStream(handle_, url); 111 client_->willOpenStream(handle_, url);
(...skipping 14 matching lines...) Expand all
126 126
127 void WebSocketStreamHandleImpl::Context::DidReceiveData( 127 void WebSocketStreamHandleImpl::Context::DidReceiveData(
128 WebKit::WebSocketStreamHandle* web_handle, const char* data, int size) { 128 WebKit::WebSocketStreamHandle* web_handle, const char* data, int size) {
129 if (client_) 129 if (client_)
130 client_->didReceiveData(handle_, WebKit::WebData(data, size)); 130 client_->didReceiveData(handle_, WebKit::WebData(data, size));
131 } 131 }
132 132
133 void WebSocketStreamHandleImpl::Context::DidClose( 133 void WebSocketStreamHandleImpl::Context::DidClose(
134 WebKit::WebSocketStreamHandle* web_handle) { 134 WebKit::WebSocketStreamHandle* web_handle) {
135 LOG(INFO) << "DidClose"; 135 LOG(INFO) << "DidClose";
136 delete bridge_;
137 bridge_ = NULL; 136 bridge_ = NULL;
138 WebSocketStreamHandleImpl* handle = handle_; 137 WebSocketStreamHandleImpl* handle = handle_;
139 handle_ = NULL; 138 handle_ = NULL;
140 if (client_) { 139 if (client_) {
141 WebKit::WebSocketStreamHandleClient* client = client_; 140 WebKit::WebSocketStreamHandleClient* client = client_;
142 client_ = NULL; 141 client_ = NULL;
143 client->didClose(handle); 142 client->didClose(handle);
144 } 143 }
145 Release(); 144 Release();
146 } 145 }
(...skipping 22 matching lines...) Expand all
169 168
170 bool WebSocketStreamHandleImpl::send(const WebKit::WebData& data) { 169 bool WebSocketStreamHandleImpl::send(const WebKit::WebData& data) {
171 return context_->Send(data); 170 return context_->Send(data);
172 } 171 }
173 172
174 void WebSocketStreamHandleImpl::close() { 173 void WebSocketStreamHandleImpl::close() {
175 context_->Close(); 174 context_->Close();
176 } 175 }
177 176
178 } // namespace webkit_glue 177 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/websocketstreamhandle_bridge.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