Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1076 if (param->drive_metadata.conflicted()) { | 1076 if (param->drive_metadata.conflicted()) { |
| 1077 if (missing_local_file) { | 1077 if (missing_local_file) { |
| 1078 if (param->remote_change.change.IsAddOrUpdate()) { | 1078 if (param->remote_change.change.IsAddOrUpdate()) { |
| 1079 NOTIMPLEMENTED() << "ResolveToRemote()"; | 1079 NOTIMPLEMENTED() << "ResolveToRemote()"; |
| 1080 AbortRemoteSync(param.Pass(), fileapi::SYNC_STATUS_FAILED); | 1080 AbortRemoteSync(param.Pass(), fileapi::SYNC_STATUS_FAILED); |
| 1081 return; | 1081 return; |
| 1082 } | 1082 } |
| 1083 | 1083 |
| 1084 DCHECK(param->remote_change.change.IsDelete()); | 1084 DCHECK(param->remote_change.change.IsDelete()); |
| 1085 param->operation_type = fileapi::SYNC_OPERATION_NONE; | 1085 param->operation_type = fileapi::SYNC_OPERATION_NONE; |
| 1086 DeleteMetadataForRemoteSync(param.Pass()); | 1086 if (missing_db_entry) |
| 1087 CompleteRemoteSync(param.Pass(), fileapi::SYNC_STATUS_OK); | |
|
kinuko
2012/12/04 08:55:42
Could this happen? (We're in metadata.conflicted()
tzik
2012/12/04 09:14:29
Done. It can't be reached.
| |
| 1088 else | |
| 1089 DeleteMetadataForRemoteSync(param.Pass()); | |
| 1087 return; | 1090 return; |
| 1088 } | 1091 } |
| 1089 | 1092 |
| 1090 DCHECK(!missing_local_file); | 1093 DCHECK(!missing_local_file); |
| 1091 if (param->remote_change.change.IsAddOrUpdate()) { | 1094 if (param->remote_change.change.IsAddOrUpdate()) { |
| 1092 param->operation_type = fileapi::SYNC_OPERATION_NONE; | 1095 param->operation_type = fileapi::SYNC_OPERATION_NONE; |
| 1093 param->drive_metadata.set_conflicted(true); | 1096 param->drive_metadata.set_conflicted(true); |
| 1094 | 1097 |
| 1095 metadata_store_->UpdateEntry( | 1098 metadata_store_->UpdateEntry( |
| 1096 url, drive_metadata, | 1099 url, drive_metadata, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1135 DCHECK(local_changes.list().back().IsDelete()); | 1138 DCHECK(local_changes.list().back().IsDelete()); |
| 1136 param->operation_type = fileapi::SYNC_OPERATION_ADD; | 1139 param->operation_type = fileapi::SYNC_OPERATION_ADD; |
| 1137 DownloadForRemoteSync(param.Pass()); | 1140 DownloadForRemoteSync(param.Pass()); |
| 1138 return; | 1141 return; |
| 1139 } | 1142 } |
| 1140 | 1143 |
| 1141 DCHECK(param->remote_change.change.IsDelete()); | 1144 DCHECK(param->remote_change.change.IsDelete()); |
| 1142 if (local_changes.empty()) { | 1145 if (local_changes.empty()) { |
| 1143 if (missing_local_file) { | 1146 if (missing_local_file) { |
| 1144 param->operation_type = fileapi::SYNC_OPERATION_NONE; | 1147 param->operation_type = fileapi::SYNC_OPERATION_NONE; |
| 1145 DeleteMetadataForRemoteSync(param.Pass()); | 1148 if (missing_db_entry) |
| 1149 CompleteRemoteSync(param.Pass(), fileapi::SYNC_STATUS_OK); | |
| 1150 else | |
| 1151 DeleteMetadataForRemoteSync(param.Pass()); | |
| 1146 return; | 1152 return; |
| 1147 } | 1153 } |
| 1148 DCHECK(!missing_local_file); | 1154 DCHECK(!missing_local_file); |
| 1149 param->operation_type = fileapi::SYNC_OPERATION_DELETE; | 1155 param->operation_type = fileapi::SYNC_OPERATION_DELETE; |
| 1150 | 1156 |
| 1151 const fileapi::FileChange& file_change = param->remote_change.change; | 1157 const fileapi::FileChange& file_change = param->remote_change.change; |
| 1152 param->processor->ApplyRemoteChange( | 1158 param->processor->ApplyRemoteChange( |
| 1153 file_change, FilePath(), url, | 1159 file_change, FilePath(), url, |
| 1154 base::Bind(&DriveFileSyncService::DidApplyRemoteChange, AsWeakPtr(), | 1160 base::Bind(&DriveFileSyncService::DidApplyRemoteChange, AsWeakPtr(), |
| 1155 base::Passed(¶m))); | 1161 base::Passed(¶m))); |
| 1156 return; | 1162 return; |
| 1157 } | 1163 } |
| 1158 | 1164 |
| 1159 DCHECK(!local_changes.empty()); | 1165 DCHECK(!local_changes.empty()); |
| 1160 if (local_changes.list().back().IsAddOrUpdate()) { | 1166 if (local_changes.list().back().IsAddOrUpdate()) { |
| 1161 param->operation_type = fileapi::SYNC_OPERATION_NONE; | 1167 param->operation_type = fileapi::SYNC_OPERATION_NONE; |
| 1162 CompleteRemoteSync(param.Pass(), fileapi::SYNC_STATUS_OK); | 1168 CompleteRemoteSync(param.Pass(), fileapi::SYNC_STATUS_OK); |
| 1163 return; | 1169 return; |
| 1164 } | 1170 } |
| 1165 | 1171 |
| 1166 DCHECK(local_changes.list().back().IsDelete()); | 1172 DCHECK(local_changes.list().back().IsDelete()); |
| 1167 param->operation_type = fileapi::SYNC_OPERATION_NONE; | 1173 param->operation_type = fileapi::SYNC_OPERATION_NONE; |
| 1168 DeleteMetadataForRemoteSync(param.Pass()); | 1174 if (missing_db_entry) |
| 1175 CompleteRemoteSync(param.Pass(), fileapi::SYNC_STATUS_OK); | |
| 1176 else | |
| 1177 DeleteMetadataForRemoteSync(param.Pass()); | |
| 1169 } | 1178 } |
| 1170 | 1179 |
| 1171 void DriveFileSyncService::DownloadForRemoteSync( | 1180 void DriveFileSyncService::DownloadForRemoteSync( |
| 1172 scoped_ptr<ProcessRemoteChangeParam> param) { | 1181 scoped_ptr<ProcessRemoteChangeParam> param) { |
| 1173 // TODO(tzik): Use ShareableFileReference here after we get thread-safe | 1182 // TODO(tzik): Use ShareableFileReference here after we get thread-safe |
| 1174 // version of it. crbug.com/162598 | 1183 // version of it. crbug.com/162598 |
| 1175 FilePath* temporary_file_path = ¶m->temporary_file_path; | 1184 FilePath* temporary_file_path = ¶m->temporary_file_path; |
| 1176 content::BrowserThread::PostTaskAndReplyWithResult( | 1185 content::BrowserThread::PostTaskAndReplyWithResult( |
| 1177 content::BrowserThread::FILE, FROM_HERE, | 1186 content::BrowserThread::FILE, FROM_HERE, |
| 1178 base::Bind(&CreateTemporaryFile, | 1187 base::Bind(&CreateTemporaryFile, |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1396 | 1405 |
| 1397 polling_enabled_ = false; | 1406 polling_enabled_ = false; |
| 1398 token->set_completion_callback(base::Bind(&EnablePolling, &polling_enabled_)); | 1407 token->set_completion_callback(base::Bind(&EnablePolling, &polling_enabled_)); |
| 1399 | 1408 |
| 1400 if (metadata_store_->incremental_sync_origins().empty()) { | 1409 if (metadata_store_->incremental_sync_origins().empty()) { |
| 1401 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); | 1410 NotifyTaskDone(fileapi::SYNC_STATUS_OK, token.Pass()); |
| 1402 return; | 1411 return; |
| 1403 } | 1412 } |
| 1404 | 1413 |
| 1405 sync_client_->ListChanges( | 1414 sync_client_->ListChanges( |
| 1406 largest_fetched_changestamp_, | 1415 largest_fetched_changestamp_ + 1, |
| 1407 base::Bind(&DriveFileSyncService::DidFetchChangesForIncrementalSync, | 1416 base::Bind(&DriveFileSyncService::DidFetchChangesForIncrementalSync, |
| 1408 AsWeakPtr(), base::Passed(&token))); | 1417 AsWeakPtr(), base::Passed(&token))); |
| 1409 } | 1418 } |
| 1410 | 1419 |
| 1411 void DriveFileSyncService::DidFetchChangesForIncrementalSync( | 1420 void DriveFileSyncService::DidFetchChangesForIncrementalSync( |
| 1412 scoped_ptr<TaskToken> token, | 1421 scoped_ptr<TaskToken> token, |
| 1413 google_apis::GDataErrorCode error, | 1422 google_apis::GDataErrorCode error, |
| 1414 scoped_ptr<google_apis::DocumentFeed> changes) { | 1423 scoped_ptr<google_apis::DocumentFeed> changes) { |
| 1415 if (error != google_apis::HTTP_SUCCESS) { | 1424 if (error != google_apis::HTTP_SUCCESS) { |
| 1416 NotifyTaskDone(GDataErrorCodeToSyncStatusCodeWrapper(error), token.Pass()); | 1425 NotifyTaskDone(GDataErrorCodeToSyncStatusCodeWrapper(error), token.Pass()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1507 fileapi::SyncStatusCode | 1516 fileapi::SyncStatusCode |
| 1508 DriveFileSyncService::GDataErrorCodeToSyncStatusCodeWrapper( | 1517 DriveFileSyncService::GDataErrorCodeToSyncStatusCodeWrapper( |
| 1509 google_apis::GDataErrorCode error) const { | 1518 google_apis::GDataErrorCode error) const { |
| 1510 fileapi::SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); | 1519 fileapi::SyncStatusCode status = GDataErrorCodeToSyncStatusCode(error); |
| 1511 if (status != fileapi::SYNC_STATUS_OK && !sync_client_->IsAuthenticated()) | 1520 if (status != fileapi::SYNC_STATUS_OK && !sync_client_->IsAuthenticated()) |
| 1512 return fileapi::SYNC_STATUS_AUTHENTICATION_FAILED; | 1521 return fileapi::SYNC_STATUS_AUTHENTICATION_FAILED; |
| 1513 return status; | 1522 return status; |
| 1514 } | 1523 } |
| 1515 | 1524 |
| 1516 } // namespace sync_file_system | 1525 } // namespace sync_file_system |
| OLD | NEW |