OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sync/api/model_type_service.h" | 5 #include "sync/api/model_type_service.h" |
6 | 6 |
| 7 #include "sync/api/model_type_change_processor.h" |
| 8 |
7 namespace syncer_v2 { | 9 namespace syncer_v2 { |
8 | 10 |
9 ModelTypeService::ModelTypeService() {} | 11 ModelTypeService::ModelTypeService( |
| 12 const ChangeProcessorFactory& change_processor_factory, |
| 13 syncer::ModelType type) |
| 14 : change_processor_factory_(change_processor_factory), type_(type) {} |
10 | 15 |
11 ModelTypeService::~ModelTypeService() {} | 16 ModelTypeService::~ModelTypeService() {} |
12 | 17 |
13 ModelTypeChangeProcessor* ModelTypeService::change_processor() const { | 18 ModelTypeChangeProcessor* ModelTypeService::change_processor() const { |
14 return change_processor_.get(); | 19 return change_processor_.get(); |
15 } | 20 } |
16 | 21 |
17 void ModelTypeService::set_change_processor( | 22 ModelTypeChangeProcessor* ModelTypeService::GetOrCreateChangeProcessor() { |
18 scoped_ptr<ModelTypeChangeProcessor> change_processor) { | 23 if (!change_processor_) { |
19 DCHECK(!change_processor_); | 24 change_processor_ = change_processor_factory_.Run(type(), this); |
20 change_processor_.swap(change_processor); | 25 DCHECK(change_processor_); |
21 OnChangeProcessorSet(); | 26 OnChangeProcessorSet(); |
| 27 } |
| 28 return change_processor_.get(); |
22 } | 29 } |
23 | 30 |
24 void ModelTypeService::clear_change_processor() { | 31 void ModelTypeService::clear_change_processor() { |
25 change_processor_.reset(); | 32 change_processor_.reset(); |
26 } | 33 } |
27 | 34 |
| 35 ModelTypeChangeProcessor* ModelTypeService::OnSyncStarting( |
| 36 const ModelTypeChangeProcessor::StartCallback& start_callback) { |
| 37 ModelTypeChangeProcessor* processor = GetOrCreateChangeProcessor(); |
| 38 DCHECK(processor); |
| 39 processor->OnSyncStarting(start_callback); |
| 40 return processor; |
| 41 } |
| 42 |
| 43 syncer::ModelType ModelTypeService::type() const { |
| 44 return type_; |
| 45 } |
| 46 |
28 } // namespace syncer_v2 | 47 } // namespace syncer_v2 |
OLD | NEW |