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/c/pp_errors.h"
6#include "ppapi/c/private/ppb_flash_file.h"
7#include "ppapi/thunk/enter.h"
8#include "ppapi/thunk/ppb_flash_file_api.h"
9#include "ppapi/thunk/thunk.h"
10
11namespace ppapi {
12namespace thunk {
13
14namespace {
15
16bool CreateThreadAdapterForInstance(PP_Instance instance) {
17  return true;
18}
19
20void ClearThreadAdapterForInstance(PP_Instance instance) {
21}
22
23int32_t OpenFile(PP_Instance instance,
24                 const char* path,
25                 int32_t mode,
26                 PP_FileHandle* file) {
27  EnterInstanceAPI<PPB_Flash_File_API> enter(instance);
28  if (enter.failed())
29    return PP_ERROR_BADARGUMENT;
30  return enter.functions()->OpenFile(instance, path, mode, file);
31}
32
33int32_t RenameFile(PP_Instance instance,
34                   const char* path_from,
35                   const char* path_to) {
36  EnterInstanceAPI<PPB_Flash_File_API> enter(instance);
37  if (enter.failed())
38    return PP_ERROR_BADARGUMENT;
39  return enter.functions()->RenameFile(instance, path_from, path_to);
40}
41
42int32_t DeleteFileOrDir(PP_Instance instance,
43                        const char* path,
44                        PP_Bool recursive) {
45  EnterInstanceAPI<PPB_Flash_File_API> enter(instance);
46  if (enter.failed())
47    return PP_ERROR_BADARGUMENT;
48  return enter.functions()->DeleteFileOrDir(instance, path, recursive);
49}
50
51int32_t CreateDir(PP_Instance instance, const char* path) {
52  EnterInstanceAPI<PPB_Flash_File_API> enter(instance);
53  if (enter.failed())
54    return PP_ERROR_BADARGUMENT;
55  return enter.functions()->CreateDir(instance, path);
56}
57
58int32_t QueryFile(PP_Instance instance, const char* path, PP_FileInfo* info) {
59  EnterInstanceAPI<PPB_Flash_File_API> enter(instance);
60  if (enter.failed())
61    return PP_ERROR_BADARGUMENT;
62  return enter.functions()->QueryFile(instance, path, info);
63}
64
65int32_t GetDirContents(PP_Instance instance,
66                       const char* path,
67                       PP_DirContents_Dev** contents) {
68  EnterInstanceAPI<PPB_Flash_File_API> enter(instance);
69  if (enter.failed())
70    return PP_ERROR_BADARGUMENT;
71  return enter.functions()->GetDirContents(instance, path, contents);
72}
73
74void FreeDirContents(PP_Instance instance,
75                     PP_DirContents_Dev* contents) {
76  EnterInstanceAPI<PPB_Flash_File_API> enter(instance);
77  if (enter.succeeded())
78    enter.functions()->FreeDirContents(instance, contents);
79}
80
81int32_t CreateTemporaryFile(PP_Instance instance, PP_FileHandle* file) {
82  EnterInstanceAPI<PPB_Flash_File_API> enter(instance);
83  if (enter.failed())
84    return PP_ERROR_BADARGUMENT;
85
86  *file = PP_kInvalidFileHandle;
87  return enter.functions()->CreateTemporaryFile(instance, file);
88}
89
90const PPB_Flash_File_ModuleLocal_3_0 g_ppb_flash_file_modulelocal_thunk_3_0 = {
91  &CreateThreadAdapterForInstance,
92  &ClearThreadAdapterForInstance,
93  &OpenFile,
94  &RenameFile,
95  &DeleteFileOrDir,
96  &CreateDir,
97  &QueryFile,
98  &GetDirContents,
99  &FreeDirContents,
100  &CreateTemporaryFile
101};
102
103}  // namespace
104
105const PPB_Flash_File_ModuleLocal_3_0*
106    GetPPB_Flash_File_ModuleLocal_3_0_Thunk() {
107  return &g_ppb_flash_file_modulelocal_thunk_3_0;
108}
109
110}  // namespace thunk
111}  // namespace ppapi
112