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 "chrome/browser/sync_file_system/local/syncable_file_system_operation.h
" | 5 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h
" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" | 11 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" |
10 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 12 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
11 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h
" | 13 #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h
" |
12 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 14 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
13 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
14 #include "storage/browser/blob/shareable_file_reference.h" | 16 #include "storage/browser/blob/shareable_file_reference.h" |
15 #include "storage/browser/fileapi/file_system_context.h" | 17 #include "storage/browser/fileapi/file_system_context.h" |
16 #include "storage/browser/fileapi/file_system_operation.h" | 18 #include "storage/browser/fileapi/file_system_operation.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 85 } |
84 DCHECK(operation_runner_.get()); | 86 DCHECK(operation_runner_.get()); |
85 target_paths_.push_back(url); | 87 target_paths_.push_back(url); |
86 completion_callback_ = callback; | 88 completion_callback_ = callback; |
87 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 89 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
88 weak_factory_.GetWeakPtr(), | 90 weak_factory_.GetWeakPtr(), |
89 base::Bind(&FileSystemOperation::CreateFile, | 91 base::Bind(&FileSystemOperation::CreateFile, |
90 base::Unretained(impl_.get()), | 92 base::Unretained(impl_.get()), |
91 url, exclusive, | 93 url, exclusive, |
92 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 94 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
93 operation_runner_->PostOperationTask(task.Pass()); | 95 operation_runner_->PostOperationTask(std::move(task)); |
94 } | 96 } |
95 | 97 |
96 void SyncableFileSystemOperation::CreateDirectory( | 98 void SyncableFileSystemOperation::CreateDirectory( |
97 const FileSystemURL& url, | 99 const FileSystemURL& url, |
98 bool exclusive, | 100 bool exclusive, |
99 bool recursive, | 101 bool recursive, |
100 const StatusCallback& callback) { | 102 const StatusCallback& callback) { |
101 DCHECK(CalledOnValidThread()); | 103 DCHECK(CalledOnValidThread()); |
102 if (!operation_runner_.get()) { | 104 if (!operation_runner_.get()) { |
103 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 105 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
104 return; | 106 return; |
105 } | 107 } |
106 DCHECK(operation_runner_.get()); | 108 DCHECK(operation_runner_.get()); |
107 target_paths_.push_back(url); | 109 target_paths_.push_back(url); |
108 completion_callback_ = callback; | 110 completion_callback_ = callback; |
109 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 111 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
110 weak_factory_.GetWeakPtr(), | 112 weak_factory_.GetWeakPtr(), |
111 base::Bind(&FileSystemOperation::CreateDirectory, | 113 base::Bind(&FileSystemOperation::CreateDirectory, |
112 base::Unretained(impl_.get()), | 114 base::Unretained(impl_.get()), |
113 url, exclusive, recursive, | 115 url, exclusive, recursive, |
114 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 116 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
115 operation_runner_->PostOperationTask(task.Pass()); | 117 operation_runner_->PostOperationTask(std::move(task)); |
116 } | 118 } |
117 | 119 |
118 void SyncableFileSystemOperation::Copy( | 120 void SyncableFileSystemOperation::Copy( |
119 const FileSystemURL& src_url, | 121 const FileSystemURL& src_url, |
120 const FileSystemURL& dest_url, | 122 const FileSystemURL& dest_url, |
121 CopyOrMoveOption option, | 123 CopyOrMoveOption option, |
122 ErrorBehavior error_behavior, | 124 ErrorBehavior error_behavior, |
123 const CopyProgressCallback& progress_callback, | 125 const CopyProgressCallback& progress_callback, |
124 const StatusCallback& callback) { | 126 const StatusCallback& callback) { |
125 DCHECK(CalledOnValidThread()); | 127 DCHECK(CalledOnValidThread()); |
126 if (!operation_runner_.get()) { | 128 if (!operation_runner_.get()) { |
127 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 129 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
128 return; | 130 return; |
129 } | 131 } |
130 DCHECK(operation_runner_.get()); | 132 DCHECK(operation_runner_.get()); |
131 target_paths_.push_back(dest_url); | 133 target_paths_.push_back(dest_url); |
132 completion_callback_ = callback; | 134 completion_callback_ = callback; |
133 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 135 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
134 weak_factory_.GetWeakPtr(), | 136 weak_factory_.GetWeakPtr(), |
135 base::Bind(&FileSystemOperation::Copy, base::Unretained(impl_.get()), | 137 base::Bind(&FileSystemOperation::Copy, base::Unretained(impl_.get()), |
136 src_url, dest_url, option, error_behavior, progress_callback, | 138 src_url, dest_url, option, error_behavior, progress_callback, |
137 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 139 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
138 operation_runner_->PostOperationTask(task.Pass()); | 140 operation_runner_->PostOperationTask(std::move(task)); |
139 } | 141 } |
140 | 142 |
141 void SyncableFileSystemOperation::Move( | 143 void SyncableFileSystemOperation::Move( |
142 const FileSystemURL& src_url, | 144 const FileSystemURL& src_url, |
143 const FileSystemURL& dest_url, | 145 const FileSystemURL& dest_url, |
144 CopyOrMoveOption option, | 146 CopyOrMoveOption option, |
145 const StatusCallback& callback) { | 147 const StatusCallback& callback) { |
146 DCHECK(CalledOnValidThread()); | 148 DCHECK(CalledOnValidThread()); |
147 if (!operation_runner_.get()) { | 149 if (!operation_runner_.get()) { |
148 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 150 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
149 return; | 151 return; |
150 } | 152 } |
151 DCHECK(operation_runner_.get()); | 153 DCHECK(operation_runner_.get()); |
152 target_paths_.push_back(src_url); | 154 target_paths_.push_back(src_url); |
153 target_paths_.push_back(dest_url); | 155 target_paths_.push_back(dest_url); |
154 completion_callback_ = callback; | 156 completion_callback_ = callback; |
155 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 157 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
156 weak_factory_.GetWeakPtr(), | 158 weak_factory_.GetWeakPtr(), |
157 base::Bind(&FileSystemOperation::Move, | 159 base::Bind(&FileSystemOperation::Move, |
158 base::Unretained(impl_.get()), | 160 base::Unretained(impl_.get()), |
159 src_url, dest_url, option, | 161 src_url, dest_url, option, |
160 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 162 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
161 operation_runner_->PostOperationTask(task.Pass()); | 163 operation_runner_->PostOperationTask(std::move(task)); |
162 } | 164 } |
163 | 165 |
164 void SyncableFileSystemOperation::DirectoryExists( | 166 void SyncableFileSystemOperation::DirectoryExists( |
165 const FileSystemURL& url, | 167 const FileSystemURL& url, |
166 const StatusCallback& callback) { | 168 const StatusCallback& callback) { |
167 DCHECK(CalledOnValidThread()); | 169 DCHECK(CalledOnValidThread()); |
168 impl_->DirectoryExists(url, callback); | 170 impl_->DirectoryExists(url, callback); |
169 } | 171 } |
170 | 172 |
171 void SyncableFileSystemOperation::FileExists( | 173 void SyncableFileSystemOperation::FileExists( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 205 } |
204 DCHECK(operation_runner_.get()); | 206 DCHECK(operation_runner_.get()); |
205 target_paths_.push_back(url); | 207 target_paths_.push_back(url); |
206 completion_callback_ = callback; | 208 completion_callback_ = callback; |
207 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 209 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
208 weak_factory_.GetWeakPtr(), | 210 weak_factory_.GetWeakPtr(), |
209 base::Bind(&FileSystemOperation::Remove, | 211 base::Bind(&FileSystemOperation::Remove, |
210 base::Unretained(impl_.get()), | 212 base::Unretained(impl_.get()), |
211 url, recursive, | 213 url, recursive, |
212 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 214 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
213 operation_runner_->PostOperationTask(task.Pass()); | 215 operation_runner_->PostOperationTask(std::move(task)); |
214 } | 216 } |
215 | 217 |
216 void SyncableFileSystemOperation::Write( | 218 void SyncableFileSystemOperation::Write( |
217 const FileSystemURL& url, | 219 const FileSystemURL& url, |
218 scoped_ptr<storage::FileWriterDelegate> writer_delegate, | 220 scoped_ptr<storage::FileWriterDelegate> writer_delegate, |
219 scoped_ptr<net::URLRequest> blob_request, | 221 scoped_ptr<net::URLRequest> blob_request, |
220 const WriteCallback& callback) { | 222 const WriteCallback& callback) { |
221 DCHECK(CalledOnValidThread()); | 223 DCHECK(CalledOnValidThread()); |
222 if (!operation_runner_.get()) { | 224 if (!operation_runner_.get()) { |
223 callback.Run(base::File::FILE_ERROR_NOT_FOUND, 0, true); | 225 callback.Run(base::File::FILE_ERROR_NOT_FOUND, 0, true); |
224 return; | 226 return; |
225 } | 227 } |
226 DCHECK(operation_runner_.get()); | 228 DCHECK(operation_runner_.get()); |
227 target_paths_.push_back(url); | 229 target_paths_.push_back(url); |
228 completion_callback_ = base::Bind(&WriteCallbackAdapter, callback); | 230 completion_callback_ = base::Bind(&WriteCallbackAdapter, callback); |
229 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 231 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
230 weak_factory_.GetWeakPtr(), | 232 weak_factory_.GetWeakPtr(), |
231 base::Bind(&FileSystemOperation::Write, | 233 base::Bind(&FileSystemOperation::Write, |
232 base::Unretained(impl_.get()), | 234 base::Unretained(impl_.get()), |
233 url, | 235 url, |
234 base::Passed(&writer_delegate), | 236 base::Passed(&writer_delegate), |
235 base::Passed(&blob_request), | 237 base::Passed(&blob_request), |
236 base::Bind(&self::DidWrite, weak_factory_.GetWeakPtr(), | 238 base::Bind(&self::DidWrite, weak_factory_.GetWeakPtr(), |
237 callback)))); | 239 callback)))); |
238 operation_runner_->PostOperationTask(task.Pass()); | 240 operation_runner_->PostOperationTask(std::move(task)); |
239 } | 241 } |
240 | 242 |
241 void SyncableFileSystemOperation::Truncate(const FileSystemURL& url, | 243 void SyncableFileSystemOperation::Truncate(const FileSystemURL& url, |
242 int64_t length, | 244 int64_t length, |
243 const StatusCallback& callback) { | 245 const StatusCallback& callback) { |
244 DCHECK(CalledOnValidThread()); | 246 DCHECK(CalledOnValidThread()); |
245 if (!operation_runner_.get()) { | 247 if (!operation_runner_.get()) { |
246 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 248 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
247 return; | 249 return; |
248 } | 250 } |
249 DCHECK(operation_runner_.get()); | 251 DCHECK(operation_runner_.get()); |
250 target_paths_.push_back(url); | 252 target_paths_.push_back(url); |
251 completion_callback_ = callback; | 253 completion_callback_ = callback; |
252 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 254 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
253 weak_factory_.GetWeakPtr(), | 255 weak_factory_.GetWeakPtr(), |
254 base::Bind(&FileSystemOperation::Truncate, | 256 base::Bind(&FileSystemOperation::Truncate, |
255 base::Unretained(impl_.get()), | 257 base::Unretained(impl_.get()), |
256 url, length, | 258 url, length, |
257 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 259 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
258 operation_runner_->PostOperationTask(task.Pass()); | 260 operation_runner_->PostOperationTask(std::move(task)); |
259 } | 261 } |
260 | 262 |
261 void SyncableFileSystemOperation::TouchFile( | 263 void SyncableFileSystemOperation::TouchFile( |
262 const FileSystemURL& url, | 264 const FileSystemURL& url, |
263 const base::Time& last_access_time, | 265 const base::Time& last_access_time, |
264 const base::Time& last_modified_time, | 266 const base::Time& last_modified_time, |
265 const StatusCallback& callback) { | 267 const StatusCallback& callback) { |
266 DCHECK(CalledOnValidThread()); | 268 DCHECK(CalledOnValidThread()); |
267 impl_->TouchFile(url, last_access_time, last_modified_time, callback); | 269 impl_->TouchFile(url, last_access_time, last_modified_time, callback); |
268 } | 270 } |
(...skipping 29 matching lines...) Expand all Loading... |
298 } | 300 } |
299 DCHECK(operation_runner_.get()); | 301 DCHECK(operation_runner_.get()); |
300 target_paths_.push_back(dest_url); | 302 target_paths_.push_back(dest_url); |
301 completion_callback_ = callback; | 303 completion_callback_ = callback; |
302 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( | 304 scoped_ptr<SyncableFileOperationRunner::Task> task(new QueueableTask( |
303 weak_factory_.GetWeakPtr(), | 305 weak_factory_.GetWeakPtr(), |
304 base::Bind(&FileSystemOperation::CopyInForeignFile, | 306 base::Bind(&FileSystemOperation::CopyInForeignFile, |
305 base::Unretained(impl_.get()), | 307 base::Unretained(impl_.get()), |
306 src_local_disk_path, dest_url, | 308 src_local_disk_path, dest_url, |
307 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); | 309 base::Bind(&self::DidFinish, weak_factory_.GetWeakPtr())))); |
308 operation_runner_->PostOperationTask(task.Pass()); | 310 operation_runner_->PostOperationTask(std::move(task)); |
309 } | 311 } |
310 | 312 |
311 void SyncableFileSystemOperation::RemoveFile( | 313 void SyncableFileSystemOperation::RemoveFile( |
312 const FileSystemURL& url, | 314 const FileSystemURL& url, |
313 const StatusCallback& callback) { | 315 const StatusCallback& callback) { |
314 DCHECK(CalledOnValidThread()); | 316 DCHECK(CalledOnValidThread()); |
315 impl_->RemoveFile(url, callback); | 317 impl_->RemoveFile(url, callback); |
316 } | 318 } |
317 | 319 |
318 void SyncableFileSystemOperation::RemoveDirectory( | 320 void SyncableFileSystemOperation::RemoveDirectory( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 SyncFileSystemBackend* backend = | 358 SyncFileSystemBackend* backend = |
357 SyncFileSystemBackend::GetBackend(file_system_context); | 359 SyncFileSystemBackend::GetBackend(file_system_context); |
358 DCHECK(backend); | 360 DCHECK(backend); |
359 if (!backend->sync_context()) { | 361 if (!backend->sync_context()) { |
360 // Syncable FileSystem is opened in a file system context which doesn't | 362 // Syncable FileSystem is opened in a file system context which doesn't |
361 // support (or is not initialized for) the API. | 363 // support (or is not initialized for) the API. |
362 // Returning here to leave operation_runner_ as NULL. | 364 // Returning here to leave operation_runner_ as NULL. |
363 return; | 365 return; |
364 } | 366 } |
365 impl_.reset(storage::FileSystemOperation::Create( | 367 impl_.reset(storage::FileSystemOperation::Create( |
366 url_, file_system_context, operation_context.Pass())); | 368 url_, file_system_context, std::move(operation_context))); |
367 operation_runner_ = backend->sync_context()->operation_runner(); | 369 operation_runner_ = backend->sync_context()->operation_runner(); |
368 } | 370 } |
369 | 371 |
370 void SyncableFileSystemOperation::DidFinish(base::File::Error status) { | 372 void SyncableFileSystemOperation::DidFinish(base::File::Error status) { |
371 DCHECK(CalledOnValidThread()); | 373 DCHECK(CalledOnValidThread()); |
372 DCHECK(!completion_callback_.is_null()); | 374 DCHECK(!completion_callback_.is_null()); |
373 if (operation_runner_.get()) | 375 if (operation_runner_.get()) |
374 operation_runner_->OnOperationCompleted(target_paths_); | 376 operation_runner_->OnOperationCompleted(target_paths_); |
375 completion_callback_.Run(status); | 377 completion_callback_.Run(status); |
376 } | 378 } |
(...skipping 11 matching lines...) Expand all Loading... |
388 operation_runner_->OnOperationCompleted(target_paths_); | 390 operation_runner_->OnOperationCompleted(target_paths_); |
389 callback.Run(result, bytes, complete); | 391 callback.Run(result, bytes, complete); |
390 } | 392 } |
391 | 393 |
392 void SyncableFileSystemOperation::OnCancelled() { | 394 void SyncableFileSystemOperation::OnCancelled() { |
393 DCHECK(!completion_callback_.is_null()); | 395 DCHECK(!completion_callback_.is_null()); |
394 completion_callback_.Run(base::File::FILE_ERROR_ABORT); | 396 completion_callback_.Run(base::File::FILE_ERROR_ABORT); |
395 } | 397 } |
396 | 398 |
397 } // namespace sync_file_system | 399 } // namespace sync_file_system |
OLD | NEW |