OLD | NEW |
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/engine/all_status.h" | 5 #include "sync/engine/all_status.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/port.h" | 10 #include "base/port.h" |
11 #include "sync/engine/net/server_connection_manager.h" | 11 #include "sync/engine/net/server_connection_manager.h" |
12 #include "sync/internal_api/public/base/model_type.h" | 12 #include "sync/internal_api/public/base/model_type.h" |
13 #include "sync/sessions/session_state.h" | |
14 | 13 |
15 namespace syncer { | 14 namespace syncer { |
16 | 15 |
17 AllStatus::AllStatus() { | 16 AllStatus::AllStatus() { |
18 status_.initial_sync_ended = true; | 17 status_.initial_sync_ended = true; |
19 status_.notifications_enabled = false; | 18 status_.notifications_enabled = false; |
20 status_.cryptographer_ready = false; | 19 status_.cryptographer_ready = false; |
21 status_.crypto_has_pending_keys = false; | 20 status_.crypto_has_pending_keys = false; |
22 } | 21 } |
23 | 22 |
24 AllStatus::~AllStatus() { | 23 AllStatus::~AllStatus() { |
25 } | 24 } |
26 | 25 |
27 SyncStatus AllStatus::CreateBlankStatus() const { | 26 SyncStatus AllStatus::CreateBlankStatus() const { |
28 // Status is initialized with the previous status value. Variables | 27 // Status is initialized with the previous status value. Variables |
29 // whose values accumulate (e.g. lifetime counters like updates_received) | 28 // whose values accumulate (e.g. lifetime counters like updates_received) |
30 // are not to be cleared here. | 29 // are not to be cleared here. |
31 SyncStatus status = status_; | 30 SyncStatus status = status_; |
32 status.encryption_conflicts = 0; | 31 status.encryption_conflicts = 0; |
33 status.hierarchy_conflicts = 0; | 32 status.hierarchy_conflicts = 0; |
34 status.simple_conflicts = 0; | |
35 status.server_conflicts = 0; | 33 status.server_conflicts = 0; |
36 status.committed_count = 0; | 34 status.committed_count = 0; |
37 status.initial_sync_ended = false; | 35 status.initial_sync_ended = false; |
38 status.updates_available = 0; | 36 status.updates_available = 0; |
39 return status; | 37 return status; |
40 } | 38 } |
41 | 39 |
42 SyncStatus AllStatus::CalcSyncing(const SyncEngineEvent &event) const { | 40 SyncStatus AllStatus::CalcSyncing(const SyncEngineEvent &event) const { |
43 SyncStatus status = CreateBlankStatus(); | 41 SyncStatus status = CreateBlankStatus(); |
44 const sessions::SyncSessionSnapshot& snapshot = event.snapshot; | 42 const sessions::SyncSessionSnapshot& snapshot = event.snapshot; |
45 status.encryption_conflicts = snapshot.num_encryption_conflicts(); | 43 status.encryption_conflicts = snapshot.num_encryption_conflicts(); |
46 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts(); | 44 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts(); |
47 status.simple_conflicts = snapshot.num_simple_conflicts(); | |
48 status.server_conflicts = snapshot.num_server_conflicts(); | 45 status.server_conflicts = snapshot.num_server_conflicts(); |
49 status.committed_count = | 46 status.committed_count = |
50 snapshot.model_neutral_state().num_successful_commits; | 47 snapshot.model_neutral_state().num_successful_commits; |
51 | 48 |
52 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { | 49 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { |
53 status.syncing = true; | 50 status.syncing = true; |
54 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | 51 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { |
55 status.syncing = false; | 52 status.syncing = false; |
56 } | 53 } |
57 | 54 |
58 status.initial_sync_ended |= snapshot.is_share_usable(); | 55 status.initial_sync_ended |= snapshot.is_share_usable(); |
59 | 56 |
60 status.updates_available += snapshot.num_server_changes_remaining(); | 57 status.updates_available += snapshot.num_server_changes_remaining(); |
61 status.sync_protocol_error = | 58 status.sync_protocol_error = |
62 snapshot.model_neutral_state().sync_protocol_error; | 59 snapshot.model_neutral_state().sync_protocol_error; |
63 | 60 |
64 // Accumulate update count only once per session to avoid double-counting. | 61 // Accumulate update count only once per session to avoid double-counting. |
65 // TODO(ncarter): Make this realtime by having the syncer_status | |
66 // counter preserve its value across sessions. http://crbug.com/26339 | |
67 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | 62 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { |
68 status.updates_received += | 63 status.updates_received += |
69 snapshot.model_neutral_state().num_updates_downloaded_total; | 64 snapshot.model_neutral_state().num_updates_downloaded_total; |
70 status.tombstone_updates_received += | 65 status.tombstone_updates_received += |
71 snapshot.model_neutral_state().num_tombstone_updates_downloaded_total; | 66 snapshot.model_neutral_state().num_tombstone_updates_downloaded_total; |
72 status.reflected_updates_received += | 67 status.reflected_updates_received += |
73 snapshot.model_neutral_state().num_reflected_updates_downloaded_total; | 68 snapshot.model_neutral_state().num_reflected_updates_downloaded_total; |
74 status.num_commits_total += | 69 status.num_commits_total += |
75 snapshot.model_neutral_state().num_successful_commits; | 70 snapshot.model_neutral_state().num_successful_commits; |
76 status.num_local_overwrites_total += | 71 status.num_local_overwrites_total += |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 switch(source) { | 174 switch(source) { |
180 case NUDGE_SOURCE_LOCAL_REFRESH: | 175 case NUDGE_SOURCE_LOCAL_REFRESH: |
181 status_.nudge_source_local_refresh++; | 176 status_.nudge_source_local_refresh++; |
182 return; | 177 return; |
183 case NUDGE_SOURCE_LOCAL: | 178 case NUDGE_SOURCE_LOCAL: |
184 status_.nudge_source_local++; | 179 status_.nudge_source_local++; |
185 return; | 180 return; |
186 case NUDGE_SOURCE_NOTIFICATION: | 181 case NUDGE_SOURCE_NOTIFICATION: |
187 status_.nudge_source_notification++; | 182 status_.nudge_source_notification++; |
188 return; | 183 return; |
189 case NUDGE_SOURCE_CONTINUATION: | |
190 status_.nudge_source_continuation++; | |
191 return; | |
192 case NUDGE_SOURCE_UNKNOWN: | 184 case NUDGE_SOURCE_UNKNOWN: |
193 break; | 185 break; |
194 } | 186 } |
195 // If we're here, the source is most likely | 187 // If we're here, the source is most likely |
196 // NUDGE_SOURCE_UNKNOWN. That shouldn't happen. | 188 // NUDGE_SOURCE_UNKNOWN. That shouldn't happen. |
197 NOTREACHED(); | 189 NOTREACHED(); |
198 } | 190 } |
199 | 191 |
200 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus) | 192 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus) |
201 : allstatus_(allstatus) { | 193 : allstatus_(allstatus) { |
202 allstatus->mutex_.Acquire(); | 194 allstatus->mutex_.Acquire(); |
203 } | 195 } |
204 | 196 |
205 ScopedStatusLock::~ScopedStatusLock() { | 197 ScopedStatusLock::~ScopedStatusLock() { |
206 allstatus_->mutex_.Release(); | 198 allstatus_->mutex_.Release(); |
207 } | 199 } |
208 | 200 |
209 } // namespace syncer | 201 } // namespace syncer |
OLD | NEW |