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"
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),
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
,
31 int num_encryption_conflicts
,
32 int num_hierarchy_conflicts
,
33 int num_server_conflicts
,
34 bool notifications_enabled
,
36 base::Time sync_start_time
,
37 base::Time poll_finish_time
,
38 const std::vector
<int>& num_entries_by_type
,
39 const std::vector
<int>& num_to_delete_entries_by_type
,
40 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source
)
41 : model_neutral_state_(model_neutral_state
),
42 download_progress_markers_(download_progress_markers
),
43 is_silenced_(is_silenced
),
44 num_encryption_conflicts_(num_encryption_conflicts
),
45 num_hierarchy_conflicts_(num_hierarchy_conflicts
),
46 num_server_conflicts_(num_server_conflicts
),
47 notifications_enabled_(notifications_enabled
),
48 num_entries_(num_entries
),
49 sync_start_time_(sync_start_time
),
50 poll_finish_time_(poll_finish_time
),
51 num_entries_by_type_(num_entries_by_type
),
52 num_to_delete_entries_by_type_(num_to_delete_entries_by_type
),
53 legacy_updates_source_(legacy_updates_source
),
54 is_initialized_(true) {
57 SyncSessionSnapshot::~SyncSessionSnapshot() {}
59 scoped_ptr
<base::DictionaryValue
> SyncSessionSnapshot::ToValue() const {
60 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
61 value
->SetInteger("numSuccessfulCommits",
62 model_neutral_state_
.num_successful_commits
);
63 value
->SetInteger("numSuccessfulBookmarkCommits",
64 model_neutral_state_
.num_successful_bookmark_commits
);
65 value
->SetInteger("numUpdatesDownloadedTotal",
66 model_neutral_state_
.num_updates_downloaded_total
);
67 value
->SetInteger("numTombstoneUpdatesDownloadedTotal",
68 model_neutral_state_
.num_tombstone_updates_downloaded_total
);
69 value
->SetInteger("numReflectedUpdatesDownloadedTotal",
70 model_neutral_state_
.num_reflected_updates_downloaded_total
);
71 value
->SetInteger("numLocalOverwrites",
72 model_neutral_state_
.num_local_overwrites
);
73 value
->SetInteger("numServerOverwrites",
74 model_neutral_state_
.num_server_overwrites
);
75 value
->Set("downloadProgressMarkers",
76 ProgressMarkerMapToValue(download_progress_markers_
));
77 value
->SetBoolean("isSilenced", is_silenced_
);
78 // We don't care too much if we lose precision here, also.
79 value
->SetInteger("numEncryptionConflicts",
80 num_encryption_conflicts_
);
81 value
->SetInteger("numHierarchyConflicts",
82 num_hierarchy_conflicts_
);
83 value
->SetInteger("numServerConflicts",
84 num_server_conflicts_
);
85 value
->SetInteger("numEntries", num_entries_
);
86 value
->SetString("legacySource",
87 GetUpdatesSourceString(legacy_updates_source_
));
88 value
->SetBoolean("notificationsEnabled", notifications_enabled_
);
90 scoped_ptr
<base::DictionaryValue
> counter_entries(
91 new base::DictionaryValue());
92 for (int i
= FIRST_REAL_MODEL_TYPE
; i
< MODEL_TYPE_COUNT
; i
++) {
93 scoped_ptr
<base::DictionaryValue
> type_entries(new base::DictionaryValue());
94 type_entries
->SetInteger("numEntries", num_entries_by_type_
[i
]);
95 type_entries
->SetInteger("numToDeleteEntries",
96 num_to_delete_entries_by_type_
[i
]);
98 const std::string model_type
= ModelTypeToString(static_cast<ModelType
>(i
));
99 counter_entries
->Set(model_type
, type_entries
.release());
101 value
->Set("counter_entries", counter_entries
.Pass());
105 std::string
SyncSessionSnapshot::ToString() const {
107 base::JSONWriter::WriteWithOptions(
108 *ToValue(), base::JSONWriter::OPTIONS_PRETTY_PRINT
, &json
);
112 const ProgressMarkerMap
&
113 SyncSessionSnapshot::download_progress_markers() const {
114 return download_progress_markers_
;
117 bool SyncSessionSnapshot::is_silenced() const {
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 {
141 base::Time
SyncSessionSnapshot::sync_start_time() const {
142 return sync_start_time_
;
145 base::Time
SyncSessionSnapshot::poll_finish_time() const {
146 return poll_finish_time_
;
149 bool SyncSessionSnapshot::is_initialized() const {
150 return is_initialized_
;
153 const std::vector
<int>& SyncSessionSnapshot::num_entries_by_type() const {
154 return num_entries_by_type_
;
157 const std::vector
<int>&
158 SyncSessionSnapshot::num_to_delete_entries_by_type() const {
159 return num_to_delete_entries_by_type_
;
162 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource
163 SyncSessionSnapshot::legacy_updates_source() const {
164 return legacy_updates_source_
;
167 } // namespace sessions
168 } // namespace syncer