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

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: Fix memory leak in tests 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
« no previous file with comments | « sync/sessions/sync_session_context.h ('k') | sync/sessions/sync_session_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 (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/sessions/debug_info_getter.h" 7 #include "sync/sessions/debug_info_getter.h"
8 #include "sync/util/extensions_activity.h" 8 #include "sync/util/extensions_activity.h"
9 9
10 namespace syncer { 10 namespace syncer {
11 namespace sessions { 11 namespace sessions {
12 12
13 SyncSessionContext::SyncSessionContext( 13 SyncSessionContext::SyncSessionContext(
14 ServerConnectionManager* connection_manager, 14 ServerConnectionManager* connection_manager,
15 syncable::Directory* directory, 15 syncable::Directory* directory,
16 const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
17 ExtensionsActivity* extensions_activity, 16 ExtensionsActivity* extensions_activity,
18 const std::vector<SyncEngineEventListener*>& listeners, 17 const std::vector<SyncEngineEventListener*>& listeners,
19 DebugInfoGetter* debug_info_getter, 18 DebugInfoGetter* debug_info_getter,
20 TrafficRecorder* traffic_recorder, 19 TrafficRecorder* traffic_recorder,
20 ModelTypeRegistry* model_type_registry,
21 bool keystore_encryption_enabled, 21 bool keystore_encryption_enabled,
22 bool client_enabled_pre_commit_update_avoidance, 22 bool client_enabled_pre_commit_update_avoidance,
23 const std::string& invalidator_client_id) 23 const std::string& invalidator_client_id)
24 : connection_manager_(connection_manager), 24 : connection_manager_(connection_manager),
25 directory_(directory), 25 directory_(directory),
26 update_handler_deleter_(&update_handler_map_),
27 commit_contributor_deleter_(&commit_contributor_map_),
28 extensions_activity_(extensions_activity), 26 extensions_activity_(extensions_activity),
29 notifications_enabled_(false), 27 notifications_enabled_(false),
30 max_commit_batch_size_(kDefaultMaxCommitBatchSize), 28 max_commit_batch_size_(kDefaultMaxCommitBatchSize),
31 debug_info_getter_(debug_info_getter), 29 debug_info_getter_(debug_info_getter),
32 traffic_recorder_(traffic_recorder), 30 traffic_recorder_(traffic_recorder),
31 model_type_registry_(model_type_registry),
33 keystore_encryption_enabled_(keystore_encryption_enabled), 32 keystore_encryption_enabled_(keystore_encryption_enabled),
34 invalidator_client_id_(invalidator_client_id), 33 invalidator_client_id_(invalidator_client_id),
35 server_enabled_pre_commit_update_avoidance_(false), 34 server_enabled_pre_commit_update_avoidance_(false),
36 client_enabled_pre_commit_update_avoidance_( 35 client_enabled_pre_commit_update_avoidance_(
37 client_enabled_pre_commit_update_avoidance) { 36 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; 37 std::vector<SyncEngineEventListener*>::const_iterator it;
44 for (it = listeners.begin(); it != listeners.end(); ++it) 38 for (it = listeners.begin(); it != listeners.end(); ++it)
45 listeners_.AddObserver(*it); 39 listeners_.AddObserver(*it);
46 } 40 }
47 41
48 SyncSessionContext::~SyncSessionContext() { 42 SyncSessionContext::~SyncSessionContext() {
49 } 43 }
50 44
51 void SyncSessionContext::set_routing_info( 45 void SyncSessionContext::SetRoutingInfo(
52 const ModelSafeRoutingInfo& routing_info) { 46 const ModelSafeRoutingInfo& routing_info) {
53 enabled_types_ = GetRoutingInfoTypes(routing_info); 47 enabled_types_ = GetRoutingInfoTypes(routing_info);
54 48 model_type_registry_->SetEnabledDirectoryTypes(routing_info);
55 // TODO(rlarocque): This is not a good long-term solution. We must find a
56 // better way to initialize the set of CommitContributors and UpdateHandlers.
57 STLDeleteValues<UpdateHandlerMap>(&update_handler_map_);
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
68 SyncDirectoryUpdateHandler* handler =
69 new SyncDirectoryUpdateHandler(directory(), type, worker);
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 } 49 }
77 50
78 } // namespace sessions 51 } // namespace sessions
79 } // namespace syncer 52 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/sessions/sync_session_context.h ('k') | sync/sessions/sync_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698