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

Unified Diff: ppapi/proxy/ppb_file_ref_proxy.cc

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up for review. Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/proxy/ppb_file_ref_proxy.cc
diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc
index 9298eb251b9d69a55262cea6eebb5e283085297d..3391171b8c3dac0cfcf02f8a9e6130ae1a9e02df 100644
--- a/ppapi/proxy/ppb_file_ref_proxy.cc
+++ b/ppapi/proxy/ppb_file_ref_proxy.cc
@@ -40,13 +40,13 @@ class FileRef : public PPB_FileRef_Shared {
// PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared).
virtual PP_Resource GetParent() OVERRIDE;
virtual int32_t MakeDirectory(PP_Bool make_ancestors,
- PP_CompletionCallback callback) OVERRIDE;
+ ApiCallbackType callback) OVERRIDE;
virtual int32_t Touch(PP_Time last_access_time,
PP_Time last_modified_time,
- PP_CompletionCallback callback) OVERRIDE;
- virtual int32_t Delete(PP_CompletionCallback callback) OVERRIDE;
+ ApiCallbackType callback) OVERRIDE;
+ virtual int32_t Delete(ApiCallbackType callback) OVERRIDE;
virtual int32_t Rename(PP_Resource new_file_ref,
- PP_CompletionCallback callback) OVERRIDE;
+ ApiCallbackType callback) OVERRIDE;
virtual PP_Var GetAbsolutePath() OVERRIDE;
// Executes the pending callback with the given ID. See pending_callbacks_.
@@ -57,9 +57,8 @@ class FileRef : public PPB_FileRef_Shared {
return PluginDispatcher::GetForResource(this);
}
- // Adds a callback to the list and returns its ID. Returns 0 if the callback
- // is invalid.
- int SendCallback(PP_CompletionCallback callback);
+ // Adds a callback to the list and returns its ID.
+ int SendCallback(ApiCallbackType callback);
// This class can have any number of out-standing requests with completion
// callbacks, in contrast to most resources which have one possible pending
@@ -67,9 +66,10 @@ class FileRef : public PPB_FileRef_Shared {
//
// To keep track of them, assign integer IDs to the callbacks, which is how
// the callback will be identified when it's passed to the host and then
- // back here.
- int next_callback_id_;
- typedef std::map<int, scoped_refptr<TrackedCallback> > PendingCallbackMap;
+ // back here. Use unsigned so that overflow is well-defined.
+ unsigned int next_callback_id_;
+ typedef std::map<unsigned int,
+ scoped_refptr<TrackedCallback> > PendingCallbackMap;
PendingCallbackMap pending_callbacks_;
DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef);
@@ -77,7 +77,7 @@ class FileRef : public PPB_FileRef_Shared {
FileRef::FileRef(const PPB_FileRef_CreateInfo& info)
: PPB_FileRef_Shared(OBJECT_IS_PROXY, info),
- next_callback_id_(1) {
+ next_callback_id_(0u) {
}
FileRef::~FileRef() {
@@ -98,45 +98,30 @@ PP_Resource FileRef::GetParent() {
}
int32_t FileRef::MakeDirectory(PP_Bool make_ancestors,
- PP_CompletionCallback callback) {
- int callback_id = SendCallback(callback);
- if (!callback_id)
- return PP_ERROR_BADARGUMENT;
-
+ ApiCallbackType callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_MakeDirectory(
- API_ID_PPB_FILE_REF, host_resource(), make_ancestors, callback_id));
+ API_ID_PPB_FILE_REF, host_resource(), make_ancestors,
+ SendCallback(callback)));
return PP_OK_COMPLETIONPENDING;
}
int32_t FileRef::Touch(PP_Time last_access_time,
PP_Time last_modified_time,
- PP_CompletionCallback callback) {
- int callback_id = SendCallback(callback);
- if (!callback_id)
- return PP_ERROR_BADARGUMENT;
-
+ ApiCallbackType callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Touch(
- API_ID_PPB_FILE_REF, host_resource(),
- last_access_time, last_modified_time, callback_id));
+ API_ID_PPB_FILE_REF, host_resource(), last_access_time,
+ last_modified_time, SendCallback(callback)));
return PP_OK_COMPLETIONPENDING;
}
-int32_t FileRef::Delete(PP_CompletionCallback callback) {
- int callback_id = SendCallback(callback);
- if (!callback_id)
- return PP_ERROR_BADARGUMENT;
-
+int32_t FileRef::Delete(ApiCallbackType callback) {
GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Delete(
- API_ID_PPB_FILE_REF, host_resource(), callback_id));
+ API_ID_PPB_FILE_REF, host_resource(), SendCallback(callback)));
return PP_OK_COMPLETIONPENDING;
}
int32_t FileRef::Rename(PP_Resource new_file_ref,
- PP_CompletionCallback callback) {
- int callback_id = SendCallback(callback);
- if (!callback_id)
- return PP_ERROR_BADARGUMENT;
-
+ ApiCallbackType callback) {
Resource* new_file_ref_object =
PpapiGlobals::Get()->GetResourceTracker()->GetResource(new_file_ref);
if (!new_file_ref_object ||
@@ -145,7 +130,7 @@ int32_t FileRef::Rename(PP_Resource new_file_ref,
GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Rename(
API_ID_PPB_FILE_REF, host_resource(),
- new_file_ref_object->host_resource(), callback_id));
+ new_file_ref_object->host_resource(), SendCallback(callback)));
return PP_OK_COMPLETIONPENDING;
}
@@ -171,15 +156,12 @@ void FileRef::ExecuteCallback(int callback_id, int32_t result) {
callback->Run(result);
}
-int FileRef::SendCallback(PP_CompletionCallback callback) {
- if (!callback.func)
- return 0;
-
+int FileRef::SendCallback(ApiCallbackType callback) {
// In extreme cases the IDs may wrap around, so avoid duplicates.
- while (pending_callbacks_.find(next_callback_id_) != pending_callbacks_.end())
- next_callback_id_++;
+ while (pending_callbacks_.count(next_callback_id_))
+ ++next_callback_id_;
- pending_callbacks_[next_callback_id_] = new TrackedCallback(this, callback);
+ pending_callbacks_[next_callback_id_] = callback;
return next_callback_id_++;
}

Powered by Google App Engine
This is Rietveld 408576698