1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_
#define PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_
#include <deque>
#include "base/compiler_specific.h"
#include "ppapi/shared_impl/ppapi_shared_export.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/ppb_file_io_api.h"
namespace ppapi {
namespace thunk {
class PPB_FileRef_API;
}
class PPAPI_SHARED_EXPORT PPB_FileIO_Shared : public Resource,
public thunk::PPB_FileIO_API {
public:
PPB_FileIO_Shared(PP_Instance instance);
PPB_FileIO_Shared(const HostResource& host_resource);
~PPB_FileIO_Shared();
// Resource overrides.
virtual thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE;
// PPB_FileIO_API implementation.
virtual int32_t Open(PP_Resource file_ref,
int32_t open_flags,
PP_CompletionCallback callback) OVERRIDE;
virtual int32_t Query(PP_FileInfo* info,
PP_CompletionCallback callback) OVERRIDE;
virtual int32_t Touch(PP_Time last_access_time,
PP_Time last_modified_time,
PP_CompletionCallback callback) OVERRIDE;
virtual int32_t Read(int64_t offset,
char* buffer,
int32_t bytes_to_read,
PP_CompletionCallback callback) OVERRIDE;
virtual int32_t Write(int64_t offset,
const char* buffer,
int32_t bytes_to_write,
PP_CompletionCallback callback) OVERRIDE;
virtual int32_t SetLength(int64_t length,
PP_CompletionCallback callback) OVERRIDE;
virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE;
// Callback handler for different types of operations.
void ExecuteGeneralCallback(int32_t pp_error);
void ExecuteOpenFileCallback(int32_t pp_error);
void ExecuteQueryCallback(int32_t pp_error, const PP_FileInfo& info);
void ExecuteReadCallback(int32_t pp_error, const char* data);
protected:
struct CallbackEntry {
CallbackEntry();
CallbackEntry(const CallbackEntry& entry);
~CallbackEntry();
scoped_refptr<TrackedCallback> callback;
// Pointer back to the caller's read buffer; only used by |Read()|, NULL
// for non-read operations. Not owned.
char* read_buffer;
// Pointer back to the caller's PP_FileInfo structure for Query operations.
// NULL for non-query operations. Not owned.
PP_FileInfo* info;
};
enum OperationType {
// There is no pending operation right now.
OPERATION_NONE,
// If there are pending reads, any other kind of async operation is not
// allowed.
OPERATION_READ,
// If there are pending writes, any other kind of async operation is not
// allowed.
OPERATION_WRITE,
// If there is a pending operation that is neither read nor write, no
// further async operation is allowed.
OPERATION_EXCLUSIVE
};
// Validated versions of the FileIO API. Subclasses in the proxy and impl
// implement these so the common error checking stays here.
virtual int32_t OpenValidated(PP_Resource file_ref_resource,
thunk::PPB_FileRef_API* file_ref_api,
int32_t open_flags,
PP_CompletionCallback callback) = 0;
virtual int32_t QueryValidated(PP_FileInfo* info,
PP_CompletionCallback callback) = 0;
virtual int32_t TouchValidated(PP_Time last_access_time,
PP_Time last_modified_time,
PP_CompletionCallback callback) = 0;
virtual int32_t ReadValidated(int64_t offset,
char* buffer,
int32_t bytes_to_read,
PP_CompletionCallback callback) = 0;
virtual int32_t WriteValidated(int64_t offset,
const char* buffer,
int32_t bytes_to_write,
PP_CompletionCallback callback) = 0;
virtual int32_t SetLengthValidated(int64_t length,
PP_CompletionCallback callback) = 0;
virtual int32_t FlushValidated(PP_CompletionCallback callback) = 0;
// Called for every "Validated" function.
//
// This verifies that the callback is valid and that no callback is already
// pending, or it is a read(write) request and currently the pending
// operations are reads(writes).
//
// Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if
// the call should be aborted and that code returned to the plugin.
int32_t CommonCallValidation(bool should_be_open,
OperationType new_op,
PP_CompletionCallback callback);
// Sets up a pending callback. This should only be called once it is certain
// that |PP_OK_COMPLETIONPENDING| will be returned.
//
// |read_buffer| is only used by read operations, |info| is used only by
// query operations.
void RegisterCallback(OperationType op,
PP_CompletionCallback callback,
char* read_buffer,
PP_FileInfo* info);
// Pops the oldest callback from the queue and runs it.
void RunAndRemoveFirstPendingCallback(int32_t result);
// The file system type specified in the Open() call. This will be
// PP_FILESYSTEMTYPE_INVALID before open was called. This value does not
// indicate that the open command actually succeeded.
PP_FileSystemType file_system_type_;
// Set to true when the file has been successfully opened.
bool file_open_;
std::deque<CallbackEntry> callbacks_;
OperationType pending_op_;
DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Shared);
};
} // namespace ppapi
#endif // PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_
|