summaryrefslogtreecommitdiffstats
path: root/ppapi/shared_impl/file_io_state_manager.h
diff options
context:
space:
mode:
authorbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-19 04:16:36 +0000
committerbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-19 04:16:36 +0000
commitc77144727785be9a25c10a7954e38a3a579b417a (patch)
tree5fe5083e10e8af5ec822848a07cb04b416682496 /ppapi/shared_impl/file_io_state_manager.h
parent7a6acd091023b662745562592406b5efbc1a5b42 (diff)
downloadchromium_src-c77144727785be9a25c10a7954e38a3a579b417a.zip
chromium_src-c77144727785be9a25c10a7954e38a3a579b417a.tar.gz
chromium_src-c77144727785be9a25c10a7954e38a3a579b417a.tar.bz2
Refactor FileIO to the new resource host system.
Taking over from Victor's CL: https://codereview.chromium.org/11419131/ Re-landing, with a fix. The original waited to reset the file state until after the callback had completed. This is too late, as the client should be able to perform another file operation during the callback. Changeset #1 is the original patch. The fix is in change set #2 Original author=Victor Hsieh BUG=none TEST=browser_tests --gtest_filter=PPAPINaClNewlibTest.FileIO* Review URL: https://chromiumcodereview.appspot.com/11941022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177830 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl/file_io_state_manager.h')
-rw-r--r--ppapi/shared_impl/file_io_state_manager.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/ppapi/shared_impl/file_io_state_manager.h b/ppapi/shared_impl/file_io_state_manager.h
new file mode 100644
index 0000000..7b5f926
--- /dev/null
+++ b/ppapi/shared_impl/file_io_state_manager.h
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_SHARED_IMPL_FILE_IO_STATE_MANAGER_H_
+#define PPAPI_SHARED_IMPL_FILE_IO_STATE_MANAGER_H_
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ppapi/c/pp_stdint.h"
+#include "ppapi/shared_impl/ppapi_shared_export.h"
+
+namespace ppapi {
+
+// FileIOStateManager is a helper class that maintains the state of operations.
+// For example, some operations are mutually exclusive, meaning that an
+// operation could be rejected because of the current pending operation. Also,
+// most of the operations only work when the file has been opened.
+class PPAPI_SHARED_EXPORT FileIOStateManager {
+ public:
+ FileIOStateManager();
+ ~FileIOStateManager();
+
+ enum OperationType {
+ // There is no pending operation right now.
+ OPERATION_NONE,
+
+ // If there are pending reads, any other kind of async operation is not
+ // allowed.
+ OPERATION_READ,
+
+ // If there are pending writes, any other kind of async operation is not
+ // allowed.
+ OPERATION_WRITE,
+
+ // If there is a pending operation that is neither read nor write, no
+ // further async operation is allowed.
+ OPERATION_EXCLUSIVE
+ };
+
+ OperationType get_pending_operation() const { return pending_op_; }
+
+ void SetOpenSucceed();
+
+ // Called at the beginning of each operation. 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 exclusively.
+ //
+ // It returns |PP_OK| on success, or |PP_ERROR_...| for various reasons.
+ int32_t CheckOperationState(OperationType new_op, bool should_be_open);
+
+ // Marks the state of current operations as started or finished.
+ void SetPendingOperation(OperationType op);
+ void SetOperationFinished();
+
+ private:
+ int num_pending_ops_;
+ OperationType pending_op_;
+
+ // Set to true when the file has been successfully opened.
+ bool file_open_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileIOStateManager);
+};
+
+} // namespace ppapi
+
+#endif // PPAPI_SHARED_IMPL_FILE_IO_STATE_MANAGER_H_
+