1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PPAPI_SHARED_IMPL_FILE_IO_STATE_MANAGER_H_
6 #define PPAPI_SHARED_IMPL_FILE_IO_STATE_MANAGER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "ppapi/c/pp_stdint.h"
11 #include "ppapi/shared_impl/ppapi_shared_export.h"
15 // FileIOStateManager is a helper class that maintains the state of operations.
16 // For example, some operations are mutually exclusive, meaning that an
17 // operation could be rejected because of the current pending operation. Also,
18 // most of the operations only work when the file has been opened.
19 class PPAPI_SHARED_EXPORT FileIOStateManager
{
22 ~FileIOStateManager();
25 // There is no pending operation right now.
28 // If there are pending reads, any other kind of async operation is not
32 // If there are pending writes, any other kind of async operation is not
36 // If there is a pending operation that is neither read nor write, no
37 // further async operation is allowed.
41 OperationType
get_pending_operation() const { return pending_op_
; }
43 void SetOpenSucceed();
45 // Called at the beginning of each operation. It is responsible to make sure
46 // that state is correct. For example, some operations are only valid after
47 // the file is opened, or operations might need to run exclusively.
49 // It returns |PP_OK| on success, or |PP_ERROR_...| for various reasons.
50 int32_t CheckOperationState(OperationType new_op
, bool should_be_open
);
52 // Marks the state of current operations as started or finished.
53 void SetPendingOperation(OperationType op
);
54 void SetOperationFinished();
58 OperationType pending_op_
;
60 // Set to true when the file has been successfully opened.
63 DISALLOW_COPY_AND_ASSIGN(FileIOStateManager
);
68 #endif // PPAPI_SHARED_IMPL_FILE_IO_STATE_MANAGER_H_