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