OLD | NEW |
---|---|
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "chrome/browser/sync/engine/all_status.h" | 5 #include "chrome/browser/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 "chrome/browser/sync/engine/net/server_connection_manager.h" | 11 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
12 #include "chrome/browser/sync/protocol/service_constants.h" | 12 #include "chrome/browser/sync/protocol/service_constants.h" |
13 #include "chrome/browser/sync/sessions/session_state.h" | 13 #include "chrome/browser/sync/sessions/session_state.h" |
14 #include "chrome/browser/sync/syncable/directory_manager.h" | 14 #include "chrome/browser/sync/syncable/directory_manager.h" |
15 | 15 |
16 namespace browser_sync { | 16 namespace browser_sync { |
17 | 17 |
18 const char* AllStatus::GetSyncStatusString(SyncStatus icon) { | 18 const char* AllStatus::GetSyncStatusString( |
19 const char* strings[] = {"OFFLINE", "OFFLINE_UNSYNCED", "SYNCING", "READY", | 19 sync_api::SyncManager::Status::Summary summary) { |
tim (not reviewing)
2011/01/11 19:14:23
Did you consider moving this to syncapi too? We sh
ncarter (slow)
2011/01/13 00:06:13
Moved this body to PSS. This function was never a
| |
20 "CONFLICT", "OFFLINE_UNUSABLE"}; | 20 const char* strings[] = {"INVALID", "OFFLINE", "OFFLINE_UNSYNCED", "SYNCING", |
21 COMPILE_ASSERT(arraysize(strings) == ICON_STATUS_COUNT, enum_indexed_array); | 21 "READY", "CONFLICT", "OFFLINE_UNUSABLE"}; |
22 if (icon < 0 || icon >= static_cast<SyncStatus>(arraysize(strings))) | 22 COMPILE_ASSERT(arraysize(strings) == |
23 LOG(FATAL) << "Illegal Icon State:" << icon; | 23 sync_api::SyncManager::Status::SUMMARY_STATUS_COUNT, |
24 return strings[icon]; | 24 enum_indexed_array); |
25 if (summary < 0 || | |
26 summary >= sync_api::SyncManager::Status::SUMMARY_STATUS_COUNT) { | |
27 LOG(FATAL) << "Illegal Summary Value: " << summary; | |
28 } | |
29 return strings[summary]; | |
25 } | 30 } |
26 | 31 |
27 static const AllStatus::Status init_status = | 32 static const sync_api::SyncManager::Status init_status = |
28 { AllStatus::OFFLINE }; | 33 { sync_api::SyncManager::Status::OFFLINE }; |
29 | 34 |
30 AllStatus::AllStatus() : status_(init_status) { | 35 AllStatus::AllStatus() : status_(init_status) { |
31 status_.initial_sync_ended = true; | 36 status_.initial_sync_ended = true; |
32 status_.notifications_enabled = false; | 37 status_.notifications_enabled = false; |
33 } | 38 } |
34 | 39 |
35 AllStatus::~AllStatus() { | 40 AllStatus::~AllStatus() { |
36 } | 41 } |
37 | 42 |
38 AllStatus::Status AllStatus::CreateBlankStatus() const { | 43 sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { |
39 Status status = status_; | 44 // Status is initialized with the previous status value. Variables |
45 // whose values accumulate (e.g. lifetime counters like updates_received) | |
46 // are not to be cleared here. | |
47 sync_api::SyncManager::Status status = status_; | |
40 status.syncing = true; | 48 status.syncing = true; |
41 status.unsynced_count = 0; | 49 status.unsynced_count = 0; |
42 status.conflicting_count = 0; | 50 status.conflicting_count = 0; |
43 status.initial_sync_ended = false; | 51 status.initial_sync_ended = false; |
44 status.syncer_stuck = false; | 52 status.syncer_stuck = false; |
45 status.max_consecutive_errors = 0; | 53 status.max_consecutive_errors = 0; |
46 status.server_broken = false; | 54 status.server_broken = false; |
47 status.updates_available = 0; | 55 status.updates_available = 0; |
48 status.updates_received = 0; | |
49 return status; | 56 return status; |
50 } | 57 } |
51 | 58 |
52 AllStatus::Status AllStatus::CalcSyncing(const SyncEngineEvent &event) const { | 59 sync_api::SyncManager::Status AllStatus::CalcSyncing( |
53 Status status = CreateBlankStatus(); | 60 const SyncEngineEvent &event) const { |
61 sync_api::SyncManager::Status status = CreateBlankStatus(); | |
54 const sessions::SyncSessionSnapshot* snapshot = event.snapshot; | 62 const sessions::SyncSessionSnapshot* snapshot = event.snapshot; |
55 status.unsynced_count += static_cast<int>(snapshot->unsynced_count); | 63 status.unsynced_count += static_cast<int>(snapshot->unsynced_count); |
56 status.conflicting_count += snapshot->errors.num_conflicting_commits; | 64 status.conflicting_count += snapshot->errors.num_conflicting_commits; |
57 // The syncer may not be done yet, which could cause conflicting updates. | 65 // The syncer may not be done yet, which could cause conflicting updates. |
58 // But this is only used for status, so it is better to have visibility. | 66 // But this is only used for status, so it is better to have visibility. |
59 status.conflicting_count += snapshot->num_conflicting_updates; | 67 status.conflicting_count += snapshot->num_conflicting_updates; |
60 | 68 |
61 status.syncing |= snapshot->syncer_status.syncing; | 69 status.syncing |= snapshot->syncer_status.syncing; |
62 status.syncing = snapshot->has_more_to_sync && snapshot->is_silenced; | 70 status.syncing = snapshot->has_more_to_sync && snapshot->is_silenced; |
63 status.initial_sync_ended |= snapshot->is_share_usable; | 71 status.initial_sync_ended |= snapshot->is_share_usable; |
64 status.syncer_stuck |= snapshot->syncer_status.syncer_stuck; | 72 status.syncer_stuck |= snapshot->syncer_status.syncer_stuck; |
65 | 73 |
66 const sessions::ErrorCounters& errors(snapshot->errors); | 74 const sessions::ErrorCounters& errors(snapshot->errors); |
67 if (errors.consecutive_errors > status.max_consecutive_errors) | 75 if (errors.consecutive_errors > status.max_consecutive_errors) |
68 status.max_consecutive_errors = errors.consecutive_errors; | 76 status.max_consecutive_errors = errors.consecutive_errors; |
69 | 77 |
70 // 100 is an arbitrary limit. | 78 // 100 is an arbitrary limit. |
71 if (errors.consecutive_transient_error_commits > 100) | 79 if (errors.consecutive_transient_error_commits > 100) |
72 status.server_broken = true; | 80 status.server_broken = true; |
73 | 81 |
74 status.updates_available += snapshot->num_server_changes_remaining; | 82 status.updates_available += snapshot->num_server_changes_remaining; |
75 status.updates_received += snapshot->max_local_timestamp; | 83 |
84 // Accumulate update count only once per session to avoid double-counting. | |
85 // TODO(ncarter): make this realtime by having the syncer_status | |
86 // counter preserve its value across sessions. | |
tim (not reviewing)
2011/01/11 19:14:23
Referencing bug 26339 here would be better than no
ncarter (slow)
2011/01/13 00:06:13
Done.
| |
87 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { | |
88 status.updates_received += snapshot->syncer_status.num_updates_downloaded; | |
89 status.tombstone_updates_received += | |
90 snapshot->syncer_status.num_tombstone_updates_downloaded; | |
91 } | |
76 return status; | 92 return status; |
77 } | 93 } |
78 | 94 |
79 void AllStatus::CalcStatusChanges() { | 95 void AllStatus::CalcStatusChanges() { |
80 const bool unsynced_changes = status_.unsynced_count > 0; | 96 const bool unsynced_changes = status_.unsynced_count > 0; |
81 const bool online = status_.authenticated && | 97 const bool online = status_.authenticated && |
82 status_.server_reachable && status_.server_up && !status_.server_broken; | 98 status_.server_reachable && status_.server_up && !status_.server_broken; |
83 if (online) { | 99 if (online) { |
84 if (status_.syncer_stuck) | 100 if (status_.syncer_stuck) |
85 status_.icon = CONFLICT; | 101 status_.summary = sync_api::SyncManager::Status::CONFLICT; |
86 else if (unsynced_changes || status_.syncing) | 102 else if (unsynced_changes || status_.syncing) |
87 status_.icon = SYNCING; | 103 status_.summary = sync_api::SyncManager::Status::SYNCING; |
88 else | 104 else |
89 status_.icon = READY; | 105 status_.summary = sync_api::SyncManager::Status::READY; |
90 } else if (!status_.initial_sync_ended) { | 106 } else if (!status_.initial_sync_ended) { |
91 status_.icon = OFFLINE_UNUSABLE; | 107 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNUSABLE; |
92 } else if (unsynced_changes) { | 108 } else if (unsynced_changes) { |
93 status_.icon = OFFLINE_UNSYNCED; | 109 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNSYNCED; |
94 } else { | 110 } else { |
95 status_.icon = OFFLINE; | 111 status_.summary = sync_api::SyncManager::Status::OFFLINE; |
96 } | 112 } |
97 } | 113 } |
98 | 114 |
99 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { | 115 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { |
100 ScopedStatusLock lock(this); | 116 ScopedStatusLock lock(this); |
101 switch (event.what_happened) { | 117 switch (event.what_happened) { |
102 case SyncEngineEvent::SYNC_CYCLE_ENDED: | 118 case SyncEngineEvent::SYNC_CYCLE_ENDED: |
103 case SyncEngineEvent::STATUS_CHANGED: | 119 case SyncEngineEvent::STATUS_CHANGED: |
104 status_ = CalcSyncing(event); | 120 status_ = CalcSyncing(event); |
105 break; | 121 break; |
(...skipping 21 matching lines...) Expand all Loading... | |
127 if (!status_.authenticated) { | 143 if (!status_.authenticated) { |
128 status_ = CreateBlankStatus(); | 144 status_ = CreateBlankStatus(); |
129 } | 145 } |
130 status_.authenticated = true; | 146 status_.authenticated = true; |
131 } else { | 147 } else { |
132 status_.authenticated = false; | 148 status_.authenticated = false; |
133 } | 149 } |
134 } | 150 } |
135 } | 151 } |
136 | 152 |
137 AllStatus::Status AllStatus::status() const { | 153 sync_api::SyncManager::Status AllStatus::status() const { |
138 AutoLock lock(mutex_); | 154 AutoLock lock(mutex_); |
139 return status_; | 155 return status_; |
140 } | 156 } |
141 | 157 |
142 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { | 158 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { |
143 ScopedStatusLock lock(this); | 159 ScopedStatusLock lock(this); |
144 status_.notifications_enabled = notifications_enabled; | 160 status_.notifications_enabled = notifications_enabled; |
145 } | 161 } |
146 | 162 |
147 void AllStatus::IncrementNotificationsSent() { | 163 void AllStatus::IncrementNotificationsSent() { |
(...skipping 10 matching lines...) Expand all Loading... | |
158 : allstatus_(allstatus) { | 174 : allstatus_(allstatus) { |
159 allstatus->mutex_.Acquire(); | 175 allstatus->mutex_.Acquire(); |
160 } | 176 } |
161 | 177 |
162 ScopedStatusLock::~ScopedStatusLock() { | 178 ScopedStatusLock::~ScopedStatusLock() { |
163 allstatus_->CalcStatusChanges(); | 179 allstatus_->CalcStatusChanges(); |
164 allstatus_->mutex_.Release(); | 180 allstatus_->mutex_.Release(); |
165 } | 181 } |
166 | 182 |
167 } // namespace browser_sync | 183 } // namespace browser_sync |
OLD | NEW |