OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sync/sessions/session_state.h" | 5 #include "sync/sessions/session_state.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 num_updates_downloaded_total); | 68 num_updates_downloaded_total); |
69 value->SetInteger("numTombstoneUpdatesDownloadedTotal", | 69 value->SetInteger("numTombstoneUpdatesDownloadedTotal", |
70 num_tombstone_updates_downloaded_total); | 70 num_tombstone_updates_downloaded_total); |
71 value->SetInteger("numReflectedUpdatesDownloadedTotal", | 71 value->SetInteger("numReflectedUpdatesDownloadedTotal", |
72 num_reflected_updates_downloaded_total); | 72 num_reflected_updates_downloaded_total); |
73 value->SetInteger("numLocalOverwrites", num_local_overwrites); | 73 value->SetInteger("numLocalOverwrites", num_local_overwrites); |
74 value->SetInteger("numServerOverwrites", num_server_overwrites); | 74 value->SetInteger("numServerOverwrites", num_server_overwrites); |
75 return value; | 75 return value; |
76 } | 76 } |
77 | 77 |
78 DictionaryValue* DownloadProgressMarkersToValue( | |
79 const std::string | |
80 (&download_progress_markers)[syncable::MODEL_TYPE_COUNT]) { | |
81 DictionaryValue* value = new DictionaryValue(); | |
82 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | |
83 i < syncable::MODEL_TYPE_COUNT; ++i) { | |
84 // TODO(akalin): Unpack the value into a protobuf. | |
85 std::string base64_marker; | |
86 bool encoded = | |
87 base::Base64Encode(download_progress_markers[i], &base64_marker); | |
88 DCHECK(encoded); | |
89 value->SetString( | |
90 syncable::ModelTypeToString(syncable::ModelTypeFromInt(i)), | |
91 base64_marker); | |
92 } | |
93 return value; | |
94 } | |
95 | |
96 ErrorCounters::ErrorCounters() | 78 ErrorCounters::ErrorCounters() |
97 : last_download_updates_result(UNSET), | 79 : last_download_updates_result(UNSET), |
98 last_post_commit_result(UNSET), | 80 last_post_commit_result(UNSET), |
99 last_process_commit_response_result(UNSET) { | 81 last_process_commit_response_result(UNSET) { |
100 } | 82 } |
101 | 83 |
| 84 SyncSessionSnapshot::SyncSessionSnapshot() |
| 85 : num_server_changes_remaining_(0), |
| 86 is_share_usable_(false), |
| 87 has_more_to_sync_(false), |
| 88 is_silenced_(false), |
| 89 unsynced_count_(0), |
| 90 num_encryption_conflicts_(0), |
| 91 num_hierarchy_conflicts_(0), |
| 92 num_simple_conflicts_(0), |
| 93 num_server_conflicts_(0), |
| 94 did_commit_items_(false), |
| 95 notifications_enabled_(false), |
| 96 num_entries_(0), |
| 97 retry_scheduled_(false) { |
| 98 } |
| 99 |
102 SyncSessionSnapshot::SyncSessionSnapshot( | 100 SyncSessionSnapshot::SyncSessionSnapshot( |
103 const SyncerStatus& syncer_status, | 101 const SyncerStatus& syncer_status, |
104 const ErrorCounters& errors, | 102 const ErrorCounters& errors, |
105 int64 num_server_changes_remaining, | 103 int64 num_server_changes_remaining, |
106 bool is_share_usable, | 104 bool is_share_usable, |
107 syncable::ModelTypeSet initial_sync_ended, | 105 syncable::ModelTypeSet initial_sync_ended, |
108 const std::string | 106 const syncable::ModelTypePayloadMap& download_progress_markers, |
109 (&download_progress_markers)[syncable::MODEL_TYPE_COUNT], | |
110 bool more_to_sync, | 107 bool more_to_sync, |
111 bool is_silenced, | 108 bool is_silenced, |
112 int64 unsynced_count, | 109 int64 unsynced_count, |
113 int num_encryption_conflicts, | 110 int num_encryption_conflicts, |
114 int num_hierarchy_conflicts, | 111 int num_hierarchy_conflicts, |
115 int num_simple_conflicts, | 112 int num_simple_conflicts, |
116 int num_server_conflicts, | 113 int num_server_conflicts, |
117 bool did_commit_items, | 114 bool did_commit_items, |
118 const SyncSourceInfo& source, | 115 const SyncSourceInfo& source, |
119 bool notifications_enabled, | 116 bool notifications_enabled, |
120 size_t num_entries, | 117 size_t num_entries, |
121 base::Time sync_start_time, | 118 base::Time sync_start_time, |
122 bool retry_scheduled) | 119 bool retry_scheduled) |
123 : syncer_status(syncer_status), | 120 : syncer_status_(syncer_status), |
124 errors(errors), | 121 errors_(errors), |
125 num_server_changes_remaining(num_server_changes_remaining), | 122 num_server_changes_remaining_(num_server_changes_remaining), |
126 is_share_usable(is_share_usable), | 123 is_share_usable_(is_share_usable), |
127 initial_sync_ended(initial_sync_ended), | 124 initial_sync_ended_(initial_sync_ended), |
128 download_progress_markers(), | 125 download_progress_markers_(download_progress_markers), |
129 has_more_to_sync(more_to_sync), | 126 has_more_to_sync_(more_to_sync), |
130 is_silenced(is_silenced), | 127 is_silenced_(is_silenced), |
131 unsynced_count(unsynced_count), | 128 unsynced_count_(unsynced_count), |
132 num_encryption_conflicts(num_encryption_conflicts), | 129 num_encryption_conflicts_(num_encryption_conflicts), |
133 num_hierarchy_conflicts(num_hierarchy_conflicts), | 130 num_hierarchy_conflicts_(num_hierarchy_conflicts), |
134 num_simple_conflicts(num_simple_conflicts), | 131 num_simple_conflicts_(num_simple_conflicts), |
135 num_server_conflicts(num_server_conflicts), | 132 num_server_conflicts_(num_server_conflicts), |
136 did_commit_items(did_commit_items), | 133 did_commit_items_(did_commit_items), |
137 source(source), | 134 source_(source), |
138 notifications_enabled(notifications_enabled), | 135 notifications_enabled_(notifications_enabled), |
139 num_entries(num_entries), | 136 num_entries_(num_entries), |
140 sync_start_time(sync_start_time), | 137 sync_start_time_(sync_start_time), |
141 retry_scheduled(retry_scheduled) { | 138 retry_scheduled_(retry_scheduled) { |
142 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | |
143 i < syncable::MODEL_TYPE_COUNT; ++i) { | |
144 const_cast<std::string&>(this->download_progress_markers[i]).assign( | |
145 download_progress_markers[i]); | |
146 } | |
147 } | 139 } |
148 | 140 |
149 SyncSessionSnapshot::~SyncSessionSnapshot() {} | 141 SyncSessionSnapshot::~SyncSessionSnapshot() {} |
150 | 142 |
151 DictionaryValue* SyncSessionSnapshot::ToValue() const { | 143 DictionaryValue* SyncSessionSnapshot::ToValue() const { |
152 DictionaryValue* value = new DictionaryValue(); | 144 DictionaryValue* value = new DictionaryValue(); |
153 value->Set("syncerStatus", syncer_status.ToValue()); | 145 value->Set("syncerStatus", syncer_status_.ToValue()); |
154 // We don't care too much if we lose precision here. | 146 // We don't care too much if we lose precision here. |
155 value->SetInteger("numServerChangesRemaining", | 147 value->SetInteger("numServerChangesRemaining", |
156 static_cast<int>(num_server_changes_remaining)); | 148 static_cast<int>(num_server_changes_remaining_)); |
157 value->SetBoolean("isShareUsable", is_share_usable); | 149 value->SetBoolean("isShareUsable", is_share_usable_); |
158 value->Set("initialSyncEnded", | 150 value->Set("initialSyncEnded", |
159 syncable::ModelTypeSetToValue(initial_sync_ended)); | 151 syncable::ModelTypeSetToValue(initial_sync_ended_)); |
160 value->Set("downloadProgressMarkers", | 152 value->Set("downloadProgressMarkers", |
161 DownloadProgressMarkersToValue(download_progress_markers)); | 153 syncable::ModelTypePayloadMapToValue(download_progress_markers_)); |
162 value->SetBoolean("hasMoreToSync", has_more_to_sync); | 154 value->SetBoolean("hasMoreToSync", has_more_to_sync_); |
163 value->SetBoolean("isSilenced", is_silenced); | 155 value->SetBoolean("isSilenced", is_silenced_); |
164 // We don't care too much if we lose precision here, also. | 156 // We don't care too much if we lose precision here, also. |
165 value->SetInteger("unsyncedCount", | 157 value->SetInteger("unsyncedCount", |
166 static_cast<int>(unsynced_count)); | 158 static_cast<int>(unsynced_count_)); |
167 value->SetInteger("numEncryptionConflicts", | 159 value->SetInteger("numEncryptionConflicts", |
168 num_encryption_conflicts); | 160 num_encryption_conflicts_); |
169 value->SetInteger("numHierarchyConflicts", | 161 value->SetInteger("numHierarchyConflicts", |
170 num_hierarchy_conflicts); | 162 num_hierarchy_conflicts_); |
171 value->SetInteger("numSimpleConflicts", | 163 value->SetInteger("numSimpleConflicts", |
172 num_simple_conflicts); | 164 num_simple_conflicts_); |
173 value->SetInteger("numServerConflicts", | 165 value->SetInteger("numServerConflicts", |
174 num_server_conflicts); | 166 num_server_conflicts_); |
175 value->SetBoolean("didCommitItems", did_commit_items); | 167 value->SetBoolean("didCommitItems", did_commit_items_); |
176 value->SetInteger("numEntries", num_entries); | 168 value->SetInteger("numEntries", num_entries_); |
177 value->Set("source", source.ToValue()); | 169 value->Set("source", source_.ToValue()); |
178 value->SetBoolean("notificationsEnabled", notifications_enabled); | 170 value->SetBoolean("notificationsEnabled", notifications_enabled_); |
179 return value; | 171 return value; |
180 } | 172 } |
181 | 173 |
182 std::string SyncSessionSnapshot::ToString() const { | 174 std::string SyncSessionSnapshot::ToString() const { |
183 scoped_ptr<DictionaryValue> value(ToValue()); | 175 scoped_ptr<DictionaryValue> value(ToValue()); |
184 std::string json; | 176 std::string json; |
185 base::JSONWriter::WriteWithOptions(value.get(), | 177 base::JSONWriter::WriteWithOptions(value.get(), |
186 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 178 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
187 &json); | 179 &json); |
188 return json; | 180 return json; |
189 } | 181 } |
190 | 182 |
| 183 SyncerStatus SyncSessionSnapshot::syncer_status() const { |
| 184 return syncer_status_; |
| 185 } |
| 186 |
| 187 ErrorCounters SyncSessionSnapshot::errors() const { |
| 188 return errors_; |
| 189 } |
| 190 |
| 191 int64 SyncSessionSnapshot::num_server_changes_remaining() const { |
| 192 return num_server_changes_remaining_; |
| 193 } |
| 194 |
| 195 bool SyncSessionSnapshot::is_share_usable() const { |
| 196 return is_share_usable_; |
| 197 } |
| 198 |
| 199 syncable::ModelTypeSet SyncSessionSnapshot::initial_sync_ended() const { |
| 200 return initial_sync_ended_; |
| 201 } |
| 202 |
| 203 syncable::ModelTypePayloadMap |
| 204 SyncSessionSnapshot::download_progress_markers() const { |
| 205 return download_progress_markers_; |
| 206 } |
| 207 |
| 208 bool SyncSessionSnapshot::has_more_to_sync() const { |
| 209 return has_more_to_sync_; |
| 210 } |
| 211 |
| 212 bool SyncSessionSnapshot::is_silenced() const { |
| 213 return is_silenced_; |
| 214 } |
| 215 |
| 216 int64 SyncSessionSnapshot::unsynced_count() const { |
| 217 return unsynced_count_; |
| 218 } |
| 219 |
| 220 int SyncSessionSnapshot::num_encryption_conflicts() const { |
| 221 return num_encryption_conflicts_; |
| 222 } |
| 223 |
| 224 int SyncSessionSnapshot::num_hierarchy_conflicts() const { |
| 225 return num_hierarchy_conflicts_; |
| 226 } |
| 227 |
| 228 int SyncSessionSnapshot::num_simple_conflicts() const { |
| 229 return num_simple_conflicts_; |
| 230 } |
| 231 |
| 232 int SyncSessionSnapshot::num_server_conflicts() const { |
| 233 return num_server_conflicts_; |
| 234 } |
| 235 |
| 236 bool SyncSessionSnapshot::did_commit_items() const { |
| 237 return did_commit_items_; |
| 238 } |
| 239 |
| 240 SyncSourceInfo SyncSessionSnapshot::source() const { |
| 241 return source_; |
| 242 } |
| 243 |
| 244 bool SyncSessionSnapshot::notifications_enabled() const { |
| 245 return notifications_enabled_; |
| 246 } |
| 247 |
| 248 size_t SyncSessionSnapshot::num_entries() const { |
| 249 return num_entries_; |
| 250 } |
| 251 |
| 252 base::Time SyncSessionSnapshot::sync_start_time() const { |
| 253 return sync_start_time_; |
| 254 } |
| 255 |
| 256 bool SyncSessionSnapshot::retry_scheduled() const { |
| 257 return retry_scheduled_; |
| 258 } |
| 259 |
191 ConflictProgress::ConflictProgress(bool* dirty_flag) | 260 ConflictProgress::ConflictProgress(bool* dirty_flag) |
192 : num_server_conflicting_items(0), num_hierarchy_conflicting_items(0), | 261 : num_server_conflicting_items(0), num_hierarchy_conflicting_items(0), |
193 num_encryption_conflicting_items(0), dirty_(dirty_flag) { | 262 num_encryption_conflicting_items(0), dirty_(dirty_flag) { |
194 } | 263 } |
195 | 264 |
196 ConflictProgress::~ConflictProgress() { | 265 ConflictProgress::~ConflictProgress() { |
197 } | 266 } |
198 | 267 |
199 bool ConflictProgress::HasSimpleConflictItem(const syncable::Id& id) const { | 268 bool ConflictProgress::HasSimpleConflictItem(const syncable::Id& id) const { |
200 return simple_conflicting_item_ids_.count(id) > 0; | 269 return simple_conflicting_item_ids_.count(id) > 0; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 392 |
324 PerModelSafeGroupState::PerModelSafeGroupState(bool* dirty_flag) | 393 PerModelSafeGroupState::PerModelSafeGroupState(bool* dirty_flag) |
325 : conflict_progress(dirty_flag) { | 394 : conflict_progress(dirty_flag) { |
326 } | 395 } |
327 | 396 |
328 PerModelSafeGroupState::~PerModelSafeGroupState() { | 397 PerModelSafeGroupState::~PerModelSafeGroupState() { |
329 } | 398 } |
330 | 399 |
331 } // namespace sessions | 400 } // namespace sessions |
332 } // namespace browser_sync | 401 } // namespace browser_sync |
OLD | NEW |