Index: chrome/browser/sync/glue/shared_change_processor.cc |
diff --git a/chrome/browser/sync/glue/shared_change_processor.cc b/chrome/browser/sync/glue/shared_change_processor.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0818a92eb6c891c3c4624a8d83cfd4717dd6abda |
--- /dev/null |
+++ b/chrome/browser/sync/glue/shared_change_processor.cc |
@@ -0,0 +1,115 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/sync/glue/shared_change_processor.h" |
+ |
+#include "chrome/browser/sync/profile_sync_service.h" |
+#include "chrome/browser/sync/api/sync_change.h" |
+#include "chrome/browser/sync/glue/generic_change_processor.h" |
+#include "content/browser/browser_thread.h" |
+ |
+using base::AutoLock; |
+ |
+namespace browser_sync { |
+ |
+SharedChangeProcessor::SharedChangeProcessor() |
+ : disconnected_(false) { |
+ // We're always created on the UI thread. |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ DetachFromThread(); |
+} |
+ |
+SharedChangeProcessor::~SharedChangeProcessor() { |
+ // We can either be deleted when the DTC is destroyed (on UI thread), |
+ // or when the SyncableService stop's syncing (datatype thread). |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
+ CalledOnValidThread()); |
+ DetachFromThread(); |
akalin
2011/10/11 22:41:08
DeleteSoon() the GCP here if necessary
Nicolas Zea
2011/10/12 04:24:19
Not necessary. If we've been given a GC, we'll be
|
+} |
+ |
+void SharedChangeProcessor::Connect( |
+ GenericChangeProcessor* generic_change_processor) { |
+ DCHECK(CalledOnValidThread()); |
+ DCHECK(generic_change_processor); |
+ AutoLock lock(monitor_lock_); |
+ if (disconnected_) |
+ return; |
+ generic_change_processor_.reset(generic_change_processor); |
+} |
+ |
+void SharedChangeProcessor::Disconnect() { |
+ // May be called from any thread. |
+ VLOG(1) << "Disconnecting change processor."; |
+ AutoLock lock(monitor_lock_); |
+ disconnected_ = true; |
+} |
+ |
+SyncError SharedChangeProcessor::GetSyncDataForType( |
+ syncable::ModelType type, |
+ SyncDataList* current_sync_data) { |
+ DCHECK(CalledOnValidThread()); |
+ AutoLock lock(monitor_lock_); |
+ if (disconnected_) { |
+ SyncError error(FROM_HERE, "Change processor disconnected.", type); |
+ return error; |
+ } |
+ return generic_change_processor_->GetSyncDataForType(type, current_sync_data); |
+} |
+ |
+SyncError SharedChangeProcessor::ProcessSyncChanges( |
+ const tracked_objects::Location& from_here, |
+ const SyncChangeList& list_of_changes) { |
+ DCHECK(CalledOnValidThread()); |
+ AutoLock lock(monitor_lock_); |
+ if (disconnected_) { |
+ // The DTC that disconnects us must ensure it posts a StopSyncing task. |
+ // If we reach this, it means it just hasn't executed yet. |
+ syncable::ModelType type; |
akalin
2011/10/11 22:41:08
what should type be if list_of_changes is empty?
Nicolas Zea
2011/10/12 04:24:19
UNSPECIFIED. I prefer returning an error even with
|
+ if (list_of_changes.size() > 0) { |
+ type = list_of_changes[0].sync_data().GetDataType(); |
+ } |
+ SyncError error(FROM_HERE, "Change processor disconnected.", type); |
+ return error; |
+ } |
+ return generic_change_processor_->ProcessSyncChanges( |
+ from_here, list_of_changes); |
+} |
+ |
+bool SharedChangeProcessor::SyncModelHasUserCreatedNodes( |
+ syncable::ModelType type, |
+ bool* has_nodes) { |
+ DCHECK(CalledOnValidThread()); |
+ AutoLock lock(monitor_lock_); |
+ if (disconnected_) { |
+ LOG(ERROR) << "Change processor disconnected."; |
+ return false; |
+ } |
+ return generic_change_processor_->SyncModelHasUserCreatedNodes( |
+ type, has_nodes); |
+} |
+ |
+bool SharedChangeProcessor::CryptoReadyIfNecessary(syncable::ModelType type) { |
+ DCHECK(CalledOnValidThread()); |
+ AutoLock lock(monitor_lock_); |
+ if (disconnected_) { |
+ LOG(ERROR) << "Change processor disconnected."; |
+ return true; // Otherwise we get into infinite spin waiting. |
+ } |
+ return generic_change_processor_->CryptoReadyIfNecessary(type); |
+} |
+ |
+void SharedChangeProcessor::ActivateDataType( |
+ ProfileSyncService* sync_service, |
+ syncable::ModelType model_type, |
+ browser_sync::ModelSafeGroup model_safe_group) { |
+ AutoLock lock(monitor_lock_); |
+ if (disconnected_) { |
+ LOG(ERROR) << "Change processor disconnected."; |
+ return; |
+ } |
+ sync_service->ActivateDataType( |
+ model_type, model_safe_group, generic_change_processor_.get()); |
+} |
+ |
+} // namespace browser_sync |