OLD | NEW |
| (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/engine/all_status.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "base/logging.h" | |
10 #include "sync/engine/net/server_connection_manager.h" | |
11 #include "sync/engine/sync_cycle_event.h" | |
12 #include "sync/internal_api/public/base/model_type.h" | |
13 | |
14 namespace syncer { | |
15 | |
16 AllStatus::AllStatus() { | |
17 status_.notifications_enabled = false; | |
18 status_.cryptographer_ready = false; | |
19 status_.crypto_has_pending_keys = false; | |
20 } | |
21 | |
22 AllStatus::~AllStatus() { | |
23 } | |
24 | |
25 SyncStatus AllStatus::CreateBlankStatus() const { | |
26 // Status is initialized with the previous status value. Variables | |
27 // whose values accumulate (e.g. lifetime counters like updates_received) | |
28 // are not to be cleared here. | |
29 SyncStatus status = status_; | |
30 status.encryption_conflicts = 0; | |
31 status.hierarchy_conflicts = 0; | |
32 status.server_conflicts = 0; | |
33 status.committed_count = 0; | |
34 return status; | |
35 } | |
36 | |
37 SyncStatus AllStatus::CalcSyncing(const SyncCycleEvent &event) const { | |
38 SyncStatus status = CreateBlankStatus(); | |
39 const sessions::SyncSessionSnapshot& snapshot = event.snapshot; | |
40 status.encryption_conflicts = snapshot.num_encryption_conflicts(); | |
41 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts(); | |
42 status.server_conflicts = snapshot.num_server_conflicts(); | |
43 status.committed_count = | |
44 snapshot.model_neutral_state().num_successful_commits; | |
45 | |
46 if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_BEGIN) { | |
47 status.syncing = true; | |
48 } else if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_ENDED) { | |
49 status.syncing = false; | |
50 } | |
51 | |
52 status.num_entries_by_type = snapshot.num_entries_by_type(); | |
53 status.num_to_delete_entries_by_type = | |
54 snapshot.num_to_delete_entries_by_type(); | |
55 | |
56 // Accumulate update count only once per session to avoid double-counting. | |
57 if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_ENDED) { | |
58 status.updates_received += | |
59 snapshot.model_neutral_state().num_updates_downloaded_total; | |
60 status.tombstone_updates_received += | |
61 snapshot.model_neutral_state().num_tombstone_updates_downloaded_total; | |
62 status.reflected_updates_received += | |
63 snapshot.model_neutral_state().num_reflected_updates_downloaded_total; | |
64 status.num_commits_total += | |
65 snapshot.model_neutral_state().num_successful_commits; | |
66 status.num_local_overwrites_total += | |
67 snapshot.model_neutral_state().num_local_overwrites; | |
68 status.num_server_overwrites_total += | |
69 snapshot.model_neutral_state().num_server_overwrites; | |
70 } | |
71 return status; | |
72 } | |
73 | |
74 void AllStatus::OnSyncCycleEvent(const SyncCycleEvent& event) { | |
75 ScopedStatusLock lock(this); | |
76 switch (event.what_happened) { | |
77 case SyncCycleEvent::SYNC_CYCLE_BEGIN: | |
78 case SyncCycleEvent::STATUS_CHANGED: | |
79 case SyncCycleEvent::SYNC_CYCLE_ENDED: | |
80 status_ = CalcSyncing(event); | |
81 break; | |
82 default: | |
83 LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened; | |
84 break; | |
85 } | |
86 } | |
87 | |
88 void AllStatus::OnActionableError( | |
89 const SyncProtocolError& sync_protocol_error) { | |
90 ScopedStatusLock lock(this); | |
91 status_ = CreateBlankStatus(); | |
92 status_.sync_protocol_error = sync_protocol_error; | |
93 } | |
94 | |
95 void AllStatus::OnRetryTimeChanged(base::Time retry_time) { | |
96 ScopedStatusLock lock(this); | |
97 status_.retry_time = retry_time; | |
98 } | |
99 | |
100 void AllStatus::OnThrottledTypesChanged(ModelTypeSet throttled_types) { | |
101 ScopedStatusLock lock(this); | |
102 status_.throttled_types = throttled_types; | |
103 } | |
104 | |
105 void AllStatus::OnMigrationRequested(ModelTypeSet) {} | |
106 | |
107 void AllStatus::OnProtocolEvent(const ProtocolEvent&) {} | |
108 | |
109 SyncStatus AllStatus::status() const { | |
110 base::AutoLock lock(mutex_); | |
111 return status_; | |
112 } | |
113 | |
114 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { | |
115 ScopedStatusLock lock(this); | |
116 status_.notifications_enabled = notifications_enabled; | |
117 } | |
118 | |
119 void AllStatus::IncrementNotificationsReceived() { | |
120 ScopedStatusLock lock(this); | |
121 ++status_.notifications_received; | |
122 } | |
123 | |
124 void AllStatus::SetEncryptedTypes(ModelTypeSet types) { | |
125 ScopedStatusLock lock(this); | |
126 status_.encrypted_types = types; | |
127 } | |
128 | |
129 void AllStatus::SetCryptographerReady(bool ready) { | |
130 ScopedStatusLock lock(this); | |
131 status_.cryptographer_ready = ready; | |
132 } | |
133 | |
134 void AllStatus::SetCryptoHasPendingKeys(bool has_pending_keys) { | |
135 ScopedStatusLock lock(this); | |
136 status_.crypto_has_pending_keys = has_pending_keys; | |
137 } | |
138 | |
139 void AllStatus::SetPassphraseType(PassphraseType type) { | |
140 ScopedStatusLock lock(this); | |
141 status_.passphrase_type = type; | |
142 } | |
143 | |
144 void AllStatus::SetHasKeystoreKey(bool has_keystore_key) { | |
145 ScopedStatusLock lock(this); | |
146 status_.has_keystore_key = has_keystore_key; | |
147 } | |
148 | |
149 void AllStatus::SetKeystoreMigrationTime(const base::Time& migration_time) { | |
150 ScopedStatusLock lock(this); | |
151 status_.keystore_migration_time = migration_time; | |
152 } | |
153 | |
154 void AllStatus::SetSyncId(const std::string& sync_id) { | |
155 ScopedStatusLock lock(this); | |
156 status_.sync_id = sync_id; | |
157 } | |
158 | |
159 void AllStatus::SetInvalidatorClientId( | |
160 const std::string& invalidator_client_id) { | |
161 ScopedStatusLock lock(this); | |
162 status_.invalidator_client_id = invalidator_client_id; | |
163 } | |
164 | |
165 void AllStatus::IncrementNudgeCounter(NudgeSource source) { | |
166 ScopedStatusLock lock(this); | |
167 switch (source) { | |
168 case NUDGE_SOURCE_LOCAL_REFRESH: | |
169 status_.nudge_source_local_refresh++; | |
170 return; | |
171 case NUDGE_SOURCE_LOCAL: | |
172 status_.nudge_source_local++; | |
173 return; | |
174 case NUDGE_SOURCE_NOTIFICATION: | |
175 status_.nudge_source_notification++; | |
176 return; | |
177 case NUDGE_SOURCE_UNKNOWN: | |
178 break; | |
179 } | |
180 // If we're here, the source is most likely | |
181 // NUDGE_SOURCE_UNKNOWN. That shouldn't happen. | |
182 NOTREACHED(); | |
183 } | |
184 | |
185 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus) | |
186 : allstatus_(allstatus) { | |
187 allstatus->mutex_.Acquire(); | |
188 } | |
189 | |
190 ScopedStatusLock::~ScopedStatusLock() { | |
191 allstatus_->mutex_.Release(); | |
192 } | |
193 | |
194 } // namespace syncer | |
OLD | NEW |