diff options
author | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-24 19:32:28 +0000 |
---|---|---|
committer | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-24 19:32:28 +0000 |
commit | 90ce61b5448c93e52a34b71535d86605a4f7f90d (patch) | |
tree | 357c076b80e6bf248511878c8cde5b262466158f | |
parent | 7500c55e2fc2219e50e3b6b40e6c8e3ed3820d20 (diff) | |
download | chromium_src-90ce61b5448c93e52a34b71535d86605a4f7f90d.zip chromium_src-90ce61b5448c93e52a34b71535d86605a4f7f90d.tar.gz chromium_src-90ce61b5448c93e52a34b71535d86605a4f7f90d.tar.bz2 |
[Sync] Convert SyncSessionSnapshot to a copy-able class.
Previously it was an immutable struct that was passed around by making
dynamic allocations and passing pointers. We now just have a class with
only getters and no setters, but support for default copy and assign.
This cleans up some code and makes some future work easier to pass snapshots
around.
BUG=none
TEST=sync_unit_tests
Review URL: http://codereview.chromium.org/10197004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133747 0039d316-1c4b-4281-b951-d872f2087c98
38 files changed, 491 insertions, 441 deletions
diff --git a/chrome/browser/sync/backend_migrator.cc b/chrome/browser/sync/backend_migrator.cc index 3894bbd..e8eb407 100644 --- a/chrome/browser/sync/backend_migrator.cc +++ b/chrome/browser/sync/backend_migrator.cc @@ -20,7 +20,6 @@ using syncable::ModelTypeSet; namespace browser_sync { -using sessions::SyncSessionSnapshot; using syncable::ModelTypeToString; MigrationObserver::~MigrationObserver() {} diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc index 0d59793..42aed59 100644 --- a/chrome/browser/sync/glue/sync_backend_host.cc +++ b/chrome/browser/sync/glue/sync_backend_host.cc @@ -45,7 +45,6 @@ #include "sync/notifier/sync_notifier.h" #include "sync/protocol/encryption.pb.h" #include "sync/protocol/sync.pb.h" -#include "sync/sessions/session_state.h" #include "sync/util/nigori.h" static const int kSaveChangesIntervalSeconds = 10; @@ -81,7 +80,7 @@ class SyncBackendHost::Core // traffic controller here, forwarding incoming messages to appropriate // landing threads. virtual void OnSyncCycleCompleted( - const sessions::SyncSessionSnapshot* snapshot) OVERRIDE; + const sessions::SyncSessionSnapshot& snapshot) OVERRIDE; virtual void OnInitializationComplete( const WeakHandle<JsBackend>& js_backend, bool success) OVERRIDE; @@ -614,8 +613,8 @@ SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() { return core_->sync_manager()->GetDetailedStatus(); } -const SyncSessionSnapshot* SyncBackendHost::GetLastSessionSnapshot() const { - return last_snapshot_.get(); +SyncSessionSnapshot SyncBackendHost::GetLastSessionSnapshot() const { + return last_snapshot_; } bool SyncBackendHost::HasUnsyncedItems() const { @@ -657,17 +656,17 @@ void SyncBackendHost::InitCore(const DoInitializeOptions& options) { } void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop( - SyncSessionSnapshot* snapshot) { + const SyncSessionSnapshot& snapshot) { if (!frontend_) return; DCHECK_EQ(MessageLoop::current(), frontend_loop_); - last_snapshot_.reset(snapshot); + last_snapshot_ = snapshot; - SDVLOG(1) << "Got snapshot " << snapshot->ToString(); + SDVLOG(1) << "Got snapshot " << snapshot.ToString(); const syncable::ModelTypeSet to_migrate = - snapshot->syncer_status.types_needing_local_migration; + snapshot.syncer_status().types_needing_local_migration; if (!to_migrate.Empty()) frontend_->OnMigrationNeededForTypes(to_migrate); @@ -686,7 +685,7 @@ void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop( pending_download_state_->added_types; DCHECK(types_to_add.HasAll(added_types)); const syncable::ModelTypeSet initial_sync_ended = - snapshot->initial_sync_ended; + snapshot.initial_sync_ended(); const syncable::ModelTypeSet failed_configuration_types = Difference(added_types, initial_sync_ended); SDVLOG(1) @@ -698,7 +697,7 @@ void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop( << syncable::ModelTypeSetToString(failed_configuration_types); if (!failed_configuration_types.Empty() && - snapshot->retry_scheduled) { + snapshot.retry_scheduled()) { // Inform the caller that download failed but we are retrying. if (!pending_download_state_->retry_in_progress) { pending_download_state_->retry_callback.Run(); @@ -864,14 +863,14 @@ SyncBackendHost::PendingConfigureDataTypesState:: ~PendingConfigureDataTypesState() {} void SyncBackendHost::Core::OnSyncCycleCompleted( - const SyncSessionSnapshot* snapshot) { + const SyncSessionSnapshot& snapshot) { if (!sync_loop_) return; DCHECK_EQ(MessageLoop::current(), sync_loop_); host_.Call( FROM_HERE, &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop, - new SyncSessionSnapshot(*snapshot)); + snapshot); } diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h index 3073d6d..691586a 100644 --- a/chrome/browser/sync/glue/sync_backend_host.h +++ b/chrome/browser/sync/glue/sync_backend_host.h @@ -26,6 +26,7 @@ #include "sync/notifier/sync_notifier_factory.h" #include "sync/protocol/encryption.pb.h" #include "sync/protocol/sync_protocol_error.h" +#include "sync/sessions/session_state.h" #include "sync/syncable/model_type.h" #include "sync/util/report_unrecoverable_error_function.h" #include "sync/util/unrecoverable_error_handler.h" @@ -36,10 +37,6 @@ class Profile; namespace browser_sync { -namespace sessions { -struct SyncSessionSnapshot; -} - class ChangeProcessor; class JsBackend; class JsEventHandler; @@ -256,7 +253,7 @@ class SyncBackendHost : public BackendDataTypeConfigurer { // Called from any thread to obtain current status information in detailed or // summarized form. Status GetDetailedStatus(); - const sessions::SyncSessionSnapshot* GetLastSessionSnapshot() const; + sessions::SyncSessionSnapshot GetLastSessionSnapshot() const; // Determines if the underlying sync engine has made any local changes to // items that have not yet been synced with the server. @@ -328,7 +325,7 @@ class SyncBackendHost : public BackendDataTypeConfigurer { // Called from Core::OnSyncCycleCompleted to handle updating frontend // thread components. void HandleSyncCycleCompletedOnFrontendLoop( - sessions::SyncSessionSnapshot* snapshot); + const sessions::SyncSessionSnapshot& snapshot); // Called to finish the job of ConfigureDataTypes once the syncer is in // configuration mode. @@ -515,7 +512,7 @@ class SyncBackendHost : public BackendDataTypeConfigurer { sync_pb::EncryptedData cached_pending_keys_; // UI-thread cache of the last SyncSessionSnapshot received from syncapi. - scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; + sessions::SyncSessionSnapshot last_snapshot_; DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); }; diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 40910f0..5832936 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -1233,13 +1233,13 @@ sync_api::UserShare* ProfileSyncService::GetUserShare() const { return NULL; } -const browser_sync::sessions::SyncSessionSnapshot* +browser_sync::sessions::SyncSessionSnapshot ProfileSyncService::GetLastSessionSnapshot() const { if (backend_.get() && backend_initialized_) { return backend_->GetLastSessionSnapshot(); } NOTREACHED(); - return NULL; + return browser_sync::sessions::SyncSessionSnapshot(); } bool ProfileSyncService::HasUnsyncedItems() const { diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index 0abf55d..3a779ba 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -48,7 +48,7 @@ class ChangeProcessor; class DataTypeManager; class JsController; class SessionModelAssociator; -namespace sessions { struct SyncSessionSnapshot; } +namespace sessions { class SyncSessionSnapshot; } } namespace sync_api { @@ -360,7 +360,7 @@ class ProfileSyncService : public browser_sync::SyncFrontend, // ProfileSyncServiceHarness. Figure out a different way to expose // this info to that class, and remove these functions. - virtual const browser_sync::sessions::SyncSessionSnapshot* + virtual browser_sync::sessions::SyncSessionSnapshot GetLastSessionSnapshot() const; // Returns whether or not the underlying sync engine has made any diff --git a/chrome/browser/sync/profile_sync_service_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc index d7bdb1c..d4073b6 100644 --- a/chrome/browser/sync/profile_sync_service_harness.cc +++ b/chrome/browser/sync/profile_sync_service_harness.cc @@ -337,7 +337,7 @@ bool ProfileSyncServiceHarness::RunStateChangeMachine() { // TODO(rlarocque): Figure out a less brittle way of detecting this. if (IsTypeEncrypted(waiting_for_encryption_type_) && IsFullySynced() && - GetLastSessionSnapshot()->num_encryption_conflicts == 0) { + GetLastSessionSnapshot().num_encryption_conflicts() == 0) { // Encryption is now complete for the the type in which we were waiting. SignalStateCompleteWithNextState(FULLY_SYNCED); break; @@ -363,10 +363,8 @@ bool ProfileSyncServiceHarness::RunStateChangeMachine() { case WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION: { DVLOG(1) << GetClientInfoString( "WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION"); - const browser_sync::sessions::SyncSessionSnapshot *snap = - GetLastSessionSnapshot(); - CHECK(snap); - retry_verifier_.VerifyRetryInterval(*snap); + const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); + retry_verifier_.VerifyRetryInterval(snap); if (retry_verifier_.done()) { // Retry verifier is done verifying exponential backoff. SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); @@ -580,10 +578,8 @@ bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) { } bool ProfileSyncServiceHarness::AwaitExponentialBackoffVerification() { - const browser_sync::sessions::SyncSessionSnapshot *snap = - GetLastSessionSnapshot(); - CHECK(snap); - retry_verifier_.Initialize(*snap); + const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); + retry_verifier_.Initialize(snap); wait_state_ = WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION; AwaitStatusChangeWithTimeout(kExponentialBackoffVerificationTimeoutMs, "Verify Exponential backoff"); @@ -754,14 +750,13 @@ ProfileSyncService::Status ProfileSyncServiceHarness::GetStatus() { // We use this function to share code between IsFullySynced and IsDataSynced // while ensuring that all conditions are evaluated using on the same snapshot. bool ProfileSyncServiceHarness::IsDataSyncedImpl( - const browser_sync::sessions::SyncSessionSnapshot *snap) { - return snap && - snap->num_simple_conflicts == 0 && - ServiceIsPushingChanges() && - GetStatus().notifications_enabled && - !service()->HasUnsyncedItems() && - !snap->has_more_to_sync && - !HasPendingBackendMigration(); + const SyncSessionSnapshot& snap) { + return snap.num_simple_conflicts() == 0 && + ServiceIsPushingChanges() && + GetStatus().notifications_enabled && + !service()->HasUnsyncedItems() && + !snap.has_more_to_sync() && + !HasPendingBackendMigration(); } bool ProfileSyncServiceHarness::IsDataSynced() { @@ -770,7 +765,7 @@ bool ProfileSyncServiceHarness::IsDataSynced() { return false; } - const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); + const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); bool is_data_synced = IsDataSyncedImpl(snap); DVLOG(1) << GetClientInfoString( @@ -783,11 +778,11 @@ bool ProfileSyncServiceHarness::IsFullySynced() { DVLOG(1) << GetClientInfoString("IsFullySynced: false"); return false; } - const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); - // snap->unsynced_count == 0 is a fairly reliable indicator of whether or not + const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); + // snap.unsynced_count() == 0 is a fairly reliable indicator of whether or not // our timestamp is in sync with the server. bool is_fully_synced = IsDataSyncedImpl(snap) && - snap->unsynced_count == 0; + snap.unsynced_count() == 0; DVLOG(1) << GetClientInfoString( is_fully_synced ? "IsFullySynced: true" : "IsFullySynced: false"); @@ -856,13 +851,12 @@ bool ProfileSyncServiceHarness::MatchesOtherClient( return true; } -const SyncSessionSnapshot* - ProfileSyncServiceHarness::GetLastSessionSnapshot() const { +SyncSessionSnapshot ProfileSyncServiceHarness::GetLastSessionSnapshot() const { DCHECK(service_ != NULL) << "Sync service has not yet been set up."; if (service_->sync_initialized()) { return service_->GetLastSessionSnapshot(); } - return NULL; + return SyncSessionSnapshot(); } bool ProfileSyncServiceHarness::EnableSyncForDatatype( @@ -975,9 +969,8 @@ bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( syncable::ModelType model_type) { - const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); - DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; - return snap->download_progress_markers[model_type]; + const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); + return snap.download_progress_markers()[model_type]; } std::string ProfileSyncServiceHarness::GetClientInfoString( @@ -985,38 +978,34 @@ std::string ProfileSyncServiceHarness::GetClientInfoString( std::stringstream os; os << profile_debug_name_ << ": " << message << ": "; if (service()) { - const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); + const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); const ProfileSyncService::Status& status = GetStatus(); - if (snap) { - // Capture select info from the sync session snapshot and syncer status. - os << "has_more_to_sync: " - << snap->has_more_to_sync - << ", has_unsynced_items: " - << service()->HasUnsyncedItems() - << ", unsynced_count: " - << snap->unsynced_count - << ", encryption conflicts: " - << snap->num_encryption_conflicts - << ", hierarchy conflicts: " - << snap->num_hierarchy_conflicts - << ", simple conflicts: " - << snap->num_simple_conflicts - << ", server conflicts: " - << snap->num_server_conflicts - << ", num_updates_downloaded : " - << snap->syncer_status.num_updates_downloaded_total - << ", passphrase_required_reason: " - << sync_api::PassphraseRequiredReasonToString( - service()->passphrase_required_reason()) - << ", notifications_enabled: " - << status.notifications_enabled - << ", service_is_pushing_changes: " - << ServiceIsPushingChanges() - << ", has_pending_backend_migration: " - << HasPendingBackendMigration(); - } else { - os << "Sync session snapshot not available"; - } + // Capture select info from the sync session snapshot and syncer status. + os << "has_more_to_sync: " + << snap.has_more_to_sync() + << ", has_unsynced_items: " + << service()->HasUnsyncedItems() + << ", unsynced_count: " + << snap.unsynced_count() + << ", encryption conflicts: " + << snap.num_encryption_conflicts() + << ", hierarchy conflicts: " + << snap.num_hierarchy_conflicts() + << ", simple conflicts: " + << snap.num_simple_conflicts() + << ", server conflicts: " + << snap.num_server_conflicts() + << ", num_updates_downloaded : " + << snap.syncer_status().num_updates_downloaded_total + << ", passphrase_required_reason: " + << sync_api::PassphraseRequiredReasonToString( + service()->passphrase_required_reason()) + << ", notifications_enabled: " + << status.notifications_enabled + << ", service_is_pushing_changes: " + << ServiceIsPushingChanges() + << ", has_pending_backend_migration: " + << HasPendingBackendMigration(); } else { os << "Sync service not available"; } @@ -1052,7 +1041,7 @@ bool ProfileSyncServiceHarness::WaitForTypeEncryption( // TODO(rlarocque): Figure out a less brittle way of detecting this. if (IsTypeEncrypted(type) && IsFullySynced() && - GetLastSessionSnapshot()->num_encryption_conflicts == 0) { + GetLastSessionSnapshot().num_encryption_conflicts() == 0) { // Encryption is already complete for |type|; do not wait. return true; } @@ -1092,7 +1081,7 @@ bool ProfileSyncServiceHarness::IsTypePreferred(syncable::ModelType type) { } size_t ProfileSyncServiceHarness::GetNumEntries() const { - return GetLastSessionSnapshot()->num_entries; + return GetLastSessionSnapshot().num_entries(); } size_t ProfileSyncServiceHarness::GetNumDatatypes() const { diff --git a/chrome/browser/sync/profile_sync_service_harness.h b/chrome/browser/sync/profile_sync_service_harness.h index 48de1d4..7ae069c 100644 --- a/chrome/browser/sync/profile_sync_service_harness.h +++ b/chrome/browser/sync/profile_sync_service_harness.h @@ -20,9 +20,9 @@ class Profile; namespace browser_sync { - namespace sessions { - struct SyncSessionSnapshot; - } +namespace sessions { +class SyncSessionSnapshot; +} } // An instance of this class is basically our notion of a "sync client" for @@ -161,8 +161,7 @@ class ProfileSyncServiceHarness bool DisableSyncForAllDatatypes(); // Returns a snapshot of the current sync session. - const browser_sync::sessions::SyncSessionSnapshot* - GetLastSessionSnapshot() const; + browser_sync::sessions::SyncSessionSnapshot GetLastSessionSnapshot() const; // Encrypt the datatype |type|. This method will block while the sync backend // host performs the encryption or a timeout is reached. @@ -290,7 +289,8 @@ class ProfileSyncServiceHarness const std::string& reason); // A helper for implementing IsDataSynced() and IsFullySynced(). - bool IsDataSyncedImpl(const browser_sync::sessions::SyncSessionSnapshot*); + bool IsDataSyncedImpl( + const browser_sync::sessions::SyncSessionSnapshot& snapshot); // Returns true if the sync client has no unsynced items. bool IsDataSynced(); diff --git a/chrome/browser/sync/profile_sync_service_mock.h b/chrome/browser/sync/profile_sync_service_mock.h index bcad588..68e9700 100644 --- a/chrome/browser/sync/profile_sync_service_mock.h +++ b/chrome/browser/sync/profile_sync_service_mock.h @@ -74,7 +74,7 @@ class ProfileSyncServiceMock : public ProfileSyncService { MOCK_CONST_METHOD0(GetPreferredDataTypes, syncable::ModelTypeSet()); MOCK_CONST_METHOD0(GetRegisteredDataTypes, syncable::ModelTypeSet()); MOCK_CONST_METHOD0(GetLastSessionSnapshot, - const browser_sync::sessions::SyncSessionSnapshot*()); + browser_sync::sessions::SyncSessionSnapshot()); MOCK_METHOD0(QueryDetailedSyncStatus, browser_sync::SyncBackendHost::Status()); diff --git a/chrome/browser/sync/retry_verifier.cc b/chrome/browser/sync/retry_verifier.cc index 0fa3843..b7f395b 100644 --- a/chrome/browser/sync/retry_verifier.cc +++ b/chrome/browser/sync/retry_verifier.cc @@ -81,7 +81,7 @@ RetryVerifier::~RetryVerifier() { void RetryVerifier::Initialize( const browser_sync::sessions::SyncSessionSnapshot& snap) { retry_count_ = 0; - last_sync_time_ = snap.sync_start_time; + last_sync_time_ = snap.sync_start_time(); FillDelayTable(delay_table_, kMaxRetry); done_ = false; success_ = false; @@ -91,9 +91,9 @@ void RetryVerifier::VerifyRetryInterval( const browser_sync::sessions::SyncSessionSnapshot& snap) { DCHECK(retry_count_ < kMaxRetry); if (retry_count_ == 0) { - if (snap.sync_start_time != last_sync_time_) { + if (snap.sync_start_time() != last_sync_time_) { retry_count_++; - last_sync_time_ = snap.sync_start_time; + last_sync_time_ = snap.sync_start_time(); } success_ = true; return; @@ -101,10 +101,10 @@ void RetryVerifier::VerifyRetryInterval( // Check if the sync start time has changed. If so indicates a new sync // has taken place. - if (snap.sync_start_time != last_sync_time_) { - base::TimeDelta delta = snap.sync_start_time - last_sync_time_; + if (snap.sync_start_time() != last_sync_time_) { + base::TimeDelta delta = snap.sync_start_time() - last_sync_time_; success_ = IsRetryOnTime(delay_table_,retry_count_ -1, delta); - last_sync_time_ = snap.sync_start_time; + last_sync_time_ = snap.sync_start_time(); ++retry_count_; done_ = (retry_count_ >= kMaxRetry); return; diff --git a/chrome/browser/sync/retry_verifier.h b/chrome/browser/sync/retry_verifier.h index 755dab9..95023e2 100644 --- a/chrome/browser/sync/retry_verifier.h +++ b/chrome/browser/sync/retry_verifier.h @@ -9,12 +9,11 @@ #include "base/time.h" namespace browser_sync { + namespace sessions { -struct SyncSessionSnapshot; +class SyncSessionSnapshot; } // namespace sessions -} // namespace browser_sync -namespace browser_sync { // The minimum and maximum wait times for a retry. The actual retry would take // place somewhere in this range. The algorithm that calculates the retry wait // time uses rand functions. @@ -47,5 +46,7 @@ class RetryVerifier { bool done_; DISALLOW_COPY_AND_ASSIGN(RetryVerifier); }; + } // namespace browser_sync + #endif // CHROME_BROWSER_SYNC_RETRY_VERIFIER_H_ diff --git a/chrome/browser/sync/sync_ui_util.cc b/chrome/browser/sync/sync_ui_util.cc index a4ba0ae..9a8307a 100644 --- a/chrome/browser/sync/sync_ui_util.cc +++ b/chrome/browser/sync/sync_ui_util.cc @@ -520,7 +520,7 @@ void ConstructAboutInformation(ProfileSyncService* service, service->QueryDetailedSyncStatus()); // This is a cache of the last snapshot of type SYNC_CYCLE_ENDED where - // !snapshot->has_more_to_sync. In other words, it's the last in this + // !snapshot.has_more_to_sync(). In other words, it's the last in this // series of sync cycles. The series ends only when we've done all we can // to resolve conflicts and there is nothing left to commit, or an error // occurs. @@ -530,9 +530,10 @@ void ConstructAboutInformation(ProfileSyncService* service, // the values from a single sync cycle. // // |snapshot| could be NULL if sync is not yet initialized. - const browser_sync::sessions::SyncSessionSnapshot* snapshot = + const browser_sync::sessions::SyncSessionSnapshot& snapshot = service->sync_initialized() ? - service->GetLastSessionSnapshot() : NULL; + service->GetLastSessionSnapshot() : + browser_sync::sessions::SyncSessionSnapshot(); sync_ui_util::AddStringSyncDetails(sync_summary, "Summary", service->QuerySyncStatusSummary()); @@ -574,10 +575,8 @@ void ConstructAboutInformation(ProfileSyncService* service, // Network status indicators. ListValue* network = AddSyncDetailsSection(details, "Network"); - if (snapshot) { - sync_ui_util::AddBoolSyncDetail(network, "Throttled", - snapshot->is_silenced); - } + sync_ui_util::AddBoolSyncDetail(network, "Throttled", + snapshot.is_silenced()); sync_ui_util::AddBoolSyncDetail(network, "Notifications Enabled", full_status.notifications_enabled); @@ -608,22 +607,20 @@ void ConstructAboutInformation(ProfileSyncService* service, ListValue* cycles = AddSyncDetailsSection( details, "Status from Last Completed Session"); - if (snapshot) { - sync_ui_util::AddStringSyncDetails( - cycles, "Sync Source", - browser_sync::GetUpdatesSourceString( - snapshot->source.updates_source)); - sync_ui_util::AddStringSyncDetails( - cycles, "Download Updates", - GetSyncerErrorString(snapshot->errors.last_download_updates_result)); - sync_ui_util::AddStringSyncDetails( - cycles, "Post Commit", - GetSyncerErrorString(snapshot->errors.last_post_commit_result)); - sync_ui_util::AddStringSyncDetails( - cycles, "Process Commit Response", - GetSyncerErrorString( - snapshot->errors.last_process_commit_response_result)); - } + sync_ui_util::AddStringSyncDetails( + cycles, "Sync Source", + browser_sync::GetUpdatesSourceString( + snapshot.source().updates_source)); + sync_ui_util::AddStringSyncDetails( + cycles, "Download Updates", + GetSyncerErrorString(snapshot.errors().last_download_updates_result)); + sync_ui_util::AddStringSyncDetails( + cycles, "Post Commit", + GetSyncerErrorString(snapshot.errors().last_post_commit_result)); + sync_ui_util::AddStringSyncDetails( + cycles, "Process Commit Response", + GetSyncerErrorString( + snapshot.errors().last_process_commit_response_result)); // Strictly increasing counters. ListValue* counters = AddSyncDetailsSection(details, "Running Totals"); @@ -697,24 +694,20 @@ void ConstructAboutInformation(ProfileSyncService* service, ListValue* transient_session = AddSyncDetailsSection( details, "Transient Counters (last cycle of last completed session)"); - if (snapshot) { - sync_ui_util::AddIntSyncDetail( - transient_session, "Updates Downloaded", - snapshot->syncer_status.num_updates_downloaded_total); - sync_ui_util::AddIntSyncDetail( - transient_session, "Committed Count", - snapshot->syncer_status.num_successful_commits); - } - - if (snapshot) { - // This counter is stale. The warnings related to the snapshot still - // apply, see the comments near call to GetLastSessionSnapshot() above. - // Also, because this is updated only following a complete sync cycle, - // local changes affecting this count will not be displayed until the - // syncer has attempted to commit those changes. - sync_ui_util::AddIntSyncDetail(transient_session, "Entries", - snapshot->num_entries); - } + sync_ui_util::AddIntSyncDetail( + transient_session, "Updates Downloaded", + snapshot.syncer_status().num_updates_downloaded_total); + sync_ui_util::AddIntSyncDetail( + transient_session, "Committed Count", + snapshot.syncer_status().num_successful_commits); + + // This counter is stale. The warnings related to the snapshot still + // apply, see the comments near call to GetLastSessionSnapshot() above. + // Also, because this is updated only following a complete sync cycle, + // local changes affecting this count will not be displayed until the + // syncer has attempted to commit those changes. + sync_ui_util::AddIntSyncDetail(transient_session, "Entries", + snapshot.num_entries()); // Now set the actionable errors. if ((full_status.sync_protocol_error.error_type != diff --git a/chrome/browser/sync/test/integration/two_client_bookmarks_sync_test.cc b/chrome/browser/sync/test/integration/two_client_bookmarks_sync_test.cc index f1ea473..ba4ead5 100644 --- a/chrome/browser/sync/test/integration/two_client_bookmarks_sync_test.cc +++ b/chrome/browser/sync/test/integration/two_client_bookmarks_sync_test.cc @@ -1815,8 +1815,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, ASSERT_TRUE(IsEncrypted(0, syncable::BOOKMARKS)); ASSERT_TRUE(IsEncrypted(1, syncable::BOOKMARKS)); ASSERT_TRUE(GetClient(1)->service()->IsPassphraseRequired()); - ASSERT_GT(GetClient(1)->GetLastSessionSnapshot()-> - num_encryption_conflicts, 3); // The encrypted nodes. + ASSERT_GT(GetClient(1)->GetLastSessionSnapshot().num_encryption_conflicts(), + 3); // The encrypted nodes. // Client 1 adds bookmarks between the first two and between the second two. ASSERT_TRUE(AddURL(0, 1, IndexedURLTitle(3), GURL(IndexedURL(3))) != NULL); @@ -1830,15 +1830,15 @@ IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); ASSERT_TRUE(AwaitQuiescence()); EXPECT_TRUE(AllModelsMatch()); - ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> - num_encryption_conflicts); + ASSERT_EQ(0, + GetClient(1)->GetLastSessionSnapshot().num_encryption_conflicts()); // Ensure everything is syncing normally by appending a final bookmark. ASSERT_TRUE(AddURL(1, 5, IndexedURLTitle(5), GURL(IndexedURL(5))) != NULL); ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); EXPECT_TRUE(AllModelsMatch()); - ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> - num_encryption_conflicts); + ASSERT_EQ(0, + GetClient(1)->GetLastSessionSnapshot().num_encryption_conflicts()); } // Deliberately racy rearranging of bookmarks to test that our conflict resolver diff --git a/chrome/browser/sync/test_profile_sync_service.cc b/chrome/browser/sync/test_profile_sync_service.cc index 83e04c5..500a838 100644 --- a/chrome/browser/sync/test_profile_sync_service.cc +++ b/chrome/browser/sync/test_profile_sync_service.cc @@ -49,8 +49,8 @@ void SyncBackendHostForProfileSyncTest:: syncable::ModelTypeSet sync_ended; if (!fail_initial_download_) sync_ended = syncable::ModelTypeSet::All(); - std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; - HandleSyncCycleCompletedOnFrontendLoop(new SyncSessionSnapshot( + syncable::ModelTypePayloadMap download_progress_markers; + HandleSyncCycleCompletedOnFrontendLoop(SyncSessionSnapshot( SyncerStatus(), ErrorCounters(), 0, false, sync_ended, download_progress_markers, false, false, 0, 0, 0, 0, 0, false, SyncSourceInfo(), false, 0, base::Time::Now(), false)); @@ -92,8 +92,8 @@ void SyncBackendHostForProfileSyncTest::StartConfiguration( if (!fail_initial_download_) sync_ended.Put(syncable::NIGORI); - std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; - HandleSyncCycleCompletedOnFrontendLoop(new SyncSessionSnapshot( + syncable::ModelTypePayloadMap download_progress_markers; + HandleSyncCycleCompletedOnFrontendLoop(SyncSessionSnapshot( SyncerStatus(), ErrorCounters(), 0, false, sync_ended, download_progress_markers, false, false, 0, 0, 0, 0, 0, false, SyncSourceInfo(), false, 0, base::Time::Now(), false)); diff --git a/sync/engine/syncer_types.cc b/sync/engine/sync_engine_event.cc index 1899466..9ffb281 100644 --- a/sync/engine/syncer_types.cc +++ b/sync/engine/sync_engine_event.cc @@ -2,12 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "sync/engine/syncer_types.h" +#include "sync/engine/sync_engine_event.h" namespace browser_sync { -SyncEngineEvent::SyncEngineEvent(EventCause cause) : what_happened(cause), - snapshot(NULL) { +SyncEngineEvent::SyncEngineEvent(EventCause cause) : what_happened(cause) { } SyncEngineEvent::~SyncEngineEvent() {} diff --git a/sync/engine/sync_engine_event.h b/sync/engine/sync_engine_event.h new file mode 100644 index 0000000..54990d2 --- /dev/null +++ b/sync/engine/sync_engine_event.h @@ -0,0 +1,78 @@ +// 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_SYNC_ENGINE_EVENT_H_ +#define SYNC_ENGINE_SYNC_ENGINE_EVENT_H_ +#pragma once + +#include <string> + +#include "base/observer_list.h" +#include "sync/sessions/session_state.h" +#include "sync/syncable/model_type.h" + +namespace syncable { +class Id; +} + +namespace browser_sync { + +struct SyncEngineEvent { + enum EventCause { + //////////////////////////////////////////////////////////////// + // Sent on entry of Syncer state machine + SYNC_CYCLE_BEGIN, + + // SyncerCommand generated events. + STATUS_CHANGED, + + // We have reached the SYNCER_END state in the main sync loop. + SYNC_CYCLE_ENDED, + + //////////////////////////////////////////////////////////////// + // Generated in response to specific protocol actions or events. + + // New token in updated_token. + UPDATED_TOKEN, + + // This is sent after the Syncer (and SyncerThread) have initiated self + // halt due to no longer being permitted to communicate with the server. + // The listener should sever the sync / browser connections and delete sync + // data (i.e. as if the user clicked 'Stop Syncing' in the browser. + STOP_SYNCING_PERMANENTLY, + + // These events are sent to indicate when we know the clearing of + // server data have failed or succeeded. + CLEAR_SERVER_DATA_SUCCEEDED, + CLEAR_SERVER_DATA_FAILED, + + // This event is sent when we receive an actionable error. It is upto + // the listeners to figure out the action to take using the snapshot sent. + ACTIONABLE_ERROR, + }; + + explicit SyncEngineEvent(EventCause cause); + ~SyncEngineEvent(); + + EventCause what_happened; + + // The last session used for syncing. + sessions::SyncSessionSnapshot snapshot; + + // Update-Client-Auth returns a new token for sync use. + std::string updated_token; +}; + +class SyncEngineEventListener { + public: + // TODO(tim): Consider splitting this up to multiple callbacks, rather than + // have to do Event e(type); OnSyncEngineEvent(e); at all callsites, + virtual void OnSyncEngineEvent(const SyncEngineEvent& event) = 0; + protected: + virtual ~SyncEngineEventListener() {} +}; + +} // namespace browser_sync + +#endif // SYNC_ENGINE_SYNC_ENGINE_EVENT_H_ diff --git a/sync/engine/sync_scheduler.cc b/sync/engine/sync_scheduler.cc index 87304ea..8baee7c 100644 --- a/sync/engine/sync_scheduler.cc +++ b/sync/engine/sync_scheduler.cc @@ -270,8 +270,7 @@ void SyncScheduler::SendInitialSnapshot() { SyncSourceInfo(), ModelSafeRoutingInfo(), std::vector<ModelSafeWorker*>())); SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); - sessions::SyncSessionSnapshot snapshot(dummy->TakeSnapshot()); - event.snapshot = &snapshot; + event.snapshot = dummy->TakeSnapshot(); session_context_->NotifyListeners(event); } @@ -1168,19 +1167,18 @@ void SyncScheduler::OnActionableError( DCHECK_EQ(MessageLoop::current(), sync_loop_); SDVLOG(2) << "OnActionableError"; SyncEngineEvent event(SyncEngineEvent::ACTIONABLE_ERROR); - sessions::SyncSessionSnapshot snapshot(snap); - event.snapshot = &snapshot; + event.snapshot = snap; session_context_->NotifyListeners(event); } void SyncScheduler::OnSyncProtocolError( const sessions::SyncSessionSnapshot& snapshot) { DCHECK_EQ(MessageLoop::current(), sync_loop_); - if (ShouldRequestEarlyExit(snapshot.errors.sync_protocol_error)) { + if (ShouldRequestEarlyExit(snapshot.errors().sync_protocol_error)) { SDVLOG(2) << "Sync Scheduler requesting early exit."; syncer_->RequestEarlyExit(); // Thread-safe. } - if (IsActionableError(snapshot.errors.sync_protocol_error)) + if (IsActionableError(snapshot.errors().sync_protocol_error)) OnActionableError(snapshot); } diff --git a/sync/engine/sync_scheduler_unittest.cc b/sync/engine/sync_scheduler_unittest.cc index 45b148a..4488eb2 100644 --- a/sync/engine/sync_scheduler_unittest.cc +++ b/sync/engine/sync_scheduler_unittest.cc @@ -45,7 +45,7 @@ class MockSyncer : public Syncer { // Used when tests want to record syncing activity to examine later. struct SyncShareRecords { std::vector<TimeTicks> times; - std::vector<linked_ptr<SyncSessionSnapshot> > snapshots; + std::vector<SyncSessionSnapshot> snapshots; }; void QuitLoopNow() { @@ -130,7 +130,7 @@ class SyncSchedulerTest : public testing::Test { TimeTicks optimal_next_sync = optimal_start + poll_interval * i; EXPECT_GE(data[i], optimal_next_sync); EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, - records.snapshots[i]->source.updates_source); + records.snapshots[i].source().updates_source); } } @@ -220,8 +220,7 @@ class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { void RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record) { record->times.push_back(TimeTicks::Now()); - record->snapshots.push_back(make_linked_ptr(new SyncSessionSnapshot( - s->TakeSnapshot()))); + record->snapshots.push_back(s->TakeSnapshot()); } ACTION_P(RecordSyncShare, record) { @@ -265,9 +264,9 @@ TEST_F(SyncSchedulerTest, Nudge) { ASSERT_EQ(1U, records.snapshots.size()); EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, - records.snapshots[0]->source.types)); + records.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, - records.snapshots[0]->source.updates_source); + records.snapshots[0].source().updates_source); Mock::VerifyAndClearExpectations(syncer()); @@ -284,9 +283,9 @@ TEST_F(SyncSchedulerTest, Nudge) { ASSERT_EQ(1U, records2.snapshots.size()); EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, - records2.snapshots[0]->source.types)); + records2.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, - records2.snapshots[0]->source.updates_source); + records2.snapshots[0].source().updates_source); } // Make sure a regular config command is scheduled fine in the absence of any @@ -308,9 +307,9 @@ TEST_F(SyncSchedulerTest, Config) { ASSERT_EQ(1U, records.snapshots.size()); EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, - records.snapshots[0]->source.types)); + records.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, - records.snapshots[0]->source.updates_source); + records.snapshots[0].source().updates_source); } // Simulate a failure and make sure the config request is retried. @@ -340,9 +339,9 @@ TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { ASSERT_EQ(2U, records.snapshots.size()); EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, - records.snapshots[1]->source.types)); + records.snapshots[1].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, - records.snapshots[1]->source.updates_source); + records.snapshots[1].source().updates_source); } // Issue 2 config commands. Second one right after the first has failed @@ -382,9 +381,9 @@ TEST_F(SyncSchedulerTest, MultipleConfigWithBackingOff) { ASSERT_EQ(3U, records.snapshots.size()); EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types2, - records.snapshots[2]->source.types)); + records.snapshots[2].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, - records.snapshots[2]->source.updates_source); + records.snapshots[2].source().updates_source); } // Issue a nudge when the config has failed. Make sure both the config and @@ -430,14 +429,14 @@ TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { ASSERT_EQ(4U, records.snapshots.size()); EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, - records.snapshots[2]->source.types)); + records.snapshots[2].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, - records.snapshots[2]->source.updates_source); + records.snapshots[2].source().updates_source); EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, - records.snapshots[3]->source.types)); + records.snapshots[3].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, - records.snapshots[3]->source.updates_source); + records.snapshots[3].source().updates_source); } @@ -465,9 +464,9 @@ TEST_F(SyncSchedulerTest, NudgeCoalescing) { ASSERT_EQ(1U, r.snapshots.size()); EXPECT_GE(r.times[0], optimal_time); EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap( - Union(types1, types2), r.snapshots[0]->source.types)); + Union(types1, types2), r.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, - r.snapshots[0]->source.updates_source); + r.snapshots[0].source().updates_source); Mock::VerifyAndClearExpectations(syncer()); @@ -481,9 +480,9 @@ TEST_F(SyncSchedulerTest, NudgeCoalescing) { ASSERT_EQ(1U, r2.snapshots.size()); EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(types3, - r2.snapshots[0]->source.types)); + r2.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, - r2.snapshots[0]->source.updates_source); + r2.snapshots[0].source().updates_source); } // Test that nudges are coalesced. @@ -515,7 +514,7 @@ TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { // Make sure the sync has happened. ASSERT_EQ(1U, r.snapshots.size()); EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap( - Union(types1, types2), r.snapshots[0]->source.types)); + Union(types1, types2), r.snapshots[0].source().types)); // Make sure the sync happened at the right time. EXPECT_GE(r.times[0], min_time); @@ -540,9 +539,9 @@ TEST_F(SyncSchedulerTest, NudgeWithPayloads) { RunLoop(); ASSERT_EQ(1U, records.snapshots.size()); - EXPECT_EQ(model_types_with_payloads, records.snapshots[0]->source.types); + EXPECT_EQ(model_types_with_payloads, records.snapshots[0].source().types); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, - records.snapshots[0]->source.updates_source); + records.snapshots[0].source().updates_source); Mock::VerifyAndClearExpectations(syncer()); @@ -558,9 +557,9 @@ TEST_F(SyncSchedulerTest, NudgeWithPayloads) { RunLoop(); ASSERT_EQ(1U, records2.snapshots.size()); - EXPECT_EQ(model_types_with_payloads, records2.snapshots[0]->source.types); + EXPECT_EQ(model_types_with_payloads, records2.snapshots[0].source().types); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, - records2.snapshots[0]->source.updates_source); + records2.snapshots[0].source().updates_source); } // Test that nudges are coalesced. @@ -589,9 +588,9 @@ TEST_F(SyncSchedulerTest, NudgeWithPayloadsCoalescing) { syncable::ModelTypePayloadMap coalesced_types; syncable::CoalescePayloads(&coalesced_types, types1); syncable::CoalescePayloads(&coalesced_types, types2); - EXPECT_EQ(coalesced_types, r.snapshots[0]->source.types); + EXPECT_EQ(coalesced_types, r.snapshots[0].source().types); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, - r.snapshots[0]->source.updates_source); + r.snapshots[0].source().updates_source); Mock::VerifyAndClearExpectations(syncer()); @@ -604,9 +603,9 @@ TEST_F(SyncSchedulerTest, NudgeWithPayloadsCoalescing) { RunLoop(); ASSERT_EQ(1U, r2.snapshots.size()); - EXPECT_EQ(types3, r2.snapshots[0]->source.types); + EXPECT_EQ(types3, r2.snapshots[0].source().types); EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, - r2.snapshots[0]->source.updates_source); + r2.snapshots[0].source().updates_source); } // Test that polling works as expected. @@ -799,7 +798,7 @@ TEST_F(SyncSchedulerTest, ConfigurationMode) { ASSERT_EQ(1U, records.snapshots.size()); EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, - records.snapshots[0]->source.types)); + records.snapshots[0].source().types)); } // Have the sycner fail during commit. Expect that the scheduler enters @@ -866,7 +865,8 @@ TEST_F(SyncSchedulerTest, BackoffDropsJobs) { Mock::VerifyAndClearExpectations(syncer()); ASSERT_EQ(1U, r.snapshots.size()); - EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, r.snapshots[0]->source.updates_source); + EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, + r.snapshots[0].source().updates_source); EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), @@ -880,7 +880,8 @@ TEST_F(SyncSchedulerTest, BackoffDropsJobs) { Mock::VerifyAndClearExpectations(syncer()); Mock::VerifyAndClearExpectations(delay()); ASSERT_EQ(2U, r.snapshots.size()); - EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, r.snapshots[1]->source.updates_source); + EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, + r.snapshots[1].source().updates_source); EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0); EXPECT_CALL(*delay(), GetDelay(_)).Times(0); @@ -977,20 +978,20 @@ TEST_F(SyncSchedulerTest, BackoffRelief) { TimeTicks optimal_job_time = optimal_start; EXPECT_GE(r.times[0], optimal_job_time); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, - r.snapshots[0]->source.updates_source); + r.snapshots[0].source().updates_source); // It was followed by a successful retry nudge shortly afterward. optimal_job_time = optimal_job_time + backoff; EXPECT_GE(r.times[1], optimal_job_time); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, - r.snapshots[1]->source.updates_source); + r.snapshots[1].source().updates_source); // After that, we went back to polling. for (size_t i = 2; i < r.snapshots.size(); i++) { optimal_job_time = optimal_job_time + poll; SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); EXPECT_GE(r.times[i], optimal_job_time); EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, - r.snapshots[i]->source.updates_source); + r.snapshots[i].source().updates_source); } } diff --git a/sync/engine/syncer_command.cc b/sync/engine/syncer_command.cc index e2e5138..60e8deb 100644 --- a/sync/engine/syncer_command.cc +++ b/sync/engine/syncer_command.cc @@ -22,8 +22,7 @@ SyncerError SyncerCommand::Execute(SyncSession* session) { void SyncerCommand::SendNotifications(SyncSession* session) { if (session->mutable_status_controller()->TestAndClearIsDirty()) { SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); - const sessions::SyncSessionSnapshot& snapshot(session->TakeSnapshot()); - event.snapshot = &snapshot; + event.snapshot = session->TakeSnapshot(); session->context()->NotifyListeners(event); } } diff --git a/sync/engine/syncer_types.h b/sync/engine/syncer_types.h index c34621e..5639d98 100644 --- a/sync/engine/syncer_types.h +++ b/sync/engine/syncer_types.h @@ -6,26 +6,10 @@ #define SYNC_ENGINE_SYNCER_TYPES_H_ #pragma once -#include <map> -#include <string> -#include <vector> - -#include "base/observer_list.h" -#include "sync/syncable/model_type.h" - -namespace syncable { -class Id; -} - // The intent of this is to keep all shared data types and enums for the syncer // in a single place without having dependencies between other files. namespace browser_sync { -namespace sessions { -struct SyncSessionSnapshot; -} -class Syncer; - enum UpdateAttemptResponse { // Update was applied or safely ignored. SUCCESS, @@ -98,61 +82,6 @@ enum VerifyCommitResult { VERIFY_OK, }; -struct SyncEngineEvent { - enum EventCause { - //////////////////////////////////////////////////////////////// - // Sent on entry of Syncer state machine - SYNC_CYCLE_BEGIN, - - // SyncerCommand generated events. - STATUS_CHANGED, - - // We have reached the SYNCER_END state in the main sync loop. - SYNC_CYCLE_ENDED, - - //////////////////////////////////////////////////////////////// - // Generated in response to specific protocol actions or events. - - // New token in updated_token. - UPDATED_TOKEN, - - // This is sent after the Syncer (and SyncerThread) have initiated self - // halt due to no longer being permitted to communicate with the server. - // The listener should sever the sync / browser connections and delete sync - // data (i.e. as if the user clicked 'Stop Syncing' in the browser. - STOP_SYNCING_PERMANENTLY, - - // These events are sent to indicate when we know the clearing of - // server data have failed or succeeded. - CLEAR_SERVER_DATA_SUCCEEDED, - CLEAR_SERVER_DATA_FAILED, - - // This event is sent when we receive an actionable error. It is upto - // the listeners to figure out the action to take using the snapshot sent. - ACTIONABLE_ERROR, - }; - - explicit SyncEngineEvent(EventCause cause); - ~SyncEngineEvent(); - - EventCause what_happened; - - // The last session used for syncing. - const sessions::SyncSessionSnapshot* snapshot; - - // Update-Client-Auth returns a new token for sync use. - std::string updated_token; -}; - -class SyncEngineEventListener { - public: - // TODO(tim): Consider splitting this up to multiple callbacks, rather than - // have to do Event e(type); OnSyncEngineEvent(e); at all callsites, - virtual void OnSyncEngineEvent(const SyncEngineEvent& event) = 0; - protected: - virtual ~SyncEngineEventListener() {} -}; - } // namespace browser_sync #endif // SYNC_ENGINE_SYNCER_TYPES_H_ diff --git a/sync/internal_api/all_status.cc b/sync/internal_api/all_status.cc index 89fe414..3cbfb8f 100644 --- a/sync/internal_api/all_status.cc +++ b/sync/internal_api/all_status.cc @@ -44,13 +44,13 @@ sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { sync_api::SyncManager::Status AllStatus::CalcSyncing( const SyncEngineEvent &event) const { sync_api::SyncManager::Status status = CreateBlankStatus(); - const sessions::SyncSessionSnapshot* snapshot = event.snapshot; - status.unsynced_count = static_cast<int>(snapshot->unsynced_count); - status.encryption_conflicts = snapshot->num_encryption_conflicts; - status.hierarchy_conflicts = snapshot->num_hierarchy_conflicts; - status.simple_conflicts = snapshot->num_simple_conflicts; - status.server_conflicts = snapshot->num_server_conflicts; - status.committed_count = snapshot->syncer_status.num_successful_commits; + const sessions::SyncSessionSnapshot& snapshot = event.snapshot; + status.unsynced_count = static_cast<int>(snapshot.unsynced_count()); + status.encryption_conflicts = snapshot.num_encryption_conflicts(); + status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts(); + status.simple_conflicts = snapshot.num_simple_conflicts(); + status.server_conflicts = snapshot.num_server_conflicts(); + status.committed_count = snapshot.syncer_status().num_successful_commits; if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { status.syncing = true; @@ -58,37 +58,37 @@ sync_api::SyncManager::Status AllStatus::CalcSyncing( status.syncing = false; } - status.initial_sync_ended |= snapshot->is_share_usable; + status.initial_sync_ended |= snapshot.is_share_usable(); - status.updates_available += snapshot->num_server_changes_remaining; - status.sync_protocol_error = snapshot->errors.sync_protocol_error; + status.updates_available += snapshot.num_server_changes_remaining(); + status.sync_protocol_error = snapshot.errors().sync_protocol_error; // Accumulate update count only once per session to avoid double-counting. // TODO(ncarter): Make this realtime by having the syncer_status // counter preserve its value across sessions. http://crbug.com/26339 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { status.updates_received += - snapshot->syncer_status.num_updates_downloaded_total; + snapshot.syncer_status().num_updates_downloaded_total; status.tombstone_updates_received += - snapshot->syncer_status.num_tombstone_updates_downloaded_total; + snapshot.syncer_status().num_tombstone_updates_downloaded_total; status.reflected_updates_received += - snapshot->syncer_status.num_reflected_updates_downloaded_total; + snapshot.syncer_status().num_reflected_updates_downloaded_total; status.num_local_overwrites_total += - snapshot->syncer_status.num_local_overwrites; + snapshot.syncer_status().num_local_overwrites; status.num_server_overwrites_total += - snapshot->syncer_status.num_server_overwrites; - if (snapshot->syncer_status.num_updates_downloaded_total == 0) { + snapshot.syncer_status().num_server_overwrites; + if (snapshot.syncer_status().num_updates_downloaded_total == 0) { ++status.empty_get_updates; } else { ++status.nonempty_get_updates; } - if (snapshot->syncer_status.num_successful_commits == 0) { + if (snapshot.syncer_status().num_successful_commits == 0) { ++status.sync_cycles_without_commits; } else { ++status.sync_cycles_with_commits; } - if (snapshot->syncer_status.num_successful_commits == 0 && - snapshot->syncer_status.num_updates_downloaded_total == 0) { + if (snapshot.syncer_status().num_successful_commits == 0 && + snapshot.syncer_status().num_updates_downloaded_total == 0) { ++status.useless_sync_cycles; } else { ++status.useful_sync_cycles; @@ -112,7 +112,7 @@ void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { break; case SyncEngineEvent::ACTIONABLE_ERROR: status_ = CreateBlankStatus(); - status_.sync_protocol_error = event.snapshot->errors.sync_protocol_error; + status_.sync_protocol_error = event.snapshot.errors().sync_protocol_error; break; default: LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened; diff --git a/sync/internal_api/all_status.h b/sync/internal_api/all_status.h index d108727..9887533 100644 --- a/sync/internal_api/all_status.h +++ b/sync/internal_api/all_status.h @@ -15,6 +15,7 @@ #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" #include "sync/engine/syncer_types.h" +#include "sync/engine/sync_engine_event.h" #include "sync/internal_api/sync_manager.h" #include "sync/syncable/model_type.h" diff --git a/sync/internal_api/debug_info_event_listener.cc b/sync/internal_api/debug_info_event_listener.cc index 53fc9b1..6b3cd23 100644 --- a/sync/internal_api/debug_info_event_listener.cc +++ b/sync/internal_api/debug_info_event_listener.cc @@ -17,31 +17,28 @@ DebugInfoEventListener::~DebugInfoEventListener() { } void DebugInfoEventListener::OnSyncCycleCompleted( - const SyncSessionSnapshot* snapshot) { - if (!snapshot) - return; - + const SyncSessionSnapshot& snapshot) { sync_pb::DebugEventInfo event_info; sync_pb::SyncCycleCompletedEventInfo* sync_completed_event_info = event_info.mutable_sync_cycle_completed_event_info(); sync_completed_event_info->set_num_encryption_conflicts( - snapshot->num_encryption_conflicts); + snapshot.num_encryption_conflicts()); sync_completed_event_info->set_num_hierarchy_conflicts( - snapshot->num_hierarchy_conflicts); + snapshot.num_hierarchy_conflicts()); sync_completed_event_info->set_num_simple_conflicts( - snapshot->num_simple_conflicts); + snapshot.num_simple_conflicts()); sync_completed_event_info->set_num_server_conflicts( - snapshot->num_server_conflicts); + snapshot.num_server_conflicts()); sync_completed_event_info->set_num_updates_downloaded( - snapshot->syncer_status.num_updates_downloaded_total); + snapshot.syncer_status().num_updates_downloaded_total); sync_completed_event_info->set_num_reflected_updates_downloaded( - snapshot->syncer_status.num_reflected_updates_downloaded_total); + snapshot.syncer_status().num_reflected_updates_downloaded_total); sync_completed_event_info->mutable_caller_info()->set_source( - snapshot->source.updates_source); + snapshot.source().updates_source); sync_completed_event_info->mutable_caller_info()->set_notifications_enabled( - snapshot->notifications_enabled); + snapshot.notifications_enabled()); AddEventToQueue(event_info); } diff --git a/sync/internal_api/debug_info_event_listener.h b/sync/internal_api/debug_info_event_listener.h index 0169043..93cf1e1 100644 --- a/sync/internal_api/debug_info_event_listener.h +++ b/sync/internal_api/debug_info_event_listener.h @@ -30,7 +30,7 @@ class DebugInfoEventListener : public sync_api::SyncManager::Observer, // SyncManager::Observer implementation. virtual void OnSyncCycleCompleted( - const browser_sync::sessions::SyncSessionSnapshot* snapshot) OVERRIDE; + const browser_sync::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; virtual void OnInitializationComplete( const browser_sync::WeakHandle<browser_sync::JsBackend>& js_backend, bool success) OVERRIDE; diff --git a/sync/internal_api/js_sync_manager_observer.cc b/sync/internal_api/js_sync_manager_observer.cc index b9cf9f3..5aa9dc3 100644 --- a/sync/internal_api/js_sync_manager_observer.cc +++ b/sync/internal_api/js_sync_manager_observer.cc @@ -31,12 +31,12 @@ void JsSyncManagerObserver::SetJsEventHandler( } void JsSyncManagerObserver::OnSyncCycleCompleted( - const sessions::SyncSessionSnapshot* snapshot) { + const sessions::SyncSessionSnapshot& snapshot) { if (!event_handler_.IsInitialized()) { return; } DictionaryValue details; - details.Set("snapshot", snapshot->ToValue()); + details.Set("snapshot", snapshot.ToValue()); HandleJsEvent(FROM_HERE, "onSyncCycleCompleted", JsEventDetails(&details)); } diff --git a/sync/internal_api/js_sync_manager_observer.h b/sync/internal_api/js_sync_manager_observer.h index 025cfa1..02e2e5b 100644 --- a/sync/internal_api/js_sync_manager_observer.h +++ b/sync/internal_api/js_sync_manager_observer.h @@ -33,7 +33,7 @@ class JsSyncManagerObserver : public sync_api::SyncManager::Observer { // sync_api::SyncManager::Observer implementation. virtual void OnSyncCycleCompleted( - const sessions::SyncSessionSnapshot* snapshot) OVERRIDE; + const sessions::SyncSessionSnapshot& snapshot) OVERRIDE; virtual void OnConnectionStatusChange( sync_api::ConnectionStatus status) OVERRIDE; virtual void OnUpdatedToken(const std::string& token) OVERRIDE; diff --git a/sync/internal_api/js_sync_manager_observer_unittest.cc b/sync/internal_api/js_sync_manager_observer_unittest.cc index e2f63ab..a0e021a 100644 --- a/sync/internal_api/js_sync_manager_observer_unittest.cc +++ b/sync/internal_api/js_sync_manager_observer_unittest.cc @@ -72,7 +72,7 @@ TEST_F(JsSyncManagerObserverTest, NoArgNotifiations) { } TEST_F(JsSyncManagerObserverTest, OnSyncCycleCompleted) { - std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; + syncable::ModelTypePayloadMap download_progress_markers; sessions::SyncSessionSnapshot snapshot(sessions::SyncerStatus(), sessions::ErrorCounters(), 100, @@ -99,7 +99,7 @@ TEST_F(JsSyncManagerObserverTest, OnSyncCycleCompleted) { HandleJsEvent("onSyncCycleCompleted", HasDetailsAsDictionary(expected_details))); - js_sync_manager_observer_.OnSyncCycleCompleted(&snapshot); + js_sync_manager_observer_.OnSyncCycleCompleted(snapshot); PumpLoop(); } diff --git a/sync/internal_api/sync_manager.cc b/sync/internal_api/sync_manager.cc index ebe870e..d7d8c8a 100644 --- a/sync/internal_api/sync_manager.cc +++ b/sync/internal_api/sync_manager.cc @@ -2070,7 +2070,7 @@ void SyncManager::SyncInternal::OnSyncEngineEvent( OnPassphraseRequired(sync_api::REASON_DECRYPTION, pending_keys)); } else if (!cryptographer->is_ready() && - event.snapshot->initial_sync_ended.Has(syncable::NIGORI)) { + event.snapshot.initial_sync_ended().Has(syncable::NIGORI)) { DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " << "ready"; FOR_EACH_OBSERVER(SyncManager::Observer, observers_, @@ -2088,7 +2088,7 @@ void SyncManager::SyncInternal::OnSyncEngineEvent( return; } - if (!event.snapshot->has_more_to_sync) { + if (!event.snapshot.has_more_to_sync()) { // To account for a nigori node arriving with stale/bad data, we ensure // that the nigori node is up to date at the end of each cycle. WriteTransaction trans(FROM_HERE, GetUserShare()); @@ -2109,12 +2109,12 @@ void SyncManager::SyncInternal::OnSyncEngineEvent( // TODO(chron): Consider changing this back to track has_more_to_sync // only notify peers if a successful commit has occurred. bool is_notifiable_commit = - (event.snapshot->syncer_status.num_successful_commits > 0); + (event.snapshot.syncer_status().num_successful_commits > 0); if (is_notifiable_commit) { if (sync_notifier_.get()) { const ModelTypeSet changed_types = syncable::ModelTypePayloadMapToEnumSet( - event.snapshot->source.types); + event.snapshot.source().types); sync_notifier_->SendNotification(changed_types); } else { DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; @@ -2149,7 +2149,7 @@ void SyncManager::SyncInternal::OnSyncEngineEvent( if (event.what_happened == SyncEngineEvent::ACTIONABLE_ERROR) { FOR_EACH_OBSERVER(SyncManager::Observer, observers_, OnActionableError( - event.snapshot->errors.sync_protocol_error)); + event.snapshot.errors().sync_protocol_error)); return; } diff --git a/sync/internal_api/sync_manager.h b/sync/internal_api/sync_manager.h index d5f08a7..8288164 100644 --- a/sync/internal_api/sync_manager.h +++ b/sync/internal_api/sync_manager.h @@ -31,7 +31,7 @@ class JsEventHandler; class ModelSafeWorkerRegistrar; namespace sessions { -struct SyncSessionSnapshot; +class SyncSessionSnapshot; } // namespace sessions } // namespace browser_sync @@ -252,7 +252,7 @@ class SyncManager { // A round-trip sync-cycle took place and the syncer has resolved any // conflicts that may have arisen. virtual void OnSyncCycleCompleted( - const browser_sync::sessions::SyncSessionSnapshot* snapshot) = 0; + const browser_sync::sessions::SyncSessionSnapshot& snapshot) = 0; // Called when the status of the connection to the sync server has // changed. diff --git a/sync/internal_api/syncapi_unittest.cc b/sync/internal_api/syncapi_unittest.cc index a9e74ce..27bb115 100644 --- a/sync/internal_api/syncapi_unittest.cc +++ b/sync/internal_api/syncapi_unittest.cc @@ -676,7 +676,7 @@ class TestHttpPostProviderFactory : public HttpPostProviderFactory { class SyncManagerObserverMock : public SyncManager::Observer { public: MOCK_METHOD1(OnSyncCycleCompleted, - void(const SyncSessionSnapshot*)); // NOLINT + void(const SyncSessionSnapshot&)); // NOLINT MOCK_METHOD2(OnInitializationComplete, void(const WeakHandle<JsBackend>&, bool)); // NOLINT MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT diff --git a/sync/sessions/session_state.cc b/sync/sessions/session_state.cc index f49c41d..d0d23fa 100644 --- a/sync/sessions/session_state.cc +++ b/sync/sessions/session_state.cc @@ -75,38 +75,35 @@ DictionaryValue* SyncerStatus::ToValue() const { return value; } -DictionaryValue* DownloadProgressMarkersToValue( - const std::string - (&download_progress_markers)[syncable::MODEL_TYPE_COUNT]) { - DictionaryValue* value = new DictionaryValue(); - for (int i = syncable::FIRST_REAL_MODEL_TYPE; - i < syncable::MODEL_TYPE_COUNT; ++i) { - // TODO(akalin): Unpack the value into a protobuf. - std::string base64_marker; - bool encoded = - base::Base64Encode(download_progress_markers[i], &base64_marker); - DCHECK(encoded); - value->SetString( - syncable::ModelTypeToString(syncable::ModelTypeFromInt(i)), - base64_marker); - } - return value; -} - ErrorCounters::ErrorCounters() : last_download_updates_result(UNSET), last_post_commit_result(UNSET), last_process_commit_response_result(UNSET) { } +SyncSessionSnapshot::SyncSessionSnapshot() + : num_server_changes_remaining_(0), + is_share_usable_(false), + has_more_to_sync_(false), + is_silenced_(false), + unsynced_count_(0), + num_encryption_conflicts_(0), + num_hierarchy_conflicts_(0), + num_simple_conflicts_(0), + num_server_conflicts_(0), + did_commit_items_(false), + notifications_enabled_(false), + num_entries_(0), + retry_scheduled_(false) { +} + SyncSessionSnapshot::SyncSessionSnapshot( const SyncerStatus& syncer_status, const ErrorCounters& errors, int64 num_server_changes_remaining, bool is_share_usable, syncable::ModelTypeSet initial_sync_ended, - const std::string - (&download_progress_markers)[syncable::MODEL_TYPE_COUNT], + const syncable::ModelTypePayloadMap& download_progress_markers, bool more_to_sync, bool is_silenced, int64 unsynced_count, @@ -120,62 +117,57 @@ SyncSessionSnapshot::SyncSessionSnapshot( size_t num_entries, base::Time sync_start_time, bool retry_scheduled) - : syncer_status(syncer_status), - errors(errors), - num_server_changes_remaining(num_server_changes_remaining), - is_share_usable(is_share_usable), - initial_sync_ended(initial_sync_ended), - download_progress_markers(), - has_more_to_sync(more_to_sync), - is_silenced(is_silenced), - unsynced_count(unsynced_count), - num_encryption_conflicts(num_encryption_conflicts), - num_hierarchy_conflicts(num_hierarchy_conflicts), - num_simple_conflicts(num_simple_conflicts), - num_server_conflicts(num_server_conflicts), - did_commit_items(did_commit_items), - source(source), - notifications_enabled(notifications_enabled), - num_entries(num_entries), - sync_start_time(sync_start_time), - retry_scheduled(retry_scheduled) { - for (int i = syncable::FIRST_REAL_MODEL_TYPE; - i < syncable::MODEL_TYPE_COUNT; ++i) { - const_cast<std::string&>(this->download_progress_markers[i]).assign( - download_progress_markers[i]); - } + : syncer_status_(syncer_status), + errors_(errors), + num_server_changes_remaining_(num_server_changes_remaining), + is_share_usable_(is_share_usable), + initial_sync_ended_(initial_sync_ended), + download_progress_markers_(download_progress_markers), + has_more_to_sync_(more_to_sync), + is_silenced_(is_silenced), + unsynced_count_(unsynced_count), + num_encryption_conflicts_(num_encryption_conflicts), + num_hierarchy_conflicts_(num_hierarchy_conflicts), + num_simple_conflicts_(num_simple_conflicts), + num_server_conflicts_(num_server_conflicts), + did_commit_items_(did_commit_items), + source_(source), + notifications_enabled_(notifications_enabled), + num_entries_(num_entries), + sync_start_time_(sync_start_time), + retry_scheduled_(retry_scheduled) { } SyncSessionSnapshot::~SyncSessionSnapshot() {} DictionaryValue* SyncSessionSnapshot::ToValue() const { DictionaryValue* value = new DictionaryValue(); - value->Set("syncerStatus", syncer_status.ToValue()); + value->Set("syncerStatus", syncer_status_.ToValue()); // We don't care too much if we lose precision here. value->SetInteger("numServerChangesRemaining", - static_cast<int>(num_server_changes_remaining)); - value->SetBoolean("isShareUsable", is_share_usable); + static_cast<int>(num_server_changes_remaining_)); + value->SetBoolean("isShareUsable", is_share_usable_); value->Set("initialSyncEnded", - syncable::ModelTypeSetToValue(initial_sync_ended)); + syncable::ModelTypeSetToValue(initial_sync_ended_)); value->Set("downloadProgressMarkers", - DownloadProgressMarkersToValue(download_progress_markers)); - value->SetBoolean("hasMoreToSync", has_more_to_sync); - value->SetBoolean("isSilenced", is_silenced); + syncable::ModelTypePayloadMapToValue(download_progress_markers_)); + value->SetBoolean("hasMoreToSync", has_more_to_sync_); + value->SetBoolean("isSilenced", is_silenced_); // We don't care too much if we lose precision here, also. value->SetInteger("unsyncedCount", - static_cast<int>(unsynced_count)); + static_cast<int>(unsynced_count_)); value->SetInteger("numEncryptionConflicts", - num_encryption_conflicts); + num_encryption_conflicts_); value->SetInteger("numHierarchyConflicts", - num_hierarchy_conflicts); + num_hierarchy_conflicts_); value->SetInteger("numSimpleConflicts", - num_simple_conflicts); + num_simple_conflicts_); value->SetInteger("numServerConflicts", - num_server_conflicts); - value->SetBoolean("didCommitItems", did_commit_items); - value->SetInteger("numEntries", num_entries); - value->Set("source", source.ToValue()); - value->SetBoolean("notificationsEnabled", notifications_enabled); + num_server_conflicts_); + value->SetBoolean("didCommitItems", did_commit_items_); + value->SetInteger("numEntries", num_entries_); + value->Set("source", source_.ToValue()); + value->SetBoolean("notificationsEnabled", notifications_enabled_); return value; } @@ -188,6 +180,83 @@ std::string SyncSessionSnapshot::ToString() const { return json; } +SyncerStatus SyncSessionSnapshot::syncer_status() const { + return syncer_status_; +} + +ErrorCounters SyncSessionSnapshot::errors() const { + return errors_; +} + +int64 SyncSessionSnapshot::num_server_changes_remaining() const { + return num_server_changes_remaining_; +} + +bool SyncSessionSnapshot::is_share_usable() const { + return is_share_usable_; +} + +syncable::ModelTypeSet SyncSessionSnapshot::initial_sync_ended() const { + return initial_sync_ended_; +} + +syncable::ModelTypePayloadMap + SyncSessionSnapshot::download_progress_markers() const { + return download_progress_markers_; +} + +bool SyncSessionSnapshot::has_more_to_sync() const { + return has_more_to_sync_; +} + +bool SyncSessionSnapshot::is_silenced() const { + return is_silenced_; +} + +int64 SyncSessionSnapshot::unsynced_count() const { + return unsynced_count_; +} + +int SyncSessionSnapshot::num_encryption_conflicts() const { + return num_encryption_conflicts_; +} + +int SyncSessionSnapshot::num_hierarchy_conflicts() const { + return num_hierarchy_conflicts_; +} + +int SyncSessionSnapshot::num_simple_conflicts() const { + return num_simple_conflicts_; +} + +int SyncSessionSnapshot::num_server_conflicts() const { + return num_server_conflicts_; +} + +bool SyncSessionSnapshot::did_commit_items() const { + return did_commit_items_; +} + +SyncSourceInfo SyncSessionSnapshot::source() const { + return source_; +} + +bool SyncSessionSnapshot::notifications_enabled() const { + return notifications_enabled_; +} + +size_t SyncSessionSnapshot::num_entries() const { + return num_entries_; +} + +base::Time SyncSessionSnapshot::sync_start_time() const { + return sync_start_time_; +} + +bool SyncSessionSnapshot::retry_scheduled() const { + return retry_scheduled_; +} + ConflictProgress::ConflictProgress(bool* dirty_flag) : num_server_conflicting_items(0), num_hierarchy_conflicting_items(0), num_encryption_conflicting_items(0), dirty_(dirty_flag) { diff --git a/sync/sessions/session_state.h b/sync/sessions/session_state.h index 7403758..3f37cd0 100644 --- a/sync/sessions/session_state.h +++ b/sync/sessions/session_state.h @@ -97,22 +97,21 @@ struct ErrorCounters { SyncerError last_process_commit_response_result; }; -// Caller takes ownership of the returned dictionary. -base::DictionaryValue* DownloadProgressMarkersToValue( - const std::string - (&download_progress_markers)[syncable::MODEL_TYPE_COUNT]); - // An immutable snapshot of state from a SyncSession. Convenient to use as // part of notifications as it is inherently thread-safe. -struct SyncSessionSnapshot { +// TODO(zea): if copying this all over the place starts getting expensive, +// consider passing around immutable references instead of values. +// Default copy and assign welcome. +class SyncSessionSnapshot { + public: + SyncSessionSnapshot(); SyncSessionSnapshot( const SyncerStatus& syncer_status, const ErrorCounters& errors, int64 num_server_changes_remaining, bool is_share_usable, syncable::ModelTypeSet initial_sync_ended, - const std::string - (&download_progress_markers)[syncable::MODEL_TYPE_COUNT], + const syncable::ModelTypePayloadMap& download_progress_markers, bool more_to_sync, bool is_silenced, int64 unsynced_count, @@ -133,25 +132,46 @@ struct SyncSessionSnapshot { std::string ToString() const; - const SyncerStatus syncer_status; - const ErrorCounters errors; - const int64 num_server_changes_remaining; - const bool is_share_usable; - const syncable::ModelTypeSet initial_sync_ended; - const std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; - const bool has_more_to_sync; - const bool is_silenced; - const int64 unsynced_count; - const int num_encryption_conflicts; - const int num_hierarchy_conflicts; - const int num_simple_conflicts; - const int num_server_conflicts; - const bool did_commit_items; - const SyncSourceInfo source; - const bool notifications_enabled; - const size_t num_entries; - base::Time sync_start_time; - const bool retry_scheduled; + SyncerStatus syncer_status() const; + ErrorCounters errors() const; + int64 num_server_changes_remaining() const; + bool is_share_usable() const; + syncable::ModelTypeSet initial_sync_ended() const; + syncable::ModelTypePayloadMap download_progress_markers() const; + bool has_more_to_sync() const; + bool is_silenced() const; + int64 unsynced_count() const; + int num_encryption_conflicts() const; + int num_hierarchy_conflicts() const; + int num_simple_conflicts() const; + int num_server_conflicts() const; + bool did_commit_items() const; + SyncSourceInfo source() const; + bool notifications_enabled() const; + size_t num_entries() const; + base::Time sync_start_time() const; + bool retry_scheduled() const; + + private: + SyncerStatus syncer_status_; + ErrorCounters errors_; + int64 num_server_changes_remaining_; + bool is_share_usable_; + syncable::ModelTypeSet initial_sync_ended_; + syncable::ModelTypePayloadMap download_progress_markers_; + bool has_more_to_sync_; + bool is_silenced_; + int64 unsynced_count_; + int num_encryption_conflicts_; + int num_hierarchy_conflicts_; + int num_simple_conflicts_; + int num_server_conflicts_; + bool did_commit_items_; + SyncSourceInfo source_; + bool notifications_enabled_; + size_t num_entries_; + base::Time sync_start_time_; + bool retry_scheduled_; }; // Tracks progress of conflicts and their resolutions. diff --git a/sync/sessions/session_state_unittest.cc b/sync/sessions/session_state_unittest.cc index a37dc17..011f832 100644 --- a/sync/sessions/session_state_unittest.cc +++ b/sync/sessions/session_state_unittest.cc @@ -72,29 +72,6 @@ TEST_F(SessionStateTest, SyncerStatusToValue) { *value, "numServerOverwrites"); } -TEST_F(SessionStateTest, DownloadProgressMarkersToValue) { - std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; - for (int i = syncable::FIRST_REAL_MODEL_TYPE; - i < syncable::MODEL_TYPE_COUNT; ++i) { - std::string marker(i, i); - download_progress_markers[i] = marker; - } - - scoped_ptr<DictionaryValue> value( - DownloadProgressMarkersToValue(download_progress_markers)); - EXPECT_EQ(syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE, - static_cast<int>(value->size())); - for (int i = syncable::FIRST_REAL_MODEL_TYPE; - i < syncable::MODEL_TYPE_COUNT; ++i) { - syncable::ModelType model_type = syncable::ModelTypeFromInt(i); - std::string marker(i, i); - std::string expected_value; - EXPECT_TRUE(base::Base64Encode(marker, &expected_value)); - ExpectDictStringValue(expected_value, - *value, syncable::ModelTypeToString(model_type)); - } -} - TEST_F(SessionStateTest, SyncSessionSnapshotToValue) { SyncerStatus syncer_status; syncer_status.num_successful_commits = 500; @@ -111,11 +88,11 @@ TEST_F(SessionStateTest, SyncSessionSnapshotToValue) { scoped_ptr<ListValue> expected_initial_sync_ended_value( syncable::ModelTypeSetToValue(initial_sync_ended)); - std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; + syncable::ModelTypePayloadMap download_progress_markers; download_progress_markers[syncable::BOOKMARKS] = "test"; download_progress_markers[syncable::APPS] = "apps"; scoped_ptr<DictionaryValue> expected_download_progress_markers_value( - DownloadProgressMarkersToValue(download_progress_markers)); + syncable::ModelTypePayloadMapToValue(download_progress_markers)); const bool kHasMoreToSync = false; const bool kIsSilenced = true; diff --git a/sync/sessions/sync_session.cc b/sync/sessions/sync_session.cc index 0d5835e..4c58215 100644 --- a/sync/sessions/sync_session.cc +++ b/sync/sessions/sync_session.cc @@ -137,7 +137,7 @@ SyncSessionSnapshot SyncSession::TakeSnapshot() const { bool is_share_useable = true; syncable::ModelTypeSet initial_sync_ended; - std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; + syncable::ModelTypePayloadMap download_progress_markers; for (int i = syncable::FIRST_REAL_MODEL_TYPE; i < syncable::MODEL_TYPE_COUNT; ++i) { syncable::ModelType type(syncable::ModelTypeFromInt(i)); @@ -147,7 +147,7 @@ SyncSessionSnapshot SyncSession::TakeSnapshot() const { else is_share_useable = false; } - dir->GetDownloadProgressAsString(type, &download_progress_markers[i]); + dir->GetDownloadProgressAsString(type, &download_progress_markers[type]); } return SyncSessionSnapshot( @@ -174,10 +174,9 @@ SyncSessionSnapshot SyncSession::TakeSnapshot() const { void SyncSession::SendEventNotification(SyncEngineEvent::EventCause cause) { SyncEngineEvent event(cause); - const SyncSessionSnapshot& snapshot = TakeSnapshot(); - event.snapshot = &snapshot; + event.snapshot = TakeSnapshot(); - DVLOG(1) << "Sending event with snapshot: " << snapshot.ToString(); + DVLOG(1) << "Sending event with snapshot: " << event.snapshot.ToString(); context()->NotifyListeners(event); } diff --git a/sync/sessions/sync_session_context.cc b/sync/sessions/sync_session_context.cc index 2ebe655..dbbaaf91 100644 --- a/sync/sessions/sync_session_context.cc +++ b/sync/sessions/sync_session_context.cc @@ -5,7 +5,6 @@ #include "sync/sessions/sync_session_context.h" #include "sync/sessions/debug_info_getter.h" -#include "sync/sessions/session_state.h" #include "sync/util/extensions_activity_monitor.h" namespace browser_sync { diff --git a/sync/sessions/sync_session_context.h b/sync/sessions/sync_session_context.h index 5c21726..117afc4 100644 --- a/sync/sessions/sync_session_context.h +++ b/sync/sessions/sync_session_context.h @@ -27,6 +27,7 @@ #include "base/time.h" #include "sync/engine/model_safe_worker.h" #include "sync/engine/syncer_types.h" +#include "sync/engine/sync_engine_event.h" #include "sync/engine/traffic_recorder.h" #include "sync/sessions/debug_info_getter.h" @@ -46,7 +47,6 @@ static const int kDefaultMaxCommitBatchSize = 25; namespace sessions { class ScopedSessionContextConflictResolver; -struct SyncSessionSnapshot; class TestScopedSessionEventListener; class SyncSessionContext { @@ -172,9 +172,6 @@ class SyncSessionContext { // by the user. ModelSafeRoutingInfo previous_session_routing_info_; - // Cache of last session snapshot information. - scoped_ptr<sessions::SyncSessionSnapshot> previous_session_snapshot_; - // We use this to get debug info to send to the server for debugging // client behavior on server side. DebugInfoGetter* const debug_info_getter_; diff --git a/sync/sync.gyp b/sync/sync.gyp index 29f8173..81c05f9 100644 --- a/sync/sync.gyp +++ b/sync/sync.gyp @@ -77,11 +77,12 @@ '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.cc', 'engine/syncer_types.h', 'engine/syncer_util.cc', 'engine/syncer_util.h', diff --git a/sync/syncable/model_type_payload_map.cc b/sync/syncable/model_type_payload_map.cc index 99502b0..1485cec 100644 --- a/sync/syncable/model_type_payload_map.cc +++ b/sync/syncable/model_type_payload_map.cc @@ -6,6 +6,7 @@ #include <vector> +#include "base/base64.h" #include "base/json/json_writer.h" #include "base/memory/scoped_ptr.h" #include "base/values.h" @@ -59,7 +60,11 @@ DictionaryValue* ModelTypePayloadMapToValue( DictionaryValue* value = new DictionaryValue(); for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); it != type_payloads.end(); ++it) { - value->SetString(syncable::ModelTypeToString(it->first), it->second); + // TODO(akalin): Unpack the value into a protobuf. + std::string base64_marker; + bool encoded = base::Base64Encode(it->second, &base64_marker); + DCHECK(encoded); + value->SetString(syncable::ModelTypeToString(it->first), base64_marker); } return value; } diff --git a/sync/syncable/model_type_payload_map_unittest.cc b/sync/syncable/model_type_payload_map_unittest.cc index 27e36a1..212c2b7 100644 --- a/sync/syncable/model_type_payload_map_unittest.cc +++ b/sync/syncable/model_type_payload_map_unittest.cc @@ -6,6 +6,7 @@ #include <string> +#include "base/base64.h" #include "base/memory/scoped_ptr.h" #include "base/test/values_test_util.h" #include "base/values.h" @@ -29,12 +30,14 @@ TEST_F(ModelTypePayloadMapTest, TypePayloadMapToSet) { TEST_F(ModelTypePayloadMapTest, TypePayloadMapToValue) { ModelTypePayloadMap payloads; + std::string encoded; payloads[BOOKMARKS] = "bookmarkpayload"; + base::Base64Encode(payloads[BOOKMARKS], &encoded); payloads[APPS] = ""; scoped_ptr<DictionaryValue> value(ModelTypePayloadMapToValue(payloads)); EXPECT_EQ(2u, value->size()); - ExpectDictStringValue("bookmarkpayload", *value, "Bookmarks"); + ExpectDictStringValue(encoded, *value, "Bookmarks"); ExpectDictStringValue("", *value, "Apps"); EXPECT_FALSE(value->HasKey("Preferences")); } |