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

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

Issue 93433006: sync: Introduce ModelTypeRegistry and helpers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor map ownership Created 6 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sync_session_context.h" 5 #include "sync/sessions/sync_session_context.h"
6 6
7 #include "sync/engine/committer_list.h"
8 #include "sync/engine/updater_list.h"
7 #include "sync/sessions/debug_info_getter.h" 9 #include "sync/sessions/debug_info_getter.h"
8 #include "sync/util/extensions_activity.h" 10 #include "sync/util/extensions_activity.h"
9 11
10 namespace syncer { 12 namespace syncer {
11 namespace sessions { 13 namespace sessions {
12 14
13 SyncSessionContext::SyncSessionContext( 15 SyncSessionContext::SyncSessionContext(
14 ServerConnectionManager* connection_manager, 16 ServerConnectionManager* connection_manager,
15 syncable::Directory* directory, 17 syncable::Directory* directory,
16 const std::vector<ModelSafeWorker*>& workers,
17 ExtensionsActivity* extensions_activity, 18 ExtensionsActivity* extensions_activity,
18 const std::vector<SyncEngineEventListener*>& listeners, 19 const std::vector<SyncEngineEventListener*>& listeners,
19 DebugInfoGetter* debug_info_getter, 20 DebugInfoGetter* debug_info_getter,
20 TrafficRecorder* traffic_recorder, 21 TrafficRecorder* traffic_recorder,
22 ModelTypeRegistry* model_type_registry,
21 bool keystore_encryption_enabled, 23 bool keystore_encryption_enabled,
22 bool client_enabled_pre_commit_update_avoidance, 24 bool client_enabled_pre_commit_update_avoidance,
23 const std::string& invalidator_client_id) 25 const std::string& invalidator_client_id)
24 : connection_manager_(connection_manager), 26 : connection_manager_(connection_manager),
25 directory_(directory), 27 directory_(directory),
26 update_handler_deleter_(&update_handler_map_),
27 commit_contributor_deleter_(&commit_contributor_map_),
28 extensions_activity_(extensions_activity), 28 extensions_activity_(extensions_activity),
29 notifications_enabled_(false), 29 notifications_enabled_(false),
30 max_commit_batch_size_(kDefaultMaxCommitBatchSize), 30 max_commit_batch_size_(kDefaultMaxCommitBatchSize),
31 debug_info_getter_(debug_info_getter), 31 debug_info_getter_(debug_info_getter),
32 traffic_recorder_(traffic_recorder), 32 traffic_recorder_(traffic_recorder),
33 model_type_registry_(model_type_registry),
33 keystore_encryption_enabled_(keystore_encryption_enabled), 34 keystore_encryption_enabled_(keystore_encryption_enabled),
34 invalidator_client_id_(invalidator_client_id), 35 invalidator_client_id_(invalidator_client_id),
35 server_enabled_pre_commit_update_avoidance_(false), 36 server_enabled_pre_commit_update_avoidance_(false),
36 client_enabled_pre_commit_update_avoidance_( 37 client_enabled_pre_commit_update_avoidance_(
37 client_enabled_pre_commit_update_avoidance) { 38 client_enabled_pre_commit_update_avoidance) {
38 for (size_t i = 0u; i < workers.size(); ++i) {
39 workers_.insert(
40 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i]));
41 }
42
43 std::vector<SyncEngineEventListener*>::const_iterator it; 39 std::vector<SyncEngineEventListener*>::const_iterator it;
44 for (it = listeners.begin(); it != listeners.end(); ++it) 40 for (it = listeners.begin(); it != listeners.end(); ++it)
45 listeners_.AddObserver(*it); 41 listeners_.AddObserver(*it);
46 } 42 }
47 43
48 SyncSessionContext::~SyncSessionContext() { 44 SyncSessionContext::~SyncSessionContext() {
49 } 45 }
50 46
51 void SyncSessionContext::set_routing_info( 47 void SyncSessionContext::SetRoutingInfo(
52 const ModelSafeRoutingInfo& routing_info) { 48 const ModelSafeRoutingInfo& routing_info) {
53 enabled_types_ = GetRoutingInfoTypes(routing_info); 49 enabled_types_ = GetRoutingInfoTypes(routing_info);
50 model_type_registry_->SetEnabledDirectoryTypes(routing_info);
51 updater_list_.reset(
52 new UpdaterList(model_type_registry_->update_handler_map()));
53 committer_list_.reset(
54 new CommitterList(model_type_registry_->commit_contributor_map()));
55 }
54 56
55 // TODO(rlarocque): This is not a good long-term solution. We must find a 57 UpdaterList* SyncSessionContext::GetUpdaterList() {
56 // better way to initialize the set of CommitContributors and UpdateHandlers. 58 return updater_list_.get();
57 STLDeleteValues<UpdateHandlerMap>(&update_handler_map_); 59 }
58 STLDeleteValues<CommitContributorMap>(&commit_contributor_map_);
59 for (ModelSafeRoutingInfo::const_iterator routing_iter = routing_info.begin();
60 routing_iter != routing_info.end(); ++routing_iter) {
61 ModelType type = routing_iter->first;
62 ModelSafeGroup group = routing_iter->second;
63 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> >::iterator
64 worker_it = workers_.find(group);
65 DCHECK(worker_it != workers_.end());
66 scoped_refptr<ModelSafeWorker> worker = worker_it->second;
67 60
68 SyncDirectoryUpdateHandler* handler = 61 CommitterList* SyncSessionContext::GetCommitterList() {
69 new SyncDirectoryUpdateHandler(directory(), type, worker); 62 return committer_list_.get();
70 update_handler_map_.insert(std::make_pair(type, handler));
71
72 SyncDirectoryCommitContributor* contributor =
73 new SyncDirectoryCommitContributor(directory(), type);
74 commit_contributor_map_.insert(std::make_pair(type, contributor));
75 }
76 } 63 }
77 64
78 } // namespace sessions 65 } // namespace sessions
79 } // namespace syncer 66 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698