Remove unused parameter.
[chromium-blink-merge.git] / sync / internal_api / public / sessions / sync_session_snapshot.cc
blob4e7a2b11b9148802a43bed46095ec0ff6c9eb3f1
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.
5 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
7 #include "base/json/json_writer.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10 #include "sync/protocol/proto_enum_conversions.h"
12 namespace syncer {
13 namespace sessions {
15 SyncSessionSnapshot::SyncSessionSnapshot()
16 : is_silenced_(false),
17 num_encryption_conflicts_(0),
18 num_hierarchy_conflicts_(0),
19 num_server_conflicts_(0),
20 notifications_enabled_(false),
21 num_entries_(0),
22 num_entries_by_type_(MODEL_TYPE_COUNT, 0),
23 num_to_delete_entries_by_type_(MODEL_TYPE_COUNT, 0),
24 is_initialized_(false) {
27 SyncSessionSnapshot::SyncSessionSnapshot(
28 const ModelNeutralState& model_neutral_state,
29 const ProgressMarkerMap& download_progress_markers,
30 bool is_silenced,
31 int num_encryption_conflicts,
32 int num_hierarchy_conflicts,
33 int num_server_conflicts,
34 bool notifications_enabled,
35 size_t num_entries,
36 base::Time sync_start_time,
37 const std::vector<int>& num_entries_by_type,
38 const std::vector<int>& num_to_delete_entries_by_type,
39 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source)
40 : model_neutral_state_(model_neutral_state),
41 download_progress_markers_(download_progress_markers),
42 is_silenced_(is_silenced),
43 num_encryption_conflicts_(num_encryption_conflicts),
44 num_hierarchy_conflicts_(num_hierarchy_conflicts),
45 num_server_conflicts_(num_server_conflicts),
46 notifications_enabled_(notifications_enabled),
47 num_entries_(num_entries),
48 sync_start_time_(sync_start_time),
49 num_entries_by_type_(num_entries_by_type),
50 num_to_delete_entries_by_type_(num_to_delete_entries_by_type),
51 legacy_updates_source_(legacy_updates_source),
52 is_initialized_(true) {
55 SyncSessionSnapshot::~SyncSessionSnapshot() {}
57 base::DictionaryValue* SyncSessionSnapshot::ToValue() const {
58 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
59 value->SetInteger("numSuccessfulCommits",
60 model_neutral_state_.num_successful_commits);
61 value->SetInteger("numSuccessfulBookmarkCommits",
62 model_neutral_state_.num_successful_bookmark_commits);
63 value->SetInteger("numUpdatesDownloadedTotal",
64 model_neutral_state_.num_updates_downloaded_total);
65 value->SetInteger("numTombstoneUpdatesDownloadedTotal",
66 model_neutral_state_.num_tombstone_updates_downloaded_total);
67 value->SetInteger("numReflectedUpdatesDownloadedTotal",
68 model_neutral_state_.num_reflected_updates_downloaded_total);
69 value->SetInteger("numLocalOverwrites",
70 model_neutral_state_.num_local_overwrites);
71 value->SetInteger("numServerOverwrites",
72 model_neutral_state_.num_server_overwrites);
73 value->Set("downloadProgressMarkers",
74 ProgressMarkerMapToValue(download_progress_markers_).release());
75 value->SetBoolean("isSilenced", is_silenced_);
76 // We don't care too much if we lose precision here, also.
77 value->SetInteger("numEncryptionConflicts",
78 num_encryption_conflicts_);
79 value->SetInteger("numHierarchyConflicts",
80 num_hierarchy_conflicts_);
81 value->SetInteger("numServerConflicts",
82 num_server_conflicts_);
83 value->SetInteger("numEntries", num_entries_);
84 value->SetString("legacySource",
85 GetUpdatesSourceString(legacy_updates_source_));
86 value->SetBoolean("notificationsEnabled", notifications_enabled_);
88 scoped_ptr<base::DictionaryValue> counter_entries(
89 new base::DictionaryValue());
90 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; i++) {
91 scoped_ptr<base::DictionaryValue> type_entries(new base::DictionaryValue());
92 type_entries->SetInteger("numEntries", num_entries_by_type_[i]);
93 type_entries->SetInteger("numToDeleteEntries",
94 num_to_delete_entries_by_type_[i]);
96 const std::string model_type = ModelTypeToString(static_cast<ModelType>(i));
97 counter_entries->Set(model_type, type_entries.release());
99 value->Set("counter_entries", counter_entries.release());
100 return value.release();
103 std::string SyncSessionSnapshot::ToString() const {
104 scoped_ptr<base::DictionaryValue> value(ToValue());
105 std::string json;
106 base::JSONWriter::WriteWithOptions(value.get(),
107 base::JSONWriter::OPTIONS_PRETTY_PRINT,
108 &json);
109 return json;
112 const ProgressMarkerMap&
113 SyncSessionSnapshot::download_progress_markers() const {
114 return download_progress_markers_;
117 bool SyncSessionSnapshot::is_silenced() const {
118 return is_silenced_;
121 int SyncSessionSnapshot::num_encryption_conflicts() const {
122 return num_encryption_conflicts_;
125 int SyncSessionSnapshot::num_hierarchy_conflicts() const {
126 return num_hierarchy_conflicts_;
129 int SyncSessionSnapshot::num_server_conflicts() const {
130 return num_server_conflicts_;
133 bool SyncSessionSnapshot::notifications_enabled() const {
134 return notifications_enabled_;
137 size_t SyncSessionSnapshot::num_entries() const {
138 return num_entries_;
141 base::Time SyncSessionSnapshot::sync_start_time() const {
142 return sync_start_time_;
145 bool SyncSessionSnapshot::is_initialized() const {
146 return is_initialized_;
149 const std::vector<int>& SyncSessionSnapshot::num_entries_by_type() const {
150 return num_entries_by_type_;
153 const std::vector<int>&
154 SyncSessionSnapshot::num_to_delete_entries_by_type() const {
155 return num_to_delete_entries_by_type_;
158 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource
159 SyncSessionSnapshot::legacy_updates_source() const {
160 return legacy_updates_source_;
163 } // namespace sessions
164 } // namespace syncer