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/sync_file_system/sync_file_system_service.h" | 5 #include "chrome/browser/sync_file_system/sync_file_system_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 DCHECK(num_results); | 125 DCHECK(num_results); |
126 | 126 |
127 if (file) | 127 if (file) |
128 file->SetString("status", SyncFileStatusToString(sync_file_status)); | 128 file->SetString("status", SyncFileStatusToString(sync_file_status)); |
129 | 129 |
130 // Once all results have been received, run the callback to signal end. | 130 // Once all results have been received, run the callback to signal end. |
131 DCHECK_LE(*num_results, files->GetSize()); | 131 DCHECK_LE(*num_results, files->GetSize()); |
132 if (++*num_results < files->GetSize()) | 132 if (++*num_results < files->GetSize()) |
133 return; | 133 return; |
134 | 134 |
135 callback.Run(files); | 135 callback.Run(*files); |
136 } | 136 } |
137 | 137 |
138 // We need this indirection because WeakPtr can only be bound to methods | 138 // We need this indirection because WeakPtr can only be bound to methods |
139 // without a return value. | 139 // without a return value. |
140 LocalChangeProcessor* GetLocalChangeProcessorAdapter( | 140 LocalChangeProcessor* GetLocalChangeProcessorAdapter( |
141 base::WeakPtr<SyncFileSystemService> service, | 141 base::WeakPtr<SyncFileSystemService> service, |
142 const GURL& origin) { | 142 const GURL& origin) { |
143 if (!service) | 143 if (!service) |
144 return NULL; | 144 return NULL; |
145 return service->GetLocalChangeProcessor(origin); | 145 return service->GetLocalChangeProcessor(origin); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 callback.Run(status); | 501 callback.Run(status); |
502 } | 502 } |
503 | 503 |
504 void SyncFileSystemService::DidInitializeFileSystemForDump( | 504 void SyncFileSystemService::DidInitializeFileSystemForDump( |
505 const GURL& origin, | 505 const GURL& origin, |
506 const DumpFilesCallback& callback, | 506 const DumpFilesCallback& callback, |
507 SyncStatusCode status) { | 507 SyncStatusCode status) { |
508 DCHECK(!origin.is_empty()); | 508 DCHECK(!origin.is_empty()); |
509 | 509 |
510 if (status != SYNC_STATUS_OK) { | 510 if (status != SYNC_STATUS_OK) { |
511 base::ListValue empty_result; | 511 callback.Run(base::ListValue()); |
512 callback.Run(&empty_result); | |
513 return; | 512 return; |
514 } | 513 } |
515 | 514 |
516 base::ListValue* files = | 515 GetRemoteService(origin)->DumpFiles( |
517 GetRemoteService(origin)->DumpFiles(origin).release(); | 516 origin, |
518 if (!files) { | 517 base::Bind( |
519 callback.Run(new base::ListValue); | 518 &SyncFileSystemService::DidDumpFiles, |
| 519 AsWeakPtr(), |
| 520 origin, |
| 521 callback)); |
| 522 } |
| 523 |
| 524 void SyncFileSystemService::DidDumpFiles( |
| 525 const GURL& origin, |
| 526 const DumpFilesCallback& callback, |
| 527 scoped_ptr<base::ListValue> dump_files) { |
| 528 if (!dump_files || !dump_files->GetSize()) { |
| 529 callback.Run(base::ListValue()); |
520 return; | 530 return; |
521 } | 531 } |
522 | 532 |
523 if (!files->GetSize()) { | 533 base::ListValue* files = dump_files.get(); |
524 callback.Run(files); | 534 base::Callback<void(base::DictionaryValue*, |
525 return; | 535 SyncStatusCode, |
526 } | 536 SyncFileStatus)> completion_callback = |
527 | 537 base::Bind(&DidGetFileSyncStatusForDump, |
528 base::Callback<void(base::DictionaryValue* file, | 538 base::Owned(dump_files.release()), |
529 SyncStatusCode sync_status, | 539 base::Owned(new size_t(0)), |
530 SyncFileStatus sync_file_status)> completion_callback = | 540 callback); |
531 base::Bind(&DidGetFileSyncStatusForDump, base::Owned(files), | |
532 base::Owned(new size_t(0)), callback); | |
533 | 541 |
534 // After all metadata loaded, sync status can be added to each entry. | 542 // After all metadata loaded, sync status can be added to each entry. |
535 for (size_t i = 0; i < files->GetSize(); ++i) { | 543 for (size_t i = 0; i < files->GetSize(); ++i) { |
536 base::DictionaryValue* file = NULL; | 544 base::DictionaryValue* file = NULL; |
537 std::string path_string; | 545 std::string path_string; |
538 if (!files->GetDictionary(i, &file) || | 546 if (!files->GetDictionary(i, &file) || |
539 !file->GetString("path", &path_string)) { | 547 !file->GetString("path", &path_string)) { |
540 NOTREACHED(); | 548 NOTREACHED(); |
541 completion_callback.Run( | 549 completion_callback.Run( |
542 NULL, SYNC_FILE_ERROR_FAILED, SYNC_FILE_STATUS_UNKNOWN); | 550 NULL, SYNC_FILE_ERROR_FAILED, SYNC_FILE_STATUS_UNKNOWN); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 v2_remote_service_->SetRemoteChangeProcessor(local_service_.get()); | 784 v2_remote_service_->SetRemoteChangeProcessor(local_service_.get()); |
777 v2_remote_service_->SetSyncEnabled(sync_enabled_); | 785 v2_remote_service_->SetSyncEnabled(sync_enabled_); |
778 v2_remote_service_->SetDefaultConflictResolutionPolicy( | 786 v2_remote_service_->SetDefaultConflictResolutionPolicy( |
779 remote_service_->GetDefaultConflictResolutionPolicy()); | 787 remote_service_->GetDefaultConflictResolutionPolicy()); |
780 remote_sync_runners_.push_back(v2_remote_syncer.release()); | 788 remote_sync_runners_.push_back(v2_remote_syncer.release()); |
781 } | 789 } |
782 return v2_remote_service_.get(); | 790 return v2_remote_service_.get(); |
783 } | 791 } |
784 | 792 |
785 } // namespace sync_file_system | 793 } // namespace sync_file_system |
OLD | NEW |