Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 |
| OLD | NEW |