OLD | NEW |
| (Empty) |
1 // Copyright 2015 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/api/model_type_service.h" | |
6 | |
7 #include "sync/api/model_type_change_processor.h" | |
8 #include "sync/internal_api/public/data_type_error_handler.h" | |
9 | |
10 namespace syncer_v2 { | |
11 | |
12 ModelTypeService::ModelTypeService( | |
13 const ChangeProcessorFactory& change_processor_factory, | |
14 syncer::ModelType type) | |
15 : change_processor_factory_(change_processor_factory), type_(type) {} | |
16 | |
17 ModelTypeService::~ModelTypeService() {} | |
18 | |
19 ConflictResolution ModelTypeService::ResolveConflict( | |
20 const EntityData& local_data, | |
21 const EntityData& remote_data) const { | |
22 // TODO(maxbogue): Add tests once a file exists for them (crbug.com/543407). | |
23 if (remote_data.is_deleted()) { | |
24 DCHECK(!local_data.is_deleted()); | |
25 return ConflictResolution::UseLocal(); | |
26 } | |
27 return ConflictResolution::UseRemote(); | |
28 } | |
29 | |
30 void ModelTypeService::OnSyncStarting( | |
31 syncer::DataTypeErrorHandler* error_handler, | |
32 const ModelTypeChangeProcessor::StartCallback& start_callback) { | |
33 CreateChangeProcessor(); | |
34 change_processor_->OnSyncStarting(error_handler, start_callback); | |
35 } | |
36 | |
37 void ModelTypeService::DisableSync() { | |
38 DCHECK(change_processor_); | |
39 change_processor_->DisableSync(); | |
40 change_processor_.reset(); | |
41 } | |
42 | |
43 void ModelTypeService::CreateChangeProcessor() { | |
44 if (!change_processor_) { | |
45 change_processor_ = change_processor_factory_.Run(type_, this); | |
46 DCHECK(change_processor_); | |
47 OnChangeProcessorSet(); | |
48 } | |
49 } | |
50 | |
51 ModelTypeChangeProcessor* ModelTypeService::change_processor() const { | |
52 return change_processor_.get(); | |
53 } | |
54 | |
55 void ModelTypeService::clear_change_processor() { | |
56 change_processor_.reset(); | |
57 } | |
58 | |
59 } // namespace syncer_v2 | |
OLD | NEW |