[M108 Aura Migration][NaCl][PPFwk] Add error logs + SVACE/DLOG/Static analysis fix
[platform/framework/web/chromium-efl.git] / ppapi / shared_impl / file_io_state_manager.cc
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ppapi/shared_impl/file_io_state_manager.h"
6
7 #include "base/check_op.h"
8 #include "base/logging.h"
9 #include "ppapi/c/pp_errors.h"
10
11 namespace ppapi {
12
13 FileIOStateManager::FileIOStateManager()
14     : num_pending_ops_(0), pending_op_(OPERATION_NONE), file_open_(false) {}
15
16 FileIOStateManager::~FileIOStateManager() {}
17
18 void FileIOStateManager::SetOpenSucceed() { file_open_ = true; }
19
20 int32_t FileIOStateManager::CheckOperationState(OperationType new_op,
21                                                 bool should_be_open) {
22   if (should_be_open) {
23     if (!file_open_) {
24       LOG(ERROR) << "File not opened";
25       return PP_ERROR_FAILED;
26     }
27   } else {
28     if (file_open_) {
29       LOG(ERROR) << "File already opened";
30       return PP_ERROR_FAILED;
31     }
32   }
33
34   if (pending_op_ != OPERATION_NONE &&
35       (pending_op_ != new_op || pending_op_ == OPERATION_EXCLUSIVE)) {
36     LOG(ERROR) << "Operation is in progress";
37     return PP_ERROR_INPROGRESS;
38   }
39
40   return PP_OK;
41 }
42
43 void FileIOStateManager::SetPendingOperation(OperationType new_op) {
44   DCHECK(pending_op_ == OPERATION_NONE ||
45          (pending_op_ != OPERATION_EXCLUSIVE && pending_op_ == new_op));
46   pending_op_ = new_op;
47   num_pending_ops_++;
48 }
49
50 void FileIOStateManager::SetOperationFinished() {
51   DCHECK_GT(num_pending_ops_, 0);
52   if (--num_pending_ops_ == 0)
53     pending_op_ = OPERATION_NONE;
54 }
55
56 }  // namespace ppapi