Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1133)

Side by Side Diff: sync/sessions/model_type_registry.cc

Issue 280983002: Implement sync in the NonBlockingTypeProcessor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix gyp error and some tests Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/sessions/model_type_registry.h ('k') | sync/sessions/model_type_registry_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/sessions/model_type_registry.h" 5 #include "sync/sessions/model_type_registry.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/observer_list.h" 9 #include "base/observer_list.h"
10 #include "sync/engine/directory_commit_contributor.h" 10 #include "sync/engine/directory_commit_contributor.h"
11 #include "sync/engine/directory_update_handler.h" 11 #include "sync/engine/directory_update_handler.h"
12 #include "sync/engine/non_blocking_sync_common.h"
12 #include "sync/engine/non_blocking_type_processor.h" 13 #include "sync/engine/non_blocking_type_processor.h"
13 #include "sync/engine/non_blocking_type_processor_core.h" 14 #include "sync/engine/non_blocking_type_processor_core.h"
15 #include "sync/engine/non_blocking_type_processor_core_interface.h"
14 #include "sync/sessions/directory_type_debug_info_emitter.h" 16 #include "sync/sessions/directory_type_debug_info_emitter.h"
15 17
16 namespace syncer { 18 namespace syncer {
17 19
20 namespace {
21
22 class NonBlockingTypeProcessorCoreWrapper
23 : public NonBlockingTypeProcessorCoreInterface {
24 public:
25 NonBlockingTypeProcessorCoreWrapper(
26 base::WeakPtr<NonBlockingTypeProcessorCore> core,
27 scoped_refptr<base::SequencedTaskRunner> sync_thread);
28 virtual ~NonBlockingTypeProcessorCoreWrapper();
29
30 virtual void RequestCommits(const CommitRequestDataList& list) OVERRIDE;
31
32 private:
33 base::WeakPtr<NonBlockingTypeProcessorCore> core_;
34 scoped_refptr<base::SequencedTaskRunner> sync_thread_;
35 };
36
37 NonBlockingTypeProcessorCoreWrapper::NonBlockingTypeProcessorCoreWrapper(
38 base::WeakPtr<NonBlockingTypeProcessorCore> core,
39 scoped_refptr<base::SequencedTaskRunner> sync_thread)
40 : core_(core), sync_thread_(sync_thread) {
41 }
42
43 NonBlockingTypeProcessorCoreWrapper::~NonBlockingTypeProcessorCoreWrapper() {
44 }
45
46 void NonBlockingTypeProcessorCoreWrapper::RequestCommits(
47 const CommitRequestDataList& list) {
48 sync_thread_->PostTask(
49 FROM_HERE,
50 base::Bind(&NonBlockingTypeProcessorCore::RequestCommits, core_, list));
51 }
52
53 } // namespace
54
18 ModelTypeRegistry::ModelTypeRegistry() : directory_(NULL) {} 55 ModelTypeRegistry::ModelTypeRegistry() : directory_(NULL) {}
19 56
20 ModelTypeRegistry::ModelTypeRegistry( 57 ModelTypeRegistry::ModelTypeRegistry(
21 const std::vector<scoped_refptr<ModelSafeWorker> >& workers, 58 const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
22 syncable::Directory* directory) 59 syncable::Directory* directory)
23 : directory_(directory) { 60 : directory_(directory) {
24 for (size_t i = 0u; i < workers.size(); ++i) { 61 for (size_t i = 0u; i < workers.size(); ++i) {
25 workers_map_.insert( 62 workers_map_.insert(
26 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); 63 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i]));
27 } 64 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 DCHECK(inserted2) << "Attempt to override existing type handler in map"; 126 DCHECK(inserted2) << "Attempt to override existing type handler in map";
90 } 127 }
91 128
92 enabled_directory_types_ = GetRoutingInfoTypes(routing_info); 129 enabled_directory_types_ = GetRoutingInfoTypes(routing_info);
93 DCHECK(Intersection(GetEnabledDirectoryTypes(), 130 DCHECK(Intersection(GetEnabledDirectoryTypes(),
94 GetEnabledNonBlockingTypes()).Empty()); 131 GetEnabledNonBlockingTypes()).Empty());
95 } 132 }
96 133
97 void ModelTypeRegistry::InitializeNonBlockingType( 134 void ModelTypeRegistry::InitializeNonBlockingType(
98 ModelType type, 135 ModelType type,
136 const DataTypeState& data_type_state,
99 scoped_refptr<base::SequencedTaskRunner> type_task_runner, 137 scoped_refptr<base::SequencedTaskRunner> type_task_runner,
100 base::WeakPtr<NonBlockingTypeProcessor> processor) { 138 base::WeakPtr<NonBlockingTypeProcessor> processor) {
101 DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); 139 DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type);
102 140
103 // Initialize CoreProcessor -> Processor communication channel. 141 // Initialize CoreProcessor -> Processor communication channel.
104 scoped_ptr<NonBlockingTypeProcessorCore> core( 142 scoped_ptr<NonBlockingTypeProcessorCore> core(
105 new NonBlockingTypeProcessorCore(type, type_task_runner, processor)); 143 new NonBlockingTypeProcessorCore(type, type_task_runner, processor));
106 144
145 // TODO(rlarocque): DataTypeState should be forwarded to core here.
146
107 // Initialize Processor -> CoreProcessor communication channel. 147 // Initialize Processor -> CoreProcessor communication channel.
108 type_task_runner->PostTask( 148 scoped_ptr<NonBlockingTypeProcessorCoreInterface> core_interface(
109 FROM_HERE, 149 new NonBlockingTypeProcessorCoreWrapper(
110 base::Bind(&NonBlockingTypeProcessor::OnConnect, 150 core->AsWeakPtr(),
111 processor, 151 scoped_refptr<base::SequencedTaskRunner>(
112 core->AsWeakPtr(), 152 base::MessageLoopProxy::current())));
113 scoped_refptr<base::SequencedTaskRunner>( 153 type_task_runner->PostTask(FROM_HERE,
114 base::MessageLoopProxy::current()))); 154 base::Bind(&NonBlockingTypeProcessor::OnConnect,
155 processor,
156 base::Passed(&core_interface)));
115 157
116 DCHECK(update_handler_map_.find(type) == update_handler_map_.end()); 158 DCHECK(update_handler_map_.find(type) == update_handler_map_.end());
117 DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end()); 159 DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end());
118 160
119 update_handler_map_.insert(std::make_pair(type, core.get())); 161 update_handler_map_.insert(std::make_pair(type, core.get()));
120 commit_contributor_map_.insert(std::make_pair(type, core.get())); 162 commit_contributor_map_.insert(std::make_pair(type, core.get()));
121 163
122 // The container takes ownership. 164 // The container takes ownership.
123 non_blocking_type_processor_cores_.push_back(core.release()); 165 non_blocking_type_processor_cores_.push_back(core.release());
124 166
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 ModelTypeSet enabled_off_thread_types; 241 ModelTypeSet enabled_off_thread_types;
200 for (ScopedVector<NonBlockingTypeProcessorCore>::const_iterator it = 242 for (ScopedVector<NonBlockingTypeProcessorCore>::const_iterator it =
201 non_blocking_type_processor_cores_.begin(); 243 non_blocking_type_processor_cores_.begin();
202 it != non_blocking_type_processor_cores_.end(); ++it) { 244 it != non_blocking_type_processor_cores_.end(); ++it) {
203 enabled_off_thread_types.Put((*it)->GetModelType()); 245 enabled_off_thread_types.Put((*it)->GetModelType());
204 } 246 }
205 return enabled_off_thread_types; 247 return enabled_off_thread_types;
206 } 248 }
207 249
208 } // namespace syncer 250 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/sessions/model_type_registry.h ('k') | sync/sessions/model_type_registry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698