| 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..129cd96697993e071b03ed9faacfa5d39a617bee
|
| --- /dev/null
|
| +++ b/chrome/browser/sync/glue/shared_change_processor.cc
|
| @@ -0,0 +1,104 @@
|
| +// 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 "base/location.h"
|
| +#include "chrome/browser/sync/api/syncable_service.h"
|
| +#include "chrome/browser/sync/api/sync_change.h"
|
| +#include "chrome/browser/sync/api/sync_error.h"
|
| +#include "content/browser/browser_thread.h"
|
| +
|
| +using base::AutoLock;
|
| +
|
| +namespace browser_sync {
|
| +
|
| +SharedChangeProcessor::SharedChangeProcessor(
|
| + UnrecoverableErrorHandler* error_handler)
|
| + : GenericChangeProcessor(error_handler),
|
| + disconnected_(false) {
|
| + // We're always created on the UI thread.
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + DetachFromThread();
|
| +}
|
| +
|
| +SharedChangeProcessor::~SharedChangeProcessor() {
|
| + // We should always be deleted on the UI thread.
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + DetachFromThread();
|
| +}
|
| +
|
| +// Connect to the syncer and SyncableService specified.
|
| +void SharedChangeProcessor::Connect(SyncableService* local_service,
|
| + sync_api::UserShare* user_share) {
|
| + DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + DCHECK(CalledOnValidThread());
|
| + AutoLock lock(monitor_lock_);
|
| + if (disconnected_)
|
| + return;
|
| + DCHECK(local_service);
|
| + set_local_service(local_service);
|
| + set_share_handle(user_share);
|
| +}
|
| +
|
| +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 GenericChangeProcessor::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;
|
| + 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 GenericChangeProcessor::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 GenericChangeProcessor::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 GenericChangeProcessor::CryptoReadyIfNecessary(type);
|
| +}
|
| +
|
| +} // namespace browser_sync
|
|
|