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 /sync | |
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
Diffstat (limited to 'sync')
25 files changed, 362 insertions, 290 deletions
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")); } |