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/drive_file_sync_service.h" | 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 FROM_HERE, | 138 FROM_HERE, |
139 base::Bind(arg5, error, base::Passed(&resource_list))); | 139 base::Bind(arg5, error, base::Passed(&resource_list))); |
140 } | 140 } |
141 | 141 |
142 ACTION(PrepareForRemoteChange_Busy) { | 142 ACTION(PrepareForRemoteChange_Busy) { |
143 base::MessageLoopProxy::current()->PostTask( | 143 base::MessageLoopProxy::current()->PostTask( |
144 FROM_HERE, | 144 FROM_HERE, |
145 base::Bind(arg2, | 145 base::Bind(arg2, |
146 fileapi::SYNC_STATUS_FILE_BUSY, | 146 fileapi::SYNC_STATUS_FILE_BUSY, |
147 fileapi::SyncFileMetadata(), | 147 fileapi::SyncFileMetadata(), |
148 fileapi::FileChangeList())); | 148 FileChangeList())); |
149 } | 149 } |
150 | 150 |
151 ACTION(PrepareForRemoteChange_NotFound) { | 151 ACTION(PrepareForRemoteChange_NotFound) { |
152 base::MessageLoopProxy::current()->PostTask( | 152 base::MessageLoopProxy::current()->PostTask( |
153 FROM_HERE, | 153 FROM_HERE, |
154 base::Bind(arg2, | 154 base::Bind(arg2, |
155 fileapi::SYNC_STATUS_OK, | 155 fileapi::SYNC_STATUS_OK, |
156 fileapi::SyncFileMetadata(fileapi::SYNC_FILE_TYPE_UNKNOWN, 0, | 156 fileapi::SyncFileMetadata(SYNC_FILE_TYPE_UNKNOWN, 0, |
157 base::Time()), | 157 base::Time()), |
158 fileapi::FileChangeList())); | 158 FileChangeList())); |
159 } | 159 } |
160 | 160 |
161 ACTION(PrepareForRemoteChange_NotModified) { | 161 ACTION(PrepareForRemoteChange_NotModified) { |
162 base::MessageLoopProxy::current()->PostTask( | 162 base::MessageLoopProxy::current()->PostTask( |
163 FROM_HERE, | 163 FROM_HERE, |
164 base::Bind(arg2, | 164 base::Bind(arg2, |
165 fileapi::SYNC_STATUS_OK, | 165 fileapi::SYNC_STATUS_OK, |
166 fileapi::SyncFileMetadata(fileapi::SYNC_FILE_TYPE_FILE, 0, | 166 fileapi::SyncFileMetadata(SYNC_FILE_TYPE_FILE, 0, |
167 base::Time()), | 167 base::Time()), |
168 fileapi::FileChangeList())); | 168 FileChangeList())); |
169 } | 169 } |
170 | 170 |
171 ACTION(InvokeDidDownloadFile) { | 171 ACTION(InvokeDidDownloadFile) { |
172 base::MessageLoopProxy::current()->PostTask( | 172 base::MessageLoopProxy::current()->PostTask( |
173 FROM_HERE, base::Bind(arg3, google_apis::HTTP_SUCCESS, arg1)); | 173 FROM_HERE, base::Bind(arg3, google_apis::HTTP_SUCCESS, arg1)); |
174 } | 174 } |
175 | 175 |
176 ACTION(InvokeDidApplyRemoteChange) { | 176 ACTION(InvokeDidApplyRemoteChange) { |
177 base::MessageLoopProxy::current()->PostTask( | 177 base::MessageLoopProxy::current()->PostTask( |
178 FROM_HERE, base::Bind(arg3, fileapi::SYNC_STATUS_OK)); | 178 FROM_HERE, base::Bind(arg3, fileapi::SYNC_STATUS_OK)); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 profile_.reset(); | 277 profile_.reset(); |
278 message_loop_.RunUntilIdle(); | 278 message_loop_.RunUntilIdle(); |
279 } | 279 } |
280 | 280 |
281 void SetSyncEnabled(bool enabled) { | 281 void SetSyncEnabled(bool enabled) { |
282 sync_service_->SetSyncEnabled(enabled); | 282 sync_service_->SetSyncEnabled(enabled); |
283 } | 283 } |
284 | 284 |
285 protected: | 285 protected: |
286 DriveFileSyncService::LocalSyncOperationType ResolveLocalSyncOperationType( | 286 DriveFileSyncService::LocalSyncOperationType ResolveLocalSyncOperationType( |
287 const fileapi::FileChange& local_change, | 287 const FileChange& local_change, |
288 const fileapi::FileSystemURL& url) { | 288 const fileapi::FileSystemURL& url) { |
289 return sync_service_->ResolveLocalSyncOperationType(local_change, url); | 289 return sync_service_->ResolveLocalSyncOperationType(local_change, url); |
290 } | 290 } |
291 | 291 |
292 bool IsLocalSyncOperationAdd( | 292 bool IsLocalSyncOperationAdd( |
293 DriveFileSyncService::LocalSyncOperationType type) { | 293 DriveFileSyncService::LocalSyncOperationType type) { |
294 return type == DriveFileSyncService::LOCAL_SYNC_OPERATION_ADD; | 294 return type == DriveFileSyncService::LOCAL_SYNC_OPERATION_ADD; |
295 } | 295 } |
296 | 296 |
297 bool IsLocalSyncOperationUpdate( | 297 bool IsLocalSyncOperationUpdate( |
(...skipping 18 matching lines...) Expand all Loading... |
316 | 316 |
317 bool IsLocalSyncOperationResolveToRemote( | 317 bool IsLocalSyncOperationResolveToRemote( |
318 DriveFileSyncService::LocalSyncOperationType type) { | 318 DriveFileSyncService::LocalSyncOperationType type) { |
319 return type == DriveFileSyncService::LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE; | 319 return type == DriveFileSyncService::LOCAL_SYNC_OPERATION_RESOLVE_TO_REMOTE; |
320 } | 320 } |
321 | 321 |
322 void AddRemoteChange(int64 changestamp, | 322 void AddRemoteChange(int64 changestamp, |
323 const std::string& resource_id, | 323 const std::string& resource_id, |
324 const std::string& md5_checksum, | 324 const std::string& md5_checksum, |
325 const fileapi::FileSystemURL& url, | 325 const fileapi::FileSystemURL& url, |
326 const fileapi::FileChange& file_change) { | 326 const FileChange& file_change) { |
327 typedef DriveFileSyncService::PendingChangeQueue::iterator iterator; | 327 typedef DriveFileSyncService::PendingChangeQueue::iterator iterator; |
328 typedef DriveFileSyncService::ChangeQueueItem ChangeQueueItem; | 328 typedef DriveFileSyncService::ChangeQueueItem ChangeQueueItem; |
329 typedef DriveFileSyncService::RemoteSyncType RemoteSyncType; | 329 typedef DriveFileSyncService::RemoteSyncType RemoteSyncType; |
330 sync_service_->pending_changes_.clear(); | 330 sync_service_->pending_changes_.clear(); |
331 | 331 |
332 RemoteSyncType sync_type = DriveFileSyncService::REMOTE_SYNC_TYPE_BATCH; | 332 RemoteSyncType sync_type = DriveFileSyncService::REMOTE_SYNC_TYPE_BATCH; |
333 std::pair<iterator, bool> inserted_to_queue = | 333 std::pair<iterator, bool> inserted_to_queue = |
334 sync_service_->pending_changes_.insert( | 334 sync_service_->pending_changes_.insert( |
335 ChangeQueueItem(changestamp, sync_type, url)); | 335 ChangeQueueItem(changestamp, sync_type, url)); |
336 DCHECK(inserted_to_queue.second); | 336 DCHECK(inserted_to_queue.second); |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 | 762 |
763 EXPECT_CALL(*mock_remote_observer(), | 763 EXPECT_CALL(*mock_remote_observer(), |
764 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) | 764 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) |
765 .Times(1); | 765 .Times(1); |
766 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) | 766 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
767 .Times(AnyNumber()); | 767 .Times(AnyNumber()); |
768 | 768 |
769 SetUpDriveSyncService(true); | 769 SetUpDriveSyncService(true); |
770 message_loop()->RunUntilIdle(); | 770 message_loop()->RunUntilIdle(); |
771 | 771 |
772 const fileapi::FileChange local_add_or_update_change( | 772 const FileChange local_add_or_update_change( |
773 fileapi::FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 773 FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE); |
774 fileapi::SYNC_FILE_TYPE_FILE); | 774 const FileChange local_delete_change( |
775 const fileapi::FileChange local_delete_change( | 775 FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_FILE); |
776 fileapi::FileChange::FILE_CHANGE_DELETE, | |
777 fileapi::SYNC_FILE_TYPE_FILE); | |
778 | 776 |
779 // There is no pending remote change and no metadata in DriveMetadataStore. | 777 // There is no pending remote change and no metadata in DriveMetadataStore. |
780 EXPECT_TRUE(IsLocalSyncOperationAdd( | 778 EXPECT_TRUE(IsLocalSyncOperationAdd( |
781 ResolveLocalSyncOperationType(local_add_or_update_change, url))); | 779 ResolveLocalSyncOperationType(local_add_or_update_change, url))); |
782 EXPECT_TRUE(IsLocalSyncOperationNone( | 780 EXPECT_TRUE(IsLocalSyncOperationNone( |
783 ResolveLocalSyncOperationType(local_delete_change, url))); | 781 ResolveLocalSyncOperationType(local_delete_change, url))); |
784 | 782 |
785 // Add metadata for the file identified by |url|. | 783 // Add metadata for the file identified by |url|. |
786 DriveMetadata metadata; | 784 DriveMetadata metadata; |
787 metadata.set_resource_id(kResourceId); | 785 metadata.set_resource_id(kResourceId); |
788 metadata.set_md5_checksum("654321"); | 786 metadata.set_md5_checksum("654321"); |
789 metadata.set_conflicted(false); | 787 metadata.set_conflicted(false); |
790 metadata.set_to_be_fetched(false); | 788 metadata.set_to_be_fetched(false); |
791 metadata_store()->UpdateEntry(url, metadata, | 789 metadata_store()->UpdateEntry(url, metadata, |
792 base::Bind(&DidUpdateEntry)); | 790 base::Bind(&DidUpdateEntry)); |
793 | 791 |
794 message_loop()->RunUntilIdle(); | 792 message_loop()->RunUntilIdle(); |
795 | 793 |
796 // There is no pending remote change, but metadata in DriveMetadataStore. | 794 // There is no pending remote change, but metadata in DriveMetadataStore. |
797 EXPECT_TRUE(IsLocalSyncOperationUpdate( | 795 EXPECT_TRUE(IsLocalSyncOperationUpdate( |
798 ResolveLocalSyncOperationType(local_add_or_update_change, url))); | 796 ResolveLocalSyncOperationType(local_add_or_update_change, url))); |
799 EXPECT_TRUE(IsLocalSyncOperationDelete( | 797 EXPECT_TRUE(IsLocalSyncOperationDelete( |
800 ResolveLocalSyncOperationType(local_delete_change, url))); | 798 ResolveLocalSyncOperationType(local_delete_change, url))); |
801 | 799 |
802 // Add an ADD_OR_UPDATE change for the file to the pending change queue. | 800 // Add an ADD_OR_UPDATE change for the file to the pending change queue. |
803 AddRemoteChange( | 801 AddRemoteChange( |
804 kChangestamp, kResourceId, "hoge", url, | 802 kChangestamp, kResourceId, "hoge", url, |
805 fileapi::FileChange(fileapi::FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 803 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE)); |
806 fileapi::SYNC_FILE_TYPE_FILE)); | |
807 | 804 |
808 EXPECT_TRUE(IsLocalSyncOperationConflict( | 805 EXPECT_TRUE(IsLocalSyncOperationConflict( |
809 ResolveLocalSyncOperationType(local_add_or_update_change, url))); | 806 ResolveLocalSyncOperationType(local_add_or_update_change, url))); |
810 EXPECT_TRUE(IsLocalSyncOperationNone( | 807 EXPECT_TRUE(IsLocalSyncOperationNone( |
811 ResolveLocalSyncOperationType(local_delete_change, url))); | 808 ResolveLocalSyncOperationType(local_delete_change, url))); |
812 | 809 |
813 // Add a DELETE change for the file to the pending change queue. | 810 // Add a DELETE change for the file to the pending change queue. |
814 AddRemoteChange( | 811 AddRemoteChange( |
815 kChangestamp, kResourceId, "fuga", url, | 812 kChangestamp, kResourceId, "fuga", url, |
816 fileapi::FileChange(fileapi::FileChange::FILE_CHANGE_DELETE, | 813 FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_FILE)); |
817 fileapi::SYNC_FILE_TYPE_FILE)); | |
818 | 814 |
819 EXPECT_TRUE(IsLocalSyncOperationAdd( | 815 EXPECT_TRUE(IsLocalSyncOperationAdd( |
820 ResolveLocalSyncOperationType(local_add_or_update_change, url))); | 816 ResolveLocalSyncOperationType(local_add_or_update_change, url))); |
821 EXPECT_TRUE(IsLocalSyncOperationNone( | 817 EXPECT_TRUE(IsLocalSyncOperationNone( |
822 ResolveLocalSyncOperationType(local_delete_change, url))); | 818 ResolveLocalSyncOperationType(local_delete_change, url))); |
823 | 819 |
824 // Mark the file as conflicted so that the conflict resolution will occur. | 820 // Mark the file as conflicted so that the conflict resolution will occur. |
825 metadata.set_conflicted(true); | 821 metadata.set_conflicted(true); |
826 metadata_store()->UpdateEntry(url, metadata, | 822 metadata_store()->UpdateEntry(url, metadata, |
827 base::Bind(&DidUpdateEntry)); | 823 base::Bind(&DidUpdateEntry)); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 kOrigin, kFilePath, true /* is_deleted */, | 1073 kOrigin, kFilePath, true /* is_deleted */, |
1078 kFileResourceId2, 7, "deleted_file_md5")); | 1074 kFileResourceId2, 7, "deleted_file_md5")); |
1079 EXPECT_TRUE(AppendIncrementalRemoteChange( | 1075 EXPECT_TRUE(AppendIncrementalRemoteChange( |
1080 kOrigin, kFilePath, false /* is_deleted */, | 1076 kOrigin, kFilePath, false /* is_deleted */, |
1081 kFileResourceId, 8, "updated_file_md5")); | 1077 kFileResourceId, 8, "updated_file_md5")); |
1082 } | 1078 } |
1083 | 1079 |
1084 #endif // !defined(OS_ANDROID) | 1080 #endif // !defined(OS_ANDROID) |
1085 | 1081 |
1086 } // namespace sync_file_system | 1082 } // namespace sync_file_system |
OLD | NEW |