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

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

Issue 11314008: sync: Follow-up to conflict resolution refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 8 years, 1 month 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.cc ('k') | sync/sessions/sync_session_context.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 // SyncSessionContext encapsulates the contextual information and engine 5 // SyncSessionContext encapsulates the contextual information and engine
6 // components specific to a SyncSession. A context is accessible via 6 // components specific to a SyncSession. A context is accessible via
7 // a SyncSession so that session SyncerCommands and parts of the engine have 7 // a SyncSession so that session SyncerCommands and parts of the engine have
8 // a convenient way to access other parts. In this way it can be thought of as 8 // a convenient way to access other parts. In this way it can be thought of as
9 // the surrounding environment for the SyncSession. The components of this 9 // the surrounding environment for the SyncSession. The components of this
10 // environment are either valid or not valid for the entire context lifetime, 10 // environment are either valid or not valid for the entire context lifetime,
(...skipping 13 matching lines...) Expand all
24 24
25 #include "sync/engine/sync_engine_event.h" 25 #include "sync/engine/sync_engine_event.h"
26 #include "sync/engine/syncer_types.h" 26 #include "sync/engine/syncer_types.h"
27 #include "sync/engine/traffic_recorder.h" 27 #include "sync/engine/traffic_recorder.h"
28 #include "sync/internal_api/public/engine/model_safe_worker.h" 28 #include "sync/internal_api/public/engine/model_safe_worker.h"
29 #include "sync/protocol/sync.pb.h" 29 #include "sync/protocol/sync.pb.h"
30 #include "sync/sessions/debug_info_getter.h" 30 #include "sync/sessions/debug_info_getter.h"
31 31
32 namespace syncer { 32 namespace syncer {
33 33
34 class ConflictResolver;
35 class ExtensionsActivityMonitor; 34 class ExtensionsActivityMonitor;
36 class ServerConnectionManager; 35 class ServerConnectionManager;
37 class ThrottledDataTypeTracker; 36 class ThrottledDataTypeTracker;
38 37
39 namespace syncable { 38 namespace syncable {
40 class Directory; 39 class Directory;
41 } 40 }
42 41
43 // Default number of items a client can commit in a single message. 42 // Default number of items a client can commit in a single message.
44 static const int kDefaultMaxCommitBatchSize = 25; 43 static const int kDefaultMaxCommitBatchSize = 25;
45 44
46 namespace sessions { 45 namespace sessions {
47 class ScopedSessionContextConflictResolver;
48 class TestScopedSessionEventListener; 46 class TestScopedSessionEventListener;
49 47
50 class SyncSessionContext { 48 class SyncSessionContext {
51 public: 49 public:
52 SyncSessionContext(ServerConnectionManager* connection_manager, 50 SyncSessionContext(ServerConnectionManager* connection_manager,
53 syncable::Directory* directory, 51 syncable::Directory* directory,
54 const std::vector<ModelSafeWorker*>& workers, 52 const std::vector<ModelSafeWorker*>& workers,
55 ExtensionsActivityMonitor* extensions_activity_monitor, 53 ExtensionsActivityMonitor* extensions_activity_monitor,
56 ThrottledDataTypeTracker* throttled_data_type_tracker, 54 ThrottledDataTypeTracker* throttled_data_type_tracker,
57 const std::vector<SyncEngineEventListener*>& listeners, 55 const std::vector<SyncEngineEventListener*>& listeners,
58 DebugInfoGetter* debug_info_getter, 56 DebugInfoGetter* debug_info_getter,
59 TrafficRecorder* traffic_recorder, 57 TrafficRecorder* traffic_recorder,
60 bool keystore_encryption_enabled); 58 bool keystore_encryption_enabled);
61 59
62 ~SyncSessionContext(); 60 ~SyncSessionContext();
63 61
64 ConflictResolver* resolver() { return resolver_; }
65 ServerConnectionManager* connection_manager() { 62 ServerConnectionManager* connection_manager() {
66 return connection_manager_; 63 return connection_manager_;
67 } 64 }
68 syncable::Directory* directory() { 65 syncable::Directory* directory() {
69 return directory_; 66 return directory_;
70 } 67 }
71 68
72 const ModelSafeRoutingInfo& routing_info() const { 69 const ModelSafeRoutingInfo& routing_info() const {
73 return routing_info_; 70 return routing_info_;
74 } 71 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 126 }
130 127
131 const sync_pb::ClientStatus& client_status() const { 128 const sync_pb::ClientStatus& client_status() const {
132 return client_status_; 129 return client_status_;
133 } 130 }
134 131
135 private: 132 private:
136 // Rather than force clients to set and null-out various context members, we 133 // Rather than force clients to set and null-out various context members, we
137 // extend our encapsulation boundary to scoped helpers that take care of this 134 // extend our encapsulation boundary to scoped helpers that take care of this
138 // once they are allocated. See definitions of these below. 135 // once they are allocated. See definitions of these below.
139 friend class ScopedSessionContextConflictResolver;
140 friend class TestScopedSessionEventListener; 136 friend class TestScopedSessionEventListener;
141 137
142 // This is installed by Syncer objects when needed and may be NULL.
143 ConflictResolver* resolver_;
144
145 ObserverList<SyncEngineEventListener> listeners_; 138 ObserverList<SyncEngineEventListener> listeners_;
146 139
147 ServerConnectionManager* const connection_manager_; 140 ServerConnectionManager* const connection_manager_;
148 syncable::Directory* const directory_; 141 syncable::Directory* const directory_;
149 142
150 // A cached copy of SyncBackendRegistrar's routing info. 143 // A cached copy of SyncBackendRegistrar's routing info.
151 // Must be updated manually when SBR's state is modified. 144 // Must be updated manually when SBR's state is modified.
152 ModelSafeRoutingInfo routing_info_; 145 ModelSafeRoutingInfo routing_info_;
153 146
154 // The set of ModelSafeWorkers. Used to execute tasks of various threads. 147 // The set of ModelSafeWorkers. Used to execute tasks of various threads.
(...skipping 25 matching lines...) Expand all
180 sync_pb::ClientStatus client_status_; 173 sync_pb::ClientStatus client_status_;
181 174
182 // Temporary variable while keystore encryption is behind a flag. True if 175 // Temporary variable while keystore encryption is behind a flag. True if
183 // we should attempt performing keystore encryption related work, false if 176 // we should attempt performing keystore encryption related work, false if
184 // the experiment is not enabled. 177 // the experiment is not enabled.
185 bool keystore_encryption_enabled_; 178 bool keystore_encryption_enabled_;
186 179
187 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); 180 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext);
188 }; 181 };
189 182
190 // Installs a ConflictResolver to a given session context for the lifetime of
191 // the ScopedSessionContextConflictResolver. There should never be more than
192 // one ConflictResolver in the system, so it is an error to use this if the
193 // context already has a resolver.
194 class ScopedSessionContextConflictResolver {
195 public:
196 // Note: |context| and |resolver| should outlive |this|.
197 ScopedSessionContextConflictResolver(SyncSessionContext* context,
198 ConflictResolver* resolver)
199 : context_(context), resolver_(resolver) {
200 DCHECK(NULL == context->resolver_);
201 context->resolver_ = resolver;
202 }
203 ~ScopedSessionContextConflictResolver() {
204 context_->resolver_ = NULL;
205 }
206
207 private:
208 SyncSessionContext* context_;
209 ConflictResolver* resolver_;
210 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver);
211 };
212
213 } // namespace sessions 183 } // namespace sessions
214 } // namespace syncer 184 } // namespace syncer
215 185
216 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ 186 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
OLDNEW
« no previous file with comments | « sync/sessions/sync_session.cc ('k') | sync/sessions/sync_session_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698