• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "ppapi/shared_impl/file_io_state_manager.h"
6 
7 #include "base/logging.h"
8 #include "ppapi/c/pp_errors.h"
9 
10 namespace ppapi {
11 
FileIOStateManager()12 FileIOStateManager::FileIOStateManager()
13     : num_pending_ops_(0), pending_op_(OPERATION_NONE), file_open_(false) {}
14 
~FileIOStateManager()15 FileIOStateManager::~FileIOStateManager() {}
16 
SetOpenSucceed()17 void FileIOStateManager::SetOpenSucceed() { file_open_ = true; }
18 
CheckOperationState(OperationType new_op,bool should_be_open)19 int32_t FileIOStateManager::CheckOperationState(OperationType new_op,
20                                                 bool should_be_open) {
21   if (should_be_open) {
22     if (!file_open_)
23       return PP_ERROR_FAILED;
24   } else {
25     if (file_open_)
26       return PP_ERROR_FAILED;
27   }
28 
29   if (pending_op_ != OPERATION_NONE &&
30       (pending_op_ != new_op || pending_op_ == OPERATION_EXCLUSIVE))
31     return PP_ERROR_INPROGRESS;
32 
33   return PP_OK;
34 }
35 
SetPendingOperation(OperationType new_op)36 void FileIOStateManager::SetPendingOperation(OperationType new_op) {
37   DCHECK(pending_op_ == OPERATION_NONE ||
38          (pending_op_ != OPERATION_EXCLUSIVE && pending_op_ == new_op));
39   pending_op_ = new_op;
40   num_pending_ops_++;
41 }
42 
SetOperationFinished()43 void FileIOStateManager::SetOperationFinished() {
44   DCHECK_GT(num_pending_ops_, 0);
45   if (--num_pending_ops_ == 0)
46     pending_op_ = OPERATION_NONE;
47 }
48 
49 }  // namespace ppapi
50