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

Side by Side Diff: native_client_sdk/src/examples/websocket/websocket.cc

Issue 10905128: Pepper WebSocket API: Fix memory leak issue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: done Created 8 years, 3 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 | ppapi/cpp/var.cc » ('j') | ppapi/cpp/var.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "ppapi/cpp/completion_callback.h" 5 #include "ppapi/cpp/completion_callback.h"
6 #include "ppapi/cpp/instance.h" 6 #include "ppapi/cpp/instance.h"
7 #include "ppapi/cpp/module.h" 7 #include "ppapi/cpp/module.h"
8 #include "ppapi/cpp/var.h" 8 #include "ppapi/cpp/var.h"
9 #include "ppapi/cpp/var_array_buffer.h" 9 #include "ppapi/cpp/var_array_buffer.h"
10 #include "ppapi/cpp/websocket.h" 10 #include "ppapi/cpp/websocket.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 89 }
90 90
91 void WebSocketInstance::Send(const std::string& message) { 91 void WebSocketInstance::Send(const std::string& message) {
92 if (!IsConnected()) 92 if (!IsConnected())
93 return; 93 return;
94 websocket_->SendMessage(pp::Var(message)); 94 websocket_->SendMessage(pp::Var(message));
95 PostMessage(pp::Var(std::string("log:send: ") + message)); 95 PostMessage(pp::Var(std::string("log:send: ") + message));
96 } 96 }
97 97
98 void WebSocketInstance::Receive() { 98 void WebSocketInstance::Receive() {
99 // Release old var resource if it is reused.
100 pp::Var release(pp::PASS_REF, receive_var_.Detach());
Takashi Toyoshima 2012/09/07 17:18:27 If we want to reuse the same pp::Var to receive re
dmichael (off chromium) 2012/09/07 18:36:58 What if we just make ReceiveMessage release the va
Takashi Toyoshima 2012/09/10 13:21:27 OK. I'll do '*message = Var();' in ReceiveMessage
99 pp::CompletionCallback callback(OnReceiveCompletionCallback, this); 101 pp::CompletionCallback callback(OnReceiveCompletionCallback, this);
100 // |receive_var_| must be valid until |callback| is invoked. 102 // |receive_var_| must be valid until |callback| is invoked.
101 // Just use a member variable. 103 // Just use a member variable.
102 websocket_->ReceiveMessage(&receive_var_, callback); 104 websocket_->ReceiveMessage(&receive_var_, callback);
103 } 105 }
104 106
105 void WebSocketInstance::OnConnectCompletion(int32_t result) { 107 void WebSocketInstance::OnConnectCompletion(int32_t result) {
106 if (result != PP_OK) { 108 if (result != PP_OK) {
107 PostMessage(pp::Var("alert:connection failed")); 109 PostMessage(pp::Var("alert:connection failed"));
108 return; 110 return;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 }; 161 };
160 162
161 163
162 // Implement the required pp::CreateModule function that creates our specific 164 // Implement the required pp::CreateModule function that creates our specific
163 // kind of Module. 165 // kind of Module.
164 namespace pp { 166 namespace pp {
165 Module* CreateModule() { 167 Module* CreateModule() {
166 return new WebSocketModule(); 168 return new WebSocketModule();
167 } 169 }
168 } // namespace pp 170 } // namespace pp
OLDNEW
« no previous file with comments | « no previous file | ppapi/cpp/var.cc » ('j') | ppapi/cpp/var.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698