summaryrefslogtreecommitdiffstats
path: root/sync/sessions
diff options
context:
space:
mode:
Diffstat (limited to 'sync/sessions')
-rw-r--r--sync/sessions/sync_session_context.cc46
-rw-r--r--sync/sessions/sync_session_context.h36
-rw-r--r--sync/sessions/sync_session_context_unittest.cc45
-rw-r--r--sync/sessions/sync_session_unittest.cc4
4 files changed, 16 insertions, 115 deletions
diff --git a/sync/sessions/sync_session_context.cc b/sync/sessions/sync_session_context.cc
index 8af1955..ce9d938 100644
--- a/sync/sessions/sync_session_context.cc
+++ b/sync/sessions/sync_session_context.cc
@@ -4,6 +4,7 @@
#include "sync/sessions/sync_session_context.h"
+#include "sync/engine/throttled_data_type_tracker.h"
#include "sync/sessions/debug_info_getter.h"
#include "sync/util/extensions_activity_monitor.h"
@@ -19,6 +20,7 @@ SyncSessionContext::SyncSessionContext(
const ModelSafeRoutingInfo& model_safe_routing_info,
const std::vector<ModelSafeWorker*>& workers,
ExtensionsActivityMonitor* extensions_activity_monitor,
+ ThrottledDataTypeTracker* throttled_data_type_tracker,
const std::vector<SyncEngineEventListener*>& listeners,
DebugInfoGetter* debug_info_getter,
browser_sync::TrafficRecorder* traffic_recorder)
@@ -30,6 +32,7 @@ SyncSessionContext::SyncSessionContext(
extensions_activity_monitor_(extensions_activity_monitor),
notifications_enabled_(false),
max_commit_batch_size_(kDefaultMaxCommitBatchSize),
+ throttled_data_type_tracker_(throttled_data_type_tracker),
debug_info_getter_(debug_info_getter),
traffic_recorder_(traffic_recorder) {
std::vector<SyncEngineEventListener*>::const_iterator it;
@@ -37,51 +40,8 @@ SyncSessionContext::SyncSessionContext(
listeners_.AddObserver(*it);
}
-SyncSessionContext::SyncSessionContext()
- : connection_manager_(NULL),
- directory_(NULL),
- extensions_activity_monitor_(NULL),
- debug_info_getter_(NULL),
- traffic_recorder_(NULL) {
-}
-
SyncSessionContext::~SyncSessionContext() {
}
-void SyncSessionContext::SetUnthrottleTime(syncable::ModelTypeSet types,
- const base::TimeTicks& time) {
- for (syncable::ModelTypeSet::Iterator it = types.First();
- it.Good(); it.Inc()) {
- unthrottle_times_[it.Get()] = time;
- }
-}
-
-void SyncSessionContext::PruneUnthrottledTypes(const base::TimeTicks& time) {
- UnthrottleTimes::iterator it = unthrottle_times_.begin();
- while (it != unthrottle_times_.end()) {
- if (it->second <= time) {
- // Delete and increment the iterator.
- UnthrottleTimes::iterator iterator_to_delete = it;
- ++it;
- unthrottle_times_.erase(iterator_to_delete);
- } else {
- // Just increment the iterator.
- ++it;
- }
- }
-}
-
-// TODO(lipalani): Call this function and fill the return values in snapshot
-// so it could be shown in the about:sync page.
-syncable::ModelTypeSet SyncSessionContext::GetThrottledTypes() const {
- syncable::ModelTypeSet types;
- for (UnthrottleTimes::const_iterator it = unthrottle_times_.begin();
- it != unthrottle_times_.end();
- ++it) {
- types.Put(it->first);
- }
- return types;
-}
-
} // namespace sessions
} // namespace browser_sync
diff --git a/sync/sessions/sync_session_context.h b/sync/sessions/sync_session_context.h
index b1fc297..ebde3f3 100644
--- a/sync/sessions/sync_session_context.h
+++ b/sync/sessions/sync_session_context.h
@@ -23,7 +23,6 @@
#include <string>
#include <vector>
-#include "base/gtest_prod_util.h"
#include "base/time.h"
#include "sync/engine/sync_engine_event.h"
#include "sync/engine/syncer_types.h"
@@ -40,6 +39,7 @@ namespace browser_sync {
class ConflictResolver;
class ExtensionsActivityMonitor;
class ServerConnectionManager;
+class ThrottledDataTypeTracker;
// Default number of items a client can commit in a single message.
static const int kDefaultMaxCommitBatchSize = 25;
@@ -55,13 +55,11 @@ class SyncSessionContext {
const ModelSafeRoutingInfo& model_safe_routing_info,
const std::vector<ModelSafeWorker*>& workers,
ExtensionsActivityMonitor* extensions_activity_monitor,
+ ThrottledDataTypeTracker* throttled_data_type_tracker,
const std::vector<SyncEngineEventListener*>& listeners,
DebugInfoGetter* debug_info_getter,
browser_sync::TrafficRecorder* traffic_recorder);
-
- // Empty constructor for unit tests.
- SyncSessionContext();
- virtual ~SyncSessionContext();
+ ~SyncSessionContext();
ConflictResolver* resolver() { return resolver_; }
ServerConnectionManager* connection_manager() {
@@ -87,6 +85,10 @@ class SyncSessionContext {
return extensions_activity_monitor_;
}
+ ThrottledDataTypeTracker* throttled_data_type_tracker() {
+ return throttled_data_type_tracker_;
+ }
+
DebugInfoGetter* debug_info_getter() {
return debug_info_getter_;
}
@@ -122,29 +124,11 @@ class SyncSessionContext {
OnSyncEngineEvent(event));
}
- // This is virtual for unit tests.
- virtual void SetUnthrottleTime(syncable::ModelTypeSet types,
- const base::TimeTicks& time);
-
- // This prunes the |unthrottle_time_| map based on the |time| passed in. This
- // is called by syncer at the SYNCER_BEGIN stage.
- void PruneUnthrottledTypes(const base::TimeTicks& time);
-
- // This returns the list of currently throttled types. Unless server returns
- // new throttled types this will remain constant through out the sync cycle.
- syncable::ModelTypeSet GetThrottledTypes() const;
-
browser_sync::TrafficRecorder* traffic_recorder() {
return traffic_recorder_;
}
private:
- typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes;
-
- FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest, AddUnthrottleTimeTest);
- FRIEND_TEST_ALL_PREFIXES(SyncSessionContextTest,
- GetCurrentlyThrottledTypesTest);
-
// Rather than force clients to set and null-out various context members, we
// extend our encapsulation boundary to scoped helpers that take care of this
// once they are allocated. See definitions of these below.
@@ -184,14 +168,12 @@ class SyncSessionContext {
// by the user.
ModelSafeRoutingInfo previous_session_routing_info_;
+ ThrottledDataTypeTracker* throttled_data_type_tracker_;
+
// We use this to get debug info to send to the server for debugging
// client behavior on server side.
DebugInfoGetter* const debug_info_getter_;
- // This is a map from throttled data types to the time at which they can be
- // unthrottled.
- UnthrottleTimes unthrottle_times_;
-
browser_sync::TrafficRecorder* traffic_recorder_;
DISALLOW_COPY_AND_ASSIGN(SyncSessionContext);
diff --git a/sync/sessions/sync_session_context_unittest.cc b/sync/sessions/sync_session_context_unittest.cc
deleted file mode 100644
index 1b0a11a..0000000
--- a/sync/sessions/sync_session_context_unittest.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "sync/sessions/sync_session_context.h"
-
-#include "sync/internal_api/public/syncable/model_type.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace browser_sync {
-namespace sessions {
-TEST(SyncSessionContextTest, AddUnthrottleTimeTest) {
- const syncable::ModelTypeSet types(
- syncable::BOOKMARKS, syncable::PASSWORDS);
-
- SyncSessionContext context;
- base::TimeTicks now = base::TimeTicks::Now();
- context.SetUnthrottleTime(types, now);
-
- EXPECT_EQ(context.unthrottle_times_.size(), 2U);
- EXPECT_EQ(context.unthrottle_times_[syncable::BOOKMARKS], now);
- EXPECT_EQ(context.unthrottle_times_[syncable::PASSWORDS], now);
-}
-
-TEST(SyncSessionContextTest, GetCurrentlyThrottledTypesTest) {
- const syncable::ModelTypeSet types(
- syncable::BOOKMARKS, syncable::PASSWORDS);
-
- SyncSessionContext context;
- base::TimeTicks now = base::TimeTicks::Now();
-
- // Now update the throttled types with time set to 10 seconds earlier from
- // now.
- context.SetUnthrottleTime(types, now - base::TimeDelta::FromSeconds(10));
- context.PruneUnthrottledTypes(base::TimeTicks::Now());
- EXPECT_TRUE(context.GetThrottledTypes().Empty());
-
- // Now update the throttled types with time set to 2 hours from now.
- context.SetUnthrottleTime(types, now + base::TimeDelta::FromSeconds(1200));
- context.PruneUnthrottledTypes(base::TimeTicks::Now());
- EXPECT_TRUE(context.GetThrottledTypes().Equals(types));
-}
-} // namespace sessions.
-} // namespace browser_sync
-
diff --git a/sync/sessions/sync_session_unittest.cc b/sync/sessions/sync_session_unittest.cc
index 8c3bd38..aa3dd7e 100644
--- a/sync/sessions/sync_session_unittest.cc
+++ b/sync/sessions/sync_session_unittest.cc
@@ -10,6 +10,7 @@
#include "base/message_loop.h"
#include "sync/engine/conflict_resolver.h"
#include "sync/engine/syncer_types.h"
+#include "sync/engine/throttled_data_type_tracker.h"
#include "sync/internal_api/public/syncable/model_type.h"
#include "sync/sessions/session_state.h"
#include "sync/sessions/status_controller.h"
@@ -48,6 +49,7 @@ class SyncSessionTest : public testing::Test,
context_.reset(
new SyncSessionContext(
NULL, NULL, routing_info, workers, &extensions_activity_monitor_,
+ throttled_data_type_tracker_.get(),
std::vector<SyncEngineEventListener*>(), NULL, NULL));
routes_.clear();
routes_[syncable::BOOKMARKS] = GROUP_UI;
@@ -63,6 +65,7 @@ class SyncSessionTest : public testing::Test,
workers_.push_back(ui_worker);
workers_.push_back(db_worker);
session_.reset(MakeSession());
+ throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL));
}
virtual void TearDown() {
session_.reset();
@@ -131,6 +134,7 @@ class SyncSessionTest : public testing::Test,
std::vector<scoped_refptr<ModelSafeWorker> > workers_;
ModelSafeRoutingInfo routes_;
FakeExtensionsActivityMonitor extensions_activity_monitor_;
+ scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_;
};
TEST_F(SyncSessionTest, EnabledGroupsEmpty) {