blob: 66a016b762d8ccd626c935aa8cc89bbe67a6f8c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// Copyright 2014 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 "sync/engine/non_blocking_type_processor.h"
#include "base/message_loop/message_loop_proxy.h"
#include "sync/engine/non_blocking_type_processor_core.h"
#include "sync/internal_api/public/sync_core_proxy.h"
namespace syncer {
NonBlockingTypeProcessor::NonBlockingTypeProcessor(ModelType type)
: type_(type),
is_preferred_(false),
is_connected_(false),
weak_ptr_factory_for_ui_(this),
weak_ptr_factory_for_sync_(this) {
}
NonBlockingTypeProcessor::~NonBlockingTypeProcessor() {
}
bool NonBlockingTypeProcessor::IsPreferred() const {
DCHECK(CalledOnValidThread());
return is_preferred_;
}
bool NonBlockingTypeProcessor::IsConnected() const {
DCHECK(CalledOnValidThread());
return is_connected_;
}
ModelType NonBlockingTypeProcessor::GetModelType() const {
DCHECK(CalledOnValidThread());
return type_;
}
void NonBlockingTypeProcessor::Enable(
scoped_ptr<SyncCoreProxy> sync_core_proxy) {
DCHECK(CalledOnValidThread());
DVLOG(1) << "Asked to enable " << ModelTypeToString(type_);
is_preferred_ = true;
sync_core_proxy_ = sync_core_proxy.Pass();
sync_core_proxy_->ConnectTypeToCore(GetModelType(),
weak_ptr_factory_for_sync_.GetWeakPtr());
}
void NonBlockingTypeProcessor::Disable() {
DCHECK(CalledOnValidThread());
is_preferred_ = false;
Disconnect();
}
void NonBlockingTypeProcessor::Disconnect() {
DCHECK(CalledOnValidThread());
DVLOG(1) << "Asked to disconnect " << ModelTypeToString(type_);
is_connected_ = false;
if (sync_core_proxy_) {
sync_core_proxy_->Disconnect(GetModelType());
sync_core_proxy_.reset();
}
weak_ptr_factory_for_sync_.InvalidateWeakPtrs();
core_ = base::WeakPtr<NonBlockingTypeProcessorCore>();
sync_thread_ = scoped_refptr<base::SequencedTaskRunner>();
}
base::WeakPtr<NonBlockingTypeProcessor>
NonBlockingTypeProcessor::AsWeakPtrForUI() {
DCHECK(CalledOnValidThread());
return weak_ptr_factory_for_ui_.GetWeakPtr();
}
void NonBlockingTypeProcessor::OnConnect(
base::WeakPtr<NonBlockingTypeProcessorCore> core,
scoped_refptr<base::SequencedTaskRunner> sync_thread) {
DCHECK(CalledOnValidThread());
DVLOG(1) << "Successfully connected " << ModelTypeToString(type_);
is_connected_ = true;
core_ = core;
sync_thread_ = sync_thread;
}
} // namespace syncer
|