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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.cc

Issue 417983002: [fsp] Add support for truncating files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi le_util.h" 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi le_util.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 206 }
207 207
208 // Routes the response of CopyEntry to a callback of MoveLocalFile() on the 208 // Routes the response of CopyEntry to a callback of MoveLocalFile() on the
209 // IO thread. 209 // IO thread.
210 void OnMoveEntry(const fileapi::AsyncFileUtil::StatusCallback& callback, 210 void OnMoveEntry(const fileapi::AsyncFileUtil::StatusCallback& callback,
211 base::File::Error result) { 211 base::File::Error result) {
212 BrowserThread::PostTask( 212 BrowserThread::PostTask(
213 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); 213 BrowserThread::IO, FROM_HERE, base::Bind(callback, result));
214 } 214 }
215 215
216 // Executes Truncate on the UI thread.
217 void TruncateOnUIThread(
218 scoped_ptr<fileapi::FileSystemOperationContext> context,
219 const fileapi::FileSystemURL& url,
220 int64 length,
221 const fileapi::AsyncFileUtil::StatusCallback& callback) {
222 util::FileSystemURLParser parser(url);
223 if (!parser.Parse()) {
224 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
225 return;
226 }
227
228 parser.file_system()->Truncate(parser.file_path(), length, callback);
229 }
230
231 // Routes the response of Truncate back to the IO thread.
232 void OnTruncate(const fileapi::AsyncFileUtil::StatusCallback& callback,
233 base::File::Error result) {
234 BrowserThread::PostTask(
235 BrowserThread::IO, FROM_HERE, base::Bind(callback, result));
236 }
237
216 } // namespace 238 } // namespace
217 239
218 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} 240 ProviderAsyncFileUtil::ProviderAsyncFileUtil() {}
219 241
220 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {} 242 ProviderAsyncFileUtil::~ProviderAsyncFileUtil() {}
221 243
222 void ProviderAsyncFileUtil::CreateOrOpen( 244 void ProviderAsyncFileUtil::CreateOrOpen(
223 scoped_ptr<fileapi::FileSystemOperationContext> context, 245 scoped_ptr<fileapi::FileSystemOperationContext> context,
224 const fileapi::FileSystemURL& url, 246 const fileapi::FileSystemURL& url,
225 int file_flags, 247 int file_flags,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 DCHECK_CURRENTLY_ON(BrowserThread::IO); 327 DCHECK_CURRENTLY_ON(BrowserThread::IO);
306 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); 328 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED);
307 } 329 }
308 330
309 void ProviderAsyncFileUtil::Truncate( 331 void ProviderAsyncFileUtil::Truncate(
310 scoped_ptr<fileapi::FileSystemOperationContext> context, 332 scoped_ptr<fileapi::FileSystemOperationContext> context,
311 const fileapi::FileSystemURL& url, 333 const fileapi::FileSystemURL& url,
312 int64 length, 334 int64 length,
313 const StatusCallback& callback) { 335 const StatusCallback& callback) {
314 DCHECK_CURRENTLY_ON(BrowserThread::IO); 336 DCHECK_CURRENTLY_ON(BrowserThread::IO);
315 callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); 337 BrowserThread::PostTask(BrowserThread::UI,
338 FROM_HERE,
339 base::Bind(&TruncateOnUIThread,
340 base::Passed(&context),
341 url,
342 length,
343 base::Bind(&OnTruncate, callback)));
316 } 344 }
317 345
318 void ProviderAsyncFileUtil::CopyFileLocal( 346 void ProviderAsyncFileUtil::CopyFileLocal(
319 scoped_ptr<fileapi::FileSystemOperationContext> context, 347 scoped_ptr<fileapi::FileSystemOperationContext> context,
320 const fileapi::FileSystemURL& src_url, 348 const fileapi::FileSystemURL& src_url,
321 const fileapi::FileSystemURL& dest_url, 349 const fileapi::FileSystemURL& dest_url,
322 CopyOrMoveOption option, 350 CopyOrMoveOption option,
323 const CopyFileProgressCallback& progress_callback, 351 const CopyFileProgressCallback& progress_callback,
324 const StatusCallback& callback) { 352 const StatusCallback& callback) {
325 DCHECK_CURRENTLY_ON(BrowserThread::IO); 353 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 NOTIMPLEMENTED(); 439 NOTIMPLEMENTED();
412 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, 440 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION,
413 base::File::Info(), 441 base::File::Info(),
414 base::FilePath(), 442 base::FilePath(),
415 scoped_refptr<webkit_blob::ShareableFileReference>()); 443 scoped_refptr<webkit_blob::ShareableFileReference>());
416 } 444 }
417 445
418 } // namespace internal 446 } // namespace internal
419 } // namespace file_system_provider 447 } // namespace file_system_provider
420 } // namespace chromeos 448 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698