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" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 // are not to be cleared here. | 28 // are not to be cleared here. |
29 SyncStatus status = status_; | 29 SyncStatus status = status_; |
30 status.encryption_conflicts = 0; | 30 status.encryption_conflicts = 0; |
31 status.hierarchy_conflicts = 0; | 31 status.hierarchy_conflicts = 0; |
32 status.server_conflicts = 0; | 32 status.server_conflicts = 0; |
33 status.committed_count = 0; | 33 status.committed_count = 0; |
34 status.updates_available = 0; | 34 status.updates_available = 0; |
35 return status; | 35 return status; |
36 } | 36 } |
37 | 37 |
38 SyncStatus AllStatus::CalcSyncing(const SyncEngineEvent &event) const { | 38 SyncStatus AllStatus::CalcSyncing(const SyncCycleEvent &event) const { |
39 SyncStatus status = CreateBlankStatus(); | 39 SyncStatus status = CreateBlankStatus(); |
40 const sessions::SyncSessionSnapshot& snapshot = event.snapshot; | 40 const sessions::SyncSessionSnapshot& snapshot = event.snapshot; |
41 status.encryption_conflicts = snapshot.num_encryption_conflicts(); | 41 status.encryption_conflicts = snapshot.num_encryption_conflicts(); |
42 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts(); | 42 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts(); |
43 status.server_conflicts = snapshot.num_server_conflicts(); | 43 status.server_conflicts = snapshot.num_server_conflicts(); |
44 status.committed_count = | 44 status.committed_count = |
45 snapshot.model_neutral_state().num_successful_commits; | 45 snapshot.model_neutral_state().num_successful_commits; |
46 | 46 |
47 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { | 47 if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_BEGIN) { |
48 status.syncing = true; | 48 status.syncing = true; |
49 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | 49 } else if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_ENDED) { |
50 status.syncing = false; | 50 status.syncing = false; |
51 } | 51 } |
52 | 52 |
53 status.updates_available += snapshot.num_server_changes_remaining(); | 53 status.updates_available += snapshot.num_server_changes_remaining(); |
54 status.sync_protocol_error = | |
55 snapshot.model_neutral_state().sync_protocol_error; | |
Nicolas Zea
2014/02/10 23:15:16
Why is this removed?
rlarocque
2014/02/11 00:19:43
It's handled in OnActionableError() now.
I suppos
| |
56 | 54 |
57 status.num_entries_by_type = snapshot.num_entries_by_type(); | 55 status.num_entries_by_type = snapshot.num_entries_by_type(); |
58 status.num_to_delete_entries_by_type = | 56 status.num_to_delete_entries_by_type = |
59 snapshot.num_to_delete_entries_by_type(); | 57 snapshot.num_to_delete_entries_by_type(); |
60 | 58 |
61 // Accumulate update count only once per session to avoid double-counting. | 59 // Accumulate update count only once per session to avoid double-counting. |
62 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | 60 if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_ENDED) { |
63 status.updates_received += | 61 status.updates_received += |
64 snapshot.model_neutral_state().num_updates_downloaded_total; | 62 snapshot.model_neutral_state().num_updates_downloaded_total; |
65 status.tombstone_updates_received += | 63 status.tombstone_updates_received += |
66 snapshot.model_neutral_state().num_tombstone_updates_downloaded_total; | 64 snapshot.model_neutral_state().num_tombstone_updates_downloaded_total; |
67 status.reflected_updates_received += | 65 status.reflected_updates_received += |
68 snapshot.model_neutral_state().num_reflected_updates_downloaded_total; | 66 snapshot.model_neutral_state().num_reflected_updates_downloaded_total; |
69 status.num_commits_total += | 67 status.num_commits_total += |
70 snapshot.model_neutral_state().num_successful_commits; | 68 snapshot.model_neutral_state().num_successful_commits; |
71 status.num_local_overwrites_total += | 69 status.num_local_overwrites_total += |
72 snapshot.model_neutral_state().num_local_overwrites; | 70 snapshot.model_neutral_state().num_local_overwrites; |
(...skipping 12 matching lines...) Expand all Loading... | |
85 if (snapshot.model_neutral_state().num_successful_commits == 0 && | 83 if (snapshot.model_neutral_state().num_successful_commits == 0 && |
86 snapshot.model_neutral_state().num_updates_downloaded_total == 0) { | 84 snapshot.model_neutral_state().num_updates_downloaded_total == 0) { |
87 ++status.useless_sync_cycles; | 85 ++status.useless_sync_cycles; |
88 } else { | 86 } else { |
89 ++status.useful_sync_cycles; | 87 ++status.useful_sync_cycles; |
90 } | 88 } |
91 } | 89 } |
92 return status; | 90 return status; |
93 } | 91 } |
94 | 92 |
95 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { | 93 void AllStatus::OnSyncCycleEvent(const SyncCycleEvent& event) { |
96 ScopedStatusLock lock(this); | 94 ScopedStatusLock lock(this); |
97 switch (event.what_happened) { | 95 switch (event.what_happened) { |
98 case SyncEngineEvent::SYNC_CYCLE_BEGIN: | 96 case SyncCycleEvent::SYNC_CYCLE_BEGIN: |
99 case SyncEngineEvent::STATUS_CHANGED: | 97 case SyncCycleEvent::STATUS_CHANGED: |
100 case SyncEngineEvent::SYNC_CYCLE_ENDED: | 98 case SyncCycleEvent::SYNC_CYCLE_ENDED: |
101 status_ = CalcSyncing(event); | 99 status_ = CalcSyncing(event); |
102 break; | 100 break; |
103 case SyncEngineEvent::STOP_SYNCING_PERMANENTLY: | |
104 break; | |
105 case SyncEngineEvent::ACTIONABLE_ERROR: | |
106 status_ = CreateBlankStatus(); | |
107 status_.sync_protocol_error = | |
108 event.snapshot.model_neutral_state().sync_protocol_error; | |
109 break; | |
110 case SyncEngineEvent::RETRY_TIME_CHANGED: | |
111 status_.retry_time = event.retry_time; | |
112 break; | |
113 case SyncEngineEvent::THROTTLED_TYPES_CHANGED: | |
114 status_.throttled_types = event.throttled_types; | |
115 break; | |
116 default: | 101 default: |
117 LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened; | 102 LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened; |
118 break; | 103 break; |
119 } | 104 } |
120 } | 105 } |
121 | 106 |
107 void AllStatus::OnActionableError( | |
108 const SyncProtocolError& sync_protocol_error) { | |
109 ScopedStatusLock lock(this); | |
110 status_ = CreateBlankStatus(); | |
111 status_.sync_protocol_error = sync_protocol_error; | |
112 } | |
113 | |
114 void AllStatus::OnRetryTimeChanged(base::Time retry_time) { | |
115 ScopedStatusLock lock(this); | |
116 status_.retry_time = retry_time; | |
117 } | |
118 | |
119 void AllStatus::OnThrottledTypesChanged(ModelTypeSet throttled_types) { | |
120 ScopedStatusLock lock(this); | |
121 status_.throttled_types = throttled_types; | |
122 } | |
123 | |
122 SyncStatus AllStatus::status() const { | 124 SyncStatus AllStatus::status() const { |
123 base::AutoLock lock(mutex_); | 125 base::AutoLock lock(mutex_); |
124 return status_; | 126 return status_; |
125 } | 127 } |
126 | 128 |
127 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { | 129 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { |
128 ScopedStatusLock lock(this); | 130 ScopedStatusLock lock(this); |
129 status_.notifications_enabled = notifications_enabled; | 131 status_.notifications_enabled = notifications_enabled; |
130 } | 132 } |
131 | 133 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus) | 200 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus) |
199 : allstatus_(allstatus) { | 201 : allstatus_(allstatus) { |
200 allstatus->mutex_.Acquire(); | 202 allstatus->mutex_.Acquire(); |
201 } | 203 } |
202 | 204 |
203 ScopedStatusLock::~ScopedStatusLock() { | 205 ScopedStatusLock::~ScopedStatusLock() { |
204 allstatus_->mutex_.Release(); | 206 allstatus_->mutex_.Release(); |
205 } | 207 } |
206 | 208 |
207 } // namespace syncer | 209 } // namespace syncer |
OLD | NEW |