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

Unified Diff: webkit/plugins/ppapi/ppb_transport_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: Address comments Created 9 years 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 side-by-side diff with in-line comments
Download patch
Index: webkit/plugins/ppapi/ppb_transport_impl.cc
diff --git a/webkit/plugins/ppapi/ppb_transport_impl.cc b/webkit/plugins/ppapi/ppb_transport_impl.cc
index 23c5ab8c546f6e955b5e517dec398cb21e842a67..cec2b481544efbb4a47a087db762773026b02d9f 100644
--- a/webkit/plugins/ppapi/ppb_transport_impl.cc
+++ b/webkit/plugins/ppapi/ppb_transport_impl.cc
@@ -13,6 +13,8 @@
#include "ppapi/c/dev/ppb_transport_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/shared_impl/callback_tracker.h"
+#include "ppapi/shared_impl/ppapi_globals.h"
#include "ppapi/shared_impl/var.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
@@ -23,6 +25,7 @@
#include "webkit/plugins/ppapi/resource_helper.h"
using ppapi::StringVar;
+using ppapi::TrackedCallback;
viettrungluu 2012/01/03 22:10:14 Alphabetical order: discuss.
using ppapi::thunk::PPB_Transport_API;
using webkit_glue::P2PTransport;
@@ -258,8 +261,7 @@ int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) {
if (!plugin_module)
return PP_ERROR_FAILED;
- connect_callback_ = new TrackedCompletionCallback(
- plugin_module->GetCallbackTracker(), pp_resource(), callback);
+ connect_callback_ = new TrackedCallback(this, callback);
return PP_OK_COMPLETIONPENDING;
}
@@ -283,8 +285,7 @@ int32_t PPB_Transport_Impl::GetNextAddress(PP_Var* address,
return PP_OK;
}
- next_address_callback_ = new TrackedCompletionCallback(
- plugin_module->GetCallbackTracker(), pp_resource(), callback);
+ next_address_callback_ = new TrackedCallback(this, callback);
return PP_OK_COMPLETIONPENDING;
}
@@ -323,10 +324,8 @@ int32_t PPB_Transport_Impl::Recv(void* data, uint32_t len,
int result = MapNetError(
channel->Read(buffer, len, base::Bind(&PPB_Transport_Impl::OnRead,
base::Unretained(this))));
- if (result == PP_OK_COMPLETIONPENDING) {
- recv_callback_ = new TrackedCompletionCallback(
- plugin_module->GetCallbackTracker(), pp_resource(), callback);
- }
+ if (result == PP_OK_COMPLETIONPENDING)
+ recv_callback_ = new TrackedCallback(this, callback);
return result;
}
@@ -354,10 +353,8 @@ int32_t PPB_Transport_Impl::Send(const void* data, uint32_t len,
int result = MapNetError(
channel->Write(buffer, len, base::Bind(&PPB_Transport_Impl::OnWritten,
base::Unretained(this))));
- if (result == PP_OK_COMPLETIONPENDING) {
- send_callback_ = new TrackedCompletionCallback(
- plugin_module->GetCallbackTracker(), pp_resource(), callback);
- }
+ if (result == PP_OK_COMPLETIONPENDING)
+ send_callback_ = new TrackedCallback(this, callback);
return result;
}
@@ -368,9 +365,8 @@ int32_t PPB_Transport_Impl::Close() {
p2p_transport_.reset();
- PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
- if (plugin_module)
- plugin_module->GetCallbackTracker()->AbortAll();
viettrungluu 2012/01/03 22:10:14 Whoa, this was just wrong.
+ ::ppapi::PpapiGlobals::Get()->GetCallbackTrackerForInstance(
+ pp_instance())->PostAbortForResource(pp_resource());
return PP_OK;
}
@@ -378,45 +374,30 @@ void PPB_Transport_Impl::OnCandidateReady(const std::string& address) {
// Store the candidate first before calling the callback.
local_candidates_.push_back(address);
- if (next_address_callback_.get() && !next_address_callback_->completed()) {
- scoped_refptr<TrackedCompletionCallback> callback;
- callback.swap(next_address_callback_);
- callback->Run(PP_OK);
- }
+ if (next_address_callback_.get() && !next_address_callback_->completed())
+ TrackedCallback::ClearAndRun(&next_address_callback_, PP_OK);
}
void PPB_Transport_Impl::OnStateChange(webkit_glue::P2PTransport::State state) {
writable_ = (state | webkit_glue::P2PTransport::STATE_WRITABLE) != 0;
- if (writable_ && connect_callback_.get() && !connect_callback_->completed()) {
- scoped_refptr<TrackedCompletionCallback> callback;
- callback.swap(connect_callback_);
- callback->Run(PP_OK);
- }
+ if (writable_ && connect_callback_.get() && !connect_callback_->completed())
+ TrackedCallback::ClearAndRun(&connect_callback_, PP_OK);
}
void PPB_Transport_Impl::OnError(int error) {
writable_ = false;
- if (connect_callback_.get() && !connect_callback_->completed()) {
- scoped_refptr<TrackedCompletionCallback> callback;
- callback.swap(connect_callback_);
- callback->Run(PP_ERROR_FAILED);
- }
+ if (connect_callback_.get() && !connect_callback_->completed())
+ TrackedCallback::ClearAndRun(&connect_callback_, PP_ERROR_FAILED);
}
void PPB_Transport_Impl::OnRead(int result) {
DCHECK(recv_callback_.get() && !recv_callback_->completed());
-
- scoped_refptr<TrackedCompletionCallback> callback;
- callback.swap(recv_callback_);
- callback->Run(MapNetError(result));
+ TrackedCallback::ClearAndRun(&recv_callback_, MapNetError(result));
}
void PPB_Transport_Impl::OnWritten(int result) {
DCHECK(send_callback_.get() && !send_callback_->completed());
-
- scoped_refptr<TrackedCompletionCallback> callback;
- callback.swap(send_callback_);
- callback->Run(MapNetError(result));
+ TrackedCallback::ClearAndRun(&send_callback_, MapNetError(result));
}
} // namespace ppapi

Powered by Google App Engine
This is Rietveld 408576698