Chromium Code Reviews| Index: ppapi/shared_impl/file_io_state_manager.h |
| 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 0000000000000000000000000000000000000000..741951da09d990c6ed6f1e556cd719097d10dad9 |
| --- /dev/null |
| +++ b/ppapi/shared_impl/file_io_state_manager.h |
| @@ -0,0 +1,68 @@ |
| +// 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/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 recjected because of the current pending operation. Also, |
|
raymes
2012/11/29 23:55:19
-recjected->rejected
-There are 2 spaces at the en
victorhsieh
2012/11/30 01:17:21
I do see other 2 spaces after period in other ppap
|
| +// 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 GetPendingOperation() const { return pending_op_; } |
|
raymes
2012/11/29 23:55:19
Check the style guide for naming of inline getters
victorhsieh
2012/11/30 01:17:21
Done.
|
| + |
| + void SetOpenSucceed(); |
| + |
| + // Called before every "Validated" function. It is responsible to make sure |
|
raymes
2012/11/29 23:55:19
There are no longer "Validated" functions. Just sa
victorhsieh
2012/11/30 01:17:21
Done.
|
| + // that "state" is correct. For example, some operations are only valid after |
|
raymes
2012/11/29 23:55:19
"state"->state (no quotations needed)
victorhsieh
2012/11/30 01:17:21
Done.
|
| + // the file is opened, or operations might need to run excludively. See |
|
raymes
2012/11/29 23:55:19
-excludively->exclusively
-There are no subclasses
victorhsieh
2012/11/30 01:17:21
Done.
|
| + // subclasses implementation for detail. |
| + // |
| + // 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 OperationFinished(); |
|
raymes
2012/11/29 23:55:19
I would change this to SetOperationFinished to be
victorhsieh
2012/11/30 01:17:21
Done.
|
| + |
| + 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_ |