OLD | NEW |
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 { |
(...skipping 17 matching lines...) Expand all Loading... |
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 keystore_encryption_enabled_(keystore_encryption_enabled), | 33 keystore_encryption_enabled_(keystore_encryption_enabled), |
34 invalidator_client_id_(invalidator_client_id), | 34 invalidator_client_id_(invalidator_client_id), |
35 server_enabled_pre_commit_update_avoidance_(false), | 35 server_enabled_pre_commit_update_avoidance_(false), |
36 client_enabled_pre_commit_update_avoidance_( | 36 client_enabled_pre_commit_update_avoidance_( |
37 client_enabled_pre_commit_update_avoidance) { | 37 client_enabled_pre_commit_update_avoidance) { |
38 for (size_t i = 0u; i < workers.size(); ++i) | 38 for (size_t i = 0u; i < workers.size(); ++i) { |
39 workers_.push_back(workers[i]); | 39 workers_.insert( |
| 40 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); |
| 41 } |
40 | 42 |
41 std::vector<SyncEngineEventListener*>::const_iterator it; | 43 std::vector<SyncEngineEventListener*>::const_iterator it; |
42 for (it = listeners.begin(); it != listeners.end(); ++it) | 44 for (it = listeners.begin(); it != listeners.end(); ++it) |
43 listeners_.AddObserver(*it); | 45 listeners_.AddObserver(*it); |
44 } | 46 } |
45 | 47 |
46 SyncSessionContext::~SyncSessionContext() { | 48 SyncSessionContext::~SyncSessionContext() { |
47 } | 49 } |
48 | 50 |
49 void SyncSessionContext::set_routing_info( | 51 void SyncSessionContext::set_routing_info( |
50 const ModelSafeRoutingInfo& routing_info) { | 52 const ModelSafeRoutingInfo& routing_info) { |
51 routing_info_ = routing_info; | 53 enabled_types_ = GetRoutingInfoTypes(routing_info); |
52 | 54 |
53 // TODO(rlarocque): This is not a good long-term solution. We must find a | 55 // TODO(rlarocque): This is not a good long-term solution. We must find a |
54 // better way to initialize the set of CommitContributors and UpdateHandlers. | 56 // better way to initialize the set of CommitContributors and UpdateHandlers. |
55 ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); | 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; |
56 | 67 |
57 STLDeleteValues<CommitContributorMap>(&commit_contributor_map_); | 68 SyncDirectoryUpdateHandler* handler = |
58 for (ModelTypeSet::Iterator it = enabled_types.First(); it.Good(); it.Inc()) { | 69 new SyncDirectoryUpdateHandler(directory(), type, worker); |
| 70 update_handler_map_.insert(std::make_pair(type, handler)); |
| 71 |
59 SyncDirectoryCommitContributor* contributor = | 72 SyncDirectoryCommitContributor* contributor = |
60 new SyncDirectoryCommitContributor(directory(), it.Get()); | 73 new SyncDirectoryCommitContributor(directory(), type); |
61 commit_contributor_map_.insert(std::make_pair(it.Get(), contributor)); | 74 commit_contributor_map_.insert(std::make_pair(type, contributor)); |
62 } | |
63 | |
64 STLDeleteValues<UpdateHandlerMap>(&update_handler_map_); | |
65 for (ModelTypeSet::Iterator it = enabled_types.First(); it.Good(); it.Inc()) { | |
66 SyncDirectoryUpdateHandler* handler = | |
67 new SyncDirectoryUpdateHandler(directory(), it.Get()); | |
68 update_handler_map_.insert(std::make_pair(it.Get(), handler)); | |
69 } | 75 } |
70 } | 76 } |
71 | 77 |
72 } // namespace sessions | 78 } // namespace sessions |
73 } // namespace syncer | 79 } // namespace syncer |
OLD | NEW |