1// Copyright 2014 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 "sync/test/engine/injectable_sync_core_proxy.h" 6 7#include "sync/engine/non_blocking_type_processor.h" 8#include "sync/engine/non_blocking_type_processor_core_interface.h" 9 10namespace syncer { 11 12InjectableSyncCoreProxy::InjectableSyncCoreProxy( 13 NonBlockingTypeProcessorCoreInterface* core) 14 : is_core_connected_(false), processor_core_(core) { 15} 16 17InjectableSyncCoreProxy::~InjectableSyncCoreProxy() { 18} 19 20void InjectableSyncCoreProxy::ConnectTypeToCore( 21 syncer::ModelType type, 22 const DataTypeState& data_type_state, 23 base::WeakPtr<syncer::NonBlockingTypeProcessor> type_processor) { 24 // This class is allowed to participate in only one connection. 25 DCHECK(!is_core_connected_); 26 is_core_connected_ = true; 27 28 // Hands off ownership of our member to the type_processor, while keeping 29 // an unsafe pointer to it. This is why we can only connect once. 30 scoped_ptr<NonBlockingTypeProcessorCoreInterface> core(processor_core_); 31 32 type_processor->OnConnect(core.Pass()); 33} 34 35void InjectableSyncCoreProxy::Disconnect(syncer::ModelType type) { 36 // This mock object is not meant for connect and disconnect tests. 37 NOTREACHED() << "Not implemented"; 38} 39 40scoped_ptr<SyncCoreProxy> InjectableSyncCoreProxy::Clone() const { 41 // This confuses ownership. We trust that our callers are well-behaved. 42 return scoped_ptr<SyncCoreProxy>( 43 new InjectableSyncCoreProxy(processor_core_)); 44} 45 46NonBlockingTypeProcessorCoreInterface* 47InjectableSyncCoreProxy::GetProcessorCore() { 48 return processor_core_; 49} 50 51} // namespace syncer 52