[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / ppapi / shared_impl / file_io_state_manager.h
blob1c4fa1a9cdad83755377184c911b8e1f0bb109b4
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"
13 namespace ppapi {
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 {
20 public:
21 FileIOStateManager();
22 ~FileIOStateManager();
24 enum OperationType {
25 // There is no pending operation right now.
26 OPERATION_NONE,
28 // If there are pending reads, any other kind of async operation is not
29 // allowed.
30 OPERATION_READ,
32 // If there are pending writes, any other kind of async operation is not
33 // allowed.
34 OPERATION_WRITE,
36 // If there is a pending operation that is neither read nor write, no
37 // further async operation is allowed.
38 OPERATION_EXCLUSIVE
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();
56 private:
57 int num_pending_ops_;
58 OperationType pending_op_;
60 // Set to true when the file has been successfully opened.
61 bool file_open_;
63 DISALLOW_COPY_AND_ASSIGN(FileIOStateManager);
66 } // namespace ppapi
68 #endif // PPAPI_SHARED_IMPL_FILE_IO_STATE_MANAGER_H_