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

Side by Side Diff: webkit/fileapi/file_util_helper.cc

Issue 10834167: Create ShareableFileReference on IO thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adding unknown policy for DCHECK Created 8 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/fileapi/file_util_helper.h" 5 #include "webkit/fileapi/file_util_helper.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "webkit/blob/shareable_file_reference.h"
10 #include "webkit/fileapi/file_system_file_util.h" 9 #include "webkit/fileapi/file_system_file_util.h"
11 #include "webkit/fileapi/file_system_operation_context.h" 10 #include "webkit/fileapi/file_system_operation_context.h"
12 #include "webkit/fileapi/file_system_url.h" 11 #include "webkit/fileapi/file_system_url.h"
13 12
14 using base::PlatformFileError; 13 using base::PlatformFileError;
15 14
16 namespace fileapi { 15 namespace fileapi {
17 16
18 namespace { 17 namespace {
19 18
19 // A helper class to delete a temporary file.
20 class ScopedFileDeleter {
21 public:
22 explicit ScopedFileDeleter(const FilePath& path) : path_(path) {}
23 ~ScopedFileDeleter() {
24 file_util::Delete(path_, false /* recursive */);
25 }
26
27 private:
28 FilePath path_;
29 };
30
20 // A helper class for cross-FileUtil Copy/Move operations. 31 // A helper class for cross-FileUtil Copy/Move operations.
21 class CrossFileUtilHelper { 32 class CrossFileUtilHelper {
22 public: 33 public:
23 enum Operation { 34 enum Operation {
24 OPERATION_COPY, 35 OPERATION_COPY,
25 OPERATION_MOVE 36 OPERATION_MOVE
26 }; 37 };
27 38
28 CrossFileUtilHelper(FileSystemOperationContext* context, 39 CrossFileUtilHelper(FileSystemOperationContext* context,
29 FileSystemFileUtil* src_util, 40 FileSystemFileUtil* src_util,
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 DCHECK(src_util_ == dest_util_); 254 DCHECK(src_util_ == dest_util_);
244 // Source and destination are in the same FileSystemFileUtil; now we can 255 // Source and destination are in the same FileSystemFileUtil; now we can
245 // safely call FileSystemFileUtil method on src_util_ (== dest_util_). 256 // safely call FileSystemFileUtil method on src_util_ (== dest_util_).
246 return src_util_->CopyOrMoveFile(context_, src_url, dest_url, 257 return src_util_->CopyOrMoveFile(context_, src_url, dest_url,
247 operation_ == OPERATION_COPY); 258 operation_ == OPERATION_COPY);
248 } 259 }
249 260
250 // Resolve the src_url's underlying file path. 261 // Resolve the src_url's underlying file path.
251 base::PlatformFileInfo file_info; 262 base::PlatformFileInfo file_info;
252 FilePath platform_file_path; 263 FilePath platform_file_path;
253 PlatformFileError error = base::PLATFORM_FILE_OK; 264 FileSystemFileUtil::SnapshotFilePolicy snapshot_policy;
254 265
255 scoped_refptr<webkit_blob::ShareableFileReference> file_ref = 266 PlatformFileError error = src_util_->CreateSnapshotFile(
256 src_util_->CreateSnapshotFile(context_, src_url, 267 context_, src_url, &file_info, &platform_file_path, &snapshot_policy);
257 &error, &file_info, &platform_file_path);
258 if (error != base::PLATFORM_FILE_OK) 268 if (error != base::PLATFORM_FILE_OK)
259 return error; 269 return error;
260 270
271 scoped_ptr<ScopedFileDeleter> file_deleter;
272 if (snapshot_policy == FileSystemFileUtil::kSnapshotFileTemporary)
273 file_deleter.reset(new ScopedFileDeleter(platform_file_path));
274
261 // Call CopyInForeignFile() on the dest_util_ with the resolved source path 275 // Call CopyInForeignFile() on the dest_util_ with the resolved source path
262 // to perform limited cross-FileSystemFileUtil copy/move. 276 // to perform limited cross-FileSystemFileUtil copy/move.
263 error = dest_util_->CopyInForeignFile( 277 error = dest_util_->CopyInForeignFile(
264 context_, platform_file_path, dest_url); 278 context_, platform_file_path, dest_url);
265 279
266 if (operation_ == OPERATION_COPY || error != base::PLATFORM_FILE_OK) 280 if (operation_ == OPERATION_COPY || error != base::PLATFORM_FILE_OK)
267 return error; 281 return error;
268 return src_util_->DeleteFile(context_, src_url); 282 return src_util_->DeleteFile(context_, src_url);
269 } 283 }
270 284
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 context, url.WithPath(directories.top())); 378 context, url.WithPath(directories.top()));
365 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND && 379 if (error != base::PLATFORM_FILE_ERROR_NOT_FOUND &&
366 error != base::PLATFORM_FILE_OK) 380 error != base::PLATFORM_FILE_OK)
367 return error; 381 return error;
368 directories.pop(); 382 directories.pop();
369 } 383 }
370 return file_util->DeleteSingleDirectory(context, url); 384 return file_util->DeleteSingleDirectory(context, url);
371 } 385 }
372 386
373 } // namespace fileapi 387 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_file_util_proxy.cc ('k') | webkit/fileapi/local_file_system_operation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698