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

Side by Side Diff: storage/browser/fileapi/file_system_operation_runner.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/browser/fileapi/file_system_operation_runner.h" 5 #include "storage/browser/fileapi/file_system_operation_runner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/url_request/url_request_context.h" 10 #include "net/url_request/url_request_context.h"
11 #include "webkit/browser/blob/blob_url_request_job_factory.h" 11 #include "storage/browser/blob/blob_url_request_job_factory.h"
12 #include "webkit/browser/fileapi/file_observers.h" 12 #include "storage/browser/fileapi/file_observers.h"
13 #include "webkit/browser/fileapi/file_stream_writer.h" 13 #include "storage/browser/fileapi/file_stream_writer.h"
14 #include "webkit/browser/fileapi/file_system_context.h" 14 #include "storage/browser/fileapi/file_system_context.h"
15 #include "webkit/browser/fileapi/file_system_operation.h" 15 #include "storage/browser/fileapi/file_system_operation.h"
16 #include "webkit/browser/fileapi/file_writer_delegate.h" 16 #include "storage/browser/fileapi/file_writer_delegate.h"
17 #include "webkit/common/blob/shareable_file_reference.h" 17 #include "storage/common/blob/shareable_file_reference.h"
18 18
19 namespace fileapi { 19 namespace storage {
20 20
21 typedef FileSystemOperationRunner::OperationID OperationID; 21 typedef FileSystemOperationRunner::OperationID OperationID;
22 22
23 class FileSystemOperationRunner::BeginOperationScoper 23 class FileSystemOperationRunner::BeginOperationScoper
24 : public base::SupportsWeakPtr< 24 : public base::SupportsWeakPtr<
25 FileSystemOperationRunner::BeginOperationScoper> { 25 FileSystemOperationRunner::BeginOperationScoper> {
26 public: 26 public:
27 BeginOperationScoper() {} 27 BeginOperationScoper() {}
28
28 private: 29 private:
29 DISALLOW_COPY_AND_ASSIGN(BeginOperationScoper); 30 DISALLOW_COPY_AND_ASSIGN(BeginOperationScoper);
30 }; 31 };
31 32
32 FileSystemOperationRunner::OperationHandle::OperationHandle() {} 33 FileSystemOperationRunner::OperationHandle::OperationHandle() {
33 FileSystemOperationRunner::OperationHandle::~OperationHandle() {} 34 }
35 FileSystemOperationRunner::OperationHandle::~OperationHandle() {
36 }
34 37
35 FileSystemOperationRunner::~FileSystemOperationRunner() { 38 FileSystemOperationRunner::~FileSystemOperationRunner() {
36 } 39 }
37 40
38 void FileSystemOperationRunner::Shutdown() { 41 void FileSystemOperationRunner::Shutdown() {
39 operations_.Clear(); 42 operations_.Clear();
40 } 43 }
41 44
42 OperationID FileSystemOperationRunner::CreateFile( 45 OperationID FileSystemOperationRunner::CreateFile(
43 const FileSystemURL& url, 46 const FileSystemURL& url,
44 bool exclusive, 47 bool exclusive,
45 const StatusCallback& callback) { 48 const StatusCallback& callback) {
46 base::File::Error error = base::File::FILE_OK; 49 base::File::Error error = base::File::FILE_OK;
47 FileSystemOperation* operation = 50 FileSystemOperation* operation =
48 file_system_context_->CreateFileSystemOperation(url, &error); 51 file_system_context_->CreateFileSystemOperation(url, &error);
49 52
50 BeginOperationScoper scope; 53 BeginOperationScoper scope;
51 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 54 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
52 if (!operation) { 55 if (!operation) {
53 DidFinish(handle, callback, error); 56 DidFinish(handle, callback, error);
54 return handle.id; 57 return handle.id;
55 } 58 }
56 PrepareForWrite(handle.id, url); 59 PrepareForWrite(handle.id, url);
57 operation->CreateFile( 60 operation->CreateFile(url,
58 url, exclusive, 61 exclusive,
59 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 62 base::Bind(&FileSystemOperationRunner::DidFinish,
60 handle, callback)); 63 AsWeakPtr(),
64 handle,
65 callback));
61 return handle.id; 66 return handle.id;
62 } 67 }
63 68
64 OperationID FileSystemOperationRunner::CreateDirectory( 69 OperationID FileSystemOperationRunner::CreateDirectory(
65 const FileSystemURL& url, 70 const FileSystemURL& url,
66 bool exclusive, 71 bool exclusive,
67 bool recursive, 72 bool recursive,
68 const StatusCallback& callback) { 73 const StatusCallback& callback) {
69 base::File::Error error = base::File::FILE_OK; 74 base::File::Error error = base::File::FILE_OK;
70 FileSystemOperation* operation = 75 FileSystemOperation* operation =
71 file_system_context_->CreateFileSystemOperation(url, &error); 76 file_system_context_->CreateFileSystemOperation(url, &error);
72 BeginOperationScoper scope; 77 BeginOperationScoper scope;
73 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 78 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
74 if (!operation) { 79 if (!operation) {
75 DidFinish(handle, callback, error); 80 DidFinish(handle, callback, error);
76 return handle.id; 81 return handle.id;
77 } 82 }
78 PrepareForWrite(handle.id, url); 83 PrepareForWrite(handle.id, url);
79 operation->CreateDirectory( 84 operation->CreateDirectory(url,
80 url, exclusive, recursive, 85 exclusive,
81 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 86 recursive,
82 handle, callback)); 87 base::Bind(&FileSystemOperationRunner::DidFinish,
88 AsWeakPtr(),
89 handle,
90 callback));
83 return handle.id; 91 return handle.id;
84 } 92 }
85 93
86 OperationID FileSystemOperationRunner::Copy( 94 OperationID FileSystemOperationRunner::Copy(
87 const FileSystemURL& src_url, 95 const FileSystemURL& src_url,
88 const FileSystemURL& dest_url, 96 const FileSystemURL& dest_url,
89 CopyOrMoveOption option, 97 CopyOrMoveOption option,
90 const CopyProgressCallback& progress_callback, 98 const CopyProgressCallback& progress_callback,
91 const StatusCallback& callback) { 99 const StatusCallback& callback) {
92 base::File::Error error = base::File::FILE_OK; 100 base::File::Error error = base::File::FILE_OK;
93 FileSystemOperation* operation = 101 FileSystemOperation* operation =
94 file_system_context_->CreateFileSystemOperation(dest_url, &error); 102 file_system_context_->CreateFileSystemOperation(dest_url, &error);
95 BeginOperationScoper scope; 103 BeginOperationScoper scope;
96 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 104 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
97 if (!operation) { 105 if (!operation) {
98 DidFinish(handle, callback, error); 106 DidFinish(handle, callback, error);
99 return handle.id; 107 return handle.id;
100 } 108 }
101 PrepareForWrite(handle.id, dest_url); 109 PrepareForWrite(handle.id, dest_url);
102 PrepareForRead(handle.id, src_url); 110 PrepareForRead(handle.id, src_url);
103 operation->Copy( 111 operation->Copy(src_url,
104 src_url, dest_url, option, 112 dest_url,
105 progress_callback.is_null() ? 113 option,
106 CopyProgressCallback() : 114 progress_callback.is_null()
107 base::Bind(&FileSystemOperationRunner::OnCopyProgress, AsWeakPtr(), 115 ? CopyProgressCallback()
108 handle, progress_callback), 116 : base::Bind(&FileSystemOperationRunner::OnCopyProgress,
109 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 117 AsWeakPtr(),
110 handle, callback)); 118 handle,
119 progress_callback),
120 base::Bind(&FileSystemOperationRunner::DidFinish,
121 AsWeakPtr(),
122 handle,
123 callback));
111 return handle.id; 124 return handle.id;
112 } 125 }
113 126
114 OperationID FileSystemOperationRunner::Move( 127 OperationID FileSystemOperationRunner::Move(const FileSystemURL& src_url,
115 const FileSystemURL& src_url, 128 const FileSystemURL& dest_url,
116 const FileSystemURL& dest_url, 129 CopyOrMoveOption option,
117 CopyOrMoveOption option, 130 const StatusCallback& callback) {
118 const StatusCallback& callback) {
119 base::File::Error error = base::File::FILE_OK; 131 base::File::Error error = base::File::FILE_OK;
120 FileSystemOperation* operation = 132 FileSystemOperation* operation =
121 file_system_context_->CreateFileSystemOperation(dest_url, &error); 133 file_system_context_->CreateFileSystemOperation(dest_url, &error);
122 BeginOperationScoper scope; 134 BeginOperationScoper scope;
123 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 135 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
124 if (!operation) { 136 if (!operation) {
125 DidFinish(handle, callback, error); 137 DidFinish(handle, callback, error);
126 return handle.id; 138 return handle.id;
127 } 139 }
128 PrepareForWrite(handle.id, dest_url); 140 PrepareForWrite(handle.id, dest_url);
129 PrepareForWrite(handle.id, src_url); 141 PrepareForWrite(handle.id, src_url);
130 operation->Move( 142 operation->Move(src_url,
131 src_url, dest_url, option, 143 dest_url,
132 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 144 option,
133 handle, callback)); 145 base::Bind(&FileSystemOperationRunner::DidFinish,
146 AsWeakPtr(),
147 handle,
148 callback));
134 return handle.id; 149 return handle.id;
135 } 150 }
136 151
137 OperationID FileSystemOperationRunner::DirectoryExists( 152 OperationID FileSystemOperationRunner::DirectoryExists(
138 const FileSystemURL& url, 153 const FileSystemURL& url,
139 const StatusCallback& callback) { 154 const StatusCallback& callback) {
140 base::File::Error error = base::File::FILE_OK; 155 base::File::Error error = base::File::FILE_OK;
141 FileSystemOperation* operation = 156 FileSystemOperation* operation =
142 file_system_context_->CreateFileSystemOperation(url, &error); 157 file_system_context_->CreateFileSystemOperation(url, &error);
143 BeginOperationScoper scope; 158 BeginOperationScoper scope;
144 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 159 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
145 if (!operation) { 160 if (!operation) {
146 DidFinish(handle, callback, error); 161 DidFinish(handle, callback, error);
147 return handle.id; 162 return handle.id;
148 } 163 }
149 PrepareForRead(handle.id, url); 164 PrepareForRead(handle.id, url);
150 operation->DirectoryExists( 165 operation->DirectoryExists(url,
151 url, 166 base::Bind(&FileSystemOperationRunner::DidFinish,
152 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 167 AsWeakPtr(),
153 handle, callback)); 168 handle,
169 callback));
154 return handle.id; 170 return handle.id;
155 } 171 }
156 172
157 OperationID FileSystemOperationRunner::FileExists( 173 OperationID FileSystemOperationRunner::FileExists(
158 const FileSystemURL& url, 174 const FileSystemURL& url,
159 const StatusCallback& callback) { 175 const StatusCallback& callback) {
160 base::File::Error error = base::File::FILE_OK; 176 base::File::Error error = base::File::FILE_OK;
161 FileSystemOperation* operation = 177 FileSystemOperation* operation =
162 file_system_context_->CreateFileSystemOperation(url, &error); 178 file_system_context_->CreateFileSystemOperation(url, &error);
163 BeginOperationScoper scope; 179 BeginOperationScoper scope;
164 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 180 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
165 if (!operation) { 181 if (!operation) {
166 DidFinish(handle, callback, error); 182 DidFinish(handle, callback, error);
167 return handle.id; 183 return handle.id;
168 } 184 }
169 PrepareForRead(handle.id, url); 185 PrepareForRead(handle.id, url);
170 operation->FileExists( 186 operation->FileExists(url,
171 url, 187 base::Bind(&FileSystemOperationRunner::DidFinish,
172 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 188 AsWeakPtr(),
173 handle, callback)); 189 handle,
190 callback));
174 return handle.id; 191 return handle.id;
175 } 192 }
176 193
177 OperationID FileSystemOperationRunner::GetMetadata( 194 OperationID FileSystemOperationRunner::GetMetadata(
178 const FileSystemURL& url, 195 const FileSystemURL& url,
179 const GetMetadataCallback& callback) { 196 const GetMetadataCallback& callback) {
180 base::File::Error error = base::File::FILE_OK; 197 base::File::Error error = base::File::FILE_OK;
181 FileSystemOperation* operation = 198 FileSystemOperation* operation =
182 file_system_context_->CreateFileSystemOperation(url, &error); 199 file_system_context_->CreateFileSystemOperation(url, &error);
183 BeginOperationScoper scope; 200 BeginOperationScoper scope;
184 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 201 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
185 if (!operation) { 202 if (!operation) {
186 DidGetMetadata(handle, callback, error, base::File::Info()); 203 DidGetMetadata(handle, callback, error, base::File::Info());
187 return handle.id; 204 return handle.id;
188 } 205 }
189 PrepareForRead(handle.id, url); 206 PrepareForRead(handle.id, url);
190 operation->GetMetadata( 207 operation->GetMetadata(url,
191 url, 208 base::Bind(&FileSystemOperationRunner::DidGetMetadata,
192 base::Bind(&FileSystemOperationRunner::DidGetMetadata, AsWeakPtr(), 209 AsWeakPtr(),
193 handle, callback)); 210 handle,
211 callback));
194 return handle.id; 212 return handle.id;
195 } 213 }
196 214
197 OperationID FileSystemOperationRunner::ReadDirectory( 215 OperationID FileSystemOperationRunner::ReadDirectory(
198 const FileSystemURL& url, 216 const FileSystemURL& url,
199 const ReadDirectoryCallback& callback) { 217 const ReadDirectoryCallback& callback) {
200 base::File::Error error = base::File::FILE_OK; 218 base::File::Error error = base::File::FILE_OK;
201 FileSystemOperation* operation = 219 FileSystemOperation* operation =
202 file_system_context_->CreateFileSystemOperation(url, &error); 220 file_system_context_->CreateFileSystemOperation(url, &error);
203 BeginOperationScoper scope; 221 BeginOperationScoper scope;
204 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 222 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
205 if (!operation) { 223 if (!operation) {
206 DidReadDirectory(handle, callback, error, std::vector<DirectoryEntry>(), 224 DidReadDirectory(
207 false); 225 handle, callback, error, std::vector<DirectoryEntry>(), false);
208 return handle.id; 226 return handle.id;
209 } 227 }
210 PrepareForRead(handle.id, url); 228 PrepareForRead(handle.id, url);
211 operation->ReadDirectory( 229 operation->ReadDirectory(
212 url, 230 url,
213 base::Bind(&FileSystemOperationRunner::DidReadDirectory, AsWeakPtr(), 231 base::Bind(&FileSystemOperationRunner::DidReadDirectory,
214 handle, callback)); 232 AsWeakPtr(),
233 handle,
234 callback));
215 return handle.id; 235 return handle.id;
216 } 236 }
217 237
218 OperationID FileSystemOperationRunner::Remove( 238 OperationID FileSystemOperationRunner::Remove(const FileSystemURL& url,
219 const FileSystemURL& url, bool recursive, 239 bool recursive,
220 const StatusCallback& callback) { 240 const StatusCallback& callback) {
221 base::File::Error error = base::File::FILE_OK; 241 base::File::Error error = base::File::FILE_OK;
222 FileSystemOperation* operation = 242 FileSystemOperation* operation =
223 file_system_context_->CreateFileSystemOperation(url, &error); 243 file_system_context_->CreateFileSystemOperation(url, &error);
224 BeginOperationScoper scope; 244 BeginOperationScoper scope;
225 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 245 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
226 if (!operation) { 246 if (!operation) {
227 DidFinish(handle, callback, error); 247 DidFinish(handle, callback, error);
228 return handle.id; 248 return handle.id;
229 } 249 }
230 PrepareForWrite(handle.id, url); 250 PrepareForWrite(handle.id, url);
231 operation->Remove( 251 operation->Remove(url,
232 url, recursive, 252 recursive,
233 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 253 base::Bind(&FileSystemOperationRunner::DidFinish,
234 handle, callback)); 254 AsWeakPtr(),
255 handle,
256 callback));
235 return handle.id; 257 return handle.id;
236 } 258 }
237 259
238 OperationID FileSystemOperationRunner::Write( 260 OperationID FileSystemOperationRunner::Write(
239 const net::URLRequestContext* url_request_context, 261 const net::URLRequestContext* url_request_context,
240 const FileSystemURL& url, 262 const FileSystemURL& url,
241 scoped_ptr<webkit_blob::BlobDataHandle> blob, 263 scoped_ptr<storage::BlobDataHandle> blob,
242 int64 offset, 264 int64 offset,
243 const WriteCallback& callback) { 265 const WriteCallback& callback) {
244 base::File::Error error = base::File::FILE_OK; 266 base::File::Error error = base::File::FILE_OK;
245 FileSystemOperation* operation = 267 FileSystemOperation* operation =
246 file_system_context_->CreateFileSystemOperation(url, &error); 268 file_system_context_->CreateFileSystemOperation(url, &error);
247 269
248 BeginOperationScoper scope; 270 BeginOperationScoper scope;
249 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 271 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
250 if (!operation) { 272 if (!operation) {
251 DidWrite(handle, callback, error, 0, true); 273 DidWrite(handle, callback, error, 0, true);
252 return handle.id; 274 return handle.id;
253 } 275 }
254 276
255 scoped_ptr<FileStreamWriter> writer( 277 scoped_ptr<FileStreamWriter> writer(
256 file_system_context_->CreateFileStreamWriter(url, offset)); 278 file_system_context_->CreateFileStreamWriter(url, offset));
257 if (!writer) { 279 if (!writer) {
258 // Write is not supported. 280 // Write is not supported.
259 DidWrite(handle, callback, base::File::FILE_ERROR_SECURITY, 0, true); 281 DidWrite(handle, callback, base::File::FILE_ERROR_SECURITY, 0, true);
260 return handle.id; 282 return handle.id;
261 } 283 }
262 284
263 FileWriterDelegate::FlushPolicy flush_policy = 285 FileWriterDelegate::FlushPolicy flush_policy =
264 file_system_context_->ShouldFlushOnWriteCompletion(url.type()) 286 file_system_context_->ShouldFlushOnWriteCompletion(url.type())
265 ? FileWriterDelegate::FLUSH_ON_COMPLETION 287 ? FileWriterDelegate::FLUSH_ON_COMPLETION
266 : FileWriterDelegate::NO_FLUSH_ON_COMPLETION; 288 : FileWriterDelegate::NO_FLUSH_ON_COMPLETION;
267 scoped_ptr<FileWriterDelegate> writer_delegate( 289 scoped_ptr<FileWriterDelegate> writer_delegate(
268 new FileWriterDelegate(writer.Pass(), flush_policy)); 290 new FileWriterDelegate(writer.Pass(), flush_policy));
269 291
270 scoped_ptr<net::URLRequest> blob_request( 292 scoped_ptr<net::URLRequest> blob_request(
271 webkit_blob::BlobProtocolHandler::CreateBlobRequest( 293 storage::BlobProtocolHandler::CreateBlobRequest(
272 blob.Pass(), 294 blob.Pass(), url_request_context, writer_delegate.get()));
273 url_request_context,
274 writer_delegate.get()));
275 295
276 PrepareForWrite(handle.id, url); 296 PrepareForWrite(handle.id, url);
277 operation->Write( 297 operation->Write(
278 url, writer_delegate.Pass(), blob_request.Pass(), 298 url,
279 base::Bind(&FileSystemOperationRunner::DidWrite, AsWeakPtr(), 299 writer_delegate.Pass(),
280 handle, callback)); 300 blob_request.Pass(),
301 base::Bind(
302 &FileSystemOperationRunner::DidWrite, AsWeakPtr(), handle, callback));
281 return handle.id; 303 return handle.id;
282 } 304 }
283 305
284 OperationID FileSystemOperationRunner::Truncate( 306 OperationID FileSystemOperationRunner::Truncate(
285 const FileSystemURL& url, int64 length, 307 const FileSystemURL& url,
308 int64 length,
286 const StatusCallback& callback) { 309 const StatusCallback& callback) {
287 base::File::Error error = base::File::FILE_OK; 310 base::File::Error error = base::File::FILE_OK;
288 FileSystemOperation* operation = 311 FileSystemOperation* operation =
289 file_system_context_->CreateFileSystemOperation(url, &error); 312 file_system_context_->CreateFileSystemOperation(url, &error);
290 BeginOperationScoper scope; 313 BeginOperationScoper scope;
291 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 314 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
292 if (!operation) { 315 if (!operation) {
293 DidFinish(handle, callback, error); 316 DidFinish(handle, callback, error);
294 return handle.id; 317 return handle.id;
295 } 318 }
296 PrepareForWrite(handle.id, url); 319 PrepareForWrite(handle.id, url);
297 operation->Truncate( 320 operation->Truncate(url,
298 url, length, 321 length,
299 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 322 base::Bind(&FileSystemOperationRunner::DidFinish,
300 handle, callback)); 323 AsWeakPtr(),
324 handle,
325 callback));
301 return handle.id; 326 return handle.id;
302 } 327 }
303 328
304 void FileSystemOperationRunner::Cancel( 329 void FileSystemOperationRunner::Cancel(OperationID id,
305 OperationID id, 330 const StatusCallback& callback) {
306 const StatusCallback& callback) {
307 if (ContainsKey(finished_operations_, id)) { 331 if (ContainsKey(finished_operations_, id)) {
308 DCHECK(!ContainsKey(stray_cancel_callbacks_, id)); 332 DCHECK(!ContainsKey(stray_cancel_callbacks_, id));
309 stray_cancel_callbacks_[id] = callback; 333 stray_cancel_callbacks_[id] = callback;
310 return; 334 return;
311 } 335 }
312 FileSystemOperation* operation = operations_.Lookup(id); 336 FileSystemOperation* operation = operations_.Lookup(id);
313 if (!operation) { 337 if (!operation) {
314 // There is no operation with |id|. 338 // There is no operation with |id|.
315 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); 339 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
316 return; 340 return;
317 } 341 }
318 operation->Cancel(callback); 342 operation->Cancel(callback);
319 } 343 }
320 344
321 OperationID FileSystemOperationRunner::TouchFile( 345 OperationID FileSystemOperationRunner::TouchFile(
322 const FileSystemURL& url, 346 const FileSystemURL& url,
323 const base::Time& last_access_time, 347 const base::Time& last_access_time,
324 const base::Time& last_modified_time, 348 const base::Time& last_modified_time,
325 const StatusCallback& callback) { 349 const StatusCallback& callback) {
326 base::File::Error error = base::File::FILE_OK; 350 base::File::Error error = base::File::FILE_OK;
327 FileSystemOperation* operation = 351 FileSystemOperation* operation =
328 file_system_context_->CreateFileSystemOperation(url, &error); 352 file_system_context_->CreateFileSystemOperation(url, &error);
329 BeginOperationScoper scope; 353 BeginOperationScoper scope;
330 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 354 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
331 if (!operation) { 355 if (!operation) {
332 DidFinish(handle, callback, error); 356 DidFinish(handle, callback, error);
333 return handle.id; 357 return handle.id;
334 } 358 }
335 PrepareForWrite(handle.id, url); 359 PrepareForWrite(handle.id, url);
336 operation->TouchFile( 360 operation->TouchFile(url,
337 url, last_access_time, last_modified_time, 361 last_access_time,
338 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 362 last_modified_time,
339 handle, callback)); 363 base::Bind(&FileSystemOperationRunner::DidFinish,
364 AsWeakPtr(),
365 handle,
366 callback));
340 return handle.id; 367 return handle.id;
341 } 368 }
342 369
343 OperationID FileSystemOperationRunner::OpenFile( 370 OperationID FileSystemOperationRunner::OpenFile(
344 const FileSystemURL& url, 371 const FileSystemURL& url,
345 int file_flags, 372 int file_flags,
346 const OpenFileCallback& callback) { 373 const OpenFileCallback& callback) {
347 base::File::Error error = base::File::FILE_OK; 374 base::File::Error error = base::File::FILE_OK;
348 FileSystemOperation* operation = 375 FileSystemOperation* operation =
349 file_system_context_->CreateFileSystemOperation(url, &error); 376 file_system_context_->CreateFileSystemOperation(url, &error);
350 BeginOperationScoper scope; 377 BeginOperationScoper scope;
351 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 378 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
352 if (!operation) { 379 if (!operation) {
353 DidOpenFile(handle, callback, base::File(error), base::Closure()); 380 DidOpenFile(handle, callback, base::File(error), base::Closure());
354 return handle.id; 381 return handle.id;
355 } 382 }
356 if (file_flags & 383 if (file_flags &
357 (base::File::FLAG_CREATE | base::File::FLAG_OPEN_ALWAYS | 384 (base::File::FLAG_CREATE | base::File::FLAG_OPEN_ALWAYS |
358 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_OPEN_TRUNCATED | 385 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_OPEN_TRUNCATED |
359 base::File::FLAG_WRITE | base::File::FLAG_EXCLUSIVE_WRITE | 386 base::File::FLAG_WRITE | base::File::FLAG_EXCLUSIVE_WRITE |
360 base::File::FLAG_DELETE_ON_CLOSE | 387 base::File::FLAG_DELETE_ON_CLOSE | base::File::FLAG_WRITE_ATTRIBUTES)) {
361 base::File::FLAG_WRITE_ATTRIBUTES)) {
362 PrepareForWrite(handle.id, url); 388 PrepareForWrite(handle.id, url);
363 } else { 389 } else {
364 PrepareForRead(handle.id, url); 390 PrepareForRead(handle.id, url);
365 } 391 }
366 operation->OpenFile( 392 operation->OpenFile(url,
367 url, file_flags, 393 file_flags,
368 base::Bind(&FileSystemOperationRunner::DidOpenFile, AsWeakPtr(), 394 base::Bind(&FileSystemOperationRunner::DidOpenFile,
369 handle, callback)); 395 AsWeakPtr(),
396 handle,
397 callback));
370 return handle.id; 398 return handle.id;
371 } 399 }
372 400
373 OperationID FileSystemOperationRunner::CreateSnapshotFile( 401 OperationID FileSystemOperationRunner::CreateSnapshotFile(
374 const FileSystemURL& url, 402 const FileSystemURL& url,
375 const SnapshotFileCallback& callback) { 403 const SnapshotFileCallback& callback) {
376 base::File::Error error = base::File::FILE_OK; 404 base::File::Error error = base::File::FILE_OK;
377 FileSystemOperation* operation = 405 FileSystemOperation* operation =
378 file_system_context_->CreateFileSystemOperation(url, &error); 406 file_system_context_->CreateFileSystemOperation(url, &error);
379 BeginOperationScoper scope; 407 BeginOperationScoper scope;
380 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 408 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
381 if (!operation) { 409 if (!operation) {
382 DidCreateSnapshot(handle, callback, error, base::File::Info(), 410 DidCreateSnapshot(
383 base::FilePath(), NULL); 411 handle, callback, error, base::File::Info(), base::FilePath(), NULL);
384 return handle.id; 412 return handle.id;
385 } 413 }
386 PrepareForRead(handle.id, url); 414 PrepareForRead(handle.id, url);
387 operation->CreateSnapshotFile( 415 operation->CreateSnapshotFile(
388 url, 416 url,
389 base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, AsWeakPtr(), 417 base::Bind(&FileSystemOperationRunner::DidCreateSnapshot,
390 handle, callback)); 418 AsWeakPtr(),
419 handle,
420 callback));
391 return handle.id; 421 return handle.id;
392 } 422 }
393 423
394 OperationID FileSystemOperationRunner::CopyInForeignFile( 424 OperationID FileSystemOperationRunner::CopyInForeignFile(
395 const base::FilePath& src_local_disk_path, 425 const base::FilePath& src_local_disk_path,
396 const FileSystemURL& dest_url, 426 const FileSystemURL& dest_url,
397 const StatusCallback& callback) { 427 const StatusCallback& callback) {
398 base::File::Error error = base::File::FILE_OK; 428 base::File::Error error = base::File::FILE_OK;
399 FileSystemOperation* operation = 429 FileSystemOperation* operation =
400 file_system_context_->CreateFileSystemOperation(dest_url, &error); 430 file_system_context_->CreateFileSystemOperation(dest_url, &error);
401 BeginOperationScoper scope; 431 BeginOperationScoper scope;
402 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 432 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
403 if (!operation) { 433 if (!operation) {
404 DidFinish(handle, callback, error); 434 DidFinish(handle, callback, error);
405 return handle.id; 435 return handle.id;
406 } 436 }
407 operation->CopyInForeignFile( 437 operation->CopyInForeignFile(src_local_disk_path,
408 src_local_disk_path, dest_url, 438 dest_url,
409 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 439 base::Bind(&FileSystemOperationRunner::DidFinish,
410 handle, callback)); 440 AsWeakPtr(),
441 handle,
442 callback));
411 return handle.id; 443 return handle.id;
412 } 444 }
413 445
414 OperationID FileSystemOperationRunner::RemoveFile( 446 OperationID FileSystemOperationRunner::RemoveFile(
415 const FileSystemURL& url, 447 const FileSystemURL& url,
416 const StatusCallback& callback) { 448 const StatusCallback& callback) {
417 base::File::Error error = base::File::FILE_OK; 449 base::File::Error error = base::File::FILE_OK;
418 FileSystemOperation* operation = 450 FileSystemOperation* operation =
419 file_system_context_->CreateFileSystemOperation(url, &error); 451 file_system_context_->CreateFileSystemOperation(url, &error);
420 BeginOperationScoper scope; 452 BeginOperationScoper scope;
421 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 453 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
422 if (!operation) { 454 if (!operation) {
423 DidFinish(handle, callback, error); 455 DidFinish(handle, callback, error);
424 return handle.id; 456 return handle.id;
425 } 457 }
426 operation->RemoveFile( 458 operation->RemoveFile(url,
427 url, 459 base::Bind(&FileSystemOperationRunner::DidFinish,
428 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 460 AsWeakPtr(),
429 handle, callback)); 461 handle,
462 callback));
430 return handle.id; 463 return handle.id;
431 } 464 }
432 465
433 OperationID FileSystemOperationRunner::RemoveDirectory( 466 OperationID FileSystemOperationRunner::RemoveDirectory(
434 const FileSystemURL& url, 467 const FileSystemURL& url,
435 const StatusCallback& callback) { 468 const StatusCallback& callback) {
436 base::File::Error error = base::File::FILE_OK; 469 base::File::Error error = base::File::FILE_OK;
437 FileSystemOperation* operation = 470 FileSystemOperation* operation =
438 file_system_context_->CreateFileSystemOperation(url, &error); 471 file_system_context_->CreateFileSystemOperation(url, &error);
439 BeginOperationScoper scope; 472 BeginOperationScoper scope;
440 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 473 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
441 if (!operation) { 474 if (!operation) {
442 DidFinish(handle, callback, error); 475 DidFinish(handle, callback, error);
443 return handle.id; 476 return handle.id;
444 } 477 }
445 operation->RemoveDirectory( 478 operation->RemoveDirectory(url,
446 url, 479 base::Bind(&FileSystemOperationRunner::DidFinish,
447 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 480 AsWeakPtr(),
448 handle, callback)); 481 handle,
482 callback));
449 return handle.id; 483 return handle.id;
450 } 484 }
451 485
452 OperationID FileSystemOperationRunner::CopyFileLocal( 486 OperationID FileSystemOperationRunner::CopyFileLocal(
453 const FileSystemURL& src_url, 487 const FileSystemURL& src_url,
454 const FileSystemURL& dest_url, 488 const FileSystemURL& dest_url,
455 CopyOrMoveOption option, 489 CopyOrMoveOption option,
456 const CopyFileProgressCallback& progress_callback, 490 const CopyFileProgressCallback& progress_callback,
457 const StatusCallback& callback) { 491 const StatusCallback& callback) {
458 base::File::Error error = base::File::FILE_OK; 492 base::File::Error error = base::File::FILE_OK;
459 FileSystemOperation* operation = 493 FileSystemOperation* operation =
460 file_system_context_->CreateFileSystemOperation(src_url, &error); 494 file_system_context_->CreateFileSystemOperation(src_url, &error);
461 BeginOperationScoper scope; 495 BeginOperationScoper scope;
462 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 496 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
463 if (!operation) { 497 if (!operation) {
464 DidFinish(handle, callback, error); 498 DidFinish(handle, callback, error);
465 return handle.id; 499 return handle.id;
466 } 500 }
467 operation->CopyFileLocal( 501 operation->CopyFileLocal(src_url,
468 src_url, dest_url, option, progress_callback, 502 dest_url,
469 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 503 option,
470 handle, callback)); 504 progress_callback,
505 base::Bind(&FileSystemOperationRunner::DidFinish,
506 AsWeakPtr(),
507 handle,
508 callback));
471 return handle.id; 509 return handle.id;
472 } 510 }
473 511
474 OperationID FileSystemOperationRunner::MoveFileLocal( 512 OperationID FileSystemOperationRunner::MoveFileLocal(
475 const FileSystemURL& src_url, 513 const FileSystemURL& src_url,
476 const FileSystemURL& dest_url, 514 const FileSystemURL& dest_url,
477 CopyOrMoveOption option, 515 CopyOrMoveOption option,
478 const StatusCallback& callback) { 516 const StatusCallback& callback) {
479 base::File::Error error = base::File::FILE_OK; 517 base::File::Error error = base::File::FILE_OK;
480 FileSystemOperation* operation = 518 FileSystemOperation* operation =
481 file_system_context_->CreateFileSystemOperation(src_url, &error); 519 file_system_context_->CreateFileSystemOperation(src_url, &error);
482 BeginOperationScoper scope; 520 BeginOperationScoper scope;
483 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 521 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
484 if (!operation) { 522 if (!operation) {
485 DidFinish(handle, callback, error); 523 DidFinish(handle, callback, error);
486 return handle.id; 524 return handle.id;
487 } 525 }
488 operation->MoveFileLocal( 526 operation->MoveFileLocal(src_url,
489 src_url, dest_url, option, 527 dest_url,
490 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 528 option,
491 handle, callback)); 529 base::Bind(&FileSystemOperationRunner::DidFinish,
530 AsWeakPtr(),
531 handle,
532 callback));
492 return handle.id; 533 return handle.id;
493 } 534 }
494 535
495 base::File::Error FileSystemOperationRunner::SyncGetPlatformPath( 536 base::File::Error FileSystemOperationRunner::SyncGetPlatformPath(
496 const FileSystemURL& url, 537 const FileSystemURL& url,
497 base::FilePath* platform_path) { 538 base::FilePath* platform_path) {
498 base::File::Error error = base::File::FILE_OK; 539 base::File::Error error = base::File::FILE_OK;
499 scoped_ptr<FileSystemOperation> operation( 540 scoped_ptr<FileSystemOperation> operation(
500 file_system_context_->CreateFileSystemOperation(url, &error)); 541 file_system_context_->CreateFileSystemOperation(url, &error));
501 if (!operation.get()) 542 if (!operation.get())
502 return error; 543 return error;
503 return operation->SyncGetPlatformPath(url, platform_path); 544 return operation->SyncGetPlatformPath(url, platform_path);
504 } 545 }
505 546
506 FileSystemOperationRunner::FileSystemOperationRunner( 547 FileSystemOperationRunner::FileSystemOperationRunner(
507 FileSystemContext* file_system_context) 548 FileSystemContext* file_system_context)
508 : file_system_context_(file_system_context) {} 549 : file_system_context_(file_system_context) {
550 }
509 551
510 void FileSystemOperationRunner::DidFinish( 552 void FileSystemOperationRunner::DidFinish(const OperationHandle& handle,
511 const OperationHandle& handle, 553 const StatusCallback& callback,
512 const StatusCallback& callback, 554 base::File::Error rv) {
513 base::File::Error rv) {
514 if (handle.scope) { 555 if (handle.scope) {
515 finished_operations_.insert(handle.id); 556 finished_operations_.insert(handle.id);
516 base::MessageLoopProxy::current()->PostTask( 557 base::MessageLoopProxy::current()->PostTask(
517 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidFinish, 558 FROM_HERE,
518 AsWeakPtr(), handle, callback, rv)); 559 base::Bind(&FileSystemOperationRunner::DidFinish,
560 AsWeakPtr(),
561 handle,
562 callback,
563 rv));
519 return; 564 return;
520 } 565 }
521 callback.Run(rv); 566 callback.Run(rv);
522 FinishOperation(handle.id); 567 FinishOperation(handle.id);
523 } 568 }
524 569
525 void FileSystemOperationRunner::DidGetMetadata( 570 void FileSystemOperationRunner::DidGetMetadata(
526 const OperationHandle& handle, 571 const OperationHandle& handle,
527 const GetMetadataCallback& callback, 572 const GetMetadataCallback& callback,
528 base::File::Error rv, 573 base::File::Error rv,
529 const base::File::Info& file_info) { 574 const base::File::Info& file_info) {
530 if (handle.scope) { 575 if (handle.scope) {
531 finished_operations_.insert(handle.id); 576 finished_operations_.insert(handle.id);
532 base::MessageLoopProxy::current()->PostTask( 577 base::MessageLoopProxy::current()->PostTask(
533 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidGetMetadata, 578 FROM_HERE,
534 AsWeakPtr(), handle, callback, rv, file_info)); 579 base::Bind(&FileSystemOperationRunner::DidGetMetadata,
580 AsWeakPtr(),
581 handle,
582 callback,
583 rv,
584 file_info));
535 return; 585 return;
536 } 586 }
537 callback.Run(rv, file_info); 587 callback.Run(rv, file_info);
538 FinishOperation(handle.id); 588 FinishOperation(handle.id);
539 } 589 }
540 590
541 void FileSystemOperationRunner::DidReadDirectory( 591 void FileSystemOperationRunner::DidReadDirectory(
542 const OperationHandle& handle, 592 const OperationHandle& handle,
543 const ReadDirectoryCallback& callback, 593 const ReadDirectoryCallback& callback,
544 base::File::Error rv, 594 base::File::Error rv,
545 const std::vector<DirectoryEntry>& entries, 595 const std::vector<DirectoryEntry>& entries,
546 bool has_more) { 596 bool has_more) {
547 if (handle.scope) { 597 if (handle.scope) {
548 finished_operations_.insert(handle.id); 598 finished_operations_.insert(handle.id);
549 base::MessageLoopProxy::current()->PostTask( 599 base::MessageLoopProxy::current()->PostTask(
550 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidReadDirectory, 600 FROM_HERE,
551 AsWeakPtr(), handle, callback, rv, 601 base::Bind(&FileSystemOperationRunner::DidReadDirectory,
552 entries, has_more)); 602 AsWeakPtr(),
603 handle,
604 callback,
605 rv,
606 entries,
607 has_more));
553 return; 608 return;
554 } 609 }
555 callback.Run(rv, entries, has_more); 610 callback.Run(rv, entries, has_more);
556 if (rv != base::File::FILE_OK || !has_more) 611 if (rv != base::File::FILE_OK || !has_more)
557 FinishOperation(handle.id); 612 FinishOperation(handle.id);
558 } 613 }
559 614
560 void FileSystemOperationRunner::DidWrite( 615 void FileSystemOperationRunner::DidWrite(const OperationHandle& handle,
561 const OperationHandle& handle, 616 const WriteCallback& callback,
562 const WriteCallback& callback, 617 base::File::Error rv,
563 base::File::Error rv, 618 int64 bytes,
564 int64 bytes, 619 bool complete) {
565 bool complete) {
566 if (handle.scope) { 620 if (handle.scope) {
567 finished_operations_.insert(handle.id); 621 finished_operations_.insert(handle.id);
568 base::MessageLoopProxy::current()->PostTask( 622 base::MessageLoopProxy::current()->PostTask(
569 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidWrite, AsWeakPtr(), 623 FROM_HERE,
570 handle, callback, rv, bytes, complete)); 624 base::Bind(&FileSystemOperationRunner::DidWrite,
625 AsWeakPtr(),
626 handle,
627 callback,
628 rv,
629 bytes,
630 complete));
571 return; 631 return;
572 } 632 }
573 callback.Run(rv, bytes, complete); 633 callback.Run(rv, bytes, complete);
574 if (rv != base::File::FILE_OK || complete) 634 if (rv != base::File::FILE_OK || complete)
575 FinishOperation(handle.id); 635 FinishOperation(handle.id);
576 } 636 }
577 637
578 void FileSystemOperationRunner::DidOpenFile( 638 void FileSystemOperationRunner::DidOpenFile(
579 const OperationHandle& handle, 639 const OperationHandle& handle,
580 const OpenFileCallback& callback, 640 const OpenFileCallback& callback,
581 base::File file, 641 base::File file,
582 const base::Closure& on_close_callback) { 642 const base::Closure& on_close_callback) {
583 if (handle.scope) { 643 if (handle.scope) {
584 finished_operations_.insert(handle.id); 644 finished_operations_.insert(handle.id);
585 base::MessageLoopProxy::current()->PostTask( 645 base::MessageLoopProxy::current()->PostTask(
586 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidOpenFile, 646 FROM_HERE,
587 AsWeakPtr(), handle, callback, Passed(&file), 647 base::Bind(&FileSystemOperationRunner::DidOpenFile,
588 on_close_callback)); 648 AsWeakPtr(),
649 handle,
650 callback,
651 Passed(&file),
652 on_close_callback));
589 return; 653 return;
590 } 654 }
591 callback.Run(file.Pass(), on_close_callback); 655 callback.Run(file.Pass(), on_close_callback);
592 FinishOperation(handle.id); 656 FinishOperation(handle.id);
593 } 657 }
594 658
595 void FileSystemOperationRunner::DidCreateSnapshot( 659 void FileSystemOperationRunner::DidCreateSnapshot(
596 const OperationHandle& handle, 660 const OperationHandle& handle,
597 const SnapshotFileCallback& callback, 661 const SnapshotFileCallback& callback,
598 base::File::Error rv, 662 base::File::Error rv,
599 const base::File::Info& file_info, 663 const base::File::Info& file_info,
600 const base::FilePath& platform_path, 664 const base::FilePath& platform_path,
601 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { 665 const scoped_refptr<storage::ShareableFileReference>& file_ref) {
602 if (handle.scope) { 666 if (handle.scope) {
603 finished_operations_.insert(handle.id); 667 finished_operations_.insert(handle.id);
604 base::MessageLoopProxy::current()->PostTask( 668 base::MessageLoopProxy::current()->PostTask(
605 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, 669 FROM_HERE,
606 AsWeakPtr(), handle, callback, rv, file_info, 670 base::Bind(&FileSystemOperationRunner::DidCreateSnapshot,
607 platform_path, file_ref)); 671 AsWeakPtr(),
672 handle,
673 callback,
674 rv,
675 file_info,
676 platform_path,
677 file_ref));
608 return; 678 return;
609 } 679 }
610 callback.Run(rv, file_info, platform_path, file_ref); 680 callback.Run(rv, file_info, platform_path, file_ref);
611 FinishOperation(handle.id); 681 FinishOperation(handle.id);
612 } 682 }
613 683
614 void FileSystemOperationRunner::OnCopyProgress( 684 void FileSystemOperationRunner::OnCopyProgress(
615 const OperationHandle& handle, 685 const OperationHandle& handle,
616 const CopyProgressCallback& callback, 686 const CopyProgressCallback& callback,
617 FileSystemOperation::CopyProgressType type, 687 FileSystemOperation::CopyProgressType type,
618 const FileSystemURL& source_url, 688 const FileSystemURL& source_url,
619 const FileSystemURL& dest_url, 689 const FileSystemURL& dest_url,
620 int64 size) { 690 int64 size) {
621 if (handle.scope) { 691 if (handle.scope) {
622 base::MessageLoopProxy::current()->PostTask( 692 base::MessageLoopProxy::current()->PostTask(
623 FROM_HERE, base::Bind( 693 FROM_HERE,
624 &FileSystemOperationRunner::OnCopyProgress, 694 base::Bind(&FileSystemOperationRunner::OnCopyProgress,
625 AsWeakPtr(), handle, callback, type, source_url, dest_url, size)); 695 AsWeakPtr(),
696 handle,
697 callback,
698 type,
699 source_url,
700 dest_url,
701 size));
626 return; 702 return;
627 } 703 }
628 callback.Run(type, source_url, dest_url, size); 704 callback.Run(type, source_url, dest_url, size);
629 } 705 }
630 706
631 void FileSystemOperationRunner::PrepareForWrite(OperationID id, 707 void FileSystemOperationRunner::PrepareForWrite(OperationID id,
632 const FileSystemURL& url) { 708 const FileSystemURL& url) {
633 if (file_system_context_->GetUpdateObservers(url.type())) { 709 if (file_system_context_->GetUpdateObservers(url.type())) {
634 file_system_context_->GetUpdateObservers(url.type())->Notify( 710 file_system_context_->GetUpdateObservers(url.type())
635 &FileUpdateObserver::OnStartUpdate, MakeTuple(url)); 711 ->Notify(&FileUpdateObserver::OnStartUpdate, MakeTuple(url));
636 } 712 }
637 write_target_urls_[id].insert(url); 713 write_target_urls_[id].insert(url);
638 } 714 }
639 715
640 void FileSystemOperationRunner::PrepareForRead(OperationID id, 716 void FileSystemOperationRunner::PrepareForRead(OperationID id,
641 const FileSystemURL& url) { 717 const FileSystemURL& url) {
642 if (file_system_context_->GetAccessObservers(url.type())) { 718 if (file_system_context_->GetAccessObservers(url.type())) {
643 file_system_context_->GetAccessObservers(url.type())->Notify( 719 file_system_context_->GetAccessObservers(url.type())
644 &FileAccessObserver::OnAccess, MakeTuple(url)); 720 ->Notify(&FileAccessObserver::OnAccess, MakeTuple(url));
645 } 721 }
646 } 722 }
647 723
648 FileSystemOperationRunner::OperationHandle 724 FileSystemOperationRunner::OperationHandle
649 FileSystemOperationRunner::BeginOperation( 725 FileSystemOperationRunner::BeginOperation(
650 FileSystemOperation* operation, 726 FileSystemOperation* operation,
651 base::WeakPtr<BeginOperationScoper> scope) { 727 base::WeakPtr<BeginOperationScoper> scope) {
652 OperationHandle handle; 728 OperationHandle handle;
653 handle.id = operations_.Add(operation); 729 handle.id = operations_.Add(operation);
654 handle.scope = scope; 730 handle.scope = scope;
655 return handle; 731 return handle;
656 } 732 }
657 733
658 void FileSystemOperationRunner::FinishOperation(OperationID id) { 734 void FileSystemOperationRunner::FinishOperation(OperationID id) {
659 OperationToURLSet::iterator found = write_target_urls_.find(id); 735 OperationToURLSet::iterator found = write_target_urls_.find(id);
660 if (found != write_target_urls_.end()) { 736 if (found != write_target_urls_.end()) {
661 const FileSystemURLSet& urls = found->second; 737 const FileSystemURLSet& urls = found->second;
662 for (FileSystemURLSet::const_iterator iter = urls.begin(); 738 for (FileSystemURLSet::const_iterator iter = urls.begin();
663 iter != urls.end(); ++iter) { 739 iter != urls.end();
740 ++iter) {
664 if (file_system_context_->GetUpdateObservers(iter->type())) { 741 if (file_system_context_->GetUpdateObservers(iter->type())) {
665 file_system_context_->GetUpdateObservers(iter->type())->Notify( 742 file_system_context_->GetUpdateObservers(iter->type())
666 &FileUpdateObserver::OnEndUpdate, MakeTuple(*iter)); 743 ->Notify(&FileUpdateObserver::OnEndUpdate, MakeTuple(*iter));
667 } 744 }
668 } 745 }
669 write_target_urls_.erase(found); 746 write_target_urls_.erase(found);
670 } 747 }
671 748
672 // IDMap::Lookup fails if the operation is NULL, so we don't check 749 // IDMap::Lookup fails if the operation is NULL, so we don't check
673 // operations_.Lookup(id) here. 750 // operations_.Lookup(id) here.
674 751
675 operations_.Remove(id); 752 operations_.Remove(id);
676 finished_operations_.erase(id); 753 finished_operations_.erase(id);
677 754
678 // Dispatch stray cancel callback if exists. 755 // Dispatch stray cancel callback if exists.
679 std::map<OperationID, StatusCallback>::iterator found_cancel = 756 std::map<OperationID, StatusCallback>::iterator found_cancel =
680 stray_cancel_callbacks_.find(id); 757 stray_cancel_callbacks_.find(id);
681 if (found_cancel != stray_cancel_callbacks_.end()) { 758 if (found_cancel != stray_cancel_callbacks_.end()) {
682 // This cancel has been requested after the operation has finished, 759 // This cancel has been requested after the operation has finished,
683 // so report that we failed to stop it. 760 // so report that we failed to stop it.
684 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); 761 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION);
685 stray_cancel_callbacks_.erase(found_cancel); 762 stray_cancel_callbacks_.erase(found_cancel);
686 } 763 }
687 } 764 }
688 765
689 } // namespace fileapi 766 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/fileapi/file_system_operation_runner.h ('k') | storage/browser/fileapi/file_system_options.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698