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

Side by Side Diff: webkit/browser/fileapi/file_system_operation_impl.cc

Issue 21370003: Rename fileapi::LocalFileSystemOperation to FileSystemOperationImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 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/browser/fileapi/local_file_system_operation.h" 5 #include "webkit/browser/fileapi/file_system_operation_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "net/base/escape.h" 11 #include "net/base/escape.h"
12 #include "net/url_request/url_request.h" 12 #include "net/url_request/url_request.h"
13 #include "webkit/browser/fileapi/async_file_util.h" 13 #include "webkit/browser/fileapi/async_file_util.h"
14 #include "webkit/browser/fileapi/copy_or_move_operation_delegate.h" 14 #include "webkit/browser/fileapi/copy_or_move_operation_delegate.h"
15 #include "webkit/browser/fileapi/file_observers.h" 15 #include "webkit/browser/fileapi/file_observers.h"
16 #include "webkit/browser/fileapi/file_system_backend.h" 16 #include "webkit/browser/fileapi/file_system_backend.h"
17 #include "webkit/browser/fileapi/file_system_context.h" 17 #include "webkit/browser/fileapi/file_system_context.h"
18 #include "webkit/browser/fileapi/file_system_file_util.h" 18 #include "webkit/browser/fileapi/file_system_file_util.h"
19 #include "webkit/browser/fileapi/file_system_operation_context.h" 19 #include "webkit/browser/fileapi/file_system_operation_context.h"
20 #include "webkit/browser/fileapi/file_system_task_runners.h" 20 #include "webkit/browser/fileapi/file_system_task_runners.h"
21 #include "webkit/browser/fileapi/file_system_url.h" 21 #include "webkit/browser/fileapi/file_system_url.h"
22 #include "webkit/browser/fileapi/file_writer_delegate.h" 22 #include "webkit/browser/fileapi/file_writer_delegate.h"
23 #include "webkit/browser/fileapi/remove_operation_delegate.h" 23 #include "webkit/browser/fileapi/remove_operation_delegate.h"
24 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" 24 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h"
25 #include "webkit/browser/quota/quota_manager.h" 25 #include "webkit/browser/quota/quota_manager.h"
26 #include "webkit/common/blob/shareable_file_reference.h" 26 #include "webkit/common/blob/shareable_file_reference.h"
27 #include "webkit/common/fileapi/file_system_types.h" 27 #include "webkit/common/fileapi/file_system_types.h"
28 #include "webkit/common/fileapi/file_system_util.h" 28 #include "webkit/common/fileapi/file_system_util.h"
29 #include "webkit/common/quota/quota_types.h" 29 #include "webkit/common/quota/quota_types.h"
30 30
31 using webkit_blob::ScopedFile; 31 using webkit_blob::ScopedFile;
32 32
33 namespace fileapi { 33 namespace fileapi {
34 34
35 LocalFileSystemOperation::LocalFileSystemOperation( 35 FileSystemOperationImpl::FileSystemOperationImpl(
36 const FileSystemURL& url, 36 const FileSystemURL& url,
37 FileSystemContext* file_system_context, 37 FileSystemContext* file_system_context,
38 scoped_ptr<FileSystemOperationContext> operation_context) 38 scoped_ptr<FileSystemOperationContext> operation_context)
39 : file_system_context_(file_system_context), 39 : file_system_context_(file_system_context),
40 operation_context_(operation_context.Pass()), 40 operation_context_(operation_context.Pass()),
41 async_file_util_(NULL), 41 async_file_util_(NULL),
42 peer_handle_(base::kNullProcessHandle), 42 peer_handle_(base::kNullProcessHandle),
43 pending_operation_(kOperationNone) { 43 pending_operation_(kOperationNone) {
44 DCHECK(operation_context_.get()); 44 DCHECK(operation_context_.get());
45 operation_context_->DetachUserDataThread(); 45 operation_context_->DetachUserDataThread();
46 async_file_util_ = file_system_context_->GetAsyncFileUtil(url.type()); 46 async_file_util_ = file_system_context_->GetAsyncFileUtil(url.type());
47 DCHECK(async_file_util_); 47 DCHECK(async_file_util_);
48 } 48 }
49 49
50 LocalFileSystemOperation::~LocalFileSystemOperation() { 50 FileSystemOperationImpl::~FileSystemOperationImpl() {
51 } 51 }
52 52
53 void LocalFileSystemOperation::CreateFile(const FileSystemURL& url, 53 void FileSystemOperationImpl::CreateFile(const FileSystemURL& url,
54 bool exclusive, 54 bool exclusive,
55 const StatusCallback& callback) { 55 const StatusCallback& callback) {
56 DCHECK(SetPendingOperationType(kOperationCreateFile)); 56 DCHECK(SetPendingOperationType(kOperationCreateFile));
57 GetUsageAndQuotaThenRunTask( 57 GetUsageAndQuotaThenRunTask(
58 url, 58 url,
59 base::Bind(&LocalFileSystemOperation::DoCreateFile, 59 base::Bind(&FileSystemOperationImpl::DoCreateFile,
60 AsWeakPtr(), url, callback, exclusive), 60 AsWeakPtr(), url, callback, exclusive),
61 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 61 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
62 } 62 }
63 63
64 void LocalFileSystemOperation::CreateDirectory(const FileSystemURL& url, 64 void FileSystemOperationImpl::CreateDirectory(const FileSystemURL& url,
65 bool exclusive, 65 bool exclusive,
66 bool recursive, 66 bool recursive,
67 const StatusCallback& callback) { 67 const StatusCallback& callback) {
68 DCHECK(SetPendingOperationType(kOperationCreateDirectory)); 68 DCHECK(SetPendingOperationType(kOperationCreateDirectory));
69 GetUsageAndQuotaThenRunTask( 69 GetUsageAndQuotaThenRunTask(
70 url, 70 url,
71 base::Bind(&LocalFileSystemOperation::DoCreateDirectory, 71 base::Bind(&FileSystemOperationImpl::DoCreateDirectory,
72 AsWeakPtr(), url, callback, exclusive, recursive), 72 AsWeakPtr(), url, callback, exclusive, recursive),
73 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 73 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
74 } 74 }
75 75
76 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, 76 void FileSystemOperationImpl::Copy(const FileSystemURL& src_url,
77 const FileSystemURL& dest_url, 77 const FileSystemURL& dest_url,
78 const StatusCallback& callback) { 78 const StatusCallback& callback) {
79 DCHECK(SetPendingOperationType(kOperationCopy)); 79 DCHECK(SetPendingOperationType(kOperationCopy));
80 DCHECK(!recursive_operation_delegate_); 80 DCHECK(!recursive_operation_delegate_);
81 recursive_operation_delegate_.reset( 81 recursive_operation_delegate_.reset(
82 new CopyOrMoveOperationDelegate( 82 new CopyOrMoveOperationDelegate(
83 file_system_context(), 83 file_system_context(),
84 src_url, dest_url, 84 src_url, dest_url,
85 CopyOrMoveOperationDelegate::OPERATION_COPY, 85 CopyOrMoveOperationDelegate::OPERATION_COPY,
86 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 86 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
87 AsWeakPtr(), callback))); 87 AsWeakPtr(), callback)));
88 recursive_operation_delegate_->RunRecursively(); 88 recursive_operation_delegate_->RunRecursively();
89 } 89 }
90 90
91 void LocalFileSystemOperation::Move(const FileSystemURL& src_url, 91 void FileSystemOperationImpl::Move(const FileSystemURL& src_url,
92 const FileSystemURL& dest_url, 92 const FileSystemURL& dest_url,
93 const StatusCallback& callback) { 93 const StatusCallback& callback) {
94 DCHECK(SetPendingOperationType(kOperationMove)); 94 DCHECK(SetPendingOperationType(kOperationMove));
95 DCHECK(!recursive_operation_delegate_); 95 DCHECK(!recursive_operation_delegate_);
96 recursive_operation_delegate_.reset( 96 recursive_operation_delegate_.reset(
97 new CopyOrMoveOperationDelegate( 97 new CopyOrMoveOperationDelegate(
98 file_system_context(), 98 file_system_context(),
99 src_url, dest_url, 99 src_url, dest_url,
100 CopyOrMoveOperationDelegate::OPERATION_MOVE, 100 CopyOrMoveOperationDelegate::OPERATION_MOVE,
101 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 101 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
102 AsWeakPtr(), callback))); 102 AsWeakPtr(), callback)));
103 recursive_operation_delegate_->RunRecursively(); 103 recursive_operation_delegate_->RunRecursively();
104 } 104 }
105 105
106 void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url, 106 void FileSystemOperationImpl::DirectoryExists(const FileSystemURL& url,
107 const StatusCallback& callback) { 107 const StatusCallback& callback) {
108 DCHECK(SetPendingOperationType(kOperationDirectoryExists)); 108 DCHECK(SetPendingOperationType(kOperationDirectoryExists));
109 async_file_util_->GetFileInfo( 109 async_file_util_->GetFileInfo(
110 operation_context_.Pass(), url, 110 operation_context_.Pass(), url,
111 base::Bind(&LocalFileSystemOperation::DidDirectoryExists, 111 base::Bind(&FileSystemOperationImpl::DidDirectoryExists,
112 AsWeakPtr(), callback)); 112 AsWeakPtr(), callback));
113 } 113 }
114 114
115 void LocalFileSystemOperation::FileExists(const FileSystemURL& url, 115 void FileSystemOperationImpl::FileExists(const FileSystemURL& url,
116 const StatusCallback& callback) { 116 const StatusCallback& callback) {
117 DCHECK(SetPendingOperationType(kOperationFileExists)); 117 DCHECK(SetPendingOperationType(kOperationFileExists));
118 async_file_util_->GetFileInfo( 118 async_file_util_->GetFileInfo(
119 operation_context_.Pass(), url, 119 operation_context_.Pass(), url,
120 base::Bind(&LocalFileSystemOperation::DidFileExists, 120 base::Bind(&FileSystemOperationImpl::DidFileExists,
121 AsWeakPtr(), callback)); 121 AsWeakPtr(), callback));
122 } 122 }
123 123
124 void LocalFileSystemOperation::GetMetadata( 124 void FileSystemOperationImpl::GetMetadata(
125 const FileSystemURL& url, const GetMetadataCallback& callback) { 125 const FileSystemURL& url, const GetMetadataCallback& callback) {
126 DCHECK(SetPendingOperationType(kOperationGetMetadata)); 126 DCHECK(SetPendingOperationType(kOperationGetMetadata));
127 async_file_util_->GetFileInfo(operation_context_.Pass(), url, callback); 127 async_file_util_->GetFileInfo(operation_context_.Pass(), url, callback);
128 } 128 }
129 129
130 void LocalFileSystemOperation::ReadDirectory( 130 void FileSystemOperationImpl::ReadDirectory(
131 const FileSystemURL& url, const ReadDirectoryCallback& callback) { 131 const FileSystemURL& url, const ReadDirectoryCallback& callback) {
132 DCHECK(SetPendingOperationType(kOperationReadDirectory)); 132 DCHECK(SetPendingOperationType(kOperationReadDirectory));
133 async_file_util_->ReadDirectory( 133 async_file_util_->ReadDirectory(
134 operation_context_.Pass(), url, callback); 134 operation_context_.Pass(), url, callback);
135 } 135 }
136 136
137 void LocalFileSystemOperation::Remove(const FileSystemURL& url, 137 void FileSystemOperationImpl::Remove(const FileSystemURL& url,
138 bool recursive, 138 bool recursive,
139 const StatusCallback& callback) { 139 const StatusCallback& callback) {
140 DCHECK(SetPendingOperationType(kOperationRemove)); 140 DCHECK(SetPendingOperationType(kOperationRemove));
141 DCHECK(!recursive_operation_delegate_); 141 DCHECK(!recursive_operation_delegate_);
142 142
143 if (recursive) { 143 if (recursive) {
144 // For recursive removal, try to delegate the operation to AsyncFileUtil 144 // For recursive removal, try to delegate the operation to AsyncFileUtil
145 // first. If not supported, it is delegated to RemoveOperationDelegate 145 // first. If not supported, it is delegated to RemoveOperationDelegate
146 // in DidDeleteRecursively. 146 // in DidDeleteRecursively.
147 async_file_util_->DeleteRecursively( 147 async_file_util_->DeleteRecursively(
148 operation_context_.Pass(), url, 148 operation_context_.Pass(), url,
149 base::Bind(&LocalFileSystemOperation::DidDeleteRecursively, 149 base::Bind(&FileSystemOperationImpl::DidDeleteRecursively,
150 AsWeakPtr(), url, callback)); 150 AsWeakPtr(), url, callback));
151 return; 151 return;
152 } 152 }
153 153
154 recursive_operation_delegate_.reset( 154 recursive_operation_delegate_.reset(
155 new RemoveOperationDelegate( 155 new RemoveOperationDelegate(
156 file_system_context(), url, 156 file_system_context(), url,
157 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 157 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
158 AsWeakPtr(), callback))); 158 AsWeakPtr(), callback)));
159 recursive_operation_delegate_->Run(); 159 recursive_operation_delegate_->Run();
160 } 160 }
161 161
162 void LocalFileSystemOperation::Write( 162 void FileSystemOperationImpl::Write(
163 const FileSystemURL& url, 163 const FileSystemURL& url,
164 scoped_ptr<FileWriterDelegate> writer_delegate, 164 scoped_ptr<FileWriterDelegate> writer_delegate,
165 scoped_ptr<net::URLRequest> blob_request, 165 scoped_ptr<net::URLRequest> blob_request,
166 const WriteCallback& callback) { 166 const WriteCallback& callback) {
167 DCHECK(SetPendingOperationType(kOperationWrite)); 167 DCHECK(SetPendingOperationType(kOperationWrite));
168 file_writer_delegate_ = writer_delegate.Pass(); 168 file_writer_delegate_ = writer_delegate.Pass();
169 file_writer_delegate_->Start( 169 file_writer_delegate_->Start(
170 blob_request.Pass(), 170 blob_request.Pass(),
171 base::Bind(&LocalFileSystemOperation::DidWrite, AsWeakPtr(), 171 base::Bind(&FileSystemOperationImpl::DidWrite, AsWeakPtr(),
172 url, callback)); 172 url, callback));
173 } 173 }
174 174
175 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, 175 void FileSystemOperationImpl::Truncate(const FileSystemURL& url, int64 length,
176 const StatusCallback& callback) { 176 const StatusCallback& callback) {
177 DCHECK(SetPendingOperationType(kOperationTruncate)); 177 DCHECK(SetPendingOperationType(kOperationTruncate));
178 GetUsageAndQuotaThenRunTask( 178 GetUsageAndQuotaThenRunTask(
179 url, 179 url,
180 base::Bind(&LocalFileSystemOperation::DoTruncate, 180 base::Bind(&FileSystemOperationImpl::DoTruncate,
181 AsWeakPtr(), url, callback, length), 181 AsWeakPtr(), url, callback, length),
182 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 182 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
183 } 183 }
184 184
185 void LocalFileSystemOperation::TouchFile(const FileSystemURL& url, 185 void FileSystemOperationImpl::TouchFile(const FileSystemURL& url,
186 const base::Time& last_access_time, 186 const base::Time& last_access_time,
187 const base::Time& last_modified_time, 187 const base::Time& last_modified_time,
188 const StatusCallback& callback) { 188 const StatusCallback& callback) {
189 DCHECK(SetPendingOperationType(kOperationTouchFile)); 189 DCHECK(SetPendingOperationType(kOperationTouchFile));
190 async_file_util_->Touch( 190 async_file_util_->Touch(
191 operation_context_.Pass(), url, 191 operation_context_.Pass(), url,
192 last_access_time, last_modified_time, 192 last_access_time, last_modified_time,
193 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 193 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
194 AsWeakPtr(), callback)); 194 AsWeakPtr(), callback));
195 } 195 }
196 196
197 void LocalFileSystemOperation::OpenFile(const FileSystemURL& url, 197 void FileSystemOperationImpl::OpenFile(const FileSystemURL& url,
198 int file_flags, 198 int file_flags,
199 base::ProcessHandle peer_handle, 199 base::ProcessHandle peer_handle,
200 const OpenFileCallback& callback) { 200 const OpenFileCallback& callback) {
201 DCHECK(SetPendingOperationType(kOperationOpenFile)); 201 DCHECK(SetPendingOperationType(kOperationOpenFile));
202 peer_handle_ = peer_handle; 202 peer_handle_ = peer_handle;
203 203
204 if (file_flags & ( 204 if (file_flags & (
205 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | 205 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY |
206 base::PLATFORM_FILE_HIDDEN))) { 206 base::PLATFORM_FILE_HIDDEN))) {
207 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, 207 callback.Run(base::PLATFORM_FILE_ERROR_FAILED,
208 base::kInvalidPlatformFileValue, 208 base::kInvalidPlatformFileValue,
209 base::Closure(), 209 base::Closure(),
210 base::kNullProcessHandle); 210 base::kNullProcessHandle);
211 return; 211 return;
212 } 212 }
213 GetUsageAndQuotaThenRunTask( 213 GetUsageAndQuotaThenRunTask(
214 url, 214 url,
215 base::Bind(&LocalFileSystemOperation::DoOpenFile, 215 base::Bind(&FileSystemOperationImpl::DoOpenFile,
216 AsWeakPtr(), 216 AsWeakPtr(),
217 url, callback, file_flags), 217 url, callback, file_flags),
218 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, 218 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED,
219 base::kInvalidPlatformFileValue, 219 base::kInvalidPlatformFileValue,
220 base::Closure(), 220 base::Closure(),
221 base::kNullProcessHandle)); 221 base::kNullProcessHandle));
222 } 222 }
223 223
224 // We can only get here on a write or truncate that's not yet completed. 224 // We can only get here on a write or truncate that's not yet completed.
225 // We don't support cancelling any other operation at this time. 225 // We don't support cancelling any other operation at this time.
226 void LocalFileSystemOperation::Cancel(const StatusCallback& cancel_callback) { 226 void FileSystemOperationImpl::Cancel(const StatusCallback& cancel_callback) {
227 DCHECK(cancel_callback_.is_null()); 227 DCHECK(cancel_callback_.is_null());
228 cancel_callback_ = cancel_callback; 228 cancel_callback_ = cancel_callback;
229 229
230 if (file_writer_delegate_.get()) { 230 if (file_writer_delegate_.get()) {
231 DCHECK_EQ(kOperationWrite, pending_operation_); 231 DCHECK_EQ(kOperationWrite, pending_operation_);
232 // This will call DidWrite() with ABORT status code. 232 // This will call DidWrite() with ABORT status code.
233 file_writer_delegate_->Cancel(); 233 file_writer_delegate_->Cancel();
234 } else { 234 } else {
235 // For truncate we have no way to cancel the inflight operation (for now). 235 // For truncate we have no way to cancel the inflight operation (for now).
236 // Let it just run and dispatch cancel callback later. 236 // Let it just run and dispatch cancel callback later.
237 DCHECK_EQ(kOperationTruncate, pending_operation_); 237 DCHECK_EQ(kOperationTruncate, pending_operation_);
238 } 238 }
239 } 239 }
240 240
241 LocalFileSystemOperation* 241 FileSystemOperationImpl* FileSystemOperationImpl::AsFileSystemOperationImpl() {
242 LocalFileSystemOperation::AsLocalFileSystemOperation() {
243 return this; 242 return this;
244 } 243 }
245 244
246 base::PlatformFileError LocalFileSystemOperation::SyncGetPlatformPath( 245 base::PlatformFileError FileSystemOperationImpl::SyncGetPlatformPath(
247 const FileSystemURL& url, 246 const FileSystemURL& url,
248 base::FilePath* platform_path) { 247 base::FilePath* platform_path) {
249 DCHECK(SetPendingOperationType(kOperationGetLocalPath)); 248 DCHECK(SetPendingOperationType(kOperationGetLocalPath));
250 FileSystemFileUtil* file_util = file_system_context()->GetFileUtil( 249 FileSystemFileUtil* file_util = file_system_context()->GetFileUtil(
251 url.type()); 250 url.type());
252 if (!file_util) 251 if (!file_util)
253 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; 252 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
254 file_util->GetLocalFilePath(operation_context_.get(), url, platform_path); 253 file_util->GetLocalFilePath(operation_context_.get(), url, platform_path);
255 return base::PLATFORM_FILE_OK; 254 return base::PLATFORM_FILE_OK;
256 } 255 }
257 256
258 void LocalFileSystemOperation::CreateSnapshotFile( 257 void FileSystemOperationImpl::CreateSnapshotFile(
259 const FileSystemURL& url, 258 const FileSystemURL& url,
260 const SnapshotFileCallback& callback) { 259 const SnapshotFileCallback& callback) {
261 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile)); 260 DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile));
262 async_file_util_->CreateSnapshotFile( 261 async_file_util_->CreateSnapshotFile(
263 operation_context_.Pass(), url, callback); 262 operation_context_.Pass(), url, callback);
264 } 263 }
265 264
266 void LocalFileSystemOperation::CopyInForeignFile( 265 void FileSystemOperationImpl::CopyInForeignFile(
267 const base::FilePath& src_local_disk_file_path, 266 const base::FilePath& src_local_disk_file_path,
268 const FileSystemURL& dest_url, 267 const FileSystemURL& dest_url,
269 const StatusCallback& callback) { 268 const StatusCallback& callback) {
270 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); 269 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile));
271 GetUsageAndQuotaThenRunTask( 270 GetUsageAndQuotaThenRunTask(
272 dest_url, 271 dest_url,
273 base::Bind(&LocalFileSystemOperation::DoCopyInForeignFile, 272 base::Bind(&FileSystemOperationImpl::DoCopyInForeignFile,
274 AsWeakPtr(), src_local_disk_file_path, dest_url, 273 AsWeakPtr(), src_local_disk_file_path, dest_url,
275 callback), 274 callback),
276 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 275 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
277 } 276 }
278 277
279 void LocalFileSystemOperation::RemoveFile( 278 void FileSystemOperationImpl::RemoveFile(
280 const FileSystemURL& url, 279 const FileSystemURL& url,
281 const StatusCallback& callback) { 280 const StatusCallback& callback) {
282 DCHECK(SetPendingOperationType(kOperationRemove)); 281 DCHECK(SetPendingOperationType(kOperationRemove));
283 async_file_util_->DeleteFile( 282 async_file_util_->DeleteFile(
284 operation_context_.Pass(), url, 283 operation_context_.Pass(), url,
285 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 284 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
286 AsWeakPtr(), callback)); 285 AsWeakPtr(), callback));
287 } 286 }
288 287
289 void LocalFileSystemOperation::RemoveDirectory( 288 void FileSystemOperationImpl::RemoveDirectory(
290 const FileSystemURL& url, 289 const FileSystemURL& url,
291 const StatusCallback& callback) { 290 const StatusCallback& callback) {
292 DCHECK(SetPendingOperationType(kOperationRemove)); 291 DCHECK(SetPendingOperationType(kOperationRemove));
293 async_file_util_->DeleteDirectory( 292 async_file_util_->DeleteDirectory(
294 operation_context_.Pass(), url, 293 operation_context_.Pass(), url,
295 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 294 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
296 AsWeakPtr(), callback)); 295 AsWeakPtr(), callback));
297 } 296 }
298 297
299 void LocalFileSystemOperation::CopyFileLocal( 298 void FileSystemOperationImpl::CopyFileLocal(
300 const FileSystemURL& src_url, 299 const FileSystemURL& src_url,
301 const FileSystemURL& dest_url, 300 const FileSystemURL& dest_url,
302 const StatusCallback& callback) { 301 const StatusCallback& callback) {
303 DCHECK(SetPendingOperationType(kOperationCopy)); 302 DCHECK(SetPendingOperationType(kOperationCopy));
304 DCHECK(src_url.IsInSameFileSystem(dest_url)); 303 DCHECK(src_url.IsInSameFileSystem(dest_url));
305 GetUsageAndQuotaThenRunTask( 304 GetUsageAndQuotaThenRunTask(
306 dest_url, 305 dest_url,
307 base::Bind(&LocalFileSystemOperation::DoCopyFileLocal, 306 base::Bind(&FileSystemOperationImpl::DoCopyFileLocal,
308 AsWeakPtr(), src_url, dest_url, callback), 307 AsWeakPtr(), src_url, dest_url, callback),
309 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 308 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
310 } 309 }
311 310
312 void LocalFileSystemOperation::MoveFileLocal( 311 void FileSystemOperationImpl::MoveFileLocal(
313 const FileSystemURL& src_url, 312 const FileSystemURL& src_url,
314 const FileSystemURL& dest_url, 313 const FileSystemURL& dest_url,
315 const StatusCallback& callback) { 314 const StatusCallback& callback) {
316 DCHECK(SetPendingOperationType(kOperationMove)); 315 DCHECK(SetPendingOperationType(kOperationMove));
317 DCHECK(src_url.IsInSameFileSystem(dest_url)); 316 DCHECK(src_url.IsInSameFileSystem(dest_url));
318 GetUsageAndQuotaThenRunTask( 317 GetUsageAndQuotaThenRunTask(
319 dest_url, 318 dest_url,
320 base::Bind(&LocalFileSystemOperation::DoMoveFileLocal, 319 base::Bind(&FileSystemOperationImpl::DoMoveFileLocal,
321 AsWeakPtr(), src_url, dest_url, callback), 320 AsWeakPtr(), src_url, dest_url, callback),
322 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); 321 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
323 } 322 }
324 323
325 void LocalFileSystemOperation::GetUsageAndQuotaThenRunTask( 324 void FileSystemOperationImpl::GetUsageAndQuotaThenRunTask(
326 const FileSystemURL& url, 325 const FileSystemURL& url,
327 const base::Closure& task, 326 const base::Closure& task,
328 const base::Closure& error_callback) { 327 const base::Closure& error_callback) {
329 quota::QuotaManagerProxy* quota_manager_proxy = 328 quota::QuotaManagerProxy* quota_manager_proxy =
330 file_system_context()->quota_manager_proxy(); 329 file_system_context()->quota_manager_proxy();
331 if (!quota_manager_proxy || 330 if (!quota_manager_proxy ||
332 !file_system_context()->GetQuotaUtil(url.type())) { 331 !file_system_context()->GetQuotaUtil(url.type())) {
333 // If we don't have the quota manager or the requested filesystem type 332 // If we don't have the quota manager or the requested filesystem type
334 // does not support quota, we should be able to let it go. 333 // does not support quota, we should be able to let it go.
335 operation_context_->set_allowed_bytes_growth(kint64max); 334 operation_context_->set_allowed_bytes_growth(kint64max);
336 task.Run(); 335 task.Run();
337 return; 336 return;
338 } 337 }
339 338
340 DCHECK(quota_manager_proxy); 339 DCHECK(quota_manager_proxy);
341 DCHECK(quota_manager_proxy->quota_manager()); 340 DCHECK(quota_manager_proxy->quota_manager());
342 quota_manager_proxy->quota_manager()->GetUsageAndQuota( 341 quota_manager_proxy->quota_manager()->GetUsageAndQuota(
343 url.origin(), 342 url.origin(),
344 FileSystemTypeToQuotaStorageType(url.type()), 343 FileSystemTypeToQuotaStorageType(url.type()),
345 base::Bind(&LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask, 344 base::Bind(&FileSystemOperationImpl::DidGetUsageAndQuotaAndRunTask,
346 AsWeakPtr(), task, error_callback)); 345 AsWeakPtr(), task, error_callback));
347 } 346 }
348 347
349 void LocalFileSystemOperation::DidGetUsageAndQuotaAndRunTask( 348 void FileSystemOperationImpl::DidGetUsageAndQuotaAndRunTask(
350 const base::Closure& task, 349 const base::Closure& task,
351 const base::Closure& error_callback, 350 const base::Closure& error_callback,
352 quota::QuotaStatusCode status, 351 quota::QuotaStatusCode status,
353 int64 usage, int64 quota) { 352 int64 usage, int64 quota) {
354 if (status != quota::kQuotaStatusOk) { 353 if (status != quota::kQuotaStatusOk) {
355 LOG(WARNING) << "Got unexpected quota error : " << status; 354 LOG(WARNING) << "Got unexpected quota error : " << status;
356 error_callback.Run(); 355 error_callback.Run();
357 return; 356 return;
358 } 357 }
359 358
360 operation_context_->set_allowed_bytes_growth(quota - usage); 359 operation_context_->set_allowed_bytes_growth(quota - usage);
361 task.Run(); 360 task.Run();
362 } 361 }
363 362
364 void LocalFileSystemOperation::DoCreateFile( 363 void FileSystemOperationImpl::DoCreateFile(
365 const FileSystemURL& url, 364 const FileSystemURL& url,
366 const StatusCallback& callback, 365 const StatusCallback& callback,
367 bool exclusive) { 366 bool exclusive) {
368 async_file_util_->EnsureFileExists( 367 async_file_util_->EnsureFileExists(
369 operation_context_.Pass(), url, 368 operation_context_.Pass(), url,
370 base::Bind( 369 base::Bind(
371 exclusive ? 370 exclusive ?
372 &LocalFileSystemOperation::DidEnsureFileExistsExclusive : 371 &FileSystemOperationImpl::DidEnsureFileExistsExclusive :
373 &LocalFileSystemOperation::DidEnsureFileExistsNonExclusive, 372 &FileSystemOperationImpl::DidEnsureFileExistsNonExclusive,
374 AsWeakPtr(), callback)); 373 AsWeakPtr(), callback));
375 } 374 }
376 375
377 void LocalFileSystemOperation::DoCreateDirectory( 376 void FileSystemOperationImpl::DoCreateDirectory(
378 const FileSystemURL& url, 377 const FileSystemURL& url,
379 const StatusCallback& callback, 378 const StatusCallback& callback,
380 bool exclusive, bool recursive) { 379 bool exclusive, bool recursive) {
381 async_file_util_->CreateDirectory( 380 async_file_util_->CreateDirectory(
382 operation_context_.Pass(), 381 operation_context_.Pass(),
383 url, exclusive, recursive, 382 url, exclusive, recursive,
384 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 383 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
385 AsWeakPtr(), callback)); 384 AsWeakPtr(), callback));
386 } 385 }
387 386
388 void LocalFileSystemOperation::DoCopyFileLocal( 387 void FileSystemOperationImpl::DoCopyFileLocal(
389 const FileSystemURL& src_url, 388 const FileSystemURL& src_url,
390 const FileSystemURL& dest_url, 389 const FileSystemURL& dest_url,
391 const StatusCallback& callback) { 390 const StatusCallback& callback) {
392 async_file_util_->CopyFileLocal( 391 async_file_util_->CopyFileLocal(
393 operation_context_.Pass(), src_url, dest_url, 392 operation_context_.Pass(), src_url, dest_url,
394 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 393 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
395 AsWeakPtr(), callback)); 394 AsWeakPtr(), callback));
396 } 395 }
397 396
398 void LocalFileSystemOperation::DoMoveFileLocal( 397 void FileSystemOperationImpl::DoMoveFileLocal(
399 const FileSystemURL& src_url, 398 const FileSystemURL& src_url,
400 const FileSystemURL& dest_url, 399 const FileSystemURL& dest_url,
401 const StatusCallback& callback) { 400 const StatusCallback& callback) {
402 async_file_util_->MoveFileLocal( 401 async_file_util_->MoveFileLocal(
403 operation_context_.Pass(), src_url, dest_url, 402 operation_context_.Pass(), src_url, dest_url,
404 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 403 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
405 AsWeakPtr(), callback)); 404 AsWeakPtr(), callback));
406 } 405 }
407 406
408 void LocalFileSystemOperation::DoCopyInForeignFile( 407 void FileSystemOperationImpl::DoCopyInForeignFile(
409 const base::FilePath& src_local_disk_file_path, 408 const base::FilePath& src_local_disk_file_path,
410 const FileSystemURL& dest_url, 409 const FileSystemURL& dest_url,
411 const StatusCallback& callback) { 410 const StatusCallback& callback) {
412 async_file_util_->CopyInForeignFile( 411 async_file_util_->CopyInForeignFile(
413 operation_context_.Pass(), 412 operation_context_.Pass(),
414 src_local_disk_file_path, dest_url, 413 src_local_disk_file_path, dest_url,
415 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 414 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
416 AsWeakPtr(), callback)); 415 AsWeakPtr(), callback));
417 } 416 }
418 417
419 void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url, 418 void FileSystemOperationImpl::DoTruncate(const FileSystemURL& url,
420 const StatusCallback& callback, 419 const StatusCallback& callback,
421 int64 length) { 420 int64 length) {
422 async_file_util_->Truncate( 421 async_file_util_->Truncate(
423 operation_context_.Pass(), url, length, 422 operation_context_.Pass(), url, length,
424 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 423 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
425 AsWeakPtr(), callback)); 424 AsWeakPtr(), callback));
426 } 425 }
427 426
428 void LocalFileSystemOperation::DoOpenFile(const FileSystemURL& url, 427 void FileSystemOperationImpl::DoOpenFile(const FileSystemURL& url,
429 const OpenFileCallback& callback, 428 const OpenFileCallback& callback,
430 int file_flags) { 429 int file_flags) {
431 async_file_util_->CreateOrOpen( 430 async_file_util_->CreateOrOpen(
432 operation_context_.Pass(), url, file_flags, 431 operation_context_.Pass(), url, file_flags,
433 base::Bind(&LocalFileSystemOperation::DidOpenFile, 432 base::Bind(&FileSystemOperationImpl::DidOpenFile,
434 AsWeakPtr(), callback)); 433 AsWeakPtr(), callback));
435 } 434 }
436 435
437 void LocalFileSystemOperation::DidEnsureFileExistsExclusive( 436 void FileSystemOperationImpl::DidEnsureFileExistsExclusive(
438 const StatusCallback& callback, 437 const StatusCallback& callback,
439 base::PlatformFileError rv, bool created) { 438 base::PlatformFileError rv, bool created) {
440 if (rv == base::PLATFORM_FILE_OK && !created) { 439 if (rv == base::PLATFORM_FILE_OK && !created) {
441 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS); 440 callback.Run(base::PLATFORM_FILE_ERROR_EXISTS);
442 } else { 441 } else {
443 DidFinishOperation(callback, rv); 442 DidFinishOperation(callback, rv);
444 } 443 }
445 } 444 }
446 445
447 void LocalFileSystemOperation::DidEnsureFileExistsNonExclusive( 446 void FileSystemOperationImpl::DidEnsureFileExistsNonExclusive(
448 const StatusCallback& callback, 447 const StatusCallback& callback,
449 base::PlatformFileError rv, bool /* created */) { 448 base::PlatformFileError rv, bool /* created */) {
450 DidFinishOperation(callback, rv); 449 DidFinishOperation(callback, rv);
451 } 450 }
452 451
453 void LocalFileSystemOperation::DidFinishOperation( 452 void FileSystemOperationImpl::DidFinishOperation(
454 const StatusCallback& callback, 453 const StatusCallback& callback,
455 base::PlatformFileError rv) { 454 base::PlatformFileError rv) {
456 if (!cancel_callback_.is_null()) { 455 if (!cancel_callback_.is_null()) {
457 DCHECK_EQ(kOperationTruncate, pending_operation_); 456 DCHECK_EQ(kOperationTruncate, pending_operation_);
458 457
459 StatusCallback cancel_callback = cancel_callback_; 458 StatusCallback cancel_callback = cancel_callback_;
460 callback.Run(base::PLATFORM_FILE_ERROR_ABORT); 459 callback.Run(base::PLATFORM_FILE_ERROR_ABORT);
461 cancel_callback.Run(base::PLATFORM_FILE_OK); 460 cancel_callback.Run(base::PLATFORM_FILE_OK);
462 } else { 461 } else {
463 callback.Run(rv); 462 callback.Run(rv);
464 } 463 }
465 } 464 }
466 465
467 void LocalFileSystemOperation::DidDirectoryExists( 466 void FileSystemOperationImpl::DidDirectoryExists(
468 const StatusCallback& callback, 467 const StatusCallback& callback,
469 base::PlatformFileError rv, 468 base::PlatformFileError rv,
470 const base::PlatformFileInfo& file_info) { 469 const base::PlatformFileInfo& file_info) {
471 if (rv == base::PLATFORM_FILE_OK && !file_info.is_directory) 470 if (rv == base::PLATFORM_FILE_OK && !file_info.is_directory)
472 rv = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; 471 rv = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
473 callback.Run(rv); 472 callback.Run(rv);
474 } 473 }
475 474
476 void LocalFileSystemOperation::DidFileExists( 475 void FileSystemOperationImpl::DidFileExists(
477 const StatusCallback& callback, 476 const StatusCallback& callback,
478 base::PlatformFileError rv, 477 base::PlatformFileError rv,
479 const base::PlatformFileInfo& file_info) { 478 const base::PlatformFileInfo& file_info) {
480 if (rv == base::PLATFORM_FILE_OK && file_info.is_directory) 479 if (rv == base::PLATFORM_FILE_OK && file_info.is_directory)
481 rv = base::PLATFORM_FILE_ERROR_NOT_A_FILE; 480 rv = base::PLATFORM_FILE_ERROR_NOT_A_FILE;
482 callback.Run(rv); 481 callback.Run(rv);
483 } 482 }
484 483
485 void LocalFileSystemOperation::DidDeleteRecursively( 484 void FileSystemOperationImpl::DidDeleteRecursively(
486 const FileSystemURL& url, 485 const FileSystemURL& url,
487 const StatusCallback& callback, 486 const StatusCallback& callback,
488 base::PlatformFileError rv) { 487 base::PlatformFileError rv) {
489 if (rv == base::PLATFORM_FILE_ERROR_INVALID_OPERATION) { 488 if (rv == base::PLATFORM_FILE_ERROR_INVALID_OPERATION) {
490 // Recursive removal is not supported on this platform. 489 // Recursive removal is not supported on this platform.
491 DCHECK(!recursive_operation_delegate_); 490 DCHECK(!recursive_operation_delegate_);
492 recursive_operation_delegate_.reset( 491 recursive_operation_delegate_.reset(
493 new RemoveOperationDelegate( 492 new RemoveOperationDelegate(
494 file_system_context(), url, 493 file_system_context(), url,
495 base::Bind(&LocalFileSystemOperation::DidFinishOperation, 494 base::Bind(&FileSystemOperationImpl::DidFinishOperation,
496 AsWeakPtr(), callback))); 495 AsWeakPtr(), callback)));
497 recursive_operation_delegate_->RunRecursively(); 496 recursive_operation_delegate_->RunRecursively();
498 return; 497 return;
499 } 498 }
500 499
501 callback.Run(rv); 500 callback.Run(rv);
502 } 501 }
503 502
504 void LocalFileSystemOperation::DidWrite( 503 void FileSystemOperationImpl::DidWrite(
505 const FileSystemURL& url, 504 const FileSystemURL& url,
506 const WriteCallback& write_callback, 505 const WriteCallback& write_callback,
507 base::PlatformFileError rv, 506 base::PlatformFileError rv,
508 int64 bytes, 507 int64 bytes,
509 FileWriterDelegate::WriteProgressStatus write_status) { 508 FileWriterDelegate::WriteProgressStatus write_status) {
510 const bool complete = ( 509 const bool complete = (
511 write_status != FileWriterDelegate::SUCCESS_IO_PENDING); 510 write_status != FileWriterDelegate::SUCCESS_IO_PENDING);
512 if (complete && write_status != FileWriterDelegate::ERROR_WRITE_NOT_STARTED) { 511 if (complete && write_status != FileWriterDelegate::ERROR_WRITE_NOT_STARTED) {
513 DCHECK(operation_context_); 512 DCHECK(operation_context_);
514 operation_context_->change_observers()->Notify( 513 operation_context_->change_observers()->Notify(
515 &FileChangeObserver::OnModifyFile, MakeTuple(url)); 514 &FileChangeObserver::OnModifyFile, MakeTuple(url));
516 } 515 }
517 516
518 StatusCallback cancel_callback = cancel_callback_; 517 StatusCallback cancel_callback = cancel_callback_;
519 write_callback.Run(rv, bytes, complete); 518 write_callback.Run(rv, bytes, complete);
520 if (!cancel_callback.is_null()) 519 if (!cancel_callback.is_null())
521 cancel_callback.Run(base::PLATFORM_FILE_OK); 520 cancel_callback.Run(base::PLATFORM_FILE_OK);
522 } 521 }
523 522
524 void LocalFileSystemOperation::DidOpenFile( 523 void FileSystemOperationImpl::DidOpenFile(
525 const OpenFileCallback& callback, 524 const OpenFileCallback& callback,
526 base::PlatformFileError rv, 525 base::PlatformFileError rv,
527 base::PassPlatformFile file, 526 base::PassPlatformFile file,
528 const base::Closure& on_close_callback) { 527 const base::Closure& on_close_callback) {
529 if (rv == base::PLATFORM_FILE_OK) 528 if (rv == base::PLATFORM_FILE_OK)
530 CHECK_NE(base::kNullProcessHandle, peer_handle_); 529 CHECK_NE(base::kNullProcessHandle, peer_handle_);
531 callback.Run(rv, file.ReleaseValue(), on_close_callback, peer_handle_); 530 callback.Run(rv, file.ReleaseValue(), on_close_callback, peer_handle_);
532 } 531 }
533 532
534 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { 533 bool FileSystemOperationImpl::SetPendingOperationType(OperationType type) {
535 if (pending_operation_ != kOperationNone) 534 if (pending_operation_ != kOperationNone)
536 return false; 535 return false;
537 pending_operation_ = type; 536 pending_operation_ = type;
538 return true; 537 return true;
539 } 538 }
540 539
541 } // namespace fileapi 540 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/file_system_operation_impl.h ('k') | webkit/browser/fileapi/file_system_operation_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698