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

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

Issue 14075016: Change some snapshot- or temporary-file related changes to use ScopedFile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 8 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
« no previous file with comments | « webkit/fileapi/async_file_util.h ('k') | webkit/fileapi/file_snapshot_policy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/fileapi/async_file_util_adapter.h" 5 #include "webkit/fileapi/async_file_util_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/sequenced_task_runner.h" 8 #include "base/sequenced_task_runner.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "webkit/blob/shareable_file_reference.h"
10 #include "webkit/fileapi/file_system_context.h" 11 #include "webkit/fileapi/file_system_context.h"
11 #include "webkit/fileapi/file_system_file_util.h" 12 #include "webkit/fileapi/file_system_file_util.h"
12 #include "webkit/fileapi/file_system_operation_context.h" 13 #include "webkit/fileapi/file_system_operation_context.h"
13 #include "webkit/fileapi/file_system_url.h" 14 #include "webkit/fileapi/file_system_url.h"
14 #include "webkit/fileapi/file_system_util.h" 15 #include "webkit/fileapi/file_system_util.h"
15 16
16 namespace fileapi {
17
18 using base::Bind; 17 using base::Bind;
19 using base::Callback; 18 using base::Callback;
20 using base::Owned; 19 using base::Owned;
21 using base::PlatformFileError; 20 using base::PlatformFileError;
22 using base::Unretained; 21 using base::Unretained;
22 using webkit_blob::ShareableFileReference;
23
24 namespace fileapi {
23 25
24 namespace { 26 namespace {
25 27
26 class EnsureFileExistsHelper { 28 class EnsureFileExistsHelper {
27 public: 29 public:
28 EnsureFileExistsHelper() : error_(base::PLATFORM_FILE_OK), created_(false) {} 30 EnsureFileExistsHelper() : error_(base::PLATFORM_FILE_OK), created_(false) {}
29 31
30 void RunWork(FileSystemFileUtil* file_util, 32 void RunWork(FileSystemFileUtil* file_util,
31 FileSystemOperationContext* context, 33 FileSystemOperationContext* context,
32 const FileSystemURL& url) { 34 const FileSystemURL& url) {
33 error_ = file_util->EnsureFileExists(context, url, &created_); 35 error_ = file_util->EnsureFileExists(context, url, &created_);
34 } 36 }
35 37
36 void Reply(const AsyncFileUtil::EnsureFileExistsCallback& callback) { 38 void Reply(const AsyncFileUtil::EnsureFileExistsCallback& callback) {
37 if (!callback.is_null()) 39 if (!callback.is_null())
38 callback.Run(error_, created_); 40 callback.Run(error_, created_);
39 } 41 }
40 42
41 private: 43 private:
42 base::PlatformFileError error_; 44 base::PlatformFileError error_;
43 bool created_; 45 bool created_;
44 DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper); 46 DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper);
45 }; 47 };
46 48
47 class GetFileInfoHelper { 49 class GetFileInfoHelper {
48 public: 50 public:
49 GetFileInfoHelper() 51 GetFileInfoHelper()
50 : error_(base::PLATFORM_FILE_OK), 52 : error_(base::PLATFORM_FILE_OK) {}
51 snapshot_policy_(kSnapshotFileUnknown) {}
52 53
53 void GetFileInfo(FileSystemFileUtil* file_util, 54 void GetFileInfo(FileSystemFileUtil* file_util,
54 FileSystemOperationContext* context, 55 FileSystemOperationContext* context,
55 const FileSystemURL& url) { 56 const FileSystemURL& url) {
56 error_ = file_util->GetFileInfo(context, url, &file_info_, &platform_path_); 57 error_ = file_util->GetFileInfo(context, url, &file_info_, &platform_path_);
57 } 58 }
58 59
59 void CreateSnapshotFile(FileSystemFileUtil* file_util, 60 void CreateSnapshotFile(FileSystemFileUtil* file_util,
60 FileSystemOperationContext* context, 61 FileSystemOperationContext* context,
61 const FileSystemURL& url) { 62 const FileSystemURL& url) {
62 error_ = file_util->CreateSnapshotFile( 63 scoped_file_ = file_util->CreateSnapshotFile(
63 context, url, &file_info_, &platform_path_, &snapshot_policy_); 64 context, url, &error_, &file_info_, &platform_path_);
64 } 65 }
65 66
66 void ReplyFileInfo(const AsyncFileUtil::GetFileInfoCallback& callback) { 67 void ReplyFileInfo(const AsyncFileUtil::GetFileInfoCallback& callback) {
67 if (!callback.is_null()) 68 if (!callback.is_null())
68 callback.Run(error_, file_info_, platform_path_); 69 callback.Run(error_, file_info_, platform_path_);
69 } 70 }
70 71
71 void ReplySnapshotFile( 72 void ReplySnapshotFile(
72 const AsyncFileUtil::CreateSnapshotFileCallback& callback) { 73 const AsyncFileUtil::CreateSnapshotFileCallback& callback) {
73 DCHECK(snapshot_policy_ != kSnapshotFileUnknown);
74 if (!callback.is_null()) 74 if (!callback.is_null())
75 callback.Run(error_, file_info_, platform_path_, snapshot_policy_); 75 callback.Run(error_, file_info_, platform_path_,
76 ShareableFileReference::GetOrCreate(scoped_file_.Pass()));
76 } 77 }
77 78
78 private: 79 private:
79 base::PlatformFileError error_; 80 base::PlatformFileError error_;
80 base::PlatformFileInfo file_info_; 81 base::PlatformFileInfo file_info_;
81 base::FilePath platform_path_; 82 base::FilePath platform_path_;
82 SnapshotFilePolicy snapshot_policy_; 83 webkit_blob::ScopedFile scoped_file_;
83 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper); 84 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper);
84 }; 85 };
85 86
86 class ReadDirectoryHelper { 87 class ReadDirectoryHelper {
87 public: 88 public:
88 ReadDirectoryHelper() : error_(base::PLATFORM_FILE_OK) {} 89 ReadDirectoryHelper() : error_(base::PLATFORM_FILE_OK) {}
89 90
90 void RunWork(FileSystemFileUtil* file_util, 91 void RunWork(FileSystemFileUtil* file_util,
91 FileSystemOperationContext* context, 92 FileSystemOperationContext* context,
92 const FileSystemURL& url) { 93 const FileSystemURL& url) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 const CreateSnapshotFileCallback& callback) { 298 const CreateSnapshotFileCallback& callback) {
298 GetFileInfoHelper* helper = new GetFileInfoHelper; 299 GetFileInfoHelper* helper = new GetFileInfoHelper;
299 return context->task_runner()->PostTaskAndReply( 300 return context->task_runner()->PostTaskAndReply(
300 FROM_HERE, 301 FROM_HERE,
301 Bind(&GetFileInfoHelper::CreateSnapshotFile, Unretained(helper), 302 Bind(&GetFileInfoHelper::CreateSnapshotFile, Unretained(helper),
302 sync_file_util_.get(), context, url), 303 sync_file_util_.get(), context, url),
303 Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback)); 304 Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback));
304 } 305 }
305 306
306 } // namespace fileapi 307 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/async_file_util.h ('k') | webkit/fileapi/file_snapshot_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698