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

Side by Side Diff: webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc

Issue 9015009: Use the new callback tracker and delete the old one (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add IsPending Created 8 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h" 5 #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h"
6 6
7 #include "ppapi/c/pp_completion_callback.h" 7 #include "ppapi/c/pp_completion_callback.h"
8 #include "ppapi/c/private/ppb_flash_net_connector.h" 8 #include "ppapi/c/private/ppb_flash_net_connector.h"
9 #include "webkit/plugins/ppapi/common.h" 9 #include "webkit/plugins/ppapi/common.h"
10 #include "webkit/plugins/ppapi/plugin_delegate.h" 10 #include "webkit/plugins/ppapi/plugin_delegate.h"
11 #include "webkit/plugins/ppapi/plugin_module.h" 11 #include "webkit/plugins/ppapi/plugin_module.h"
12 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 12 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
13 #include "webkit/plugins/ppapi/resource_helper.h" 13 #include "webkit/plugins/ppapi/resource_helper.h"
14 14
15 using ::ppapi::thunk::PPB_Flash_NetConnector_API; 15 using ppapi::thunk::PPB_Flash_NetConnector_API;
16 using ppapi::TrackedCallback;
16 17
17 namespace webkit { 18 namespace webkit {
18 namespace ppapi { 19 namespace ppapi {
19 20
20 PPB_Flash_NetConnector_Impl::PPB_Flash_NetConnector_Impl(PP_Instance instance) 21 PPB_Flash_NetConnector_Impl::PPB_Flash_NetConnector_Impl(PP_Instance instance)
21 : Resource(instance), 22 : Resource(instance),
22 socket_out_(NULL), 23 socket_out_(NULL),
23 local_addr_out_(NULL), 24 local_addr_out_(NULL),
24 remote_addr_out_(NULL) { 25 remote_addr_out_(NULL) {
25 } 26 }
(...skipping 13 matching lines...) Expand all
39 PP_NetAddress_Private* local_addr_out, 40 PP_NetAddress_Private* local_addr_out,
40 PP_NetAddress_Private* remote_addr_out, 41 PP_NetAddress_Private* remote_addr_out,
41 PP_CompletionCallback callback) { 42 PP_CompletionCallback callback) {
42 // |socket_out| is not optional. 43 // |socket_out| is not optional.
43 if (!socket_out) 44 if (!socket_out)
44 return PP_ERROR_BADARGUMENT; 45 return PP_ERROR_BADARGUMENT;
45 46
46 if (!callback.func) 47 if (!callback.func)
47 return PP_ERROR_BLOCKS_MAIN_THREAD; 48 return PP_ERROR_BLOCKS_MAIN_THREAD;
48 49
49 if (callback_.get() && !callback_->completed()) 50 if (TrackedCallback::IsPending(callback_))
50 return PP_ERROR_INPROGRESS; 51 return PP_ERROR_INPROGRESS;
51 52
52 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 53 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
53 if (!plugin_instance) 54 if (!plugin_instance)
54 return false; 55 return false;
55 int32_t rv = plugin_instance->delegate()->ConnectTcp(this, host, port); 56 int32_t rv = plugin_instance->delegate()->ConnectTcp(this, host, port);
56 if (rv == PP_OK_COMPLETIONPENDING) { 57 if (rv == PP_OK_COMPLETIONPENDING) {
57 // Record callback and output buffers. 58 // Record callback and output buffers.
58 callback_ = new TrackedCompletionCallback( 59 callback_ = new TrackedCallback(this, callback);
59 plugin_instance->module()->GetCallbackTracker(),
60 pp_resource(), callback);
61 socket_out_ = socket_out; 60 socket_out_ = socket_out;
62 local_addr_out_ = local_addr_out; 61 local_addr_out_ = local_addr_out;
63 remote_addr_out_ = remote_addr_out; 62 remote_addr_out_ = remote_addr_out;
64 } else { 63 } else {
65 // This should never be completed synchronously successfully. 64 // This should never be completed synchronously successfully.
66 DCHECK_NE(rv, PP_OK); 65 DCHECK_NE(rv, PP_OK);
67 } 66 }
68 return rv; 67 return rv;
69 } 68 }
70 69
71 int32_t PPB_Flash_NetConnector_Impl::ConnectTcpAddress( 70 int32_t PPB_Flash_NetConnector_Impl::ConnectTcpAddress(
72 const PP_NetAddress_Private* addr, 71 const PP_NetAddress_Private* addr,
73 PP_FileHandle* socket_out, 72 PP_FileHandle* socket_out,
74 PP_NetAddress_Private* local_addr_out, 73 PP_NetAddress_Private* local_addr_out,
75 PP_NetAddress_Private* remote_addr_out, 74 PP_NetAddress_Private* remote_addr_out,
76 PP_CompletionCallback callback) { 75 PP_CompletionCallback callback) {
77 // |socket_out| is not optional. 76 // |socket_out| is not optional.
78 if (!socket_out) 77 if (!socket_out)
79 return PP_ERROR_BADARGUMENT; 78 return PP_ERROR_BADARGUMENT;
80 79
81 if (!callback.func) 80 if (!callback.func)
82 return PP_ERROR_BLOCKS_MAIN_THREAD; 81 return PP_ERROR_BLOCKS_MAIN_THREAD;
83 82
84 if (callback_.get() && !callback_->completed()) 83 if (TrackedCallback::IsPending(callback_))
85 return PP_ERROR_INPROGRESS; 84 return PP_ERROR_INPROGRESS;
86 85
87 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 86 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
88 if (!plugin_instance) 87 if (!plugin_instance)
89 return false; 88 return false;
90 int32_t rv = plugin_instance->delegate()->ConnectTcpAddress(this, addr); 89 int32_t rv = plugin_instance->delegate()->ConnectTcpAddress(this, addr);
91 if (rv == PP_OK_COMPLETIONPENDING) { 90 if (rv == PP_OK_COMPLETIONPENDING) {
92 // Record callback and output buffers. 91 // Record callback and output buffers.
93 callback_ = new TrackedCompletionCallback( 92 callback_ = new TrackedCallback(this, callback);
94 plugin_instance->module()->GetCallbackTracker(),
95 pp_resource(), callback);
96 socket_out_ = socket_out; 93 socket_out_ = socket_out;
97 local_addr_out_ = local_addr_out; 94 local_addr_out_ = local_addr_out;
98 remote_addr_out_ = remote_addr_out; 95 remote_addr_out_ = remote_addr_out;
99 } else { 96 } else {
100 // This should never be completed synchronously successfully. 97 // This should never be completed synchronously successfully.
101 DCHECK_NE(rv, PP_OK); 98 DCHECK_NE(rv, PP_OK);
102 } 99 }
103 return rv; 100 return rv;
104 } 101 }
105 102
(...skipping 11 matching lines...) Expand all
117 if (local_addr_out_) 114 if (local_addr_out_)
118 *local_addr_out_ = local_addr; 115 *local_addr_out_ = local_addr;
119 if (remote_addr_out_) 116 if (remote_addr_out_)
120 *remote_addr_out_ = remote_addr; 117 *remote_addr_out_ = remote_addr;
121 rv = PP_OK; 118 rv = PP_OK;
122 } else { 119 } else {
123 rv = PP_ERROR_FAILED; 120 rv = PP_ERROR_FAILED;
124 } 121 }
125 } 122 }
126 123
127 // Theoretically, the plugin should be allowed to try another |ConnectTcp()|
128 // from the callback.
129 scoped_refptr<TrackedCompletionCallback> callback;
130 callback.swap(callback_);
131 // Wipe everything else out for safety.
132 socket_out_ = NULL; 124 socket_out_ = NULL;
133 local_addr_out_ = NULL; 125 local_addr_out_ = NULL;
134 remote_addr_out_ = NULL; 126 remote_addr_out_ = NULL;
135 127 TrackedCallback::ClearAndRun(&callback_, rv);
136 callback->Run(rv); // Will complete abortively if necessary.
137 } 128 }
138 129
139 } // namespace ppapi 130 } // namespace ppapi
140 } // namespace webkit 131 } // namespace webkit
141 132
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_flash_net_connector_impl.h ('k') | webkit/plugins/ppapi/ppb_transport_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698