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

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: '' 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"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // If there are pending writes, any other kind of async operation is not 86 // If there are pending writes, any other kind of async operation is not
87 // allowed. 87 // allowed.
88 OPERATION_WRITE, 88 OPERATION_WRITE,
89 // If there is a pending operation that is neither read nor write, no 89 // If there is a pending operation that is neither read nor write, no
90 // further async operation is allowed. 90 // further async operation is allowed.
91 OPERATION_EXCLUSIVE, 91 OPERATION_EXCLUSIVE,
92 // There is no pending operation right now. 92 // There is no pending operation right now.
93 OPERATION_NONE, 93 OPERATION_NONE,
94 }; 94 };
95 95
96 struct PendingOperation {
yzshen1 2011/07/21 22:23:34 It seems we have two kinds of "pending" now. - cal
kinuko 2011/07/26 16:27:46 I've moved all the quota-related 'pending' bookkee
97 enum Type { UNKNOWN, WRITE, SETLENGTH, WILL_WRITE, WILL_SETLENGTH };
98 PendingOperation();
99 Type type;
100
101 // For WRITE.
102 int64_t offset;
103 const char* buffer;
104 int32_t bytes_to_write;
105
106 // For SETLENGTH.
107 int64_t length;
108 };
109
96 // Verifies: 110 // Verifies:
97 // - that |callback| is valid (only nonblocking operation supported); 111 // - that |callback| is valid (only nonblocking operation supported);
98 // - that the file is already open or not, depending on |should_be_open|; and 112 // - 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 113 // - that no callback is already pending, or it is a read(write) request
100 // and currently the pending operations are reads(writes). 114 // and currently the pending operations are reads(writes).
101 // Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if 115 // 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. 116 // the call should be aborted and that code returned to the plugin.
103 int32_t CommonCallValidation(bool should_be_open, 117 int32_t CommonCallValidation(bool should_be_open,
104 OperationType new_op, 118 OperationType new_op,
105 PP_CompletionCallback callback); 119 PP_CompletionCallback callback);
106 120
107 // Sets up a pending callback. This should only be called once it is certain 121 // Sets up a pending callback. This should only be called once it is certain
108 // that |PP_OK_COMPLETIONPENDING| will be returned. 122 // that |PP_OK_COMPLETIONPENDING| will be returned.
109 // |read_buffer| is only used by read operations. 123 // |read_buffer| is only used by read operations.
110 void RegisterCallback(OperationType op, 124 void RegisterCallback(std::queue<CallbackEntry>* callbacks,
125 OperationType op,
111 PP_CompletionCallback callback, 126 PP_CompletionCallback callback,
112 char* rend_buffer); 127 char* rend_buffer);
113 128 void RunAndRemoveFirstPendingCallback(std::queue<CallbackEntry>* callbacks,
114 void RunAndRemoveFirstPendingCallback(int32_t result); 129 int32_t result);
115 130
116 void StatusCallback(base::PlatformFileError error_code); 131 void StatusCallback(base::PlatformFileError error_code);
117 void AsyncOpenFileCallback(base::PlatformFileError error_code, 132 void AsyncOpenFileCallback(base::PlatformFileError error_code,
118 base::PassPlatformFile file); 133 base::PassPlatformFile file);
119 void QueryInfoCallback(base::PlatformFileError error_code, 134 void QueryInfoCallback(base::PlatformFileError error_code,
120 const base::PlatformFileInfo& file_info); 135 const base::PlatformFileInfo& file_info);
121 void ReadCallback(base::PlatformFileError error_code, 136 void ReadCallback(base::PlatformFileError error_code,
122 const char* data, int bytes_read); 137 const char* data, int bytes_read);
123 void WriteCallback(base::PlatformFileError error_code, int bytes_written); 138 void WriteCallback(base::PlatformFileError error_code, int bytes_written);
139 void SetLengthCallback(base::PlatformFileError error_code);
140
141 // Quota related methods.
142 bool DoesRequireQuotaCheck() const;
143 bool QueryFileSizeAndQuota(const PendingOperation& op);
144 void DidQueryInfoForQuota(base::PlatformFileError error_code,
145 const base::PlatformFileInfo& file_info);
146 void DidQueryAvailableSpace(int64_t avail_space);
147 void DidQueryFileSizeAndQuota();
148 bool CommonQuotaCheck(int64_t growth);
124 149
125 base::ScopedCallbackFactory<PPB_FileIO_Impl> callback_factory_; 150 base::ScopedCallbackFactory<PPB_FileIO_Impl> callback_factory_;
126 151
127 base::PlatformFile file_; 152 base::PlatformFile file_;
128 PP_FileSystemType file_system_type_; 153 PP_FileSystemType file_system_type_;
129 154
155 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}.
156 GURL path_url_;
157
130 std::queue<CallbackEntry> callbacks_; 158 std::queue<CallbackEntry> callbacks_;
131 OperationType pending_op_; 159 OperationType pending_op_;
132 160
133 // Output buffer pointer for |Query()|; only non-null when a callback is 161 // Output buffer pointer for |Query()|; only non-null when a callback is
134 // pending for it. 162 // pending for it.
135 PP_FileInfo* info_; 163 PP_FileInfo* info_;
136 164
165 // Valid only while there're pending write requests.
yzshen1 2011/07/21 22:23:34 I think SetLength/Will* also use this, right? (PS
kinuko 2011/07/26 16:27:46 Fixed the comment (in quota_file_io.h)
166 int64_t cached_file_size_;
167 int64_t cached_available_space_;
168
169 // For async quota query bookkeeping.
170 int outstanding_quota_queries_;
171 int outstanding_errors_;
172 std::queue<PendingOperation> pending_quota_checks_;
173 std::queue<CallbackEntry> pending_quota_check_callbacks_;
yzshen1 2011/07/21 22:23:34 I would suggest that you don't keep another Callba
kinuko 2011/07/26 16:27:46 In the new QuotaFileIO class I organized the code/
174 bool did_notify_will_update_;
175
176 std::queue<int64_t> pending_write_offset_;
yzshen1 2011/07/21 22:23:34 I think this should be part of CallbackEntry, righ
kinuko 2011/07/26 16:27:46 Similarly they now belong to each (QuotaFileIO's)
177 int64_t pending_setlength_length_;
178 int64_t max_written_offset_;
179
137 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Impl); 180 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Impl);
138 }; 181 };
139 182
140 } // namespace ppapi 183 } // namespace ppapi
141 } // namespace webkit 184 } // namespace webkit
142 185
143 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ 186 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698