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

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

Issue 9732008: [Sync] Store the past 10 traffic records in memory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. 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
« sync/engine/traffic_logger.cc ('K') | « sync/engine/traffic_logger.cc ('k') | no next file » | 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,
11 // or they are valid for explicitly scoped periods of time by using Scoped 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 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 13 // ownership whatsoever of any object that was not created by the context
14 // itself. 14 // itself.
15 // 15 //
16 // It can only be used from the SyncerThread. 16 // It can only be used from the SyncerThread.
17 17
18 #ifndef SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ 18 #ifndef SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
19 #define SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ 19 #define SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
20 #pragma once 20 #pragma once
21 21
22 #include <map> 22 #include <map>
23 #include <queue>
23 #include <string> 24 #include <string>
24 25
25 #include "base/gtest_prod_util.h" 26 #include "base/gtest_prod_util.h"
26 #include "base/memory/scoped_ptr.h" 27 #include "base/memory/scoped_ptr.h"
27 #include "base/time.h" 28 #include "base/time.h"
28 #include "sync/engine/model_safe_worker.h" 29 #include "sync/engine/model_safe_worker.h"
29 #include "sync/engine/syncer_types.h" 30 #include "sync/engine/syncer_types.h"
31 #include "sync/engine/traffic_logger.h"
30 #include "sync/sessions/debug_info_getter.h" 32 #include "sync/sessions/debug_info_getter.h"
31 33
32 namespace syncable { 34 namespace syncable {
33 class Directory; 35 class Directory;
34 } 36 }
35 37
36 namespace browser_sync { 38 namespace browser_sync {
37 39
38 class ConflictResolver; 40 class ConflictResolver;
39 class ExtensionsActivityMonitor; 41 class ExtensionsActivityMonitor;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 const base::TimeTicks& time); 118 const base::TimeTicks& time);
117 119
118 // This prunes the |unthrottle_time_| map based on the |time| passed in. This 120 // This prunes the |unthrottle_time_| map based on the |time| passed in. This
119 // is called by syncer at the SYNCER_BEGIN stage. 121 // is called by syncer at the SYNCER_BEGIN stage.
120 void PruneUnthrottledTypes(const base::TimeTicks& time); 122 void PruneUnthrottledTypes(const base::TimeTicks& time);
121 123
122 // This returns the list of currently throttled types. Unless server returns 124 // This returns the list of currently throttled types. Unless server returns
123 // new throttled types this will remain constant through out the sync cycle. 125 // new throttled types this will remain constant through out the sync cycle.
124 syncable::ModelTypeSet GetThrottledTypes() const; 126 syncable::ModelTypeSet GetThrottledTypes() const;
125 127
128 std::queue<TrafficRecord>* traffic_recorder() {
129 return &traffic_recorder_;
130 }
131
126 private: 132 private:
127 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes; 133 typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes;
128 134
129 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, AddUnthrottleTimeTest); 135 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, AddUnthrottleTimeTest);
130 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, 136 FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest,
131 GetCurrentlyThrottledTypesTest); 137 GetCurrentlyThrottledTypesTest);
132 138
133 // Rather than force clients to set and null-out various context members, we 139 // 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 140 // extend our encapsulation boundary to scoped helpers that take care of this
135 // once they are allocated. See definitions of these below. 141 // once they are allocated. See definitions of these below.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 scoped_ptr<sessions::SyncSessionSnapshot> previous_session_snapshot_; 176 scoped_ptr<sessions::SyncSessionSnapshot> previous_session_snapshot_;
171 177
172 // We use this to get debug info to send to the server for debugging 178 // We use this to get debug info to send to the server for debugging
173 // client behavior on server side. 179 // client behavior on server side.
174 DebugInfoGetter* const debug_info_getter_; 180 DebugInfoGetter* const debug_info_getter_;
175 181
176 // This is a map from throttled data types to the time at which they can be 182 // This is a map from throttled data types to the time at which they can be
177 // unthrottled. 183 // unthrottled.
178 UnthrottleTimes unthrottle_times_; 184 UnthrottleTimes unthrottle_times_;
179 185
186 std::queue<browser_sync::TrafficRecord> traffic_recorder_;
187
180 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext); 188 DISALLOW_COPY_AND_ASSIGN(SyncSessionContext);
181 }; 189 };
182 190
183 // Installs a ConflictResolver to a given session context for the lifetime of 191 // Installs a ConflictResolver to a given session context for the lifetime of
184 // the ScopedSessionContextConflictResolver. There should never be more than 192 // the ScopedSessionContextConflictResolver. There should never be more than
185 // one ConflictResolver in the system, so it is an error to use this if the 193 // one ConflictResolver in the system, so it is an error to use this if the
186 // context already has a resolver. 194 // context already has a resolver.
187 class ScopedSessionContextConflictResolver { 195 class ScopedSessionContextConflictResolver {
188 public: 196 public:
189 // Note: |context| and |resolver| should outlive |this|. 197 // Note: |context| and |resolver| should outlive |this|.
190 ScopedSessionContextConflictResolver(SyncSessionContext* context, 198 ScopedSessionContextConflictResolver(SyncSessionContext* context,
191 ConflictResolver* resolver) 199 ConflictResolver* resolver)
192 : context_(context), resolver_(resolver) { 200 : context_(context), resolver_(resolver) {
193 DCHECK(NULL == context->resolver_); 201 DCHECK(NULL == context->resolver_);
194 context->resolver_ = resolver; 202 context->resolver_ = resolver;
195 } 203 }
196 ~ScopedSessionContextConflictResolver() { 204 ~ScopedSessionContextConflictResolver() {
197 context_->resolver_ = NULL; 205 context_->resolver_ = NULL;
198 } 206 }
199 private: 207 private:
200 SyncSessionContext* context_; 208 SyncSessionContext* context_;
201 ConflictResolver* resolver_; 209 ConflictResolver* resolver_;
202 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver); 210 DISALLOW_COPY_AND_ASSIGN(ScopedSessionContextConflictResolver);
203 }; 211 };
204 212
205 } // namespace sessions 213 } // namespace sessions
206 } // namespace browser_sync 214 } // namespace browser_sync
207 215
208 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_ 216 #endif // SYNC_SESSIONS_SYNC_SESSION_CONTEXT_H_
OLDNEW
« sync/engine/traffic_logger.cc ('K') | « sync/engine/traffic_logger.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698