Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/sync/glue/shared_change_processor.h" | |
| 6 | |
| 7 #include "chrome/browser/sync/profile_sync_service.h" | |
| 8 #include "chrome/browser/sync/api/sync_change.h" | |
| 9 #include "chrome/browser/sync/glue/generic_change_processor.h" | |
| 10 #include "content/browser/browser_thread.h" | |
| 11 | |
| 12 using base::AutoLock; | |
| 13 | |
| 14 namespace browser_sync { | |
| 15 | |
| 16 SharedChangeProcessor::SharedChangeProcessor() | |
| 17 : disconnected_(false) { | |
| 18 // We're always created on the UI thread. | |
| 19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 20 DetachFromThread(); | |
| 21 } | |
| 22 | |
| 23 SharedChangeProcessor::~SharedChangeProcessor() { | |
| 24 // We can either be deleted when the DTC is destroyed (on UI thread), | |
| 25 // or when the SyncableService stop's syncing (datatype thread). | |
| 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | |
| 27 CalledOnValidThread()); | |
| 28 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
| |
| 29 } | |
| 30 | |
| 31 void SharedChangeProcessor::Connect( | |
| 32 GenericChangeProcessor* generic_change_processor) { | |
| 33 DCHECK(CalledOnValidThread()); | |
| 34 DCHECK(generic_change_processor); | |
| 35 AutoLock lock(monitor_lock_); | |
| 36 if (disconnected_) | |
| 37 return; | |
| 38 generic_change_processor_.reset(generic_change_processor); | |
| 39 } | |
| 40 | |
| 41 void SharedChangeProcessor::Disconnect() { | |
| 42 // May be called from any thread. | |
| 43 VLOG(1) << "Disconnecting change processor."; | |
| 44 AutoLock lock(monitor_lock_); | |
| 45 disconnected_ = true; | |
| 46 } | |
| 47 | |
| 48 SyncError SharedChangeProcessor::GetSyncDataForType( | |
| 49 syncable::ModelType type, | |
| 50 SyncDataList* current_sync_data) { | |
| 51 DCHECK(CalledOnValidThread()); | |
| 52 AutoLock lock(monitor_lock_); | |
| 53 if (disconnected_) { | |
| 54 SyncError error(FROM_HERE, "Change processor disconnected.", type); | |
| 55 return error; | |
| 56 } | |
| 57 return generic_change_processor_->GetSyncDataForType(type, current_sync_data); | |
| 58 } | |
| 59 | |
| 60 SyncError SharedChangeProcessor::ProcessSyncChanges( | |
| 61 const tracked_objects::Location& from_here, | |
| 62 const SyncChangeList& list_of_changes) { | |
| 63 DCHECK(CalledOnValidThread()); | |
| 64 AutoLock lock(monitor_lock_); | |
| 65 if (disconnected_) { | |
| 66 // The DTC that disconnects us must ensure it posts a StopSyncing task. | |
| 67 // If we reach this, it means it just hasn't executed yet. | |
| 68 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
| |
| 69 if (list_of_changes.size() > 0) { | |
| 70 type = list_of_changes[0].sync_data().GetDataType(); | |
| 71 } | |
| 72 SyncError error(FROM_HERE, "Change processor disconnected.", type); | |
| 73 return error; | |
| 74 } | |
| 75 return generic_change_processor_->ProcessSyncChanges( | |
| 76 from_here, list_of_changes); | |
| 77 } | |
| 78 | |
| 79 bool SharedChangeProcessor::SyncModelHasUserCreatedNodes( | |
| 80 syncable::ModelType type, | |
| 81 bool* has_nodes) { | |
| 82 DCHECK(CalledOnValidThread()); | |
| 83 AutoLock lock(monitor_lock_); | |
| 84 if (disconnected_) { | |
| 85 LOG(ERROR) << "Change processor disconnected."; | |
| 86 return false; | |
| 87 } | |
| 88 return generic_change_processor_->SyncModelHasUserCreatedNodes( | |
| 89 type, has_nodes); | |
| 90 } | |
| 91 | |
| 92 bool SharedChangeProcessor::CryptoReadyIfNecessary(syncable::ModelType type) { | |
| 93 DCHECK(CalledOnValidThread()); | |
| 94 AutoLock lock(monitor_lock_); | |
| 95 if (disconnected_) { | |
| 96 LOG(ERROR) << "Change processor disconnected."; | |
| 97 return true; // Otherwise we get into infinite spin waiting. | |
| 98 } | |
| 99 return generic_change_processor_->CryptoReadyIfNecessary(type); | |
| 100 } | |
| 101 | |
| 102 void SharedChangeProcessor::ActivateDataType( | |
| 103 ProfileSyncService* sync_service, | |
| 104 syncable::ModelType model_type, | |
| 105 browser_sync::ModelSafeGroup model_safe_group) { | |
| 106 AutoLock lock(monitor_lock_); | |
| 107 if (disconnected_) { | |
| 108 LOG(ERROR) << "Change processor disconnected."; | |
| 109 return; | |
| 110 } | |
| 111 sync_service->ActivateDataType( | |
| 112 model_type, model_safe_group, generic_change_processor_.get()); | |
| 113 } | |
| 114 | |
| 115 } // namespace browser_sync | |
| OLD | NEW |