OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
11 #include "chrome/browser/chromeos/drive/drive.pb.h" | 11 #include "chrome/browser/chromeos/drive/drive.pb.h" |
12 #include "chrome/browser/chromeos/drive/file_cache.h" | 12 #include "chrome/browser/chromeos/drive/file_cache.h" |
13 #include "chrome/browser/chromeos/drive/file_change.h" | 13 #include "chrome/browser/chromeos/drive/file_change.h" |
14 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" | 14 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h" |
15 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 15 #include "chrome/browser/chromeos/drive/file_system/operation_delegate.h" |
16 #include "chrome/browser/chromeos/drive/file_system_util.h" | 16 #include "chrome/browser/chromeos/drive/file_system_util.h" |
17 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 17 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
18 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" | 18 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
19 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 19 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
20 #include "chrome/browser/drive/drive_api_util.h" | 20 #include "chrome/browser/drive/drive_api_util.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "google_apis/drive/drive_api_parser.h" | 22 #include "google_apis/drive/drive_api_parser.h" |
23 | 23 |
24 using content::BrowserThread; | 24 using content::BrowserThread; |
25 | 25 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 return metadata->GetFilePath(local_id, ¶ms->changed_path); | 269 return metadata->GetFilePath(local_id, ¶ms->changed_path); |
270 } | 270 } |
271 | 271 |
272 params->location_type = HAS_PARENT; | 272 params->location_type = HAS_PARENT; |
273 return FILE_ERROR_OK; | 273 return FILE_ERROR_OK; |
274 } | 274 } |
275 | 275 |
276 } // namespace | 276 } // namespace |
277 | 277 |
278 CopyOperation::CopyOperation(base::SequencedTaskRunner* blocking_task_runner, | 278 CopyOperation::CopyOperation(base::SequencedTaskRunner* blocking_task_runner, |
279 OperationObserver* observer, | 279 OperationDelegate* delegate, |
280 JobScheduler* scheduler, | 280 JobScheduler* scheduler, |
281 internal::ResourceMetadata* metadata, | 281 internal::ResourceMetadata* metadata, |
282 internal::FileCache* cache, | 282 internal::FileCache* cache, |
283 const ResourceIdCanonicalizer& id_canonicalizer) | 283 const ResourceIdCanonicalizer& id_canonicalizer) |
284 : blocking_task_runner_(blocking_task_runner), | 284 : blocking_task_runner_(blocking_task_runner), |
285 observer_(observer), | 285 delegate_(delegate), |
286 scheduler_(scheduler), | 286 scheduler_(scheduler), |
287 metadata_(metadata), | 287 metadata_(metadata), |
288 cache_(cache), | 288 cache_(cache), |
289 id_canonicalizer_(id_canonicalizer), | 289 id_canonicalizer_(id_canonicalizer), |
290 create_file_operation_(new CreateFileOperation(blocking_task_runner, | 290 create_file_operation_(new CreateFileOperation(blocking_task_runner, |
291 observer, | 291 delegate, |
292 metadata)), | 292 metadata)), |
293 weak_ptr_factory_(this) { | 293 weak_ptr_factory_(this) { |
294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
295 } | 295 } |
296 | 296 |
297 CopyOperation::~CopyOperation() { | 297 CopyOperation::~CopyOperation() { |
298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
299 } | 299 } |
300 | 300 |
301 void CopyOperation::Copy(const base::FilePath& src_file_path, | 301 void CopyOperation::Copy(const base::FilePath& src_file_path, |
(...skipping 26 matching lines...) Expand all Loading... |
328 void CopyOperation::CopyAfterTryToCopyLocally( | 328 void CopyOperation::CopyAfterTryToCopyLocally( |
329 const CopyParams* params, | 329 const CopyParams* params, |
330 const std::vector<std::string>* updated_local_ids, | 330 const std::vector<std::string>* updated_local_ids, |
331 const bool* directory_changed, | 331 const bool* directory_changed, |
332 const bool* should_copy_on_server, | 332 const bool* should_copy_on_server, |
333 FileError error) { | 333 FileError error) { |
334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
335 DCHECK(!params->callback.is_null()); | 335 DCHECK(!params->callback.is_null()); |
336 | 336 |
337 for (size_t i = 0; i < updated_local_ids->size(); ++i) | 337 for (size_t i = 0; i < updated_local_ids->size(); ++i) |
338 observer_->OnEntryUpdatedByOperation((*updated_local_ids)[i]); | 338 delegate_->OnEntryUpdatedByOperation((*updated_local_ids)[i]); |
339 | 339 |
340 if (*directory_changed) { | 340 if (*directory_changed) { |
341 FileChange changed_file; | 341 FileChange changed_file; |
342 DCHECK(!params->src_entry.file_info().is_directory()); | 342 DCHECK(!params->src_entry.file_info().is_directory()); |
343 changed_file.Update(params->dest_file_path, | 343 changed_file.Update(params->dest_file_path, |
344 FileChange::FILE_TYPE_FILE, | 344 FileChange::FILE_TYPE_FILE, |
345 FileChange::ADD_OR_UPDATE); | 345 FileChange::ADD_OR_UPDATE); |
346 observer_->OnFileChangedByOperation(changed_file); | 346 delegate_->OnFileChangedByOperation(changed_file); |
347 } | 347 } |
348 | 348 |
349 if (error != FILE_ERROR_OK || !*should_copy_on_server) { | 349 if (error != FILE_ERROR_OK || !*should_copy_on_server) { |
350 params->callback.Run(error); | 350 params->callback.Run(error); |
351 return; | 351 return; |
352 } | 352 } |
353 | 353 |
354 if (params->parent_entry.resource_id().empty()) { | 354 if (params->parent_entry.resource_id().empty()) { |
355 // Parent entry may be being synced. | 355 // Parent entry may be being synced. |
356 const bool waiting = observer_->WaitForSyncComplete( | 356 const bool waiting = delegate_->WaitForSyncComplete( |
357 params->parent_entry.local_id(), | 357 params->parent_entry.local_id(), |
358 base::Bind(&CopyOperation::CopyAfterParentSync, | 358 base::Bind(&CopyOperation::CopyAfterParentSync, |
359 weak_ptr_factory_.GetWeakPtr(), *params)); | 359 weak_ptr_factory_.GetWeakPtr(), *params)); |
360 if (!waiting) | 360 if (!waiting) |
361 params->callback.Run(FILE_ERROR_NOT_FOUND); | 361 params->callback.Run(FILE_ERROR_NOT_FOUND); |
362 } else { | 362 } else { |
363 CopyAfterGetParentResourceId(*params, ¶ms->parent_entry, FILE_ERROR_OK); | 363 CopyAfterGetParentResourceId(*params, ¶ms->parent_entry, FILE_ERROR_OK); |
364 } | 364 } |
365 } | 365 } |
366 | 366 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 params->parent_resource_id, | 496 params->parent_resource_id, |
497 params->new_title, | 497 params->new_title, |
498 base::Time(), | 498 base::Time(), |
499 params->callback); | 499 params->callback); |
500 break; | 500 break; |
501 // When |resource_id| has no parent, we just set the new destination folder | 501 // When |resource_id| has no parent, we just set the new destination folder |
502 // as the parent, for sharing the document between the original source. | 502 // as the parent, for sharing the document between the original source. |
503 // This reparenting is already done in LocalWorkForTransferJsonGdocFile(). | 503 // This reparenting is already done in LocalWorkForTransferJsonGdocFile(). |
504 case IS_ORPHAN: { | 504 case IS_ORPHAN: { |
505 DCHECK(!params->changed_path.empty()); | 505 DCHECK(!params->changed_path.empty()); |
506 observer_->OnEntryUpdatedByOperation(params->local_id); | 506 delegate_->OnEntryUpdatedByOperation(params->local_id); |
507 | 507 |
508 FileChange changed_file; | 508 FileChange changed_file; |
509 changed_file.Update( | 509 changed_file.Update( |
510 params->changed_path, | 510 params->changed_path, |
511 FileChange::FILE_TYPE_FILE, // This must be a hosted document. | 511 FileChange::FILE_TYPE_FILE, // This must be a hosted document. |
512 FileChange::ADD_OR_UPDATE); | 512 FileChange::ADD_OR_UPDATE); |
513 observer_->OnFileChangedByOperation(changed_file); | 513 delegate_->OnFileChangedByOperation(changed_file); |
514 params->callback.Run(error); | 514 params->callback.Run(error); |
515 break; | 515 break; |
516 } | 516 } |
517 // When the |resource_id| is not in the local metadata, assume it to be a | 517 // When the |resource_id| is not in the local metadata, assume it to be a |
518 // document just now shared on the server but not synced locally. | 518 // document just now shared on the server but not synced locally. |
519 // Same as the IS_ORPHAN case, we want to deal the case by setting parent, | 519 // Same as the IS_ORPHAN case, we want to deal the case by setting parent, |
520 // but this time we need to resort to server side operation. | 520 // but this time we need to resort to server side operation. |
521 case NOT_IN_METADATA: | 521 case NOT_IN_METADATA: |
522 scheduler_->UpdateResource( | 522 scheduler_->UpdateResource( |
523 params->resource_id, | 523 params->resource_id, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 const FileOperationCallback& callback, | 586 const FileOperationCallback& callback, |
587 base::FilePath* file_path, | 587 base::FilePath* file_path, |
588 const ResourceEntry* entry, | 588 const ResourceEntry* entry, |
589 FileError error) { | 589 FileError error) { |
590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
591 DCHECK(!callback.is_null()); | 591 DCHECK(!callback.is_null()); |
592 | 592 |
593 if (error == FILE_ERROR_OK) { | 593 if (error == FILE_ERROR_OK) { |
594 FileChange changed_file; | 594 FileChange changed_file; |
595 changed_file.Update(*file_path, *entry, FileChange::ADD_OR_UPDATE); | 595 changed_file.Update(*file_path, *entry, FileChange::ADD_OR_UPDATE); |
596 observer_->OnFileChangedByOperation(changed_file); | 596 delegate_->OnFileChangedByOperation(changed_file); |
597 } | 597 } |
598 callback.Run(error); | 598 callback.Run(error); |
599 } | 599 } |
600 | 600 |
601 void CopyOperation::ScheduleTransferRegularFile( | 601 void CopyOperation::ScheduleTransferRegularFile( |
602 const base::FilePath& local_src_path, | 602 const base::FilePath& local_src_path, |
603 const base::FilePath& remote_dest_path, | 603 const base::FilePath& remote_dest_path, |
604 const FileOperationCallback& callback) { | 604 const FileOperationCallback& callback) { |
605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
606 DCHECK(!callback.is_null()); | 606 DCHECK(!callback.is_null()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 const base::FilePath& remote_dest_path, | 653 const base::FilePath& remote_dest_path, |
654 const ResourceEntry* entry, | 654 const ResourceEntry* entry, |
655 std::string* local_id, | 655 std::string* local_id, |
656 FileError error) { | 656 FileError error) { |
657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
658 DCHECK(!callback.is_null()); | 658 DCHECK(!callback.is_null()); |
659 | 659 |
660 if (error == FILE_ERROR_OK) { | 660 if (error == FILE_ERROR_OK) { |
661 FileChange changed_file; | 661 FileChange changed_file; |
662 changed_file.Update(remote_dest_path, *entry, FileChange::ADD_OR_UPDATE); | 662 changed_file.Update(remote_dest_path, *entry, FileChange::ADD_OR_UPDATE); |
663 observer_->OnFileChangedByOperation(changed_file); | 663 delegate_->OnFileChangedByOperation(changed_file); |
664 observer_->OnEntryUpdatedByOperation(*local_id); | 664 delegate_->OnEntryUpdatedByOperation(*local_id); |
665 } | 665 } |
666 callback.Run(error); | 666 callback.Run(error); |
667 } | 667 } |
668 | 668 |
669 } // namespace file_system | 669 } // namespace file_system |
670 } // namespace drive | 670 } // namespace drive |
OLD | NEW |