• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "sync/sessions/sync_session_context.h"
6 
7 #include "sync/sessions/debug_info_getter.h"
8 #include "sync/util/extensions_activity.h"
9 
10 namespace syncer {
11 namespace sessions {
12 
SyncSessionContext(ServerConnectionManager * connection_manager,syncable::Directory * directory,const std::vector<ModelSafeWorker * > & workers,ExtensionsActivity * extensions_activity,const std::vector<SyncEngineEventListener * > & listeners,DebugInfoGetter * debug_info_getter,TrafficRecorder * traffic_recorder,bool keystore_encryption_enabled,bool client_enabled_pre_commit_update_avoidance,const std::string & invalidator_client_id)13 SyncSessionContext::SyncSessionContext(
14     ServerConnectionManager* connection_manager,
15     syncable::Directory* directory,
16     const std::vector<ModelSafeWorker*>& workers,
17     ExtensionsActivity* extensions_activity,
18     const std::vector<SyncEngineEventListener*>& listeners,
19     DebugInfoGetter* debug_info_getter,
20     TrafficRecorder* traffic_recorder,
21     bool keystore_encryption_enabled,
22     bool client_enabled_pre_commit_update_avoidance,
23     const std::string& invalidator_client_id)
24     : connection_manager_(connection_manager),
25       directory_(directory),
26       update_handler_deleter_(&update_handler_map_),
27       commit_contributor_deleter_(&commit_contributor_map_),
28       extensions_activity_(extensions_activity),
29       notifications_enabled_(false),
30       max_commit_batch_size_(kDefaultMaxCommitBatchSize),
31       debug_info_getter_(debug_info_getter),
32       traffic_recorder_(traffic_recorder),
33       keystore_encryption_enabled_(keystore_encryption_enabled),
34       invalidator_client_id_(invalidator_client_id),
35       server_enabled_pre_commit_update_avoidance_(false),
36       client_enabled_pre_commit_update_avoidance_(
37           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;
44   for (it = listeners.begin(); it != listeners.end(); ++it)
45     listeners_.AddObserver(*it);
46 }
47 
~SyncSessionContext()48 SyncSessionContext::~SyncSessionContext() {
49 }
50 
set_routing_info(const ModelSafeRoutingInfo & routing_info)51 void SyncSessionContext::set_routing_info(
52     const ModelSafeRoutingInfo& routing_info) {
53   enabled_types_ = GetRoutingInfoTypes(routing_info);
54 
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 }
77 
78 }  // namespace sessions
79 }  // namespace syncer
80