Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1415)

Side by Side Diff: webkit/plugins/ppapi/ppb_file_io_impl.h

Issue 7433006: Pepper quota support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updated Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_
6 #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ 6 #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_
7 7
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h"
11 #include "base/file_path.h" 12 #include "base/file_path.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_callback_factory.h" 14 #include "base/memory/scoped_callback_factory.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/platform_file.h" 16 #include "base/platform_file.h"
16 #include "ppapi/c/pp_file_info.h" 17 #include "ppapi/c/pp_file_info.h"
17 #include "ppapi/c/pp_time.h" 18 #include "ppapi/c/pp_time.h"
18 #include "ppapi/thunk/ppb_file_io_api.h" 19 #include "ppapi/thunk/ppb_file_io_api.h"
19 #include "webkit/plugins/ppapi/callbacks.h" 20 #include "webkit/plugins/ppapi/callbacks.h"
20 #include "webkit/plugins/ppapi/plugin_delegate.h" 21 #include "webkit/plugins/ppapi/plugin_delegate.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // If there are pending writes, any other kind of async operation is not 87 // If there are pending writes, any other kind of async operation is not
87 // allowed. 88 // allowed.
88 OPERATION_WRITE, 89 OPERATION_WRITE,
89 // If there is a pending operation that is neither read nor write, no 90 // If there is a pending operation that is neither read nor write, no
90 // further async operation is allowed. 91 // further async operation is allowed.
91 OPERATION_EXCLUSIVE, 92 OPERATION_EXCLUSIVE,
92 // There is no pending operation right now. 93 // There is no pending operation right now.
93 OPERATION_NONE, 94 OPERATION_NONE,
94 }; 95 };
95 96
97 struct PendingOperation {
98 enum Type { UNKNOWN, WRITE, SETLENGTH };
99 PendingOperation();
100 Type type;
101
102 // For WRITE.
103 int64_t offset;
104 const char* buffer;
105 int32_t bytes_to_write;
106
107 // For SETLENGTH.
108 int64_t length;
109 };
110
96 // Verifies: 111 // Verifies:
97 // - that |callback| is valid (only nonblocking operation supported); 112 // - that |callback| is valid (only nonblocking operation supported);
98 // - that the file is already open or not, depending on |should_be_open|; and 113 // - that the file is already open or not, depending on |should_be_open|; and
99 // - that no callback is already pending, or it is a read(write) request 114 // - that no callback is already pending, or it is a read(write) request
100 // and currently the pending operations are reads(writes). 115 // and currently the pending operations are reads(writes).
101 // Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if 116 // Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if
102 // the call should be aborted and that code returned to the plugin. 117 // the call should be aborted and that code returned to the plugin.
103 int32_t CommonCallValidation(bool should_be_open, 118 int32_t CommonCallValidation(bool should_be_open,
104 OperationType new_op, 119 OperationType new_op,
105 PP_CompletionCallback callback); 120 PP_CompletionCallback callback);
106 121
107 // Sets up a pending callback. This should only be called once it is certain 122 // Sets up a pending callback. This should only be called once it is certain
108 // that |PP_OK_COMPLETIONPENDING| will be returned. 123 // that |PP_OK_COMPLETIONPENDING| will be returned.
109 // |read_buffer| is only used by read operations. 124 // |read_buffer| is only used by read operations.
110 void RegisterCallback(OperationType op, 125 void RegisterCallback(std::queue<CallbackEntry>* callbacks,
126 OperationType op,
111 PP_CompletionCallback callback, 127 PP_CompletionCallback callback,
112 char* rend_buffer); 128 char* rend_buffer);
113 129 void RunAndRemoveFirstPendingCallback(std::queue<CallbackEntry>* callbacks,
114 void RunAndRemoveFirstPendingCallback(int32_t result); 130 int32_t result);
115 131
116 void StatusCallback(base::PlatformFileError error_code); 132 void StatusCallback(base::PlatformFileError error_code);
117 void AsyncOpenFileCallback(base::PlatformFileError error_code, 133 void AsyncOpenFileCallback(base::PlatformFileError error_code,
118 base::PassPlatformFile file); 134 base::PassPlatformFile file,
135 int64_t file_size);
119 void QueryInfoCallback(base::PlatformFileError error_code, 136 void QueryInfoCallback(base::PlatformFileError error_code,
120 const base::PlatformFileInfo& file_info); 137 const base::PlatformFileInfo& file_info);
121 void ReadCallback(base::PlatformFileError error_code, 138 void ReadCallback(base::PlatformFileError error_code,
122 const char* data, int bytes_read); 139 const char* data, int bytes_read);
123 void WriteCallback(base::PlatformFileError error_code, int bytes_written); 140 void WriteCallback(base::PlatformFileError error_code, int bytes_written);
141 void SetLengthCallback(base::PlatformFileError error_code);
142
143 bool DoesRequireQuotaCheck() const;
144 bool HasNoPendingWrites() const;
145 void QueryAvailableSpace(const PendingOperation& op);
146 void DidQueryAvailableSpace(int64_t avail_space);
124 147
125 base::ScopedCallbackFactory<PPB_FileIO_Impl> callback_factory_; 148 base::ScopedCallbackFactory<PPB_FileIO_Impl> callback_factory_;
126 149
127 base::PlatformFile file_; 150 base::PlatformFile file_;
128 PP_FileSystemType file_system_type_; 151 PP_FileSystemType file_system_type_;
129 152
153 // They are valid only for files of
154 // PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}.
155 GURL origin_url_;
156 int64_t file_size_;
157
158 // Valid only while there're pending write requests.
159 int64_t cached_available_space_;
160
130 std::queue<CallbackEntry> callbacks_; 161 std::queue<CallbackEntry> callbacks_;
131 OperationType pending_op_; 162 OperationType pending_op_;
132 163
133 // Output buffer pointer for |Query()|; only non-null when a callback is 164 // Output buffer pointer for |Query()|; only non-null when a callback is
134 // pending for it. 165 // pending for it.
135 PP_FileInfo* info_; 166 PP_FileInfo* info_;
136 167
168 std::queue<PendingOperation> pending_quota_checks_;
169 std::queue<CallbackEntry> pending_quota_check_callbacks_;
170
171 std::queue<int64_t> pending_write_offset_;
172 int64_t pending_setlength_length_;
173
137 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Impl); 174 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Impl);
138 }; 175 };
139 176
140 } // namespace ppapi 177 } // namespace ppapi
141 } // namespace webkit 178 } // namespace webkit
142 179
143 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ 180 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698