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

Side by Side Diff: components/sync/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
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/internal_api/public/sessions/sync_session_snapshot.h" 5 #include "components/sync/sessions/sync_session_snapshot.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "sync/protocol/proto_enum_conversions.h" 14 #include "components/sync/protocol/proto_enum_conversions.h"
15 15
16 namespace syncer { 16 namespace syncer {
17 namespace sessions { 17 namespace sessions {
18 18
19 SyncSessionSnapshot::SyncSessionSnapshot() 19 SyncSessionSnapshot::SyncSessionSnapshot()
20 : is_silenced_(false), 20 : is_silenced_(false),
21 num_encryption_conflicts_(0), 21 num_encryption_conflicts_(0),
22 num_hierarchy_conflicts_(0), 22 num_hierarchy_conflicts_(0),
23 num_server_conflicts_(0), 23 num_server_conflicts_(0),
24 notifications_enabled_(false), 24 notifications_enabled_(false),
25 num_entries_(0), 25 num_entries_(0),
26 num_entries_by_type_(MODEL_TYPE_COUNT, 0), 26 num_entries_by_type_(MODEL_TYPE_COUNT, 0),
27 num_to_delete_entries_by_type_(MODEL_TYPE_COUNT, 0), 27 num_to_delete_entries_by_type_(MODEL_TYPE_COUNT, 0),
28 is_initialized_(false) { 28 is_initialized_(false) {}
29 }
30 29
31 SyncSessionSnapshot::SyncSessionSnapshot( 30 SyncSessionSnapshot::SyncSessionSnapshot(
32 const ModelNeutralState& model_neutral_state, 31 const ModelNeutralState& model_neutral_state,
33 const ProgressMarkerMap& download_progress_markers, 32 const ProgressMarkerMap& download_progress_markers,
34 bool is_silenced, 33 bool is_silenced,
35 int num_encryption_conflicts, 34 int num_encryption_conflicts,
36 int num_hierarchy_conflicts, 35 int num_hierarchy_conflicts,
37 int num_server_conflicts, 36 int num_server_conflicts,
38 bool notifications_enabled, 37 bool notifications_enabled,
39 size_t num_entries, 38 size_t num_entries,
40 base::Time sync_start_time, 39 base::Time sync_start_time,
41 base::Time poll_finish_time, 40 base::Time poll_finish_time,
42 const std::vector<int>& num_entries_by_type, 41 const std::vector<int>& num_entries_by_type,
43 const std::vector<int>& num_to_delete_entries_by_type, 42 const std::vector<int>& num_to_delete_entries_by_type,
44 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source) 43 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source)
45 : model_neutral_state_(model_neutral_state), 44 : model_neutral_state_(model_neutral_state),
46 download_progress_markers_(download_progress_markers), 45 download_progress_markers_(download_progress_markers),
47 is_silenced_(is_silenced), 46 is_silenced_(is_silenced),
48 num_encryption_conflicts_(num_encryption_conflicts), 47 num_encryption_conflicts_(num_encryption_conflicts),
49 num_hierarchy_conflicts_(num_hierarchy_conflicts), 48 num_hierarchy_conflicts_(num_hierarchy_conflicts),
50 num_server_conflicts_(num_server_conflicts), 49 num_server_conflicts_(num_server_conflicts),
51 notifications_enabled_(notifications_enabled), 50 notifications_enabled_(notifications_enabled),
52 num_entries_(num_entries), 51 num_entries_(num_entries),
53 sync_start_time_(sync_start_time), 52 sync_start_time_(sync_start_time),
54 poll_finish_time_(poll_finish_time), 53 poll_finish_time_(poll_finish_time),
55 num_entries_by_type_(num_entries_by_type), 54 num_entries_by_type_(num_entries_by_type),
56 num_to_delete_entries_by_type_(num_to_delete_entries_by_type), 55 num_to_delete_entries_by_type_(num_to_delete_entries_by_type),
57 legacy_updates_source_(legacy_updates_source), 56 legacy_updates_source_(legacy_updates_source),
58 is_initialized_(true) { 57 is_initialized_(true) {}
59 }
60 58
61 SyncSessionSnapshot::SyncSessionSnapshot(const SyncSessionSnapshot& other) = 59 SyncSessionSnapshot::SyncSessionSnapshot(const SyncSessionSnapshot& other) =
62 default; 60 default;
63 61
64 SyncSessionSnapshot::~SyncSessionSnapshot() {} 62 SyncSessionSnapshot::~SyncSessionSnapshot() {}
65 63
66 std::unique_ptr<base::DictionaryValue> SyncSessionSnapshot::ToValue() const { 64 std::unique_ptr<base::DictionaryValue> SyncSessionSnapshot::ToValue() const {
67 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 65 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
68 value->SetInteger("numSuccessfulCommits", 66 value->SetInteger("numSuccessfulCommits",
69 model_neutral_state_.num_successful_commits); 67 model_neutral_state_.num_successful_commits);
70 value->SetInteger("numSuccessfulBookmarkCommits", 68 value->SetInteger("numSuccessfulBookmarkCommits",
71 model_neutral_state_.num_successful_bookmark_commits); 69 model_neutral_state_.num_successful_bookmark_commits);
72 value->SetInteger("numUpdatesDownloadedTotal", 70 value->SetInteger("numUpdatesDownloadedTotal",
73 model_neutral_state_.num_updates_downloaded_total); 71 model_neutral_state_.num_updates_downloaded_total);
74 value->SetInteger("numTombstoneUpdatesDownloadedTotal", 72 value->SetInteger(
75 model_neutral_state_.num_tombstone_updates_downloaded_total); 73 "numTombstoneUpdatesDownloadedTotal",
76 value->SetInteger("numReflectedUpdatesDownloadedTotal", 74 model_neutral_state_.num_tombstone_updates_downloaded_total);
77 model_neutral_state_.num_reflected_updates_downloaded_total); 75 value->SetInteger(
76 "numReflectedUpdatesDownloadedTotal",
77 model_neutral_state_.num_reflected_updates_downloaded_total);
78 value->SetInteger("numLocalOverwrites", 78 value->SetInteger("numLocalOverwrites",
79 model_neutral_state_.num_local_overwrites); 79 model_neutral_state_.num_local_overwrites);
80 value->SetInteger("numServerOverwrites", 80 value->SetInteger("numServerOverwrites",
81 model_neutral_state_.num_server_overwrites); 81 model_neutral_state_.num_server_overwrites);
82 value->Set("downloadProgressMarkers", 82 value->Set("downloadProgressMarkers",
83 ProgressMarkerMapToValue(download_progress_markers_)); 83 ProgressMarkerMapToValue(download_progress_markers_));
84 value->SetBoolean("isSilenced", is_silenced_); 84 value->SetBoolean("isSilenced", is_silenced_);
85 // We don't care too much if we lose precision here, also. 85 // We don't care too much if we lose precision here, also.
86 value->SetInteger("numEncryptionConflicts", 86 value->SetInteger("numEncryptionConflicts", num_encryption_conflicts_);
87 num_encryption_conflicts_); 87 value->SetInteger("numHierarchyConflicts", num_hierarchy_conflicts_);
88 value->SetInteger("numHierarchyConflicts", 88 value->SetInteger("numServerConflicts", num_server_conflicts_);
89 num_hierarchy_conflicts_);
90 value->SetInteger("numServerConflicts",
91 num_server_conflicts_);
92 value->SetInteger("numEntries", num_entries_); 89 value->SetInteger("numEntries", num_entries_);
93 value->SetString("legacySource", 90 value->SetString("legacySource",
94 GetUpdatesSourceString(legacy_updates_source_)); 91 GetUpdatesSourceString(legacy_updates_source_));
95 value->SetBoolean("notificationsEnabled", notifications_enabled_); 92 value->SetBoolean("notificationsEnabled", notifications_enabled_);
96 93
97 std::unique_ptr<base::DictionaryValue> counter_entries( 94 std::unique_ptr<base::DictionaryValue> counter_entries(
98 new base::DictionaryValue()); 95 new base::DictionaryValue());
99 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; i++) { 96 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; i++) {
100 std::unique_ptr<base::DictionaryValue> type_entries( 97 std::unique_ptr<base::DictionaryValue> type_entries(
101 new base::DictionaryValue()); 98 new base::DictionaryValue());
102 type_entries->SetInteger("numEntries", num_entries_by_type_[i]); 99 type_entries->SetInteger("numEntries", num_entries_by_type_[i]);
103 type_entries->SetInteger("numToDeleteEntries", 100 type_entries->SetInteger("numToDeleteEntries",
104 num_to_delete_entries_by_type_[i]); 101 num_to_delete_entries_by_type_[i]);
105 102
106 const std::string model_type = ModelTypeToString(static_cast<ModelType>(i)); 103 const std::string model_type = ModelTypeToString(static_cast<ModelType>(i));
107 counter_entries->Set(model_type, type_entries.release()); 104 counter_entries->Set(model_type, type_entries.release());
108 } 105 }
109 value->Set("counter_entries", std::move(counter_entries)); 106 value->Set("counter_entries", std::move(counter_entries));
110 return value; 107 return value;
111 } 108 }
112 109
113 std::string SyncSessionSnapshot::ToString() const { 110 std::string SyncSessionSnapshot::ToString() const {
114 std::string json; 111 std::string json;
115 base::JSONWriter::WriteWithOptions( 112 base::JSONWriter::WriteWithOptions(
116 *ToValue(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json); 113 *ToValue(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
117 return json; 114 return json;
118 } 115 }
119 116
120 const ProgressMarkerMap& 117 const ProgressMarkerMap& SyncSessionSnapshot::download_progress_markers()
121 SyncSessionSnapshot::download_progress_markers() const { 118 const {
122 return download_progress_markers_; 119 return download_progress_markers_;
123 } 120 }
124 121
125 bool SyncSessionSnapshot::is_silenced() const { 122 bool SyncSessionSnapshot::is_silenced() const {
126 return is_silenced_; 123 return is_silenced_;
127 } 124 }
128 125
129 int SyncSessionSnapshot::num_encryption_conflicts() const { 126 int SyncSessionSnapshot::num_encryption_conflicts() const {
130 return num_encryption_conflicts_; 127 return num_encryption_conflicts_;
131 } 128 }
(...skipping 23 matching lines...) Expand all
155 } 152 }
156 153
157 bool SyncSessionSnapshot::is_initialized() const { 154 bool SyncSessionSnapshot::is_initialized() const {
158 return is_initialized_; 155 return is_initialized_;
159 } 156 }
160 157
161 const std::vector<int>& SyncSessionSnapshot::num_entries_by_type() const { 158 const std::vector<int>& SyncSessionSnapshot::num_entries_by_type() const {
162 return num_entries_by_type_; 159 return num_entries_by_type_;
163 } 160 }
164 161
165 const std::vector<int>& 162 const std::vector<int>& SyncSessionSnapshot::num_to_delete_entries_by_type()
166 SyncSessionSnapshot::num_to_delete_entries_by_type() const { 163 const {
167 return num_to_delete_entries_by_type_; 164 return num_to_delete_entries_by_type_;
168 } 165 }
169 166
170 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource 167 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource
171 SyncSessionSnapshot::legacy_updates_source() const { 168 SyncSessionSnapshot::legacy_updates_source() const {
172 return legacy_updates_source_; 169 return legacy_updates_source_;
173 } 170 }
174 171
175 } // namespace sessions 172 } // namespace sessions
176 } // namespace syncer 173 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/sessions/sync_session_snapshot.h ('k') | components/sync/sessions/sync_session_snapshot_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698