• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 namespace syncer {
11 
InjectableSyncCoreProxy(NonBlockingTypeProcessorCoreInterface * core)12 InjectableSyncCoreProxy::InjectableSyncCoreProxy(
13     NonBlockingTypeProcessorCoreInterface* core)
14     : is_core_connected_(false), processor_core_(core) {
15 }
16 
~InjectableSyncCoreProxy()17 InjectableSyncCoreProxy::~InjectableSyncCoreProxy() {
18 }
19 
ConnectTypeToCore(syncer::ModelType type,const DataTypeState & data_type_state,base::WeakPtr<syncer::NonBlockingTypeProcessor> type_processor)20 void 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 
Disconnect(syncer::ModelType type)35 void InjectableSyncCoreProxy::Disconnect(syncer::ModelType type) {
36   // This mock object is not meant for connect and disconnect tests.
37   NOTREACHED() << "Not implemented";
38 }
39 
Clone() const40 scoped_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 
46 NonBlockingTypeProcessorCoreInterface*
GetProcessorCore()47 InjectableSyncCoreProxy::GetProcessorCore() {
48   return processor_core_;
49 }
50 
51 }  // namespace syncer
52