Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1134)

Side by Side Diff: chrome/browser/sync/engine/all_status.cc

Issue 9149017: Remove broken variables from sync's AllStatus (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix sync_unit_test failure Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/engine/all_status.h ('k') | chrome/browser/sync/engine/syncer_proto_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
(...skipping 17 matching lines...) Expand all
28 } 28 }
29 29
30 sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { 30 sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const {
31 // Status is initialized with the previous status value. Variables 31 // Status is initialized with the previous status value. Variables
32 // whose values accumulate (e.g. lifetime counters like updates_received) 32 // whose values accumulate (e.g. lifetime counters like updates_received)
33 // are not to be cleared here. 33 // are not to be cleared here.
34 sync_api::SyncManager::Status status = status_; 34 sync_api::SyncManager::Status status = status_;
35 status.unsynced_count = 0; 35 status.unsynced_count = 0;
36 status.conflicting_count = 0; 36 status.conflicting_count = 0;
37 status.initial_sync_ended = false; 37 status.initial_sync_ended = false;
38 status.syncer_stuck = false;
39 status.max_consecutive_errors = 0; 38 status.max_consecutive_errors = 0;
40 status.server_broken = false;
41 status.updates_available = 0; 39 status.updates_available = 0;
42 return status; 40 return status;
43 } 41 }
44 42
45 sync_api::SyncManager::Status AllStatus::CalcSyncing( 43 sync_api::SyncManager::Status AllStatus::CalcSyncing(
46 const SyncEngineEvent &event) const { 44 const SyncEngineEvent &event) const {
47 sync_api::SyncManager::Status status = CreateBlankStatus(); 45 sync_api::SyncManager::Status status = CreateBlankStatus();
48 const sessions::SyncSessionSnapshot* snapshot = event.snapshot; 46 const sessions::SyncSessionSnapshot* snapshot = event.snapshot;
49 status.unsynced_count += static_cast<int>(snapshot->unsynced_count); 47 status.unsynced_count += static_cast<int>(snapshot->unsynced_count);
50 status.conflicting_count += snapshot->errors.num_conflicting_commits; 48 status.conflicting_count += snapshot->errors.num_conflicting_commits;
51 // The syncer may not be done yet, which could cause conflicting updates. 49 // The syncer may not be done yet, which could cause conflicting updates.
52 // But this is only used for status, so it is better to have visibility. 50 // But this is only used for status, so it is better to have visibility.
53 status.conflicting_count += snapshot->num_conflicting_updates; 51 status.conflicting_count += snapshot->num_conflicting_updates;
54 52
55 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { 53 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) {
56 status.syncing = true; 54 status.syncing = true;
57 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { 55 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) {
58 status.syncing = false; 56 status.syncing = false;
59 } 57 }
60 58
61 status.initial_sync_ended |= snapshot->is_share_usable; 59 status.initial_sync_ended |= snapshot->is_share_usable;
62 status.syncer_stuck |= snapshot->syncer_status.syncer_stuck;
63 60
64 const sessions::ErrorCounters& errors(snapshot->errors); 61 const sessions::ErrorCounters& errors(snapshot->errors);
65 if (errors.consecutive_errors > status.max_consecutive_errors) 62 if (errors.consecutive_errors > status.max_consecutive_errors)
66 status.max_consecutive_errors = errors.consecutive_errors; 63 status.max_consecutive_errors = errors.consecutive_errors;
67 64
68 // 100 is an arbitrary limit.
69 if (errors.consecutive_transient_error_commits > 100)
70 status.server_broken = true;
71
72 status.updates_available += snapshot->num_server_changes_remaining; 65 status.updates_available += snapshot->num_server_changes_remaining;
73
74 status.sync_protocol_error = snapshot->errors.sync_protocol_error; 66 status.sync_protocol_error = snapshot->errors.sync_protocol_error;
75 67
76 // Accumulate update count only once per session to avoid double-counting. 68 // Accumulate update count only once per session to avoid double-counting.
77 // TODO(ncarter): Make this realtime by having the syncer_status 69 // TODO(ncarter): Make this realtime by having the syncer_status
78 // counter preserve its value across sessions. http://crbug.com/26339 70 // counter preserve its value across sessions. http://crbug.com/26339
79 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { 71 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) {
80 status.updates_received += 72 status.updates_received +=
81 snapshot->syncer_status.num_updates_downloaded_total; 73 snapshot->syncer_status.num_updates_downloaded_total;
82 status.tombstone_updates_received += 74 status.tombstone_updates_received +=
83 snapshot->syncer_status.num_tombstone_updates_downloaded_total; 75 snapshot->syncer_status.num_tombstone_updates_downloaded_total;
(...skipping 12 matching lines...) Expand all
96 } else { 88 } else {
97 ++status.useful_sync_cycles; 89 ++status.useful_sync_cycles;
98 } 90 }
99 } 91 }
100 return status; 92 return status;
101 } 93 }
102 94
103 void AllStatus::CalcStatusChanges() { 95 void AllStatus::CalcStatusChanges() {
104 const bool unsynced_changes = status_.unsynced_count > 0; 96 const bool unsynced_changes = status_.unsynced_count > 0;
105 const bool online = status_.authenticated && 97 const bool online = status_.authenticated &&
106 status_.server_reachable && status_.server_up && !status_.server_broken; 98 status_.server_reachable && status_.server_up;
107 if (online) { 99 if (online) {
108 if (status_.syncer_stuck) 100 if (status_.syncing)
109 status_.summary = sync_api::SyncManager::Status::CONFLICT;
110 else if (status_.syncing)
111 status_.summary = sync_api::SyncManager::Status::SYNCING; 101 status_.summary = sync_api::SyncManager::Status::SYNCING;
112 else 102 else
113 status_.summary = sync_api::SyncManager::Status::READY; 103 status_.summary = sync_api::SyncManager::Status::READY;
114 } else if (!status_.initial_sync_ended) { 104 } else if (!status_.initial_sync_ended) {
115 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNUSABLE; 105 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNUSABLE;
116 } else if (unsynced_changes) { 106 } else if (unsynced_changes) {
117 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNSYNCED; 107 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNSYNCED;
118 } else { 108 } else {
119 status_.summary = sync_api::SyncManager::Status::OFFLINE; 109 status_.summary = sync_api::SyncManager::Status::OFFLINE;
120 } 110 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 : allstatus_(allstatus) { 190 : allstatus_(allstatus) {
201 allstatus->mutex_.Acquire(); 191 allstatus->mutex_.Acquire();
202 } 192 }
203 193
204 ScopedStatusLock::~ScopedStatusLock() { 194 ScopedStatusLock::~ScopedStatusLock() {
205 allstatus_->CalcStatusChanges(); 195 allstatus_->CalcStatusChanges();
206 allstatus_->mutex_.Release(); 196 allstatus_->mutex_.Release();
207 } 197 }
208 198
209 } // namespace browser_sync 199 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/all_status.h ('k') | chrome/browser/sync/engine/syncer_proto_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698