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.
5 #include "sync/test/engine/injectable_sync_context_proxy.h"
7 #include "sync/engine/commit_queue.h"
8 #include "sync/engine/model_type_processor_impl.h"
12 InjectableSyncContextProxy::InjectableSyncContextProxy(
14 : is_worker_connected_(false), queue_(queue
) {
17 InjectableSyncContextProxy::~InjectableSyncContextProxy() {
20 void InjectableSyncContextProxy::ConnectTypeToSync(
21 syncer::ModelType type
,
22 const DataTypeState
& data_type_state
,
23 const UpdateResponseDataList
& response_list
,
24 const base::WeakPtr
<ModelTypeProcessor
>& type_processor
) {
25 // This class is allowed to participate in only one connection.
26 DCHECK(!is_worker_connected_
);
27 is_worker_connected_
= true;
29 // Hands off ownership of our member to the type_processor, while keeping
30 // an unsafe pointer to it. This is why we can only connect once.
31 scoped_ptr
<CommitQueue
> queue(queue_
);
33 type_processor
->OnConnect(queue
.Pass());
36 void InjectableSyncContextProxy::Disconnect(syncer::ModelType type
) {
37 // This should delete the queue, but we don't own it.
41 scoped_ptr
<SyncContextProxy
> InjectableSyncContextProxy::Clone() const {
42 // This confuses ownership. We trust that our callers are well-behaved.
43 return scoped_ptr
<SyncContextProxy
>(new InjectableSyncContextProxy(queue_
));
46 CommitQueue
* InjectableSyncContextProxy::GetQueue() {