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

Unified Diff: ppapi/shared_impl/ppb_file_io_shared.h

Issue 11419131: Refactor FileIO to the new design (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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/shared_impl/ppb_file_io_shared.h
diff --git a/ppapi/shared_impl/ppb_file_io_shared.h b/ppapi/shared_impl/ppb_file_io_shared.h
index 2c39c8d4edf71f03d35d91e888b701da4940e9f8..deeb74e3a7945b018d08a2f3cdd77cf6a72f37df 100644
--- a/ppapi/shared_impl/ppb_file_io_shared.h
+++ b/ppapi/shared_impl/ppb_file_io_shared.h
@@ -5,13 +5,11 @@
#ifndef PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_
#define PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_
-#include <deque>
-
+#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "ppapi/c/pp_file_info.h"
+#include "ppapi/c/pp_resource.h"
#include "ppapi/shared_impl/ppapi_shared_export.h"
-#include "ppapi/shared_impl/resource.h"
-#include "ppapi/shared_impl/tracked_callback.h"
-#include "ppapi/thunk/ppb_file_io_api.h"
namespace ppapi {
@@ -19,63 +17,13 @@ namespace thunk {
class PPB_FileRef_API;
}
-class PPAPI_SHARED_EXPORT PPB_FileIO_Shared : public Resource,
- public thunk::PPB_FileIO_API {
- public:
- PPB_FileIO_Shared(PP_Instance instance);
- PPB_FileIO_Shared(const HostResource& host_resource);
- ~PPB_FileIO_Shared();
-
- // Resource overrides.
- virtual thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE;
-
- // PPB_FileIO_API implementation.
- virtual int32_t Open(PP_Resource file_ref,
- int32_t open_flags,
- scoped_refptr<TrackedCallback> callback) OVERRIDE;
- virtual int32_t Query(PP_FileInfo* info,
- scoped_refptr<TrackedCallback> callback) OVERRIDE;
- virtual int32_t Touch(PP_Time last_access_time,
- PP_Time last_modified_time,
- scoped_refptr<TrackedCallback> callback) OVERRIDE;
- virtual int32_t Read(int64_t offset,
- char* buffer,
- int32_t bytes_to_read,
- scoped_refptr<TrackedCallback> callback) OVERRIDE;
- virtual int32_t ReadToArray(int64_t offset,
- int32_t max_read_length,
- PP_ArrayOutput* output_array_buffer,
- scoped_refptr<TrackedCallback> callback) OVERRIDE;
- virtual int32_t Write(int64_t offset,
- const char* buffer,
- int32_t bytes_to_write,
- scoped_refptr<TrackedCallback> callback) OVERRIDE;
- virtual int32_t SetLength(int64_t length,
- scoped_refptr<TrackedCallback> callback) OVERRIDE;
- virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE;
-
- // Callback handler for different types of operations.
- void ExecuteGeneralCallback(int32_t pp_error);
- void ExecuteOpenFileCallback(int32_t pp_error);
- void ExecuteQueryCallback(int32_t pp_error, const PP_FileInfo& info);
- void ExecuteReadCallback(int32_t pp_error_or_bytes, const char* data);
-
+class PPAPI_SHARED_EXPORT PPB_FileIO_Shared {
protected:
- struct CallbackEntry {
- CallbackEntry();
- CallbackEntry(const CallbackEntry& entry);
- ~CallbackEntry();
-
- scoped_refptr<TrackedCallback> callback;
-
- // Output buffer used only by |Read()|.
- PP_ArrayOutput read_buffer;
-
- // Pointer back to the caller's PP_FileInfo structure for Query operations.
- // NULL for non-query operations. Not owned.
- PP_FileInfo* info;
- };
+ PPB_FileIO_Shared();
+ ~PPB_FileIO_Shared();
+ // Only FileIOResource needs this, but leave here as shared code to make the
+ // resource code succinct.
enum OperationType {
// There is no pending operation right now.
OPERATION_NONE,
@@ -93,64 +41,56 @@ class PPAPI_SHARED_EXPORT PPB_FileIO_Shared : public Resource,
OPERATION_EXCLUSIVE
};
+ // FileIO operations templates to perform real operation between common
+ // pre/post-condition.
+ int32_t DoOpen(PP_Resource file_ref, int32_t open_flags);
+ int32_t DoQuery();
+ int32_t DoTouch(PP_Time last_access_time, PP_Time last_modified_time);
+ int32_t DoRead(int64_t offset, int32_t bytes_to_read);
+ int32_t DoWrite(int64_t offset, const char* buffer, int32_t bytes_to_write);
+ int32_t DoSetLength(int64_t length);
+ int32_t DoFlush();
+
+ void SetOpenSucceed();
+ bool CheckOpenState(bool should_be_open) const;
+
// Validated versions of the FileIO API. Subclasses in the proxy and impl
// implement these so the common error checking stays here.
virtual int32_t OpenValidated(PP_Resource file_ref_resource,
thunk::PPB_FileRef_API* file_ref_api,
- int32_t open_flags,
- scoped_refptr<TrackedCallback> callback) = 0;
- virtual int32_t QueryValidated(PP_FileInfo* info,
- scoped_refptr<TrackedCallback> callback) = 0;
+ int32_t open_flags) = 0;
+ virtual int32_t QueryValidated() = 0;
virtual int32_t TouchValidated(PP_Time last_access_time,
- PP_Time last_modified_time,
- scoped_refptr<TrackedCallback> callback) = 0;
+ PP_Time last_modified_time) = 0;
virtual int32_t ReadValidated(int64_t offset,
- const PP_ArrayOutput& buffer,
- int32_t max_read_length,
- scoped_refptr<TrackedCallback> callback) = 0;
+ int32_t max_read_length) = 0;
virtual int32_t WriteValidated(int64_t offset,
const char* buffer,
- int32_t bytes_to_write,
- scoped_refptr<TrackedCallback> callback) = 0;
- virtual int32_t SetLengthValidated(
- int64_t length,
- scoped_refptr<TrackedCallback> callback) = 0;
- virtual int32_t FlushValidated(scoped_refptr<TrackedCallback> callback) = 0;
-
- // Called for every "Validated" function.
- //
- // This verifies that the callback is valid and that no callback is already
- // pending, or it is a read(write) request and currently the pending
- // operations are reads(writes).
+ int32_t bytes_to_write) = 0;
+ virtual int32_t SetLengthValidated(int64_t length) = 0;
+ virtual int32_t FlushValidated() = 0;
+
+ // Called before every "Validated" function. It is responsible to make sure
+ // that "state" is correct. For example, some operations are only valid after
+ // the file is opened, or operations might need to run excludively. See
+ // subclasses implementation for detail.
//
- // Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if
- // the call should be aborted and that code returned to the plugin.
- int32_t CommonCallValidation(bool should_be_open, OperationType new_op);
+ // It returns |PP_OK| on success, or |PP_ERROR_...| for various reasons.
+ virtual int32_t CommonPreCondition(bool should_be_open, OperationType new_op);
- // Sets up a pending callback. This should only be called once it is certain
- // that |PP_OK_COMPLETIONPENDING| will be returned.
- //
- // |read_buffer| is only used by read operations, |info| is used only by
- // query operations.
- void RegisterCallback(OperationType op,
- scoped_refptr<TrackedCallback> callback,
- const PP_ArrayOutput* read_buffer,
- PP_FileInfo* info);
+ // Called after every "Validated" function.
+ void CommonPostCondition(OperationType new_op);
- // Pops the oldest callback from the queue and runs it.
- void RunAndRemoveFirstPendingCallback(int32_t result);
+ // Marks the state of current operations on started or finished.
raymes1 2012/11/28 05:26:27 on -> as
victorhsieh 2012/11/28 07:11:04 Done.
+ void SetOpInProgress(OperationType op);
+ void SetOpFinished();
- // The file system type specified in the Open() call. This will be
- // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not
- // indicate that the open command actually succeeded.
- PP_FileSystemType file_system_type_;
+ int num_pending_ops_;
+ OperationType pending_op_;
// Set to true when the file has been successfully opened.
bool file_open_;
- std::deque<CallbackEntry> callbacks_;
- OperationType pending_op_;
-
DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Shared);
};

Powered by Google App Engine
This is Rietveld 408576698