diff options
Diffstat (limited to 'sync/sessions')
-rw-r--r-- | sync/sessions/error_counters.cc | 17 | ||||
-rw-r--r-- | sync/sessions/error_counters.h | 33 | ||||
-rw-r--r-- | sync/sessions/session_state.cc | 224 | ||||
-rw-r--r-- | sync/sessions/session_state.h | 145 | ||||
-rw-r--r-- | sync/sessions/session_state_unittest.cc | 4 | ||||
-rw-r--r-- | sync/sessions/sync_session.h | 1 | ||||
-rw-r--r-- | sync/sessions/sync_session_snapshot.cc | 173 | ||||
-rw-r--r-- | sync/sessions/sync_session_snapshot.h | 101 | ||||
-rw-r--r-- | sync/sessions/sync_source_info.cc | 36 | ||||
-rw-r--r-- | sync/sessions/sync_source_info.h | 42 | ||||
-rw-r--r-- | sync/sessions/syncer_status.cc | 44 | ||||
-rw-r--r-- | sync/sessions/syncer_status.h | 50 |
12 files changed, 504 insertions, 366 deletions
diff --git a/sync/sessions/error_counters.cc b/sync/sessions/error_counters.cc new file mode 100644 index 0000000..c227b82 --- /dev/null +++ b/sync/sessions/error_counters.cc @@ -0,0 +1,17 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/sessions/error_counters.h" + +namespace browser_sync { +namespace sessions { + +ErrorCounters::ErrorCounters() + : last_download_updates_result(UNSET), + last_post_commit_result(UNSET), + last_process_commit_response_result(UNSET) { +} + +} // namespace sessions +} // namespace browser_sync diff --git a/sync/sessions/error_counters.h b/sync/sessions/error_counters.h new file mode 100644 index 0000000..c2f532f --- /dev/null +++ b/sync/sessions/error_counters.h @@ -0,0 +1,33 @@ +// 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_SESSIONS_ERROR_COUNTERS_H_ +#define SYNC_SESSIONS_ERROR_COUNTERS_H_ +#pragma once + +#include "base/basictypes.h" +#include "sync/protocol/sync_protocol_error.h" +#include "sync/util/syncer_error.h" + +namespace browser_sync { +namespace sessions { + +// Counters for various errors that can occur repeatedly during a sync session. +// TODO(lipalani) : Rename this structure to Error. +struct ErrorCounters { + ErrorCounters(); + + // Any protocol errors that we received during this sync session. + SyncProtocolError sync_protocol_error; + + // Records the most recent results of PostCommit and GetUpdates commands. + SyncerError last_download_updates_result; + SyncerError last_post_commit_result; + SyncerError last_process_commit_response_result; +}; + +} // namespace sessions +} // namespace browser_sync + +#endif // SYNC_SESSIONS_ERROR_COUNTERS_H_ diff --git a/sync/sessions/session_state.cc b/sync/sessions/session_state.cc index ba9931f..1eaf2d0 100644 --- a/sync/sessions/session_state.cc +++ b/sync/sessions/session_state.cc @@ -4,17 +4,11 @@ #include "sync/sessions/session_state.h" -#include <map> #include <set> -#include <string> -#include <utility> #include <vector> -#include "base/base64.h" -#include "base/json/json_writer.h" #include "base/memory/scoped_ptr.h" #include "base/values.h" -#include "sync/protocol/proto_enum_conversions.h" using std::set; using std::vector; @@ -22,224 +16,6 @@ using std::vector; namespace browser_sync { namespace sessions { -SyncSourceInfo::SyncSourceInfo() - : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN) {} - -SyncSourceInfo::SyncSourceInfo( - const syncable::ModelTypePayloadMap& t) - : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN), types(t) {} - -SyncSourceInfo::SyncSourceInfo( - const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, - const syncable::ModelTypePayloadMap& t) - : updates_source(u), types(t) {} - -SyncSourceInfo::~SyncSourceInfo() {} - -DictionaryValue* SyncSourceInfo::ToValue() const { - DictionaryValue* value = new DictionaryValue(); - value->SetString("updatesSource", - GetUpdatesSourceString(updates_source)); - value->Set("types", syncable::ModelTypePayloadMapToValue(types)); - return value; -} - -SyncerStatus::SyncerStatus() - : invalid_store(false), - num_successful_commits(0), - num_successful_bookmark_commits(0), - num_updates_downloaded_total(0), - num_tombstone_updates_downloaded_total(0), - num_reflected_updates_downloaded_total(0), - num_local_overwrites(0), - num_server_overwrites(0) { -} - -SyncerStatus::~SyncerStatus() { -} - -DictionaryValue* SyncerStatus::ToValue() const { - DictionaryValue* value = new DictionaryValue(); - value->SetBoolean("invalidStore", invalid_store); - value->SetInteger("numSuccessfulCommits", num_successful_commits); - value->SetInteger("numSuccessfulBookmarkCommits", - num_successful_bookmark_commits); - value->SetInteger("numUpdatesDownloadedTotal", - num_updates_downloaded_total); - value->SetInteger("numTombstoneUpdatesDownloadedTotal", - num_tombstone_updates_downloaded_total); - value->SetInteger("numReflectedUpdatesDownloadedTotal", - num_reflected_updates_downloaded_total); - value->SetInteger("numLocalOverwrites", num_local_overwrites); - value->SetInteger("numServerOverwrites", num_server_overwrites); - 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), - num_encryption_conflicts_(0), - num_hierarchy_conflicts_(0), - num_simple_conflicts_(0), - num_server_conflicts_(0), - 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 syncable::ModelTypePayloadMap& download_progress_markers, - bool more_to_sync, - bool is_silenced, - int num_encryption_conflicts, - int num_hierarchy_conflicts, - int num_simple_conflicts, - int num_server_conflicts, - const SyncSourceInfo& source, - bool notifications_enabled, - 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_(download_progress_markers), - has_more_to_sync_(more_to_sync), - is_silenced_(is_silenced), - num_encryption_conflicts_(num_encryption_conflicts), - num_hierarchy_conflicts_(num_hierarchy_conflicts), - num_simple_conflicts_(num_simple_conflicts), - num_server_conflicts_(num_server_conflicts), - 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()); - // 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_); - value->Set("initialSyncEnded", - syncable::ModelTypeSetToValue(initial_sync_ended_)); - value->Set("downloadProgressMarkers", - 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("numEncryptionConflicts", - num_encryption_conflicts_); - value->SetInteger("numHierarchyConflicts", - num_hierarchy_conflicts_); - value->SetInteger("numSimpleConflicts", - num_simple_conflicts_); - value->SetInteger("numServerConflicts", - num_server_conflicts_); - value->SetInteger("numEntries", num_entries_); - value->Set("source", source_.ToValue()); - value->SetBoolean("notificationsEnabled", notifications_enabled_); - return value; -} - -std::string SyncSessionSnapshot::ToString() const { - scoped_ptr<DictionaryValue> value(ToValue()); - std::string json; - base::JSONWriter::WriteWithOptions(value.get(), - base::JSONWriter::OPTIONS_PRETTY_PRINT, - &json); - 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_; -} - -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_; -} - -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 c2a3edc..2bd6fe5 100644 --- a/sync/sessions/session_state.h +++ b/sync/sessions/session_state.h @@ -13,161 +13,22 @@ #define SYNC_SESSIONS_SESSION_STATE_H_ #pragma once -#include <map> #include <set> -#include <string> -#include <utility> #include <vector> #include "base/basictypes.h" #include "sync/engine/syncer_types.h" #include "sync/engine/syncproto.h" -#include "sync/protocol/sync_protocol_error.h" +#include "sync/sessions/error_counters.h" +#include "sync/sessions/syncer_status.h" #include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" -#include "sync/syncable/syncable.h" - -namespace base { -class DictionaryValue; -} +#include "sync/syncable/syncable_id.h" namespace browser_sync { namespace sessions { class UpdateProgress; -// A container for the source of a sync session. This includes the update -// source, the datatypes triggering the sync session, and possible session -// specific payloads which should be sent to the server. -struct SyncSourceInfo { - SyncSourceInfo(); - explicit SyncSourceInfo(const syncable::ModelTypePayloadMap& t); - SyncSourceInfo( - const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, - const syncable::ModelTypePayloadMap& t); - ~SyncSourceInfo(); - - // Caller takes ownership of the returned dictionary. - base::DictionaryValue* ToValue() const; - - sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source; - syncable::ModelTypePayloadMap types; -}; - -// Data pertaining to the status of an active Syncer object. -struct SyncerStatus { - SyncerStatus(); - ~SyncerStatus(); - - // Caller takes ownership of the returned dictionary. - base::DictionaryValue* ToValue() const; - - // True when we get such an INVALID_STORE error from the server. - bool invalid_store; - int num_successful_commits; - // This is needed for monitoring extensions activity. - int num_successful_bookmark_commits; - - // Download event counters. - int num_updates_downloaded_total; - int num_tombstone_updates_downloaded_total; - int num_reflected_updates_downloaded_total; - - // If the syncer encountered a MIGRATION_DONE code, these are the types that - // the client must now "migrate", by purging and re-downloading all updates. - syncable::ModelTypeSet types_needing_local_migration; - - // Overwrites due to conflict resolution counters. - int num_local_overwrites; - int num_server_overwrites; -}; - -// Counters for various errors that can occur repeatedly during a sync session. -// TODO(lipalani) : Rename this structure to Error. -struct ErrorCounters { - ErrorCounters(); - - // Any protocol errors that we received during this sync session. - SyncProtocolError sync_protocol_error; - - // Records the most recent results of PostCommit and GetUpdates commands. - SyncerError last_download_updates_result; - SyncerError last_post_commit_result; - SyncerError last_process_commit_response_result; -}; - -// An immutable snapshot of state from a SyncSession. Convenient to use as -// part of notifications as it is inherently thread-safe. -// 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 syncable::ModelTypePayloadMap& download_progress_markers, - bool more_to_sync, - bool is_silenced, - int num_encryption_conflicts, - int num_hierarchy_conflicts, - int num_simple_conflicts, - int num_server_conflicts, - const SyncSourceInfo& source, - bool notifications_enabled, - size_t num_entries, - base::Time sync_start_time, - bool retry_scheduled); - ~SyncSessionSnapshot(); - - // Caller takes ownership of the returned dictionary. - base::DictionaryValue* ToValue() const; - - std::string ToString() 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; - syncable::ModelTypePayloadMap download_progress_markers() const; - bool has_more_to_sync() const; - bool is_silenced() 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_; - int num_encryption_conflicts_; - int num_hierarchy_conflicts_; - int num_simple_conflicts_; - int num_server_conflicts_; - SyncSourceInfo source_; - bool notifications_enabled_; - size_t num_entries_; - base::Time sync_start_time_; - bool retry_scheduled_; -}; - // Tracks progress of conflicts and their resolutions. class ConflictProgress { public: diff --git a/sync/sessions/session_state_unittest.cc b/sync/sessions/session_state_unittest.cc index 7881de0..e6a9d34 100644 --- a/sync/sessions/session_state_unittest.cc +++ b/sync/sessions/session_state_unittest.cc @@ -11,6 +11,10 @@ #include "base/test/values_test_util.h" #include "base/time.h" #include "base/values.h" +#include "sync/sessions/error_counters.h" +#include "sync/sessions/sync_session_snapshot.h" +#include "sync/sessions/sync_source_info.h" +#include "sync/sessions/syncer_status.h" #include "testing/gtest/include/gtest/gtest.h" namespace browser_sync { diff --git a/sync/sessions/sync_session.h b/sync/sessions/sync_session.h index 1dfe78c..94148d1 100644 --- a/sync/sessions/sync_session.h +++ b/sync/sessions/sync_session.h @@ -29,6 +29,7 @@ #include "sync/sessions/session_state.h" #include "sync/sessions/status_controller.h" #include "sync/sessions/sync_session_context.h" +#include "sync/sessions/sync_session_snapshot.h" #include "sync/syncable/model_type.h" #include "sync/util/extensions_activity_monitor.h" diff --git a/sync/sessions/sync_session_snapshot.cc b/sync/sessions/sync_session_snapshot.cc new file mode 100644 index 0000000..588b840 --- /dev/null +++ b/sync/sessions/sync_session_snapshot.cc @@ -0,0 +1,173 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/sessions/sync_session_snapshot.h" + +#include "base/json/json_writer.h" +#include "base/values.h" + +namespace browser_sync { +namespace sessions { + +SyncSessionSnapshot::SyncSessionSnapshot() + : num_server_changes_remaining_(0), + is_share_usable_(false), + has_more_to_sync_(false), + is_silenced_(false), + num_encryption_conflicts_(0), + num_hierarchy_conflicts_(0), + num_simple_conflicts_(0), + num_server_conflicts_(0), + 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 syncable::ModelTypePayloadMap& download_progress_markers, + bool more_to_sync, + bool is_silenced, + int num_encryption_conflicts, + int num_hierarchy_conflicts, + int num_simple_conflicts, + int num_server_conflicts, + const SyncSourceInfo& source, + bool notifications_enabled, + 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_(download_progress_markers), + has_more_to_sync_(more_to_sync), + is_silenced_(is_silenced), + num_encryption_conflicts_(num_encryption_conflicts), + num_hierarchy_conflicts_(num_hierarchy_conflicts), + num_simple_conflicts_(num_simple_conflicts), + num_server_conflicts_(num_server_conflicts), + 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()); + // 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_); + value->Set("initialSyncEnded", + syncable::ModelTypeSetToValue(initial_sync_ended_)); + value->Set("downloadProgressMarkers", + 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("numEncryptionConflicts", + num_encryption_conflicts_); + value->SetInteger("numHierarchyConflicts", + num_hierarchy_conflicts_); + value->SetInteger("numSimpleConflicts", + num_simple_conflicts_); + value->SetInteger("numServerConflicts", + num_server_conflicts_); + value->SetInteger("numEntries", num_entries_); + value->Set("source", source_.ToValue()); + value->SetBoolean("notificationsEnabled", notifications_enabled_); + return value; +} + +std::string SyncSessionSnapshot::ToString() const { + scoped_ptr<DictionaryValue> value(ToValue()); + std::string json; + base::JSONWriter::WriteWithOptions(value.get(), + base::JSONWriter::OPTIONS_PRETTY_PRINT, + &json); + 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_; +} + +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_; +} + +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_; +} + +} // namespace sessions +} // namespace browser_sync diff --git a/sync/sessions/sync_session_snapshot.h b/sync/sessions/sync_session_snapshot.h new file mode 100644 index 0000000..8da3b80 --- /dev/null +++ b/sync/sessions/sync_session_snapshot.h @@ -0,0 +1,101 @@ +// 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_SESSIONS_SYNC_SESSION_SNAPSHOT_H_ +#define SYNC_SESSIONS_SYNC_SESSION_SNAPSHOT_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "base/time.h" +#include "sync/sessions/error_counters.h" +#include "sync/sessions/sync_source_info.h" +#include "sync/sessions/syncer_status.h" +#include "sync/syncable/model_type.h" +#include "sync/syncable/model_type_payload_map.h" + +namespace base { +class DictionaryValue; +} + +namespace browser_sync { +namespace sessions { + +// An immutable snapshot of state from a SyncSession. Convenient to use as +// part of notifications as it is inherently thread-safe. +// 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 syncable::ModelTypePayloadMap& download_progress_markers, + bool more_to_sync, + bool is_silenced, + int num_encryption_conflicts, + int num_hierarchy_conflicts, + int num_simple_conflicts, + int num_server_conflicts, + const SyncSourceInfo& source, + bool notifications_enabled, + size_t num_entries, + base::Time sync_start_time, + bool retry_scheduled); + ~SyncSessionSnapshot(); + + // Caller takes ownership of the returned dictionary. + base::DictionaryValue* ToValue() const; + + std::string ToString() 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; + syncable::ModelTypePayloadMap download_progress_markers() const; + bool has_more_to_sync() const; + bool is_silenced() 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_; + int num_encryption_conflicts_; + int num_hierarchy_conflicts_; + int num_simple_conflicts_; + int num_server_conflicts_; + SyncSourceInfo source_; + bool notifications_enabled_; + size_t num_entries_; + base::Time sync_start_time_; + bool retry_scheduled_; +}; + +} // namespace sessions +} // namespace browser_sync + +#endif // SYNC_SESSIONS_SYNC_SESSION_SNAPSHOT_H_ diff --git a/sync/sessions/sync_source_info.cc b/sync/sessions/sync_source_info.cc new file mode 100644 index 0000000..c6c47ab --- /dev/null +++ b/sync/sessions/sync_source_info.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/sessions/sync_source_info.h" + +#include "base/values.h" +#include "sync/protocol/proto_enum_conversions.h" + +namespace browser_sync { +namespace sessions { + +SyncSourceInfo::SyncSourceInfo() + : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN) {} + +SyncSourceInfo::SyncSourceInfo( + const syncable::ModelTypePayloadMap& t) + : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN), types(t) {} + +SyncSourceInfo::SyncSourceInfo( + const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, + const syncable::ModelTypePayloadMap& t) + : updates_source(u), types(t) {} + +SyncSourceInfo::~SyncSourceInfo() {} + +DictionaryValue* SyncSourceInfo::ToValue() const { + DictionaryValue* value = new DictionaryValue(); + value->SetString("updatesSource", + GetUpdatesSourceString(updates_source)); + value->Set("types", syncable::ModelTypePayloadMapToValue(types)); + return value; +} + +} // namespace sessions +} // namespace browser_sync diff --git a/sync/sessions/sync_source_info.h b/sync/sessions/sync_source_info.h new file mode 100644 index 0000000..0eedd40 --- /dev/null +++ b/sync/sessions/sync_source_info.h @@ -0,0 +1,42 @@ +// 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_SESSIONS_SYNC_SOURCE_INFO_H_ +#define SYNC_SESSIONS_SYNC_SOURCE_INFO_H_ +#pragma once + +#include "base/basictypes.h" +#include "sync/engine/syncproto.h" +#include "sync/syncable/model_type.h" +#include "sync/syncable/model_type_payload_map.h" + +namespace base { +class DictionaryValue; +} + +namespace browser_sync { +namespace sessions { + +// A container for the source of a sync session. This includes the update +// source, the datatypes triggering the sync session, and possible session +// specific payloads which should be sent to the server. +struct SyncSourceInfo { + SyncSourceInfo(); + explicit SyncSourceInfo(const syncable::ModelTypePayloadMap& t); + SyncSourceInfo( + const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, + const syncable::ModelTypePayloadMap& t); + ~SyncSourceInfo(); + + // Caller takes ownership of the returned dictionary. + base::DictionaryValue* ToValue() const; + + sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source; + syncable::ModelTypePayloadMap types; +}; + +} // namespace sessions +} // namespace browser_sync + +#endif // SYNC_SESSIONS_SYNC_SOURCE_INFO_H_ diff --git a/sync/sessions/syncer_status.cc b/sync/sessions/syncer_status.cc new file mode 100644 index 0000000..ba318e4 --- /dev/null +++ b/sync/sessions/syncer_status.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/sessions/syncer_status.h" + +#include "base/values.h" + +namespace browser_sync { +namespace sessions { + +SyncerStatus::SyncerStatus() + : invalid_store(false), + num_successful_commits(0), + num_successful_bookmark_commits(0), + num_updates_downloaded_total(0), + num_tombstone_updates_downloaded_total(0), + num_reflected_updates_downloaded_total(0), + num_local_overwrites(0), + num_server_overwrites(0) { +} + +SyncerStatus::~SyncerStatus() { +} + +DictionaryValue* SyncerStatus::ToValue() const { + DictionaryValue* value = new DictionaryValue(); + value->SetBoolean("invalidStore", invalid_store); + value->SetInteger("numSuccessfulCommits", num_successful_commits); + value->SetInteger("numSuccessfulBookmarkCommits", + num_successful_bookmark_commits); + value->SetInteger("numUpdatesDownloadedTotal", + num_updates_downloaded_total); + value->SetInteger("numTombstoneUpdatesDownloadedTotal", + num_tombstone_updates_downloaded_total); + value->SetInteger("numReflectedUpdatesDownloadedTotal", + num_reflected_updates_downloaded_total); + value->SetInteger("numLocalOverwrites", num_local_overwrites); + value->SetInteger("numServerOverwrites", num_server_overwrites); + return value; +} + +} // namespace sessions +} // namespace browser_sync diff --git a/sync/sessions/syncer_status.h b/sync/sessions/syncer_status.h new file mode 100644 index 0000000..b862d1f --- /dev/null +++ b/sync/sessions/syncer_status.h @@ -0,0 +1,50 @@ +// 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_SESSIONS_SYNCER_STATUS_H_ +#define SYNC_SESSIONS_SYNCER_STATUS_H_ +#pragma once + +#include "base/basictypes.h" +#include "sync/syncable/model_type.h" + +namespace base { +class DictionaryValue; +} + +namespace browser_sync { +namespace sessions { + +// Data pertaining to the status of an active Syncer object. +struct SyncerStatus { + SyncerStatus(); + ~SyncerStatus(); + + // Caller takes ownership of the returned dictionary. + base::DictionaryValue* ToValue() const; + + // True when we get such an INVALID_STORE error from the server. + bool invalid_store; + int num_successful_commits; + // This is needed for monitoring extensions activity. + int num_successful_bookmark_commits; + + // Download event counters. + int num_updates_downloaded_total; + int num_tombstone_updates_downloaded_total; + int num_reflected_updates_downloaded_total; + + // If the syncer encountered a MIGRATION_DONE code, these are the types that + // the client must now "migrate", by purging and re-downloading all updates. + syncable::ModelTypeSet types_needing_local_migration; + + // Overwrites due to conflict resolution counters. + int num_local_overwrites; + int num_server_overwrites; +}; + +} // namespace sessions +} // namespace browser_sync + +#endif // SYNC_SESSIONS_SYNCER_STATUS_H_ |