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

Side by Side Diff: webkit/plugins/ppapi/ppb_broker_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_broker_impl.h" 5 #include "webkit/plugins/ppapi/ppb_broker_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ppapi/shared_impl/platform_file.h" 8 #include "ppapi/shared_impl/platform_file.h"
9 #include "webkit/plugins/ppapi/common.h" 9 #include "webkit/plugins/ppapi/common.h"
10 #include "webkit/plugins/ppapi/plugin_module.h" 10 #include "webkit/plugins/ppapi/plugin_module.h"
11 #include "webkit/plugins/ppapi/resource_helper.h" 11 #include "webkit/plugins/ppapi/resource_helper.h"
12 12
13 using ::ppapi::PlatformFileToInt; 13 using ppapi::PlatformFileToInt;
14 using ::ppapi::thunk::PPB_Broker_API; 14 using ppapi::thunk::PPB_Broker_API;
15 using ppapi::TrackedCallback;
15 16
16 namespace webkit { 17 namespace webkit {
17 namespace ppapi { 18 namespace ppapi {
18 19
19 // PPB_Broker_Impl ------------------------------------------------------ 20 // PPB_Broker_Impl ------------------------------------------------------
20 21
21 PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance) 22 PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance)
22 : Resource(instance), 23 : Resource(instance),
23 broker_(NULL), 24 broker_(NULL),
24 connect_callback_(), 25 connect_callback_(),
(...skipping 28 matching lines...) Expand all
53 } 54 }
54 55
55 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 56 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
56 if (!plugin_instance) 57 if (!plugin_instance)
57 return PP_ERROR_FAILED; 58 return PP_ERROR_FAILED;
58 59
59 // The callback must be populated now in case we are connected to the broker 60 // The callback must be populated now in case we are connected to the broker
60 // and BrokerConnected is called before ConnectToPpapiBroker returns. 61 // and BrokerConnected is called before ConnectToPpapiBroker returns.
61 // Because it must be created now, it must be aborted and cleared if 62 // Because it must be created now, it must be aborted and cleared if
62 // ConnectToPpapiBroker fails. 63 // ConnectToPpapiBroker fails.
63 connect_callback_ = new TrackedCompletionCallback( 64 connect_callback_ = new TrackedCallback(this, connect_callback);
64 plugin_instance->module()->GetCallbackTracker(), pp_resource(),
65 connect_callback);
66 65
67 broker_ = plugin_instance->delegate()->ConnectToPpapiBroker(this); 66 broker_ = plugin_instance->delegate()->ConnectToPpapiBroker(this);
68 if (!broker_) { 67 if (!broker_) {
69 scoped_refptr<TrackedCompletionCallback> callback; 68 TrackedCallback::ClearAndAbort(&connect_callback_);
70 callback.swap(connect_callback_);
71 callback->Abort();
72 return PP_ERROR_FAILED; 69 return PP_ERROR_FAILED;
73 } 70 }
74 71
75 return PP_OK_COMPLETIONPENDING; 72 return PP_OK_COMPLETIONPENDING;
76 } 73 }
77 74
78 int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) { 75 int32_t PPB_Broker_Impl::GetHandle(int32_t* handle) {
79 if (pipe_handle_ == PlatformFileToInt(base::kInvalidPlatformFileValue)) 76 if (pipe_handle_ == PlatformFileToInt(base::kInvalidPlatformFileValue))
80 return PP_ERROR_FAILED; // Handle not set yet. 77 return PP_ERROR_FAILED; // Handle not set yet.
81 *handle = pipe_handle_; 78 *handle = pipe_handle_;
82 return PP_OK; 79 return PP_OK;
83 } 80 }
84 81
85 // Transfers ownership of the handle to the plugin. 82 // Transfers ownership of the handle to the plugin.
86 void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) { 83 void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) {
87 DCHECK(pipe_handle_ == 84 DCHECK(pipe_handle_ ==
88 PlatformFileToInt(base::kInvalidPlatformFileValue)); 85 PlatformFileToInt(base::kInvalidPlatformFileValue));
89 DCHECK(result == PP_OK || 86 DCHECK(result == PP_OK ||
90 handle == PlatformFileToInt(base::kInvalidPlatformFileValue)); 87 handle == PlatformFileToInt(base::kInvalidPlatformFileValue));
91 88
92 pipe_handle_ = handle; 89 pipe_handle_ = handle;
93 90
94 // Synchronous calls are not supported. 91 // Synchronous calls are not supported.
95 DCHECK(connect_callback_.get() && !connect_callback_->completed()); 92 DCHECK(TrackedCallback::IsPending(connect_callback_));
96 93
97 scoped_refptr<TrackedCompletionCallback> callback; 94 TrackedCallback::ClearAndRun(&connect_callback_, result);
98 callback.swap(connect_callback_);
99 callback->Run(result); // Will complete abortively if necessary.
100 } 95 }
101 96
102 } // namespace ppapi 97 } // namespace ppapi
103 } // namespace webkit 98 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_broker_impl.h ('k') | webkit/plugins/ppapi/ppb_directory_reader_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698