OLD | NEW |
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/syncable/syncable_file_system_operation.h" | 5 #include "webkit/browser/fileapi/syncable/syncable_file_system_operation.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "webkit/browser/fileapi/file_system_context.h" | 8 #include "webkit/browser/fileapi/file_system_context.h" |
9 #include "webkit/browser/fileapi/file_system_operation_context.h" | 9 #include "webkit/browser/fileapi/file_system_operation_context.h" |
10 #include "webkit/browser/fileapi/file_system_url.h" | 10 #include "webkit/browser/fileapi/file_system_url.h" |
| 11 #include "webkit/browser/fileapi/local_file_system_operation.h" |
11 #include "webkit/browser/fileapi/sandbox_mount_point_provider.h" | 12 #include "webkit/browser/fileapi/sandbox_mount_point_provider.h" |
12 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" | 13 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" |
13 #include "webkit/browser/fileapi/syncable/syncable_file_operation_runner.h" | 14 #include "webkit/browser/fileapi/syncable/syncable_file_operation_runner.h" |
14 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" | 15 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" |
15 #include "webkit/common/blob/shareable_file_reference.h" | 16 #include "webkit/common/blob/shareable_file_reference.h" |
16 | 17 |
17 using fileapi::FileSystemURL; | 18 using fileapi::FileSystemURL; |
18 using fileapi::FileSystemOperationContext; | 19 using fileapi::FileSystemOperationContext; |
19 using fileapi::LocalFileSystemOperation; | 20 using fileapi::LocalFileSystemOperation; |
20 | 21 |
21 namespace sync_file_system { | 22 namespace sync_file_system { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 void WriteCallbackAdapter( | 26 void WriteCallbackAdapter( |
26 const SyncableFileSystemOperation::WriteCallback& callback, | 27 const SyncableFileSystemOperation::WriteCallback& callback, |
27 base::PlatformFileError status) { | 28 base::PlatformFileError status) { |
28 callback.Run(status, 0, true); | 29 callback.Run(status, 0, true); |
29 } | 30 } |
30 | 31 |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 class SyncableFileSystemOperation::QueueableTask | 34 class SyncableFileSystemOperation::QueueableTask |
34 : public SyncableFileOperationRunner::Task { | 35 : public SyncableFileOperationRunner::Task { |
35 public: | 36 public: |
36 QueueableTask(SyncableFileSystemOperation* operation, | 37 QueueableTask(base::WeakPtr<SyncableFileSystemOperation> operation, |
37 const base::Closure& task) | 38 const base::Closure& task) |
38 : operation_(operation), task_(task) {} | 39 : operation_(operation), |
| 40 task_(task), |
| 41 target_paths_(operation->target_paths_) {} |
39 | 42 |
40 virtual ~QueueableTask() { | 43 virtual ~QueueableTask() { |
41 DCHECK(!operation_); | 44 DCHECK(!operation_); |
42 } | 45 } |
43 | 46 |
44 virtual void Run() OVERRIDE { | 47 virtual void Run() OVERRIDE { |
45 DCHECK(!task_.is_null()); | 48 DCHECK(!task_.is_null()); |
46 task_.Run(); | 49 task_.Run(); |
47 operation_ = NULL; | 50 operation_.reset(); |
48 } | 51 } |
49 | 52 |
50 virtual void Cancel() OVERRIDE { | 53 virtual void Cancel() OVERRIDE { |
51 DCHECK(!task_.is_null()); | 54 DCHECK(!task_.is_null()); |
52 DCHECK(operation_); | 55 if (operation_) |
53 operation_->OnCancelled(); | 56 operation_->OnCancelled(); |
54 task_.Reset(); // This will delete operation_. | 57 task_.Reset(); |
55 operation_ = NULL; | 58 operation_.reset(); |
56 } | 59 } |
57 | 60 |
58 virtual std::vector<FileSystemURL>& target_paths() const OVERRIDE { | 61 virtual const std::vector<FileSystemURL>& target_paths() const OVERRIDE { |
59 DCHECK(operation_); | 62 return target_paths_; |
60 return operation_->target_paths_; | |
61 } | 63 } |
62 | 64 |
63 private: | 65 private: |
64 SyncableFileSystemOperation* operation_; | 66 base::WeakPtr<SyncableFileSystemOperation> operation_; |
65 base::Closure task_; | 67 base::Closure task_; |
| 68 std::vector<FileSystemURL> target_paths_; |
66 DISALLOW_COPY_AND_ASSIGN(QueueableTask); | 69 DISALLOW_COPY_AND_ASSIGN(QueueableTask); |
67 }; | 70 }; |
68 | 71 |
69 SyncableFileSystemOperation::~SyncableFileSystemOperation() {} | 72 SyncableFileSystemOperation::~SyncableFileSystemOperation() {} |
70 | 73 |
71 void SyncableFileSystemOperation::CreateFile( | 74 void SyncableFileSystemOperation::CreateFile( |
72 const FileSystemURL& url, | 75 const FileSystemURL& url, |
73 bool exclusive, | 76 bool exclusive, |
74 const StatusCallback& callback) { | 77 const StatusCallback& callback) { |
75 DCHECK(CalledOnValidThread()); | 78 DCHECK(CalledOnValidThread()); |
76 if (!operation_runner_.get()) { | 79 if (!operation_runner_.get()) { |
77 AbortOperation(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 80 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
78 return; | 81 return; |
79 } | 82 } |
80 DCHECK(operation_runner_.get()); | 83 DCHECK(operation_runner_.get()); |
81 target_paths_.push_back(url); | 84 target_paths_.push_back(url); |
82 completion_callback_ = callback; | 85 completion_callback_ = callback; |
83 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 86 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
84 this, | 87 AsWeakPtr(), |
85 base::Bind(&FileSystemOperation::CreateFile, | 88 base::Bind(&FileSystemOperation::CreateFile, |
86 base::Unretained(NewOperation()), | 89 NewOperation()->AsWeakPtr(), |
87 url, exclusive, | 90 url, exclusive, |
88 base::Bind(&self::DidFinish, base::Owned(this))))); | 91 base::Bind(&self::DidFinish, AsWeakPtr())))); |
89 operation_runner_->PostOperationTask(task.Pass()); | 92 operation_runner_->PostOperationTask(task.Pass()); |
90 } | 93 } |
91 | 94 |
92 void SyncableFileSystemOperation::CreateDirectory( | 95 void SyncableFileSystemOperation::CreateDirectory( |
93 const FileSystemURL& url, | 96 const FileSystemURL& url, |
94 bool exclusive, | 97 bool exclusive, |
95 bool recursive, | 98 bool recursive, |
96 const StatusCallback& callback) { | 99 const StatusCallback& callback) { |
97 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
98 if (!operation_runner_.get()) { | 101 if (!operation_runner_.get()) { |
99 AbortOperation(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 102 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
100 return; | 103 return; |
101 } | 104 } |
102 if (!is_directory_operation_enabled_) { | 105 if (!is_directory_operation_enabled_) { |
103 AbortOperation(callback, base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 106 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
104 return; | 107 return; |
105 } | 108 } |
106 DCHECK(operation_runner_.get()); | 109 DCHECK(operation_runner_.get()); |
107 target_paths_.push_back(url); | 110 target_paths_.push_back(url); |
108 completion_callback_ = callback; | 111 completion_callback_ = callback; |
109 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 112 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
110 this, | 113 AsWeakPtr(), |
111 base::Bind(&FileSystemOperation::CreateDirectory, | 114 base::Bind(&FileSystemOperation::CreateDirectory, |
112 base::Unretained(NewOperation()), | 115 NewOperation()->AsWeakPtr(), |
113 url, exclusive, recursive, | 116 url, exclusive, recursive, |
114 base::Bind(&self::DidFinish, base::Owned(this))))); | 117 base::Bind(&self::DidFinish, AsWeakPtr())))); |
115 operation_runner_->PostOperationTask(task.Pass()); | 118 operation_runner_->PostOperationTask(task.Pass()); |
116 } | 119 } |
117 | 120 |
118 void SyncableFileSystemOperation::Copy( | 121 void SyncableFileSystemOperation::Copy( |
119 const FileSystemURL& src_url, | 122 const FileSystemURL& src_url, |
120 const FileSystemURL& dest_url, | 123 const FileSystemURL& dest_url, |
121 const StatusCallback& callback) { | 124 const StatusCallback& callback) { |
122 DCHECK(CalledOnValidThread()); | 125 DCHECK(CalledOnValidThread()); |
123 if (!operation_runner_.get()) { | 126 if (!operation_runner_.get()) { |
124 AbortOperation(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 127 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
125 return; | 128 return; |
126 } | 129 } |
127 DCHECK(operation_runner_.get()); | 130 DCHECK(operation_runner_.get()); |
128 target_paths_.push_back(dest_url); | 131 target_paths_.push_back(dest_url); |
129 completion_callback_ = callback; | 132 completion_callback_ = callback; |
130 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 133 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
131 this, | 134 AsWeakPtr(), |
132 base::Bind(&FileSystemOperation::Copy, | 135 base::Bind(&FileSystemOperation::Copy, |
133 base::Unretained(NewOperation()), | 136 NewOperation()->AsWeakPtr(), |
134 src_url, dest_url, | 137 src_url, dest_url, |
135 base::Bind(&self::DidFinish, base::Owned(this))))); | 138 base::Bind(&self::DidFinish, AsWeakPtr())))); |
136 operation_runner_->PostOperationTask(task.Pass()); | 139 operation_runner_->PostOperationTask(task.Pass()); |
137 } | 140 } |
138 | 141 |
139 void SyncableFileSystemOperation::Move( | 142 void SyncableFileSystemOperation::Move( |
140 const FileSystemURL& src_url, | 143 const FileSystemURL& src_url, |
141 const FileSystemURL& dest_url, | 144 const FileSystemURL& dest_url, |
142 const StatusCallback& callback) { | 145 const StatusCallback& callback) { |
143 DCHECK(CalledOnValidThread()); | 146 DCHECK(CalledOnValidThread()); |
144 if (!operation_runner_.get()) { | 147 if (!operation_runner_.get()) { |
145 AbortOperation(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 148 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
146 return; | 149 return; |
147 } | 150 } |
148 DCHECK(operation_runner_.get()); | 151 DCHECK(operation_runner_.get()); |
149 target_paths_.push_back(src_url); | 152 target_paths_.push_back(src_url); |
150 target_paths_.push_back(dest_url); | 153 target_paths_.push_back(dest_url); |
151 completion_callback_ = callback; | 154 completion_callback_ = callback; |
152 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 155 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
153 this, | 156 AsWeakPtr(), |
154 base::Bind(&FileSystemOperation::Move, | 157 base::Bind(&FileSystemOperation::Move, |
155 base::Unretained(NewOperation()), | 158 NewOperation()->AsWeakPtr(), |
156 src_url, dest_url, | 159 src_url, dest_url, |
157 base::Bind(&self::DidFinish, base::Owned(this))))); | 160 base::Bind(&self::DidFinish, AsWeakPtr())))); |
158 operation_runner_->PostOperationTask(task.Pass()); | 161 operation_runner_->PostOperationTask(task.Pass()); |
159 } | 162 } |
160 | 163 |
161 void SyncableFileSystemOperation::DirectoryExists( | 164 void SyncableFileSystemOperation::DirectoryExists( |
162 const FileSystemURL& url, | 165 const FileSystemURL& url, |
163 const StatusCallback& callback) { | 166 const StatusCallback& callback) { |
164 DCHECK(CalledOnValidThread()); | 167 DCHECK(CalledOnValidThread()); |
165 if (!operation_runner_.get()) { | |
166 AbortOperation(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | |
167 return; | |
168 } | |
169 NewOperation()->DirectoryExists(url, callback); | 168 NewOperation()->DirectoryExists(url, callback); |
170 delete this; | |
171 } | 169 } |
172 | 170 |
173 void SyncableFileSystemOperation::FileExists( | 171 void SyncableFileSystemOperation::FileExists( |
174 const FileSystemURL& url, | 172 const FileSystemURL& url, |
175 const StatusCallback& callback) { | 173 const StatusCallback& callback) { |
176 DCHECK(CalledOnValidThread()); | 174 DCHECK(CalledOnValidThread()); |
177 if (!operation_runner_.get()) { | |
178 AbortOperation(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | |
179 return; | |
180 } | |
181 NewOperation()->FileExists(url, callback); | 175 NewOperation()->FileExists(url, callback); |
182 delete this; | |
183 } | 176 } |
184 | 177 |
185 void SyncableFileSystemOperation::GetMetadata( | 178 void SyncableFileSystemOperation::GetMetadata( |
186 const FileSystemURL& url, | 179 const FileSystemURL& url, |
187 const GetMetadataCallback& callback) { | 180 const GetMetadataCallback& callback) { |
188 DCHECK(CalledOnValidThread()); | 181 DCHECK(CalledOnValidThread()); |
189 if (!operation_runner_.get()) { | |
190 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, | |
191 base::PlatformFileInfo(), | |
192 base::FilePath()); | |
193 delete this; | |
194 return; | |
195 } | |
196 NewOperation()->GetMetadata(url, callback); | 182 NewOperation()->GetMetadata(url, callback); |
197 delete this; | |
198 } | 183 } |
199 | 184 |
200 void SyncableFileSystemOperation::ReadDirectory( | 185 void SyncableFileSystemOperation::ReadDirectory( |
201 const FileSystemURL& url, | 186 const FileSystemURL& url, |
202 const ReadDirectoryCallback& callback) { | 187 const ReadDirectoryCallback& callback) { |
203 DCHECK(CalledOnValidThread()); | 188 DCHECK(CalledOnValidThread()); |
204 if (!operation_runner_.get()) { | |
205 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FileEntryList(), false); | |
206 delete this; | |
207 return; | |
208 } | |
209 // This is a read operation and there'd be no hard to let it go even if | 189 // This is a read operation and there'd be no hard to let it go even if |
210 // directory operation is disabled. (And we should allow this if it's made | 190 // directory operation is disabled. (And we should allow this if it's made |
211 // on the root directory) | 191 // on the root directory) |
212 NewOperation()->ReadDirectory(url, callback); | 192 NewOperation()->ReadDirectory(url, callback); |
213 delete this; | |
214 } | 193 } |
215 | 194 |
216 void SyncableFileSystemOperation::Remove( | 195 void SyncableFileSystemOperation::Remove( |
217 const FileSystemURL& url, bool recursive, | 196 const FileSystemURL& url, bool recursive, |
218 const StatusCallback& callback) { | 197 const StatusCallback& callback) { |
219 DCHECK(CalledOnValidThread()); | 198 DCHECK(CalledOnValidThread()); |
220 if (!operation_runner_.get()) { | 199 if (!operation_runner_.get()) { |
221 AbortOperation(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 200 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
222 return; | 201 return; |
223 } | 202 } |
224 DCHECK(operation_runner_.get()); | 203 DCHECK(operation_runner_.get()); |
225 target_paths_.push_back(url); | 204 target_paths_.push_back(url); |
226 completion_callback_ = callback; | 205 completion_callback_ = callback; |
227 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 206 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
228 this, | 207 AsWeakPtr(), |
229 base::Bind(&FileSystemOperation::Remove, | 208 base::Bind(&FileSystemOperation::Remove, |
230 base::Unretained(NewOperation()), | 209 NewOperation()->AsWeakPtr(), |
231 url, recursive, | 210 url, recursive, |
232 base::Bind(&self::DidFinish, base::Owned(this))))); | 211 base::Bind(&self::DidFinish, AsWeakPtr())))); |
233 operation_runner_->PostOperationTask(task.Pass()); | 212 operation_runner_->PostOperationTask(task.Pass()); |
234 } | 213 } |
235 | 214 |
236 void SyncableFileSystemOperation::Write( | 215 void SyncableFileSystemOperation::Write( |
237 const net::URLRequestContext* url_request_context, | 216 const net::URLRequestContext* url_request_context, |
238 const FileSystemURL& url, | 217 const FileSystemURL& url, |
239 const GURL& blob_url, | 218 const GURL& blob_url, |
240 int64 offset, | 219 int64 offset, |
241 const WriteCallback& callback) { | 220 const WriteCallback& callback) { |
242 DCHECK(CalledOnValidThread()); | 221 DCHECK(CalledOnValidThread()); |
243 if (!operation_runner_.get()) { | 222 if (!operation_runner_.get()) { |
244 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, 0, true); | 223 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, 0, true); |
245 delete this; | |
246 return; | 224 return; |
247 } | 225 } |
248 DCHECK(operation_runner_.get()); | 226 DCHECK(operation_runner_.get()); |
249 target_paths_.push_back(url); | 227 target_paths_.push_back(url); |
250 completion_callback_ = base::Bind(&WriteCallbackAdapter, callback); | 228 completion_callback_ = base::Bind(&WriteCallbackAdapter, callback); |
251 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 229 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
252 this, | 230 AsWeakPtr(), |
253 NewOperation()->GetWriteClosure( | 231 NewOperation()->GetWriteClosure( |
254 url_request_context, url, blob_url, offset, | 232 url_request_context, url, blob_url, offset, |
255 base::Bind(&self::DidWrite, base::Owned(this), callback)))); | 233 base::Bind(&self::DidWrite, AsWeakPtr(), callback)))); |
256 operation_runner_->PostOperationTask(task.Pass()); | 234 operation_runner_->PostOperationTask(task.Pass()); |
257 } | 235 } |
258 | 236 |
259 void SyncableFileSystemOperation::Truncate( | 237 void SyncableFileSystemOperation::Truncate( |
260 const FileSystemURL& url, int64 length, | 238 const FileSystemURL& url, int64 length, |
261 const StatusCallback& callback) { | 239 const StatusCallback& callback) { |
262 DCHECK(CalledOnValidThread()); | 240 DCHECK(CalledOnValidThread()); |
263 if (!operation_runner_.get()) { | 241 if (!operation_runner_.get()) { |
264 AbortOperation(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 242 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
265 return; | 243 return; |
266 } | 244 } |
267 DCHECK(operation_runner_.get()); | 245 DCHECK(operation_runner_.get()); |
268 target_paths_.push_back(url); | 246 target_paths_.push_back(url); |
269 completion_callback_ = callback; | 247 completion_callback_ = callback; |
270 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 248 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
271 this, | 249 AsWeakPtr(), |
272 base::Bind(&FileSystemOperation::Truncate, | 250 base::Bind(&FileSystemOperation::Truncate, |
273 base::Unretained(NewOperation()), | 251 NewOperation()->AsWeakPtr(), |
274 url, length, | 252 url, length, |
275 base::Bind(&self::DidFinish, base::Owned(this))))); | 253 base::Bind(&self::DidFinish, AsWeakPtr())))); |
276 operation_runner_->PostOperationTask(task.Pass()); | 254 operation_runner_->PostOperationTask(task.Pass()); |
277 } | 255 } |
278 | 256 |
279 void SyncableFileSystemOperation::TouchFile( | 257 void SyncableFileSystemOperation::TouchFile( |
280 const FileSystemURL& url, | 258 const FileSystemURL& url, |
281 const base::Time& last_access_time, | 259 const base::Time& last_access_time, |
282 const base::Time& last_modified_time, | 260 const base::Time& last_modified_time, |
283 const StatusCallback& callback) { | 261 const StatusCallback& callback) { |
284 DCHECK(CalledOnValidThread()); | 262 DCHECK(CalledOnValidThread()); |
285 if (!operation_runner_.get()) { | |
286 AbortOperation(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | |
287 return; | |
288 } | |
289 NewOperation()->TouchFile(url, last_access_time, | 263 NewOperation()->TouchFile(url, last_access_time, |
290 last_modified_time, callback); | 264 last_modified_time, callback); |
291 delete this; | |
292 } | 265 } |
293 | 266 |
294 void SyncableFileSystemOperation::OpenFile( | 267 void SyncableFileSystemOperation::OpenFile( |
295 const FileSystemURL& url, | 268 const FileSystemURL& url, |
296 int file_flags, | 269 int file_flags, |
297 base::ProcessHandle peer_handle, | 270 base::ProcessHandle peer_handle, |
298 const OpenFileCallback& callback) { | 271 const OpenFileCallback& callback) { |
299 NOTREACHED(); | 272 NOTREACHED(); |
300 delete this; | |
301 } | 273 } |
302 | 274 |
303 void SyncableFileSystemOperation::Cancel( | 275 void SyncableFileSystemOperation::Cancel( |
304 const StatusCallback& cancel_callback) { | 276 const StatusCallback& cancel_callback) { |
305 DCHECK(CalledOnValidThread()); | 277 DCHECK(CalledOnValidThread()); |
306 DCHECK(inflight_operation_); | 278 DCHECK(inflight_operation_); |
307 inflight_operation_->Cancel(cancel_callback); | 279 inflight_operation_->Cancel(cancel_callback); |
308 } | 280 } |
309 | 281 |
310 void SyncableFileSystemOperation::CreateSnapshotFile( | 282 void SyncableFileSystemOperation::CreateSnapshotFile( |
311 const FileSystemURL& path, | 283 const FileSystemURL& path, |
312 const SnapshotFileCallback& callback) { | 284 const SnapshotFileCallback& callback) { |
313 DCHECK(CalledOnValidThread()); | 285 DCHECK(CalledOnValidThread()); |
314 if (!operation_runner_.get()) { | |
315 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, | |
316 base::PlatformFileInfo(), | |
317 base::FilePath(), | |
318 NULL); | |
319 delete this; | |
320 return; | |
321 } | |
322 NewOperation()->CreateSnapshotFile(path, callback); | 286 NewOperation()->CreateSnapshotFile(path, callback); |
323 delete this; | |
324 } | 287 } |
325 | 288 |
326 void SyncableFileSystemOperation::CopyInForeignFile( | 289 void SyncableFileSystemOperation::CopyInForeignFile( |
327 const base::FilePath& src_local_disk_path, | 290 const base::FilePath& src_local_disk_path, |
328 const FileSystemURL& dest_url, | 291 const FileSystemURL& dest_url, |
329 const StatusCallback& callback) { | 292 const StatusCallback& callback) { |
330 DCHECK(CalledOnValidThread()); | 293 DCHECK(CalledOnValidThread()); |
331 if (!operation_runner_.get()) { | 294 if (!operation_runner_.get()) { |
332 AbortOperation(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); | 295 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND); |
333 return; | 296 return; |
334 } | 297 } |
335 DCHECK(operation_runner_.get()); | 298 DCHECK(operation_runner_.get()); |
336 target_paths_.push_back(dest_url); | 299 target_paths_.push_back(dest_url); |
337 completion_callback_ = callback; | 300 completion_callback_ = callback; |
338 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 301 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
339 this, | 302 AsWeakPtr(), |
340 base::Bind(&LocalFileSystemOperation::CopyInForeignFile, | 303 base::Bind(&LocalFileSystemOperation::CopyInForeignFile, |
341 base::Unretained(NewOperation()), | 304 NewOperation()->AsWeakPtr(), |
342 src_local_disk_path, dest_url, | 305 src_local_disk_path, dest_url, |
343 base::Bind(&self::DidFinish, base::Owned(this))))); | 306 base::Bind(&self::DidFinish, AsWeakPtr())))); |
344 operation_runner_->PostOperationTask(task.Pass()); | 307 operation_runner_->PostOperationTask(task.Pass()); |
345 } | 308 } |
346 | 309 |
347 SyncableFileSystemOperation::SyncableFileSystemOperation( | 310 SyncableFileSystemOperation::SyncableFileSystemOperation( |
348 const FileSystemURL& url, | 311 const FileSystemURL& url, |
349 fileapi::FileSystemContext* file_system_context, | 312 fileapi::FileSystemContext* file_system_context, |
350 scoped_ptr<FileSystemOperationContext> operation_context) | 313 scoped_ptr<FileSystemOperationContext> operation_context) |
351 : LocalFileSystemOperation(url, file_system_context, | 314 : LocalFileSystemOperation(url, file_system_context, |
352 operation_context.Pass()), | 315 operation_context.Pass()), |
353 url_(url), | 316 url_(url) { |
354 inflight_operation_(NULL) { | |
355 DCHECK(file_system_context); | 317 DCHECK(file_system_context); |
356 if (!file_system_context->sync_context()) { | 318 if (!file_system_context->sync_context()) { |
357 // Syncable FileSystem is opened in a file system context which doesn't | 319 // Syncable FileSystem is opened in a file system context which doesn't |
358 // support (or is not initialized for) the API. | 320 // support (or is not initialized for) the API. |
359 // Returning here to leave operation_runner_ as NULL. | 321 // Returning here to leave operation_runner_ as NULL. |
360 return; | 322 return; |
361 } | 323 } |
362 operation_runner_ = file_system_context->sync_context()->operation_runner(); | 324 operation_runner_ = file_system_context->sync_context()->operation_runner(); |
363 is_directory_operation_enabled_ = IsSyncFSDirectoryOperationEnabled(); | 325 is_directory_operation_enabled_ = IsSyncFSDirectoryOperationEnabled(); |
364 } | 326 } |
365 | 327 |
366 LocalFileSystemOperation* SyncableFileSystemOperation::NewOperation() { | 328 LocalFileSystemOperation* SyncableFileSystemOperation::NewOperation() { |
367 DCHECK(operation_context_); | 329 DCHECK(operation_context_); |
368 inflight_operation_ = new LocalFileSystemOperation( | 330 inflight_operation_.reset(new LocalFileSystemOperation( |
369 url_, file_system_context(), operation_context_.Pass()); | 331 url_, file_system_context(), operation_context_.Pass())); |
370 DCHECK(inflight_operation_); | 332 DCHECK(inflight_operation_); |
371 return inflight_operation_; | 333 return inflight_operation_.get(); |
372 } | 334 } |
373 | 335 |
374 void SyncableFileSystemOperation::DidFinish(base::PlatformFileError status) { | 336 void SyncableFileSystemOperation::DidFinish(base::PlatformFileError status) { |
375 DCHECK(CalledOnValidThread()); | 337 DCHECK(CalledOnValidThread()); |
376 DCHECK(!completion_callback_.is_null()); | 338 DCHECK(!completion_callback_.is_null()); |
377 if (operation_runner_.get()) | 339 if (operation_runner_.get()) |
378 operation_runner_->OnOperationCompleted(target_paths_); | 340 operation_runner_->OnOperationCompleted(target_paths_); |
379 completion_callback_.Run(status); | 341 completion_callback_.Run(status); |
380 } | 342 } |
381 | 343 |
382 void SyncableFileSystemOperation::DidWrite( | 344 void SyncableFileSystemOperation::DidWrite( |
383 const WriteCallback& callback, | 345 const WriteCallback& callback, |
384 base::PlatformFileError result, | 346 base::PlatformFileError result, |
385 int64 bytes, | 347 int64 bytes, |
386 bool complete) { | 348 bool complete) { |
387 DCHECK(CalledOnValidThread()); | 349 DCHECK(CalledOnValidThread()); |
388 if (!complete) { | 350 if (!complete) { |
389 callback.Run(result, bytes, complete); | 351 callback.Run(result, bytes, complete); |
390 return; | 352 return; |
391 } | 353 } |
392 if (operation_runner_.get()) | 354 if (operation_runner_.get()) |
393 operation_runner_->OnOperationCompleted(target_paths_); | 355 operation_runner_->OnOperationCompleted(target_paths_); |
394 callback.Run(result, bytes, complete); | 356 callback.Run(result, bytes, complete); |
395 } | 357 } |
396 | 358 |
397 void SyncableFileSystemOperation::OnCancelled() { | 359 void SyncableFileSystemOperation::OnCancelled() { |
398 DCHECK(!completion_callback_.is_null()); | 360 DCHECK(!completion_callback_.is_null()); |
399 completion_callback_.Run(base::PLATFORM_FILE_ERROR_ABORT); | 361 completion_callback_.Run(base::PLATFORM_FILE_ERROR_ABORT); |
400 delete inflight_operation_; | |
401 } | |
402 | |
403 void SyncableFileSystemOperation::AbortOperation( | |
404 const StatusCallback& callback, | |
405 base::PlatformFileError error) { | |
406 callback.Run(error); | |
407 delete inflight_operation_; | |
408 delete this; | |
409 } | 362 } |
410 | 363 |
411 } // namespace sync_file_system | 364 } // namespace sync_file_system |
OLD | NEW |