diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 22:14:05 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 22:14:05 +0000 |
commit | c0383289e19de6601268360fb7234f94f63a19e4 (patch) | |
tree | fa5cab3ae06ef88aa6aad928ca80a69a70a703c4 /sync | |
parent | 7e929f48631779ae0264733b1a7769712c204d42 (diff) | |
download | chromium_src-c0383289e19de6601268360fb7234f94f63a19e4.zip chromium_src-c0383289e19de6601268360fb7234f94f63a19e4.tar.gz chromium_src-c0383289e19de6601268360fb7234f94f63a19e4.tar.bz2 |
sync: Refactor per-datatype throttling
This CL pulls the code to track throttled data types out of the sync
session context and into a class meant for that purpose. This new
class, ThrottledDataTypeTracker, also implements code to notify the
AllStatus object whenever the set of throttled datatypes is changed.
The fact that ThrottledDataTypeTracker, which lives in sync/engine,
references AllStatus caused some problems with DEPS checks. After a few
iterations during code review, this commit now includes the following
additional changes:
- Move all_status.{cc,h} from sync/internal_api to sync/engine.
- Move the SyncManager::Status inner class out of SyncManager and into
sync/internal_api/public/engine/sync_status.{cc,h}. The class has
been renamed to SyncStatus.
This CL does not include code to expose the throttled status on the
chrome://sync page, though it does contain functionality we will use to
implement it in a future commit.
BUG=125065
TEST=
Review URL: https://chromiumcodereview.appspot.com/10454105
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141992 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
24 files changed, 450 insertions, 291 deletions
diff --git a/sync/internal_api/all_status.cc b/sync/engine/all_status.cc index a8a7efd..7afd1a4 100644 --- a/sync/internal_api/all_status.cc +++ b/sync/engine/all_status.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/internal_api/all_status.h" +#include "sync/engine/all_status.h" #include <algorithm> @@ -24,11 +24,11 @@ AllStatus::AllStatus() { AllStatus::~AllStatus() { } -sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { +sync_api::SyncStatus AllStatus::CreateBlankStatus() const { // Status is initialized with the previous status value. Variables // whose values accumulate (e.g. lifetime counters like updates_received) // are not to be cleared here. - sync_api::SyncManager::Status status = status_; + sync_api::SyncStatus status = status_; status.encryption_conflicts = 0; status.hierarchy_conflicts = 0; status.simple_conflicts = 0; @@ -39,9 +39,9 @@ sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { return status; } -sync_api::SyncManager::Status AllStatus::CalcSyncing( +sync_api::SyncStatus AllStatus::CalcSyncing( const SyncEngineEvent &event) const { - sync_api::SyncManager::Status status = CreateBlankStatus(); + sync_api::SyncStatus status = CreateBlankStatus(); const sessions::SyncSessionSnapshot& snapshot = event.snapshot; status.encryption_conflicts = snapshot.num_encryption_conflicts(); status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts(); @@ -119,7 +119,7 @@ void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { } } -sync_api::SyncManager::Status AllStatus::status() const { +sync_api::SyncStatus AllStatus::status() const { base::AutoLock lock(mutex_); return status_; } @@ -139,6 +139,11 @@ void AllStatus::SetEncryptedTypes(syncable::ModelTypeSet types) { status_.encrypted_types = types; } +void AllStatus::SetThrottledTypes(const syncable::ModelTypeSet& types) { + ScopedStatusLock lock(this); + status_.throttled_types = types; +} + void AllStatus::SetCryptographerReady(bool ready) { ScopedStatusLock lock(this); status_.cryptographer_ready = ready; diff --git a/sync/internal_api/all_status.h b/sync/engine/all_status.h index f60b9ea..68f41f4 100644 --- a/sync/internal_api/all_status.h +++ b/sync/engine/all_status.h @@ -16,25 +16,23 @@ #include "base/synchronization/lock.h" #include "sync/engine/sync_engine_event.h" #include "sync/engine/syncer_types.h" +#include "sync/internal_api/public/engine/sync_status.h" #include "sync/internal_api/public/syncable/model_type.h" -#include "sync/internal_api/sync_manager.h" namespace browser_sync { class ScopedStatusLock; struct ServerConnectionEvent; -// TODO(rlarocque): +// This class collects data and uses it to update its internal state. It can +// return a snapshot of this state as a SyncerStatus object. +// // Most of this data ends up on the about:sync page. But the page is only // 'pinged' to update itself at the end of a sync cycle. A user could refresh // manually, but unless their timing is excellent it's unlikely that a user will -// see any state in mid-sync cycle. We have no plans to change this. -// -// What we do intend to do is improve the UI so that changes following a sync -// cycle are more visible. Without such a change, the status summary for a -// healthy syncer will constantly display as "READY" and never provide any -// indication of a sync cycle being performed. See crbug.com/108100. - +// see any state in mid-sync cycle. We have no plans to change this. However, +// we will continue to collect data and update state mid-sync-cycle in case we +// need to debug slow or stuck sync cycles. class AllStatus : public SyncEngineEventListener { friend class ScopedStatusLock; public: @@ -43,7 +41,7 @@ class AllStatus : public SyncEngineEventListener { virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE; - sync_api::SyncManager::Status status() const; + sync_api::SyncStatus status() const; void SetNotificationsEnabled(bool notifications_enabled); @@ -51,6 +49,8 @@ class AllStatus : public SyncEngineEventListener { void IncrementNotificationsReceived(); + void SetThrottledTypes(const syncable::ModelTypeSet &types); + void SetEncryptedTypes(syncable::ModelTypeSet types); void SetCryptographerReady(bool ready); void SetCryptoHasPendingKeys(bool has_pending_keys); @@ -60,10 +60,10 @@ class AllStatus : public SyncEngineEventListener { protected: // Examines syncer to calculate syncing and the unsynced count, // and returns a Status with new values. - sync_api::SyncManager::Status CalcSyncing(const SyncEngineEvent& event) const; - sync_api::SyncManager::Status CreateBlankStatus() const; + sync_api::SyncStatus CalcSyncing(const SyncEngineEvent& event) const; + sync_api::SyncStatus CreateBlankStatus() const; - sync_api::SyncManager::Status status_; + sync_api::SyncStatus status_; mutable base::Lock mutex_; // Protects all data members. DISALLOW_COPY_AND_ASSIGN(AllStatus); diff --git a/sync/engine/get_commit_ids_command.cc b/sync/engine/get_commit_ids_command.cc index a09d5d7..815dca1 100644 --- a/sync/engine/get_commit_ids_command.cc +++ b/sync/engine/get_commit_ids_command.cc @@ -10,6 +10,7 @@ #include "sync/engine/nigori_util.h" #include "sync/engine/syncer_util.h" +#include "sync/engine/throttled_data_type_tracker.h" #include "sync/syncable/syncable.h" #include "sync/util/cryptographer.h" @@ -50,7 +51,7 @@ SyncerError GetCommitIdsCommand::ExecuteImpl(SyncSession* session) { }; const syncable::ModelTypeSet throttled_types = - session->context()->GetThrottledTypes(); + session->context()->throttled_data_type_tracker()->GetThrottledTypes(); // We filter out all unready entries from the set of unsynced handles. This // new set of ready and unsynced items (which excludes throttled items as // well) is then what we use to determine what is a candidate for commit. diff --git a/sync/engine/sync_scheduler.cc b/sync/engine/sync_scheduler.cc index d528604..f798d67 100644 --- a/sync/engine/sync_scheduler.cc +++ b/sync/engine/sync_scheduler.cc @@ -14,6 +14,7 @@ #include "base/message_loop.h" #include "base/rand_util.h" #include "sync/engine/syncer.h" +#include "sync/engine/throttled_data_type_tracker.h" #include "sync/protocol/proto_enum_conversions.h" #include "sync/protocol/sync.pb.h" #include "sync/util/data_type_histogram.h" @@ -327,7 +328,7 @@ SyncScheduler::JobProcessDecision SyncScheduler::DecideOnJob( // See if our type is throttled. syncable::ModelTypeSet throttled_types = - session_context_->GetThrottledTypes(); + session_context_->throttled_data_type_tracker()->GetThrottledTypes(); if (job.purpose == SyncSessionJob::NUDGE && job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { syncable::ModelTypeSet requested_types; diff --git a/sync/engine/sync_scheduler_unittest.cc b/sync/engine/sync_scheduler_unittest.cc index 256849c..a6d8059 100644 --- a/sync/engine/sync_scheduler_unittest.cc +++ b/sync/engine/sync_scheduler_unittest.cc @@ -10,6 +10,7 @@ #include "base/test/test_timeouts.h" #include "sync/engine/sync_scheduler.h" #include "sync/engine/syncer.h" +#include "sync/engine/throttled_data_type_tracker.h" #include "sync/sessions/test_util.h" #include "sync/test/engine/fake_model_worker.h" #include "sync/test/engine/mock_connection_manager.h" @@ -106,9 +107,10 @@ class SyncSchedulerTest : public testing::Test { connection_.reset(new MockConnectionManager(directory())); connection_->SetServerReachable(); + throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL)); context_.reset(new SyncSessionContext( connection_.get(), directory(), routing_info, workers, - &extensions_activity_monitor_, + &extensions_activity_monitor_, throttled_data_type_tracker_.get(), std::vector<SyncEngineEventListener*>(), NULL, NULL)); context_->set_notifications_enabled(true); context_->set_account_name("Test"); @@ -209,6 +211,7 @@ class SyncSchedulerTest : public testing::Test { MockDelayProvider* delay_; std::vector<scoped_refptr<FakeModelWorker> > workers_; FakeExtensionsActivityMonitor extensions_activity_monitor_; + scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; }; void RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record) { diff --git a/sync/engine/sync_scheduler_whitebox_unittest.cc b/sync/engine/sync_scheduler_whitebox_unittest.cc index dacc260a..34ff7d9 100644 --- a/sync/engine/sync_scheduler_whitebox_unittest.cc +++ b/sync/engine/sync_scheduler_whitebox_unittest.cc @@ -5,6 +5,7 @@ #include "base/message_loop.h" #include "base/time.h" #include "sync/engine/sync_scheduler.h" +#include "sync/engine/throttled_data_type_tracker.h" #include "sync/sessions/sync_session_context.h" #include "sync/sessions/test_util.h" #include "sync/test/engine/fake_model_worker.h" @@ -44,10 +45,12 @@ class SyncSchedulerWhiteboxTest : public testing::Test { } connection_.reset(new MockConnectionManager(NULL)); + throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL)); context_.reset( new SyncSessionContext( connection_.get(), dir_maker_.directory(), routes, workers, &extensions_activity_monitor_, + throttled_data_type_tracker_.get(), std::vector<SyncEngineEventListener*>(), NULL, NULL)); context_->set_notifications_enabled(true); context_->set_account_name("Test"); @@ -116,6 +119,7 @@ class SyncSchedulerWhiteboxTest : public testing::Test { scoped_ptr<SyncSessionContext> context_; std::vector<scoped_refptr<FakeModelWorker> > workers_; FakeExtensionsActivityMonitor extensions_activity_monitor_; + scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; TestDirectorySetterUpper dir_maker_; protected: @@ -142,8 +146,8 @@ TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) { types.Put(syncable::BOOKMARKS); // Mark bookmarks as throttled. - context()->SetUnthrottleTime(types, - base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); + context()->throttled_data_type_tracker()->SetUnthrottleTime( + types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); syncable::ModelTypePayloadMap types_with_payload; types_with_payload[syncable::BOOKMARKS] = ""; diff --git a/sync/engine/syncer.cc b/sync/engine/syncer.cc index 1a299db..c17c0f8 100644 --- a/sync/engine/syncer.cc +++ b/sync/engine/syncer.cc @@ -24,6 +24,7 @@ #include "sync/engine/store_timestamps_command.h" #include "sync/engine/syncer_types.h" #include "sync/engine/syncproto.h" +#include "sync/engine/throttled_data_type_tracker.h" #include "sync/engine/verify_updates_command.h" #include "sync/syncable/syncable-inl.h" #include "sync/syncable/syncable.h" @@ -107,7 +108,8 @@ void Syncer::SyncShare(sessions::SyncSession* session, switch (current_step) { case SYNCER_BEGIN: - session->context()->PruneUnthrottledTypes(base::TimeTicks::Now()); + session->context()->throttled_data_type_tracker()-> + PruneUnthrottledTypes(base::TimeTicks::Now()); session->SendEventNotification(SyncEngineEvent::SYNC_CYCLE_BEGIN); next_step = CLEANUP_DISABLED_TYPES; diff --git a/sync/engine/syncer_proto_util.cc b/sync/engine/syncer_proto_util.cc index bdadda1..294f0ef 100644 --- a/sync/engine/syncer_proto_util.cc +++ b/sync/engine/syncer_proto_util.cc @@ -9,6 +9,7 @@ #include "sync/engine/net/server_connection_manager.h" #include "sync/engine/syncer.h" #include "sync/engine/syncer_types.h" +#include "sync/engine/throttled_data_type_tracker.h" #include "sync/engine/traffic_logger.h" #include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/sync.pb.h" @@ -213,14 +214,14 @@ base::TimeDelta SyncerProtoUtil::GetThrottleDelay( void SyncerProtoUtil::HandleThrottleError( const SyncProtocolError& error, const base::TimeTicks& throttled_until, - sessions::SyncSessionContext* context, + ThrottledDataTypeTracker* tracker, sessions::SyncSession::Delegate* delegate) { DCHECK_EQ(error.error_type, browser_sync::THROTTLED); if (error.error_data_types.Empty()) { // No datatypes indicates the client should be completely throttled. delegate->OnSilencedUntil(throttled_until); } else { - context->SetUnthrottleTime(error.error_data_types, throttled_until); + tracker->SetUnthrottleTime(error.error_data_types, throttled_until); } } @@ -393,7 +394,7 @@ SyncerError SyncerProtoUtil::PostClientToServerMessage( LOG(WARNING) << "Client silenced by server."; HandleThrottleError(sync_protocol_error, base::TimeTicks::Now() + GetThrottleDelay(*response), - session->context(), + session->context()->throttled_data_type_tracker(), session->delegate()); return SERVER_RETURN_THROTTLED; case browser_sync::TRANSIENT_ERROR: diff --git a/sync/engine/syncer_proto_util.h b/sync/engine/syncer_proto_util.h index 14a3791..3856509 100644 --- a/sync/engine/syncer_proto_util.h +++ b/sync/engine/syncer_proto_util.h @@ -33,6 +33,7 @@ class SyncSessionContext; } class ClientToServerMessage; +class ThrottledDataTypeTracker; class ServerConnectionManager; class SyncEntity; class CommitResponse_EntryResponse; @@ -118,10 +119,11 @@ class SyncerProtoUtil { static base::TimeDelta GetThrottleDelay( const sync_pb::ClientToServerResponse& response); - static void HandleThrottleError(const SyncProtocolError& error, - const base::TimeTicks& throttled_until, - sessions::SyncSessionContext* context, - sessions::SyncSession::Delegate* delegate); + static void HandleThrottleError( + const SyncProtocolError& error, + const base::TimeTicks& throttled_until, + browser_sync::ThrottledDataTypeTracker* tracker, + sessions::SyncSession::Delegate* delegate); friend class SyncerProtoUtilTest; FRIEND_TEST_ALL_PREFIXES(SyncerProtoUtilTest, AddRequestBirthday); diff --git a/sync/engine/syncer_proto_util_unittest.cc b/sync/engine/syncer_proto_util_unittest.cc index a1431ab..fe9f0dc 100644 --- a/sync/engine/syncer_proto_util_unittest.cc +++ b/sync/engine/syncer_proto_util_unittest.cc @@ -11,6 +11,7 @@ #include "base/message_loop.h" #include "base/time.h" #include "sync/engine/syncproto.h" +#include "sync/engine/throttled_data_type_tracker.h" #include "sync/internal_api/public/syncable/model_type_test_util.h" #include "sync/protocol/bookmark_specifics.pb.h" #include "sync/protocol/password_specifics.pb.h" @@ -31,14 +32,6 @@ using ::testing::_; namespace browser_sync { using sessions::SyncSessionContext; -class MockSyncSessionContext : public SyncSessionContext { - public: - MockSyncSessionContext() {} - ~MockSyncSessionContext() {} - MOCK_METHOD2(SetUnthrottleTime, void(syncable::ModelTypeSet, - const base::TimeTicks&)); -}; - class MockDelegate : public sessions::SyncSession::Delegate { public: MockDelegate() {} @@ -269,7 +262,7 @@ TEST_F(SyncerProtoUtilTest, PostAndProcessHeaders) { } TEST_F(SyncerProtoUtilTest, HandleThrottlingWithDatatypes) { - MockSyncSessionContext context; + ThrottledDataTypeTracker tracker(NULL); SyncProtocolError error; error.error_type = browser_sync::THROTTLED; syncable::ModelTypeSet types; @@ -277,22 +270,22 @@ TEST_F(SyncerProtoUtilTest, HandleThrottlingWithDatatypes) { types.Put(syncable::PASSWORDS); error.error_data_types = types; - base::TimeTicks ticks = base::TimeTicks::Now(); - - EXPECT_CALL(context, SetUnthrottleTime(HasModelTypes(types), ticks)); - - SyncerProtoUtil::HandleThrottleError(error, ticks, &context, NULL); + base::TimeTicks ticks = base::TimeTicks::FromInternalValue(1); + SyncerProtoUtil::HandleThrottleError(error, ticks, &tracker, NULL); + EXPECT_TRUE(tracker.GetThrottledTypes().Equals(types)); } TEST_F(SyncerProtoUtilTest, HandleThrottlingNoDatatypes) { + ThrottledDataTypeTracker tracker(NULL); MockDelegate delegate; SyncProtocolError error; error.error_type = browser_sync::THROTTLED; - base::TimeTicks ticks = base::TimeTicks::Now(); + base::TimeTicks ticks = base::TimeTicks::FromInternalValue(1); EXPECT_CALL(delegate, OnSilencedUntil(ticks)); - SyncerProtoUtil::HandleThrottleError(error, ticks, NULL, &delegate); + SyncerProtoUtil::HandleThrottleError(error, ticks, &tracker, &delegate); + EXPECT_TRUE(tracker.GetThrottledTypes().Empty()); } } // namespace browser_sync diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc index 1cd9753..cce69aa 100644 --- a/sync/engine/syncer_unittest.cc +++ b/sync/engine/syncer_unittest.cc @@ -32,6 +32,7 @@ #include "sync/engine/syncer_proto_util.h" #include "sync/engine/syncer_util.h" #include "sync/engine/syncproto.h" +#include "sync/engine/throttled_data_type_tracker.h" #include "sync/engine/traffic_recorder.h" #include "sync/internal_api/public/engine/model_safe_worker.h" #include "sync/internal_api/public/syncable/model_type.h" @@ -232,11 +233,13 @@ class SyncerTest : public testing::Test, GetModelSafeRoutingInfo(&routing_info); GetWorkers(&workers); + throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL)); + context_.reset( new SyncSessionContext( mock_server_.get(), directory(), routing_info, workers, - &extensions_activity_monitor_, listeners, NULL, - &traffic_recorder_)); + &extensions_activity_monitor_, throttled_data_type_tracker_.get(), + listeners, NULL, &traffic_recorder_)); ASSERT_FALSE(context_->resolver()); syncer_ = new Syncer(); session_.reset(MakeSession()); @@ -544,6 +547,7 @@ class SyncerTest : public testing::Test, TestDirectorySetterUpper dir_maker_; FakeEncryptor encryptor_; FakeExtensionsActivityMonitor extensions_activity_monitor_; + scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; scoped_ptr<MockConnectionManager> mock_server_; Syncer* syncer_; @@ -647,7 +651,7 @@ TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { } // Now set the throttled types. - context_->SetUnthrottleTime( + context_->throttled_data_type_tracker()->SetUnthrottleTime( throttled_types, base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1200)); SyncShareNudge(); @@ -661,7 +665,7 @@ TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { } // Now unthrottle. - context_->SetUnthrottleTime( + context_->throttled_data_type_tracker()->SetUnthrottleTime( throttled_types, base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1200)); SyncShareNudge(); diff --git a/sync/engine/throttled_data_type_tracker.cc b/sync/engine/throttled_data_type_tracker.cc new file mode 100644 index 0000000..01317a8 --- /dev/null +++ b/sync/engine/throttled_data_type_tracker.cc @@ -0,0 +1,72 @@ +// 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/engine/throttled_data_type_tracker.h" + +#include "sync/engine/all_status.h" +#include "sync/internal_api/public/syncable/model_type.h" + +namespace browser_sync { + +ThrottledDataTypeTracker::ThrottledDataTypeTracker(AllStatus *allstatus) + : allstatus_(allstatus) { + if (allstatus_) { + allstatus_->SetThrottledTypes(syncable::ModelTypeSet()); + } +} + +ThrottledDataTypeTracker::~ThrottledDataTypeTracker() { } + +void ThrottledDataTypeTracker::SetUnthrottleTime(syncable::ModelTypeSet types, + const base::TimeTicks& time) { + for (syncable::ModelTypeSet::Iterator it = types.First(); + it.Good(); it.Inc()) { + unthrottle_times_[it.Get()] = time; + } + + DVLOG(2) + << "Throttling types: " << ModelTypeSetToString(types) + << ", throttled list is now: " + << ModelTypeSetToString(GetThrottledTypes()); + if (allstatus_) { + allstatus_->SetThrottledTypes(GetThrottledTypes()); + } +} + +void ThrottledDataTypeTracker::PruneUnthrottledTypes( + const base::TimeTicks& time) { + bool modified = false; + + 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); + modified = true; + } else { + // Just increment the iterator. + ++it; + } + } + + DVLOG_IF(2, modified) + << "Remaining throttled types: " + << ModelTypeSetToString(GetThrottledTypes()); + if (modified && allstatus_) { + allstatus_->SetThrottledTypes(GetThrottledTypes()); + } +} + +syncable::ModelTypeSet ThrottledDataTypeTracker::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 browser_sync diff --git a/sync/engine/throttled_data_type_tracker.h b/sync/engine/throttled_data_type_tracker.h new file mode 100644 index 0000000..aa2835b --- /dev/null +++ b/sync/engine/throttled_data_type_tracker.h @@ -0,0 +1,55 @@ +// 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. + +#ifndef SYNC_ENGINE_THROTTLED_DATA_TYPE_TRACKER_H_ +#define SYNC_ENGINE_THROTTLED_DATA_TYPE_TRACKER_H_ +#pragma once + +#include <map> + +#include "base/gtest_prod_util.h" +#include "sync/internal_api/public/syncable/model_type.h" + +namespace browser_sync { + +class AllStatus; + +class ThrottledDataTypeTracker { + public: + // The given allstatus argument will be kept up to date on this object's list + // of throttled types. The argument may be NULL in tests. + explicit ThrottledDataTypeTracker(AllStatus* allstatus); + ~ThrottledDataTypeTracker(); + + // Throttles a set of data types until the specified time is reached. + void SetUnthrottleTime(syncable::ModelTypeSet types, + const base::TimeTicks& time); + + // Given an input of the current time (usually from time::Now()), removes from + // the set of throttled types any types whose throttling period has expired. + void PruneUnthrottledTypes(const base::TimeTicks& time); + + // Returns the set of types which are currently throttled. + syncable::ModelTypeSet GetThrottledTypes() const; + + private: + FRIEND_TEST_ALL_PREFIXES(ThrottledDataTypeTrackerTest, + AddUnthrottleTimeTest); + FRIEND_TEST_ALL_PREFIXES(ThrottledDataTypeTrackerTest, + GetCurrentlyThrottledTypesTest); + + typedef std::map<syncable::ModelType, base::TimeTicks> UnthrottleTimes; + + // This is a map from throttled data types to the time at which they can be + // unthrottled. + UnthrottleTimes unthrottle_times_; + + AllStatus* allstatus_; + + DISALLOW_COPY_AND_ASSIGN(ThrottledDataTypeTracker); +}; + +} // namespace browser_sync + +#endif // SYNC_ENGINE_THROTTLED_DATA_TYPE_TRACKER_H_ diff --git a/sync/engine/throttled_data_type_tracker_unittest.cc b/sync/engine/throttled_data_type_tracker_unittest.cc new file mode 100644 index 0000000..cd80436 --- /dev/null +++ b/sync/engine/throttled_data_type_tracker_unittest.cc @@ -0,0 +1,67 @@ +// 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/engine/throttled_data_type_tracker.h" + +#include "sync/internal_api/public/syncable/model_type.h" +#include "testing/gtest/include/gtest/gtest.h" + +using base::TimeDelta; +using base::TimeTicks; + +namespace browser_sync { + +TEST(ThrottledDataTypeTrackerTest, AddUnthrottleTimeTest) { + const syncable::ModelTypeSet types(syncable::BOOKMARKS, syncable::PASSWORDS); + + ThrottledDataTypeTracker throttler(NULL); + TimeTicks now = TimeTicks::Now(); + throttler.SetUnthrottleTime(types, now); + + EXPECT_EQ(throttler.unthrottle_times_.size(), 2U); + EXPECT_EQ(throttler.unthrottle_times_[syncable::BOOKMARKS], now); + EXPECT_EQ(throttler.unthrottle_times_[syncable::PASSWORDS], now); +} + +TEST(ThrottledDataTypeTrackerTest, GetCurrentlyThrottledTypesTest) { + const syncable::ModelTypeSet types(syncable::BOOKMARKS, syncable::PASSWORDS); + + ThrottledDataTypeTracker throttler(NULL); + TimeTicks now = TimeTicks::Now(); + + // Now update the throttled types with time set to 10 seconds earlier from + // now. + throttler.SetUnthrottleTime(types, now - TimeDelta::FromSeconds(10)); + throttler.PruneUnthrottledTypes(TimeTicks::Now()); + EXPECT_TRUE(throttler.GetThrottledTypes().Empty()); + + // Now update the throttled types with time set to 2 hours from now. + throttler.SetUnthrottleTime(types, now + TimeDelta::FromSeconds(1200)); + throttler.PruneUnthrottledTypes(TimeTicks::Now()); + EXPECT_TRUE(throttler.GetThrottledTypes().Equals(types)); +} + +// Have two data types whose throttling is set to expire at different times. +TEST(ThrottledDataTypeTrackerTest, UnthrottleSomeTypesTest) { + const syncable::ModelTypeSet long_throttled(syncable::BOOKMARKS); + const syncable::ModelTypeSet short_throttled(syncable::PASSWORDS); + + const TimeTicks start_time = TimeTicks::Now(); + const TimeTicks short_throttle_time = start_time + TimeDelta::FromSeconds(1); + const TimeTicks long_throttle_time = start_time + TimeDelta::FromSeconds(20); + const TimeTicks in_between_time = start_time + TimeDelta::FromSeconds(5); + + ThrottledDataTypeTracker throttler(NULL); + + throttler.SetUnthrottleTime(long_throttled, long_throttle_time); + throttler.SetUnthrottleTime(short_throttled, short_throttle_time); + EXPECT_TRUE(throttler.GetThrottledTypes().Equals( + Union(short_throttled, long_throttled))); + + throttler.PruneUnthrottledTypes(in_between_time); + EXPECT_TRUE(throttler.GetThrottledTypes().Equals(long_throttled)); +} + +} // namespace browser_sync + diff --git a/sync/internal_api/public/engine/sync_status.cc b/sync/internal_api/public/engine/sync_status.cc new file mode 100644 index 0000000..dd363ba --- /dev/null +++ b/sync/internal_api/public/engine/sync_status.cc @@ -0,0 +1,39 @@ +// 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/internal_api/public/engine/sync_status.h" + +namespace sync_api { + +SyncStatus::SyncStatus() + : notifications_enabled(false), + notifications_received(0), + encryption_conflicts(0), + hierarchy_conflicts(0), + simple_conflicts(0), + server_conflicts(0), + committed_count(0), + syncing(false), + initial_sync_ended(false), + updates_available(0), + updates_received(0), + reflected_updates_received(0), + tombstone_updates_received(0), + num_commits_total(0), + num_local_overwrites_total(0), + num_server_overwrites_total(0), + nonempty_get_updates(0), + empty_get_updates(0), + sync_cycles_with_commits(0), + sync_cycles_without_commits(0), + useless_sync_cycles(0), + useful_sync_cycles(0), + cryptographer_ready(false), + crypto_has_pending_keys(false) { +} + +SyncStatus::~SyncStatus() { +} + +} // namespace sync_api diff --git a/sync/internal_api/public/engine/sync_status.h b/sync/internal_api/public/engine/sync_status.h new file mode 100644 index 0000000..1c9ba1a --- /dev/null +++ b/sync/internal_api/public/engine/sync_status.h @@ -0,0 +1,94 @@ +// 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. + +#ifndef SYNC_INTERNAL_API_PUBLIC_ENGINE_STATUS_SUMMARY_H_ +#define SYNC_INTERNAL_API_PUBLIC_ENGINE_STATUS_SUMMARY_H_ + +#include <string> + +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/protocol/sync_protocol_error.h" + +namespace sync_api { + +// Status encapsulates detailed state about the internals of the SyncManager. +// +// This struct is closely tied to the AllStatus object which uses instances of +// it to track and report on the sync engine's internal state, and the functions +// in sync_ui_util.cc which convert the contents of this struct into a +// DictionaryValue used to populate the about:sync summary tab. +struct SyncStatus { + SyncStatus(); + ~SyncStatus(); + + bool notifications_enabled; // True only if subscribed for notifications. + + // Notifications counters updated by the actions in synapi. + int notifications_received; + + browser_sync::SyncProtocolError sync_protocol_error; + + // Number of encryption conflicts counted during most recent sync cycle. + int encryption_conflicts; + + // Number of hierarchy conflicts counted during most recent sync cycle. + int hierarchy_conflicts; + + // Number of simple conflicts counted during most recent sync cycle. + int simple_conflicts; + + // Number of items the server refused to commit due to conflict during most + // recent sync cycle. + int server_conflicts; + + // Number of items successfully committed during most recent sync cycle. + int committed_count; + + bool syncing; + // True after a client has done a first sync. + bool initial_sync_ended; + + // Total updates available. If zero, nothing left to download. + int64 updates_available; + // Total updates received by the syncer since browser start. + int updates_received; + // Total updates received that are echoes of our own changes. + int reflected_updates_received; + // Of updates_received, how many were tombstones. + int tombstone_updates_received; + + // Total successful commits. + int num_commits_total; + + // Total number of overwrites due to conflict resolver since browser start. + int num_local_overwrites_total; + int num_server_overwrites_total; + + // Count of empty and non empty getupdates; + int nonempty_get_updates; + int empty_get_updates; + + // Count of sync cycles that successfully committed items; + int sync_cycles_with_commits; + int sync_cycles_without_commits; + + // Count of useless and useful syncs we perform. + int useless_sync_cycles; + int useful_sync_cycles; + + // Encryption related. + syncable::ModelTypeSet encrypted_types; + bool cryptographer_ready; + bool crypto_has_pending_keys; + + // Per-datatype throttled status. + syncable::ModelTypeSet throttled_types; + + // The unique identifer for this client. + std::string unique_id; +}; + +} // namespace sync_api + +#endif // SYNC_INTERNAL_API_PUBLIC_ENGINE_STATUS_SUMMARY_H_ diff --git a/sync/internal_api/sync_manager.cc b/sync/internal_api/sync_manager.cc index 5921739..8a2ff70 100644 --- a/sync/internal_api/sync_manager.cc +++ b/sync/internal_api/sync_manager.cc @@ -18,11 +18,12 @@ #include "base/string_number_conversions.h" #include "base/values.h" #include "net/base/network_change_notifier.h" +#include "sync/engine/all_status.h" #include "sync/engine/net/server_connection_manager.h" #include "sync/engine/nigori_util.h" #include "sync/engine/sync_scheduler.h" #include "sync/engine/syncer_types.h" -#include "sync/internal_api/all_status.h" +#include "sync/engine/throttled_data_type_tracker.h" #include "sync/internal_api/base_node.h" #include "sync/internal_api/change_reorder_buffer.h" #include "sync/internal_api/configure_reason.h" @@ -144,6 +145,7 @@ class SyncManager::SyncInternal initialized_(false), testing_mode_(NON_TEST), observing_ip_address_changes_(false), + throttled_data_type_tracker_(&allstatus_), traffic_recorder_(kMaxMessagesToRecord, kMaxMessageSizeToRecord), encryptor_(NULL), unrecoverable_error_handler_(NULL), @@ -346,7 +348,7 @@ class SyncManager::SyncInternal return share_.name; } - Status GetStatus(); + SyncStatus GetStatus(); void RequestNudge(const tracked_objects::Location& nudge_location); @@ -602,6 +604,8 @@ class SyncManager::SyncInternal JsSyncManagerObserver js_sync_manager_observer_; JsMutationEventObserver js_mutation_event_observer_; + browser_sync::ThrottledDataTypeTracker throttled_data_type_tracker_; + // This is for keeping track of client events to send to the server. DebugInfoEventListener debug_info_event_listener_; @@ -702,36 +706,6 @@ SyncManager::Observer::~Observer() {} SyncManager::SyncManager(const std::string& name) : data_(new SyncInternal(name)) {} -SyncManager::Status::Status() - : notifications_enabled(false), - notifications_received(0), - encryption_conflicts(0), - hierarchy_conflicts(0), - simple_conflicts(0), - server_conflicts(0), - committed_count(0), - syncing(false), - initial_sync_ended(false), - updates_available(0), - updates_received(0), - reflected_updates_received(0), - tombstone_updates_received(0), - num_commits_total(0), - num_local_overwrites_total(0), - num_server_overwrites_total(0), - nonempty_get_updates(0), - empty_get_updates(0), - sync_cycles_with_commits(0), - sync_cycles_without_commits(0), - useless_sync_cycles(0), - useful_sync_cycles(0), - cryptographer_ready(false), - crypto_has_pending_keys(false) { -} - -SyncManager::Status::~Status() { -} - bool SyncManager::Init( const FilePath& database_location, const WeakHandle<JsEventHandler>& event_handler, @@ -955,6 +929,7 @@ bool SyncManager::SyncInternal::Init( model_safe_routing_info, workers, extensions_activity_monitor, + &throttled_data_type_tracker_, listeners, &debug_info_event_listener_, &traffic_recorder_)); @@ -1959,7 +1934,7 @@ void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncer( } } -SyncManager::Status SyncManager::SyncInternal::GetStatus() { +SyncStatus SyncManager::SyncInternal::GetStatus() { return allstatus_.status(); } @@ -2378,7 +2353,7 @@ void SyncManager::SyncInternal::RemoveObserver( observers_.RemoveObserver(observer); } -SyncManager::Status SyncManager::GetDetailedStatus() const { +SyncStatus SyncManager::GetDetailedStatus() const { return data_->GetStatus(); } diff --git a/sync/internal_api/sync_manager.h b/sync/internal_api/sync_manager.h index 80cda3f..04594fd 100644 --- a/sync/internal_api/sync_manager.h +++ b/sync/internal_api/sync_manager.h @@ -18,6 +18,7 @@ #include "sync/internal_api/change_record.h" #include "sync/internal_api/configure_reason.h" #include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/engine/sync_status.h" #include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/sync_protocol_error.h" #include "sync/util/report_unrecoverable_error_function.h" @@ -90,75 +91,6 @@ class SyncManager { // internal types from clients of the interface. class SyncInternal; - // Status encapsulates detailed state about the internals of the SyncManager. - struct Status { - Status(); - ~Status(); - - bool notifications_enabled; // True only if subscribed for notifications. - - // Notifications counters updated by the actions in synapi. - int notifications_received; - - browser_sync::SyncProtocolError sync_protocol_error; - - // Number of encryption conflicts counted during most recent sync cycle. - int encryption_conflicts; - - // Number of hierarchy conflicts counted during most recent sync cycle. - int hierarchy_conflicts; - - // Number of simple conflicts counted during most recent sync cycle. - int simple_conflicts; - - // Number of items the server refused to commit due to conflict during most - // recent sync cycle. - int server_conflicts; - - // Number of items successfully committed during most recent sync cycle. - int committed_count; - - bool syncing; - // True after a client has done a first sync. - bool initial_sync_ended; - - // Total updates available. If zero, nothing left to download. - int64 updates_available; - // Total updates received by the syncer since browser start. - int updates_received; - // Total updates received that are echoes of our own changes. - int reflected_updates_received; - // Of updates_received, how many were tombstones. - int tombstone_updates_received; - - // Total successful commits. - int num_commits_total; - - // Total number of overwrites due to conflict resolver since browser start. - int num_local_overwrites_total; - int num_server_overwrites_total; - - // Count of empty and non empty getupdates; - int nonempty_get_updates; - int empty_get_updates; - - // Count of sync cycles that successfully committed items; - int sync_cycles_with_commits; - int sync_cycles_without_commits; - - // Count of useless and useful syncs we perform. - int useless_sync_cycles; - int useful_sync_cycles; - - // Encryption related. - syncable::ModelTypeSet encrypted_types; - bool cryptographer_ready; - bool crypto_has_pending_keys; - - // The unique identifer for this client. - std::string unique_id; - }; - // An interface the embedding application implements to be notified // on change events. Note that these methods may be called on *any* // thread. @@ -528,7 +460,7 @@ class SyncManager { void RemoveObserver(Observer* observer); // Status-related getter. May be called on any thread. - Status GetDetailedStatus() const; + SyncStatus GetDetailedStatus() const; // Whether or not the Nigori node is encrypted using an explicit passphrase. // May be called on any thread. 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) { diff --git a/sync/sync.gyp b/sync/sync.gyp index da7dbba..73e103c 100644 --- a/sync/sync.gyp +++ b/sync/sync.gyp @@ -39,6 +39,8 @@ 'internal_api/public/engine/passive_model_worker.h', 'internal_api/public/engine/polling_constants.cc', 'internal_api/public/engine/polling_constants.h', + 'internal_api/public/engine/sync_status.cc', + 'internal_api/public/engine/sync_status.h', 'internal_api/public/sessions/error_counters.cc', 'internal_api/public/sessions/error_counters.h', 'internal_api/public/sessions/syncer_status.cc', @@ -53,6 +55,8 @@ 'internal_api/public/util/enum_set.h', 'internal_api/public/util/syncer_error.cc', 'internal_api/public/util/syncer_error.h', + 'engine/all_status.cc', + 'engine/all_status.h', 'engine/apply_updates_command.cc', 'engine/apply_updates_command.h', 'engine/build_commit_command.cc', @@ -87,20 +91,22 @@ 'engine/resolve_conflicts_command.h', 'engine/store_timestamps_command.cc', 'engine/store_timestamps_command.h', + 'engine/sync_engine_event.cc', + 'engine/sync_engine_event.h', + 'engine/sync_scheduler.cc', + 'engine/sync_scheduler.h', 'engine/syncer.cc', 'engine/syncer.h', 'engine/syncer_command.cc', 'engine/syncer_command.h', - 'engine/sync_engine_event.cc', - 'engine/sync_engine_event.h', 'engine/syncer_proto_util.cc', 'engine/syncer_proto_util.h', - 'engine/sync_scheduler.cc', - 'engine/sync_scheduler.h', 'engine/syncer_types.h', 'engine/syncer_util.cc', 'engine/syncer_util.h', 'engine/syncproto.h', + 'engine/throttled_data_type_tracker.cc', + 'engine/throttled_data_type_tracker.h', 'engine/traffic_logger.cc', 'engine/traffic_logger.h', 'engine/traffic_recorder.cc', @@ -268,8 +274,6 @@ 'sync', ], 'sources': [ - 'internal_api/all_status.cc', - 'internal_api/all_status.h', 'internal_api/base_node.cc', 'internal_api/base_node.h', 'internal_api/base_transaction.cc', @@ -371,25 +375,25 @@ 'sessions/test_util.h', 'syncable/syncable_mock.cc', 'syncable/syncable_mock.h', - 'test/fake_encryptor.cc', - 'test/fake_encryptor.h', - 'test/fake_extensions_activity_monitor.cc', - 'test/fake_extensions_activity_monitor.h', - 'test/null_directory_change_delegate.cc', - 'test/null_directory_change_delegate.h', - 'test/null_transaction_observer.cc', - 'test/null_transaction_observer.h', - 'test/engine/test_directory_setter_upper.cc', - 'test/engine/test_directory_setter_upper.h', 'test/engine/fake_model_worker.cc', 'test/engine/fake_model_worker.h', 'test/engine/mock_connection_manager.cc', 'test/engine/mock_connection_manager.h', 'test/engine/syncer_command_test.cc', 'test/engine/syncer_command_test.h', + 'test/engine/test_directory_setter_upper.cc', + 'test/engine/test_directory_setter_upper.h', 'test/engine/test_id_factory.h', 'test/engine/test_syncable_utils.cc', 'test/engine/test_syncable_utils.h', + 'test/fake_encryptor.cc', + 'test/fake_encryptor.h', + 'test/fake_extensions_activity_monitor.cc', + 'test/fake_extensions_activity_monitor.h', + 'test/null_directory_change_delegate.cc', + 'test/null_directory_change_delegate.h', + 'test/null_transaction_observer.cc', + 'test/null_transaction_observer.h', 'test/sessions/test_scoped_session_event_listener.h', 'test/test_directory_backing_store.cc', 'test/test_directory_backing_store.h', @@ -506,8 +510,8 @@ 'internal_api/public/util/enum_set_unittest.cc', 'engine/apply_updates_command_unittest.cc', 'engine/build_commit_command_unittest.cc', - 'engine/clear_data_command_unittest.cc', 'engine/cleanup_disabled_types_command_unittest.cc', + 'engine/clear_data_command_unittest.cc', 'engine/download_updates_command_unittest.cc', 'engine/model_changing_syncer_command_unittest.cc', 'engine/nigori_util_unittest.cc', @@ -515,10 +519,11 @@ 'engine/process_updates_command_unittest.cc', 'engine/resolve_conflicts_command_unittest.cc', 'engine/syncer_proto_util_unittest.cc', - 'engine/sync_scheduler_unittest.cc', - 'engine/sync_scheduler_whitebox_unittest.cc', 'engine/syncer_unittest.cc', 'engine/syncproto_unittest.cc', + 'engine/sync_scheduler_unittest.cc', + 'engine/sync_scheduler_whitebox_unittest.cc', + 'engine/throttled_data_type_tracker_unittest.cc', 'engine/traffic_recorder_unittest.cc', 'engine/verify_updates_command_unittest.cc', 'js/js_arg_list_unittest.cc', @@ -529,7 +534,6 @@ 'sessions/ordered_commit_set_unittest.cc', 'sessions/session_state_unittest.cc', 'sessions/status_controller_unittest.cc', - 'sessions/sync_session_context_unittest.cc', 'sessions/sync_session_unittest.cc', 'syncable/directory_backing_store_unittest.cc', 'syncable/model_type_unittest.cc', diff --git a/sync/test/engine/syncer_command_test.h b/sync/test/engine/syncer_command_test.h index 713e68c..0fc70b3 100644 --- a/sync/test/engine/syncer_command_test.h +++ b/sync/test/engine/syncer_command_test.h @@ -14,6 +14,7 @@ #include "base/memory/ref_counted.h" #include "base/message_loop.h" #include "sync/engine/model_changing_syncer_command.h" +#include "sync/engine/throttled_data_type_tracker.h" #include "sync/engine/traffic_recorder.h" #include "sync/internal_api/public/engine/model_safe_worker.h" #include "sync/sessions/debug_info_getter.h" @@ -121,9 +122,11 @@ class SyncerCommandTestBase : public testing::Test, } void ResetContext() { + throttled_data_type_tracker_.reset(new ThrottledDataTypeTracker(NULL)); context_.reset(new sessions::SyncSessionContext( mock_server_.get(), directory(), routing_info_, GetWorkers(), &extensions_activity_monitor_, + throttled_data_type_tracker_.get(), std::vector<SyncEngineEventListener*>(), &mock_debug_info_getter_, &traffic_recorder_)); @@ -199,6 +202,7 @@ class SyncerCommandTestBase : public testing::Test, ModelSafeRoutingInfo routing_info_; NiceMock<MockDebugInfoGetter> mock_debug_info_getter_; FakeExtensionsActivityMonitor extensions_activity_monitor_; + scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; TrafficRecorder traffic_recorder_; DISALLOW_COPY_AND_ASSIGN(SyncerCommandTestBase); }; |