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

Side by Side Diff: webkit/chromeos/fileapi/file_util_async.cc

Issue 8907014: Implement async verision of FileSystemFileUtil and in-memory file system for testing purposes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove Read() and Write() from FileUtilAsync Created 9 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/chromeos/fileapi/file_util_async.h"
6
7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop.h"
10
11 namespace fileapi {
12
13 FileUtilAsync::FileUtilAsync() {
14 }
15
16 // Depending on the flags value the flow of file opening will be one of
17 // the following:
18 //
19 // PLATFORM_FILE_OPEN:
20 // GetFileInfo
21 // DidGetFileInfoForOpen
22 // OpenVerifiedFile
23 //
24 // PLATFORM_FILE_CREATE:
25 // Create
26 // DidCreateOrTruncateForOpen
27 // OpenVerifiedFile
28 //
29 // PLATFORM_FILE_OPEN_ALWAYS:
30 // GetFileInfo
31 // DidGetFileInfoForOpen
32 // OpenVerifiedFile OR Create
33 // DidCreateOrTruncateForOpen
34 // OpenVerifiedFile
35 //
36 // PLATFORM_FILE_CREATE_ALWAYS:
37 // Truncate
38 // OpenTruncatedFileOrCreate
39 // OpenVerifiedFile OR Create
40 // DidCreateOrTruncateForOpen
41 // OpenVerifiedFile
42 //
43 // PLATFORM_FILE_OPEN_TRUNCATED:
44 // Truncate
45 // DidCreateOrTruncateForOpen
46 // OpenVerifiedFile
47 //
48 void FileUtilAsync::Open(
satorux1 2011/12/14 08:42:29 She was doubtful of having the default implementat
satorux1 2011/12/14 08:55:32 Moved to MemoryFileUtil.
Oleg Eterevsky 2011/12/14 15:20:59 To be honest, I'm not sure about this. Having the
49 const FilePath& file_path,
50 int flags,
51 const OpenCallback& callback) {
52 int create_flag = flags & (base::PLATFORM_FILE_OPEN |
53 base::PLATFORM_FILE_CREATE |
54 base::PLATFORM_FILE_OPEN_ALWAYS |
55 base::PLATFORM_FILE_CREATE_ALWAYS |
56 base::PLATFORM_FILE_OPEN_TRUNCATED);
57 switch (create_flag) {
58 case base::PLATFORM_FILE_OPEN:
59 case base::PLATFORM_FILE_OPEN_ALWAYS:
60 GetFileInfo(
61 file_path,
62 base::Bind(&FileUtilAsync::DidGetFileInfoForOpen,
63 base::Unretained(this), file_path, flags, callback));
64
65 break;
66
67 case base::PLATFORM_FILE_CREATE:
68 Create(
69 file_path,
70 base::Bind(&FileUtilAsync::DidCreateOrTruncateForOpen,
71 base::Unretained(this), file_path, flags, 0, callback));
72 break;
73
74 case base::PLATFORM_FILE_CREATE_ALWAYS:
75 Truncate(
76 file_path,
77 0,
78 base::Bind(&FileUtilAsync::OpenTruncatedFileOrCreate,
79 base::Unretained(this), file_path, flags, callback));
80
81 case base::PLATFORM_FILE_OPEN_TRUNCATED:
82 Truncate(
83 file_path,
84 0,
85 base::Bind(&FileUtilAsync::DidCreateOrTruncateForOpen,
86 base::Unretained(this), file_path, flags, 0, callback));
87 break;
88
89 default:
90 MessageLoop::current()->PostTask(
91 FROM_HERE,
92 base::Bind(callback,
93 base::PLATFORM_FILE_ERROR_INVALID_OPERATION,
94 static_cast<AsyncFileStream*>(NULL)));
95 }
96 }
97
98 void FileUtilAsync::DidGetFileInfoForOpen(
99 const FilePath& file_path,
100 int flags,
101 const OpenCallback& callback,
102 PlatformFileError get_info_result,
103 const base::PlatformFileInfo& file_info) {
104 if (get_info_result == base::PLATFORM_FILE_OK && file_info.is_directory) {
105 callback.Run(base::PLATFORM_FILE_ERROR_NOT_A_FILE, NULL);
106 return;
107 }
108
109 if (get_info_result == base::PLATFORM_FILE_OK) {
110 OpenVerifiedFile(file_path, flags, callback);
111 return;
112 }
113
114 if (get_info_result == base::PLATFORM_FILE_ERROR_NOT_FOUND &&
115 flags & base::PLATFORM_FILE_CREATE_ALWAYS) {
116 Create(file_path,
117 base::Bind(&FileUtilAsync::DidCreateOrTruncateForOpen,
118 base::Unretained(this), file_path, flags, 0, callback));
119 return;
120 }
121
122 callback.Run(get_info_result, NULL);
123 }
124
125 void FileUtilAsync::OpenTruncatedFileOrCreate(
126 const FilePath& file_path,
127 int flags,
128 const OpenCallback& callback,
129 PlatformFileError result) {
130 if (result == base::PLATFORM_FILE_OK) {
131 OpenVerifiedFile(file_path, flags, callback);
132 return;
133 }
134
135 if (result == base::PLATFORM_FILE_ERROR_NOT_FOUND) {
136 Create(
137 file_path,
138 base::Bind(&FileUtilAsync::DidCreateOrTruncateForOpen,
139 base::Unretained(this), file_path, flags, 0, callback));
140 return;
141 }
142
143 callback.Run(result, NULL);
144 }
145
146 void FileUtilAsync::DidCreateOrTruncateForOpen(
147 const FilePath& file_path,
148 int flags,
149 int64 size,
150 const OpenCallback& callback,
151 PlatformFileError result) {
152 if (result != base::PLATFORM_FILE_OK) {
153 callback.Run(result, NULL);
154 return;
155 }
156
157 OpenVerifiedFile(file_path, flags, callback);
158 }
159
160 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698