| 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/glue/shared_change_processor.h" | 5 #include "chrome/browser/sync/glue/shared_change_processor.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sync/glue/generic_change_processor.h" | 7 #include "chrome/browser/sync/glue/generic_change_processor.h" |
| 8 #include "chrome/browser/sync/profile_sync_components_factory.h" | 8 #include "chrome/browser/sync/profile_sync_components_factory.h" |
| 9 #include "chrome/browser/sync/profile_sync_service.h" | 9 #include "chrome/browser/sync/profile_sync_service.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 bool SharedChangeProcessor::Disconnect() { | 82 bool SharedChangeProcessor::Disconnect() { |
| 83 // May be called from any thread. | 83 // May be called from any thread. |
| 84 DVLOG(1) << "Disconnecting change processor."; | 84 DVLOG(1) << "Disconnecting change processor."; |
| 85 AutoLock lock(monitor_lock_); | 85 AutoLock lock(monitor_lock_); |
| 86 bool was_connected = !disconnected_; | 86 bool was_connected = !disconnected_; |
| 87 disconnected_ = true; | 87 disconnected_ = true; |
| 88 error_handler_ = NULL; | 88 error_handler_ = NULL; |
| 89 return was_connected; | 89 return was_connected; |
| 90 } | 90 } |
| 91 | 91 |
| 92 syncer::SyncError SharedChangeProcessor::GetSyncData( | |
| 93 syncer::SyncDataList* current_sync_data) { | |
| 94 DCHECK(backend_loop_.get()); | |
| 95 DCHECK(backend_loop_->BelongsToCurrentThread()); | |
| 96 AutoLock lock(monitor_lock_); | |
| 97 if (disconnected_) { | |
| 98 syncer::SyncError error(FROM_HERE, | |
| 99 syncer::SyncError::DATATYPE_ERROR, | |
| 100 "Change processor disconnected.", | |
| 101 type_); | |
| 102 return error; | |
| 103 } | |
| 104 return generic_change_processor_->GetSyncDataForType(type_, | |
| 105 current_sync_data); | |
| 106 } | |
| 107 | |
| 108 int SharedChangeProcessor::GetSyncCount() { | 92 int SharedChangeProcessor::GetSyncCount() { |
| 109 DCHECK(backend_loop_.get()); | 93 DCHECK(backend_loop_.get()); |
| 110 DCHECK(backend_loop_->BelongsToCurrentThread()); | 94 DCHECK(backend_loop_->BelongsToCurrentThread()); |
| 111 AutoLock lock(monitor_lock_); | 95 AutoLock lock(monitor_lock_); |
| 112 if (disconnected_) { | 96 if (disconnected_) { |
| 113 LOG(ERROR) << "Change processor disconnected."; | 97 LOG(ERROR) << "Change processor disconnected."; |
| 114 return 0; | 98 return 0; |
| 115 } | 99 } |
| 116 return generic_change_processor_->GetSyncCountForType(type_); | 100 return generic_change_processor_->GetSyncCountForType(type_); |
| 117 } | 101 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 128 syncer::SyncError error(FROM_HERE, | 112 syncer::SyncError error(FROM_HERE, |
| 129 syncer::SyncError::DATATYPE_ERROR, | 113 syncer::SyncError::DATATYPE_ERROR, |
| 130 "Change processor disconnected.", | 114 "Change processor disconnected.", |
| 131 type_); | 115 type_); |
| 132 return error; | 116 return error; |
| 133 } | 117 } |
| 134 return generic_change_processor_->ProcessSyncChanges( | 118 return generic_change_processor_->ProcessSyncChanges( |
| 135 from_here, list_of_changes); | 119 from_here, list_of_changes); |
| 136 } | 120 } |
| 137 | 121 |
| 122 syncer::SyncDataList SharedChangeProcessor::GetAllSyncData( |
| 123 syncer::ModelType type) const { |
| 124 syncer::SyncDataList data; |
| 125 GetAllSyncDataReturnError(type, &data); // Handles the disconnect case. |
| 126 return data; |
| 127 } |
| 128 |
| 129 syncer::SyncError SharedChangeProcessor::GetAllSyncDataReturnError( |
| 130 syncer::ModelType type, |
| 131 syncer::SyncDataList* data) const { |
| 132 DCHECK(backend_loop_.get()); |
| 133 DCHECK(backend_loop_->BelongsToCurrentThread()); |
| 134 AutoLock lock(monitor_lock_); |
| 135 if (disconnected_) { |
| 136 syncer::SyncError error(FROM_HERE, |
| 137 syncer::SyncError::DATATYPE_ERROR, |
| 138 "Change processor disconnected.", |
| 139 type_); |
| 140 return error; |
| 141 } |
| 142 return generic_change_processor_->GetAllSyncDataReturnError(type, data); |
| 143 } |
| 144 |
| 138 bool SharedChangeProcessor::SyncModelHasUserCreatedNodes(bool* has_nodes) { | 145 bool SharedChangeProcessor::SyncModelHasUserCreatedNodes(bool* has_nodes) { |
| 139 DCHECK(backend_loop_.get()); | 146 DCHECK(backend_loop_.get()); |
| 140 DCHECK(backend_loop_->BelongsToCurrentThread()); | 147 DCHECK(backend_loop_->BelongsToCurrentThread()); |
| 141 AutoLock lock(monitor_lock_); | 148 AutoLock lock(monitor_lock_); |
| 142 if (disconnected_) { | 149 if (disconnected_) { |
| 143 LOG(ERROR) << "Change processor disconnected."; | 150 LOG(ERROR) << "Change processor disconnected."; |
| 144 return false; | 151 return false; |
| 145 } | 152 } |
| 146 return generic_change_processor_->SyncModelHasUserCreatedNodes( | 153 return generic_change_processor_->SyncModelHasUserCreatedNodes( |
| 147 type_, has_nodes); | 154 type_, has_nodes); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 return error_handler_->CreateAndUploadError(location, message, type_); | 187 return error_handler_->CreateAndUploadError(location, message, type_); |
| 181 } else { | 188 } else { |
| 182 return syncer::SyncError(location, | 189 return syncer::SyncError(location, |
| 183 syncer::SyncError::DATATYPE_ERROR, | 190 syncer::SyncError::DATATYPE_ERROR, |
| 184 message, | 191 message, |
| 185 type_); | 192 type_); |
| 186 } | 193 } |
| 187 } | 194 } |
| 188 | 195 |
| 189 } // namespace browser_sync | 196 } // namespace browser_sync |
| OLD | NEW |