Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: sync/internal_api/public/sessions/sync_session_snapshot.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "sync/internal_api/public/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 "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
31 SyncSessionSnapshot::SyncSessionSnapshot(
32 const ModelNeutralState& model_neutral_state,
33 const ProgressMarkerMap& download_progress_markers,
34 bool is_silenced,
35 int num_encryption_conflicts,
36 int num_hierarchy_conflicts,
37 int num_server_conflicts,
38 bool notifications_enabled,
39 size_t num_entries,
40 base::Time sync_start_time,
41 base::Time poll_finish_time,
42 const std::vector<int>& num_entries_by_type,
43 const std::vector<int>& num_to_delete_entries_by_type,
44 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source)
45 : model_neutral_state_(model_neutral_state),
46 download_progress_markers_(download_progress_markers),
47 is_silenced_(is_silenced),
48 num_encryption_conflicts_(num_encryption_conflicts),
49 num_hierarchy_conflicts_(num_hierarchy_conflicts),
50 num_server_conflicts_(num_server_conflicts),
51 notifications_enabled_(notifications_enabled),
52 num_entries_(num_entries),
53 sync_start_time_(sync_start_time),
54 poll_finish_time_(poll_finish_time),
55 num_entries_by_type_(num_entries_by_type),
56 num_to_delete_entries_by_type_(num_to_delete_entries_by_type),
57 legacy_updates_source_(legacy_updates_source),
58 is_initialized_(true) {
59 }
60
61 SyncSessionSnapshot::SyncSessionSnapshot(const SyncSessionSnapshot& other) =
62 default;
63
64 SyncSessionSnapshot::~SyncSessionSnapshot() {}
65
66 std::unique_ptr<base::DictionaryValue> SyncSessionSnapshot::ToValue() const {
67 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
68 value->SetInteger("numSuccessfulCommits",
69 model_neutral_state_.num_successful_commits);
70 value->SetInteger("numSuccessfulBookmarkCommits",
71 model_neutral_state_.num_successful_bookmark_commits);
72 value->SetInteger("numUpdatesDownloadedTotal",
73 model_neutral_state_.num_updates_downloaded_total);
74 value->SetInteger("numTombstoneUpdatesDownloadedTotal",
75 model_neutral_state_.num_tombstone_updates_downloaded_total);
76 value->SetInteger("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",
87 num_encryption_conflicts_);
88 value->SetInteger("numHierarchyConflicts",
89 num_hierarchy_conflicts_);
90 value->SetInteger("numServerConflicts",
91 num_server_conflicts_);
92 value->SetInteger("numEntries", num_entries_);
93 value->SetString("legacySource",
94 GetUpdatesSourceString(legacy_updates_source_));
95 value->SetBoolean("notificationsEnabled", notifications_enabled_);
96
97 std::unique_ptr<base::DictionaryValue> counter_entries(
98 new base::DictionaryValue());
99 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; i++) {
100 std::unique_ptr<base::DictionaryValue> type_entries(
101 new base::DictionaryValue());
102 type_entries->SetInteger("numEntries", num_entries_by_type_[i]);
103 type_entries->SetInteger("numToDeleteEntries",
104 num_to_delete_entries_by_type_[i]);
105
106 const std::string model_type = ModelTypeToString(static_cast<ModelType>(i));
107 counter_entries->Set(model_type, type_entries.release());
108 }
109 value->Set("counter_entries", std::move(counter_entries));
110 return value;
111 }
112
113 std::string SyncSessionSnapshot::ToString() const {
114 std::string json;
115 base::JSONWriter::WriteWithOptions(
116 *ToValue(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
117 return json;
118 }
119
120 const ProgressMarkerMap&
121 SyncSessionSnapshot::download_progress_markers() const {
122 return download_progress_markers_;
123 }
124
125 bool SyncSessionSnapshot::is_silenced() const {
126 return is_silenced_;
127 }
128
129 int SyncSessionSnapshot::num_encryption_conflicts() const {
130 return num_encryption_conflicts_;
131 }
132
133 int SyncSessionSnapshot::num_hierarchy_conflicts() const {
134 return num_hierarchy_conflicts_;
135 }
136
137 int SyncSessionSnapshot::num_server_conflicts() const {
138 return num_server_conflicts_;
139 }
140
141 bool SyncSessionSnapshot::notifications_enabled() const {
142 return notifications_enabled_;
143 }
144
145 size_t SyncSessionSnapshot::num_entries() const {
146 return num_entries_;
147 }
148
149 base::Time SyncSessionSnapshot::sync_start_time() const {
150 return sync_start_time_;
151 }
152
153 base::Time SyncSessionSnapshot::poll_finish_time() const {
154 return poll_finish_time_;
155 }
156
157 bool SyncSessionSnapshot::is_initialized() const {
158 return is_initialized_;
159 }
160
161 const std::vector<int>& SyncSessionSnapshot::num_entries_by_type() const {
162 return num_entries_by_type_;
163 }
164
165 const std::vector<int>&
166 SyncSessionSnapshot::num_to_delete_entries_by_type() const {
167 return num_to_delete_entries_by_type_;
168 }
169
170 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource
171 SyncSessionSnapshot::legacy_updates_source() const {
172 return legacy_updates_source_;
173 }
174
175 } // namespace sessions
176 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698