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

Side by Side Diff: ppapi/proxy/file_system_resource.cc

Issue 130053003: [Pepper] Wire up append mode writing support of FileIO (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/max_written_offsets/file_sizes/g Created 6 years, 11 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "ppapi/proxy/file_system_resource.h" 5 #include "ppapi/proxy/file_system_resource.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "ipc/ipc_message.h" 9 #include "ipc/ipc_message.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 callback_result_ = params.result(); 168 callback_result_ = params.result();
169 // Received callback from browser and renderer. 169 // Received callback from browser and renderer.
170 if (callback_count_ == 2) 170 if (callback_count_ == 2)
171 callback.Run(callback_result_); 171 callback.Run(callback_result_);
172 } 172 }
173 173
174 void FileSystemResource::ReserveQuota(int64_t amount) { 174 void FileSystemResource::ReserveQuota(int64_t amount) {
175 DCHECK(!reserving_quota_); 175 DCHECK(!reserving_quota_);
176 reserving_quota_ = true; 176 reserving_quota_ = true;
177 177
178 // TODO(tzik): Use FileGrowthMap here after the IPC signature changed. 178 FileGrowthMap file_growths;
179 FileSizeMap file_sizes;
180 for (std::set<PP_Resource>::iterator it = files_.begin(); 179 for (std::set<PP_Resource>::iterator it = files_.begin();
181 it != files_.end(); ++it) { 180 it != files_.end(); ++it) {
182 EnterResourceNoLock<PPB_FileIO_API> enter(*it, true); 181 EnterResourceNoLock<PPB_FileIO_API> enter(*it, true);
183 if (enter.failed()) { 182 if (enter.failed()) {
184 NOTREACHED(); 183 NOTREACHED();
185 continue; 184 continue;
186 } 185 }
187 PPB_FileIO_API* file_io_api = enter.object(); 186 PPB_FileIO_API* file_io_api = enter.object();
188 file_sizes[*it] = 187 file_growths[*it] = FileGrowth(
189 file_io_api->GetMaxWrittenOffset() + 188 file_io_api->GetMaxWrittenOffset(),
190 file_io_api->GetAppendModeWriteAmount(); 189 file_io_api->GetAppendModeWriteAmount());
191 } 190 }
192 Call<PpapiPluginMsg_FileSystem_ReserveQuotaReply>(BROWSER, 191 Call<PpapiPluginMsg_FileSystem_ReserveQuotaReply>(BROWSER,
193 PpapiHostMsg_FileSystem_ReserveQuota(amount, file_sizes), 192 PpapiHostMsg_FileSystem_ReserveQuota(amount, file_growths),
194 base::Bind(&FileSystemResource::ReserveQuotaComplete, 193 base::Bind(&FileSystemResource::ReserveQuotaComplete,
195 this)); 194 this));
196 } 195 }
197 196
198 void FileSystemResource::ReserveQuotaComplete( 197 void FileSystemResource::ReserveQuotaComplete(
199 const ResourceMessageReplyParams& params, 198 const ResourceMessageReplyParams& params,
200 int64_t amount, 199 int64_t amount,
201 const FileSizeMap& max_written_offsets) { 200 const FileSizeMap& file_sizes) {
202 DCHECK(reserving_quota_); 201 DCHECK(reserving_quota_);
203 reserving_quota_ = false; 202 reserving_quota_ = false;
204 reserved_quota_ = amount; 203 reserved_quota_ = amount;
205 204
206 for (FileSizeMap::const_iterator it = max_written_offsets.begin(); 205 for (FileSizeMap::const_iterator it = file_sizes.begin();
207 it != max_written_offsets.end(); ++it) { 206 it != file_sizes.end(); ++it) {
208 EnterResourceNoLock<PPB_FileIO_API> enter(it->first, true); 207 EnterResourceNoLock<PPB_FileIO_API> enter(it->first, true);
209 208
210 // It is possible that the host has sent an offset for a file that has been 209 // It is possible that the host has sent an offset for a file that has been
211 // destroyed in the plugin. Ignore it. 210 // destroyed in the plugin. Ignore it.
212 if (enter.failed()) 211 if (enter.failed())
213 continue; 212 continue;
214 PPB_FileIO_API* file_io_api = enter.object(); 213 PPB_FileIO_API* file_io_api = enter.object();
215 file_io_api->SetMaxWrittenOffset(it->second); 214 file_io_api->SetMaxWrittenOffset(it->second);
216 file_io_api->SetAppendModeWriteAmount(0); 215 file_io_api->SetAppendModeWriteAmount(0);
217 } 216 }
(...skipping 15 matching lines...) Expand all
233 // Refresh the quota reservation for the first pending request that we 232 // Refresh the quota reservation for the first pending request that we
234 // can't satisfy. 233 // can't satisfy.
235 ReserveQuota(request.amount); 234 ReserveQuota(request.amount);
236 break; 235 break;
237 } 236 }
238 } 237 }
239 } 238 }
240 239
241 } // namespace proxy 240 } // namespace proxy
242 } // namespace ppapi 241 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698