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

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

Issue 9699057: [Sync] Move 'sync' target to sync/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Tim's comments Created 8 years, 9 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
(Empty)
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 // SyncSessionContext encapsulates the contextual information and engine
6 // components specific to a SyncSession. A context is accessible via
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
9 // the surrounding environment for the SyncSession. The components of this
10 // environment are either valid or not valid for the entire context lifetime,
11 // or they are valid for explicitly scoped periods of time by using Scoped
12 // installation utilities found below. This means that the context assumes no
13 // ownership whatsoever of any object that was not created by the context
14 // itself.
15 //
16 // It can only be used from the SyncerThread.
17
18 #ifndef CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
19 #define CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
20 #pragma once
21
22 #include <map>
23 #include <string>
24
25 #include "base/gtest_prod_util.h"
26 #include "base/memory/scoped_ptr.h"
27 #include "base/time.h"
28 #include "chrome/browser/sync/engine/model_safe_worker.h"
29 #include "chrome/browser/sync/engine/syncer_types.h"
30 #include "chrome/browser/sync/sessions/debug_info_getter.h"
31
32 namespace syncable {
33 class Directory;
34 }
35
36 namespace browser_sync {
37
38 class ConflictResolver;
39 class ExtensionsActivityMonitor;
40 class ModelSafeWorkerRegistrar;
41 class ServerConnectionManager;
42
43 // Default number of items a client can commit in a single message.
44 static const int kDefaultMaxCommitBatchSize = 25;
45
46 namespace sessions {
47 class ScopedSessionContextConflictResolver;
48 struct SyncSessionSnapshot;
49 class TestScopedSessionEventListener;
50
51 class SyncSessionContext {
52 public:
53 SyncSessionContext(ServerConnectionManager* connection_manager,
54 syncable::Directory* directory,
55 ModelSafeWorkerRegistrar* model_safe_worker_registrar,
56 ExtensionsActivityMonitor* extensions_activity_monitor,
57 const std::vector<SyncEngineEventListener*>& listeners,
58 DebugInfoGetter* debug_info_getter);
59
60 // Empty constructor for unit tests.
61 SyncSessionContext();
62 virtual ~SyncSessionContext();
63
64 ConflictResolver* resolver() { return resolver_; }
65 ServerConnectionManager* connection_manager() {
66 return connection_manager_;
67 }
68 syncable::Directory* directory() {
69 return directory_;
70 }
71
72 ModelSafeWorkerRegistrar* registrar() {
73 return registrar_;
74 }
75 ExtensionsActivityMonitor* extensions_monitor() {
76 return extensions_activity_monitor_;
77 }
78
79 DebugInfoGetter* debug_info_getter() {
80 return debug_info_getter_;
81 }
82
83 // Talk notification status.
84 void set_notifications_enabled(bool enabled) {
85 notifications_enabled_ = enabled;
86 }
87 bool notifications_enabled() { return notifications_enabled_; }
88
89 // Account name, set once a directory has been opened.
90 void set_account_name(const std::string name) {
91 DCHECK(account_name_.empty());
92 account_name_ = name;
93 }
94 const std::string& account_name() const { return account_name_; }
95
96 void set_max_commit_batch_size(int batch_size) {
97 max_commit_batch_size_ = batch_size;
98 }
99 int32 max_commit_batch_size() const { return max_commit_batch_size_; }
100
101 const ModelSafeRoutingInfo& previous_session_routing_info() const {
102 return previous_session_routing_info_;
103 }
104
105 void set_previous_session_routing_info(const ModelSafeRoutingInfo& info) {
106 previous_session_routing_info_ = info;
107 }
108
109 void NotifyListeners(const SyncEngineEvent& event) {
110 FOR_EACH_OBSERVER(SyncEngineEventListener, listeners_,
111 OnSyncEngineEvent(event));
112 }
113
114 // This is virtual for unit tests.
115 virtual void SetUnthrottleTime(syncable::ModelTypeSet types,
116 const base::TimeTicks& time);
117
118 // This prunes the |unthrottle_time_| map based on the |time| passed in. This
119 // is called by syncer at the SYNCER_BEGIN stage.
120 void PruneUnthrottledTypes(const base::TimeTicks& time);
121
122 // This returns the list of currently throttled types. Unless server returns
123 // new throttled types this will remain constant through out the sync cycle.
124 syncable::ModelTypeSet GetThrottledTypes() const;
125
126 private:
127 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes;
128
129 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, AddUnthrottleTimeTest);
130 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest,
131 GetCurrentlyThrottledTypesTest);
132
133 // Rather than force clients to set and null-out various context members, we
134 // extend our encapsulation boundary to scoped helpers that take care of this
135 // once they are allocated. See definitions of these below.
136 friend class ScopedSessionContextConflictResolver;
137 friend class TestScopedSessionEventListener;
138
139 // This is installed by Syncer objects when needed and may be NULL.
140 ConflictResolver* resolver_;
141
142 ObserverList<SyncEngineEventListener> listeners_;
143
144 ServerConnectionManager* const connection_manager_;
145 syncable::Directory* const directory_;
146
147 // A registrar of workers capable of processing work closures on a thread
148 // that is guaranteed to be safe for model modifications.
149 ModelSafeWorkerRegistrar* registrar_;
150
151 // We use this to stuff extensions activity into CommitMessages so the server
152 // can correlate commit traffic with extension-related bookmark mutations.
153 ExtensionsActivityMonitor* extensions_activity_monitor_;
154
155 // Kept up to date with talk events to determine whether notifications are
156 // enabled. True only if the notification channel is authorized and open.
157 bool notifications_enabled_;
158
159 // The name of the account being synced.
160 std::string account_name_;
161
162 // The server limits the number of items a client can commit in one batch.
163 int max_commit_batch_size_;
164
165 // Some routing info history to help us clean up types that get disabled
166 // by the user.
167 ModelSafeRoutingInfo previous_session_routing_info_;
168
169 // Cache of last session snapshot information.
170 scoped_ptr<sessions::SyncSessionSnapshot> previous_session_snapshot_;
171
172 // We use this to get debug info to send to the server for debugging
173 // client behavior on server side.
174 DebugInfoGetter* const debug_info_getter_;
175
176 // This is a map from throttled data types to the time at which they can be
177 // unthrottled.
178 UnthrottleTimes unthrottle_times_;
179
180 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext);
181 };
182
183 // Installs a ConflictResolver to a given session context for the lifetime of
184 // the ScopedSessionContextConflictResolver. There should never be more than
185 // one ConflictResolver in the system, so it is an error to use this if the
186 // context already has a resolver.
187 class ScopedSessionContextConflictResolver {
188 public:
189 // Note: |context| and |resolver| should outlive |this|.
190 ScopedSessionContextConflictResolver(SyncSessionContext* context,
191 ConflictResolver* resolver)
192 : context_(context), resolver_(resolver) {
193 DCHECK(NULL == context->resolver_);
194 context->resolver_ = resolver;
195 }
196 ~ScopedSessionContextConflictResolver() {
197 context_->resolver_ = NULL;
198 }
199 private:
200 SyncSessionContext* context_;
201 ConflictResolver* resolver_;
202 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver);
203 };
204
205 } // namespace sessions
206 } // namespace browser_sync
207
208 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/sync_session.cc ('k') | chrome/browser/sync/sessions/sync_session_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698