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..9aeda25f68d7d6c275698d18e0766192443c9210 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 |
@@ -98,45 +97,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 +129,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 +155,16 @@ 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_)) { |
+ if (next_callback_id_ == std::numeric_limits<int>::max()) |
+ next_callback_id_ = 1; |
+ else |
+ next_callback_id_++; |
+ } |
- pending_callbacks_[next_callback_id_] = new TrackedCallback(this, callback); |
+ pending_callbacks_[next_callback_id_] = callback; |
return next_callback_id_++; |
} |