| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/sync/sessions/sync_session_snapshot.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include <memory> | |
| 10 #include <utility> | |
| 11 | |
| 12 #include "base/json/json_writer.h" | |
| 13 #include "base/values.h" | |
| 14 #include "components/sync/protocol/proto_enum_conversions.h" | |
| 15 | |
| 16 namespace syncer { | |
| 17 namespace sessions { | |
| 18 | |
| 19 SyncSessionSnapshot::SyncSessionSnapshot() | |
| 20 : is_silenced_(false), | |
| 21 num_encryption_conflicts_(0), | |
| 22 num_hierarchy_conflicts_(0), | |
| 23 num_server_conflicts_(0), | |
| 24 notifications_enabled_(false), | |
| 25 num_entries_(0), | |
| 26 num_entries_by_type_(MODEL_TYPE_COUNT, 0), | |
| 27 num_to_delete_entries_by_type_(MODEL_TYPE_COUNT, 0), | |
| 28 is_initialized_(false) {} | |
| 29 | |
| 30 SyncSessionSnapshot::SyncSessionSnapshot( | |
| 31 const ModelNeutralState& model_neutral_state, | |
| 32 const ProgressMarkerMap& download_progress_markers, | |
| 33 bool is_silenced, | |
| 34 int num_encryption_conflicts, | |
| 35 int num_hierarchy_conflicts, | |
| 36 int num_server_conflicts, | |
| 37 bool notifications_enabled, | |
| 38 size_t num_entries, | |
| 39 base::Time sync_start_time, | |
| 40 base::Time poll_finish_time, | |
| 41 const std::vector<int>& num_entries_by_type, | |
| 42 const std::vector<int>& num_to_delete_entries_by_type, | |
| 43 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source) | |
| 44 : model_neutral_state_(model_neutral_state), | |
| 45 download_progress_markers_(download_progress_markers), | |
| 46 is_silenced_(is_silenced), | |
| 47 num_encryption_conflicts_(num_encryption_conflicts), | |
| 48 num_hierarchy_conflicts_(num_hierarchy_conflicts), | |
| 49 num_server_conflicts_(num_server_conflicts), | |
| 50 notifications_enabled_(notifications_enabled), | |
| 51 num_entries_(num_entries), | |
| 52 sync_start_time_(sync_start_time), | |
| 53 poll_finish_time_(poll_finish_time), | |
| 54 num_entries_by_type_(num_entries_by_type), | |
| 55 num_to_delete_entries_by_type_(num_to_delete_entries_by_type), | |
| 56 legacy_updates_source_(legacy_updates_source), | |
| 57 is_initialized_(true) {} | |
| 58 | |
| 59 SyncSessionSnapshot::SyncSessionSnapshot(const SyncSessionSnapshot& other) = | |
| 60 default; | |
| 61 | |
| 62 SyncSessionSnapshot::~SyncSessionSnapshot() {} | |
| 63 | |
| 64 std::unique_ptr<base::DictionaryValue> SyncSessionSnapshot::ToValue() const { | |
| 65 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | |
| 66 value->SetInteger("numSuccessfulCommits", | |
| 67 model_neutral_state_.num_successful_commits); | |
| 68 value->SetInteger("numSuccessfulBookmarkCommits", | |
| 69 model_neutral_state_.num_successful_bookmark_commits); | |
| 70 value->SetInteger("numUpdatesDownloadedTotal", | |
| 71 model_neutral_state_.num_updates_downloaded_total); | |
| 72 value->SetInteger( | |
| 73 "numTombstoneUpdatesDownloadedTotal", | |
| 74 model_neutral_state_.num_tombstone_updates_downloaded_total); | |
| 75 value->SetInteger( | |
| 76 "numReflectedUpdatesDownloadedTotal", | |
| 77 model_neutral_state_.num_reflected_updates_downloaded_total); | |
| 78 value->SetInteger("numLocalOverwrites", | |
| 79 model_neutral_state_.num_local_overwrites); | |
| 80 value->SetInteger("numServerOverwrites", | |
| 81 model_neutral_state_.num_server_overwrites); | |
| 82 value->Set("downloadProgressMarkers", | |
| 83 ProgressMarkerMapToValue(download_progress_markers_)); | |
| 84 value->SetBoolean("isSilenced", is_silenced_); | |
| 85 // We don't care too much if we lose precision here, also. | |
| 86 value->SetInteger("numEncryptionConflicts", num_encryption_conflicts_); | |
| 87 value->SetInteger("numHierarchyConflicts", num_hierarchy_conflicts_); | |
| 88 value->SetInteger("numServerConflicts", num_server_conflicts_); | |
| 89 value->SetInteger("numEntries", num_entries_); | |
| 90 value->SetString("legacySource", | |
| 91 GetUpdatesSourceString(legacy_updates_source_)); | |
| 92 value->SetBoolean("notificationsEnabled", notifications_enabled_); | |
| 93 | |
| 94 std::unique_ptr<base::DictionaryValue> counter_entries( | |
| 95 new base::DictionaryValue()); | |
| 96 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; i++) { | |
| 97 std::unique_ptr<base::DictionaryValue> type_entries( | |
| 98 new base::DictionaryValue()); | |
| 99 type_entries->SetInteger("numEntries", num_entries_by_type_[i]); | |
| 100 type_entries->SetInteger("numToDeleteEntries", | |
| 101 num_to_delete_entries_by_type_[i]); | |
| 102 | |
| 103 const std::string model_type = ModelTypeToString(static_cast<ModelType>(i)); | |
| 104 counter_entries->Set(model_type, type_entries.release()); | |
| 105 } | |
| 106 value->Set("counter_entries", std::move(counter_entries)); | |
| 107 return value; | |
| 108 } | |
| 109 | |
| 110 std::string SyncSessionSnapshot::ToString() const { | |
| 111 std::string json; | |
| 112 base::JSONWriter::WriteWithOptions( | |
| 113 *ToValue(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); | |
| 114 return json; | |
| 115 } | |
| 116 | |
| 117 const ProgressMarkerMap& SyncSessionSnapshot::download_progress_markers() | |
| 118 const { | |
| 119 return download_progress_markers_; | |
| 120 } | |
| 121 | |
| 122 bool SyncSessionSnapshot::is_silenced() const { | |
| 123 return is_silenced_; | |
| 124 } | |
| 125 | |
| 126 int SyncSessionSnapshot::num_encryption_conflicts() const { | |
| 127 return num_encryption_conflicts_; | |
| 128 } | |
| 129 | |
| 130 int SyncSessionSnapshot::num_hierarchy_conflicts() const { | |
| 131 return num_hierarchy_conflicts_; | |
| 132 } | |
| 133 | |
| 134 int SyncSessionSnapshot::num_server_conflicts() const { | |
| 135 return num_server_conflicts_; | |
| 136 } | |
| 137 | |
| 138 bool SyncSessionSnapshot::notifications_enabled() const { | |
| 139 return notifications_enabled_; | |
| 140 } | |
| 141 | |
| 142 size_t SyncSessionSnapshot::num_entries() const { | |
| 143 return num_entries_; | |
| 144 } | |
| 145 | |
| 146 base::Time SyncSessionSnapshot::sync_start_time() const { | |
| 147 return sync_start_time_; | |
| 148 } | |
| 149 | |
| 150 base::Time SyncSessionSnapshot::poll_finish_time() const { | |
| 151 return poll_finish_time_; | |
| 152 } | |
| 153 | |
| 154 bool SyncSessionSnapshot::is_initialized() const { | |
| 155 return is_initialized_; | |
| 156 } | |
| 157 | |
| 158 const std::vector<int>& SyncSessionSnapshot::num_entries_by_type() const { | |
| 159 return num_entries_by_type_; | |
| 160 } | |
| 161 | |
| 162 const std::vector<int>& SyncSessionSnapshot::num_to_delete_entries_by_type() | |
| 163 const { | |
| 164 return num_to_delete_entries_by_type_; | |
| 165 } | |
| 166 | |
| 167 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource | |
| 168 SyncSessionSnapshot::legacy_updates_source() const { | |
| 169 return legacy_updates_source_; | |
| 170 } | |
| 171 | |
| 172 } // namespace sessions | |
| 173 } // namespace syncer | |
| OLD | NEW |