 Chromium Code Reviews
 Chromium Code Reviews Issue 8065016:
  [Sync] Refactor non-frontend DTC to handle new API properly.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 8065016:
  [Sync] Refactor non-frontend DTC to handle new API properly.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 "base/location.h" | |
| 8 #include "chrome/browser/sync/api/syncable_service.h" | |
| 9 #include "chrome/browser/sync/api/sync_change.h" | |
| 10 #include "chrome/browser/sync/api/sync_error.h" | |
| 11 #include "content/browser/browser_thread.h" | |
| 12 | |
| 13 using base::AutoLock; | |
| 14 | |
| 15 namespace browser_sync { | |
| 16 | |
| 17 SharedChangeProcessor::SharedChangeProcessor( | |
| 18 UnrecoverableErrorHandler* error_handler) | |
| 19 : GenericChangeProcessor(error_handler), | |
| 20 disconnected_(false) { | |
| 21 // We're always created on the UI thread. | |
| 22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 23 DetachFromThread(); | |
| 24 } | |
| 25 | |
| 26 SharedChangeProcessor::~SharedChangeProcessor() { | |
| 27 // We should always be deleted on the UI thread. | |
| 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 29 DetachFromThread(); | |
| 30 } | |
| 31 | |
| 32 // Connect to the syncer and SyncableService specified. | |
| 33 void SharedChangeProcessor::Connect(SyncableService* local_service, | |
| 34 sync_api::UserShare* user_share) { | |
| 35 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 36 DCHECK(CalledOnValidThread()); | |
| 37 AutoLock lock(monitor_lock_); | |
| 38 if (disconnected_) | |
| 39 return; | |
| 40 DCHECK(local_service); | |
| 41 set_local_service(local_service); | |
| 42 set_share_handle(user_share); | |
| 43 } | |
| 44 | |
| 45 void SharedChangeProcessor::Disconnect() { | |
| 46 // May be called from any thread. | |
| 47 VLOG(1) << "Disconnecting change processor."; | |
| 48 AutoLock lock(monitor_lock_); | |
| 49 disconnected_ = true; | |
| 50 } | |
| 51 | |
| 52 SyncError SharedChangeProcessor::GetSyncDataForType( | |
| 53 syncable::ModelType type, | |
| 54 SyncDataList* current_sync_data) { | |
| 55 DCHECK(CalledOnValidThread()); | |
| 56 AutoLock lock(monitor_lock_); | |
| 57 if (disconnected_) { | |
| 58 SyncError error(FROM_HERE, "Change processor disconnected.", type); | |
| 59 return error; | |
| 60 } | |
| 61 return GenericChangeProcessor::GetSyncDataForType(type, current_sync_data); | |
| 62 } | |
| 63 | |
| 64 SyncError SharedChangeProcessor::ProcessSyncChanges( | |
| 65 const tracked_objects::Location& from_here, | |
| 66 const SyncChangeList& list_of_changes) { | |
| 67 DCHECK(CalledOnValidThread()); | |
| 68 AutoLock lock(monitor_lock_); | |
| 69 if (disconnected_) { | |
| 70 // The DTC that disconnects us must ensure it posts a StopSyncing task. | |
| 71 // If we reach this, it means it just hasn't executed yet. | |
| 72 syncable::ModelType type; | |
| 73 if (list_of_changes.size() > 0) { | |
| 74 type = list_of_changes[0].sync_data().GetDataType(); | |
| 75 } | |
| 76 SyncError error(FROM_HERE, "Change processor disconnected.", type); | |
| 77 return error; | |
| 78 } | |
| 79 return GenericChangeProcessor::ProcessSyncChanges(from_here, list_of_changes); | |
| 
akalin
2011/10/07 22:40:05
it may suffice to store the result of the delegate
 
Nicolas Zea
2011/10/12 04:24:19
Discussed offline, there's no risk of the UI threa
 | |
| 80 } | |
| 81 | |
| 82 bool SharedChangeProcessor::SyncModelHasUserCreatedNodes( | |
| 83 syncable::ModelType type, | |
| 84 bool* has_nodes) { | |
| 85 DCHECK(CalledOnValidThread()); | |
| 86 AutoLock lock(monitor_lock_); | |
| 87 if (disconnected_) { | |
| 88 LOG(ERROR) << "Change processor disconnected."; | |
| 89 return false; | |
| 90 } | |
| 91 return GenericChangeProcessor::SyncModelHasUserCreatedNodes(type, has_nodes); | |
| 92 } | |
| 93 | |
| 94 bool SharedChangeProcessor::CryptoReadyIfNecessary(syncable::ModelType type) { | |
| 95 DCHECK(CalledOnValidThread()); | |
| 96 AutoLock lock(monitor_lock_); | |
| 97 if (disconnected_) { | |
| 98 LOG(ERROR) << "Change processor disconnected."; | |
| 99 return true; // Otherwise we get into infinite spin waiting. | |
| 100 } | |
| 101 return GenericChangeProcessor::CryptoReadyIfNecessary(type); | |
| 102 } | |
| 103 | |
| 104 } // namespace browser_sync | |
| OLD | NEW |