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

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

Issue 9323015: [Sync] - In about:sync page display if the first sync after restart has taken place or not. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 8 years, 10 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
OLDNEW
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 "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 #include "chrome/browser/sync/syncable/model_type.h" 15 #include "chrome/browser/sync/syncable/model_type.h"
16 16
17 namespace browser_sync { 17 namespace browser_sync {
18 18
19 AllStatus::AllStatus() { 19 AllStatus::AllStatus() {
20 status_.summary = sync_api::SyncManager::Status::OFFLINE; 20 status_.summary = sync_api::SyncManager::Status::UNINITIALIZED;
21 status_.initial_sync_ended = true; 21 status_.initial_sync_ended = true;
22 status_.notifications_enabled = false; 22 status_.notifications_enabled = false;
23 status_.cryptographer_ready = false; 23 status_.cryptographer_ready = false;
24 status_.crypto_has_pending_keys = false; 24 status_.crypto_has_pending_keys = false;
25 } 25 }
26 26
27 AllStatus::~AllStatus() { 27 AllStatus::~AllStatus() {
28 } 28 }
29 29
30 sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { 30 sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if (errors.consecutive_errors > status.max_consecutive_errors) 62 if (errors.consecutive_errors > status.max_consecutive_errors)
63 status.max_consecutive_errors = errors.consecutive_errors; 63 status.max_consecutive_errors = errors.consecutive_errors;
64 64
65 status.updates_available += snapshot->num_server_changes_remaining; 65 status.updates_available += snapshot->num_server_changes_remaining;
66 status.sync_protocol_error = snapshot->errors.sync_protocol_error; 66 status.sync_protocol_error = snapshot->errors.sync_protocol_error;
67 67
68 // Accumulate update count only once per session to avoid double-counting. 68 // Accumulate update count only once per session to avoid double-counting.
69 // TODO(ncarter): Make this realtime by having the syncer_status 69 // TODO(ncarter): Make this realtime by having the syncer_status
70 // counter preserve its value across sessions. http://crbug.com/26339 70 // counter preserve its value across sessions. http://crbug.com/26339
71 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { 71 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) {
72 ++status.sync_count;
72 status.updates_received += 73 status.updates_received +=
73 snapshot->syncer_status.num_updates_downloaded_total; 74 snapshot->syncer_status.num_updates_downloaded_total;
74 status.tombstone_updates_received += 75 status.tombstone_updates_received +=
75 snapshot->syncer_status.num_tombstone_updates_downloaded_total; 76 snapshot->syncer_status.num_tombstone_updates_downloaded_total;
76 status.num_local_overwrites_total += 77 status.num_local_overwrites_total +=
77 snapshot->syncer_status.num_local_overwrites; 78 snapshot->syncer_status.num_local_overwrites;
78 status.num_server_overwrites_total += 79 status.num_server_overwrites_total +=
79 snapshot->syncer_status.num_server_overwrites; 80 snapshot->syncer_status.num_server_overwrites;
80 if (snapshot->syncer_status.num_updates_downloaded_total == 0) { 81 if (snapshot->syncer_status.num_updates_downloaded_total == 0) {
81 ++status.empty_get_updates; 82 ++status.empty_get_updates;
82 } else { 83 } else {
83 ++status.nonempty_get_updates; 84 ++status.nonempty_get_updates;
84 } 85 }
85 if (snapshot->syncer_status.num_successful_commits == 0 && 86 if (snapshot->syncer_status.num_successful_commits == 0 &&
86 snapshot->syncer_status.num_updates_downloaded_total == 0) { 87 snapshot->syncer_status.num_updates_downloaded_total == 0) {
87 ++status.useless_sync_cycles; 88 ++status.useless_sync_cycles;
88 } else { 89 } else {
89 ++status.useful_sync_cycles; 90 ++status.useful_sync_cycles;
90 } 91 }
91 } 92 }
92 return status; 93 return status;
93 } 94 }
94 95
95 void AllStatus::CalcStatusChanges() { 96 void AllStatus::CalcStatusChanges() {
96 const bool unsynced_changes = status_.unsynced_count > 0; 97 const bool unsynced_changes = status_.unsynced_count > 0;
97 const bool online = status_.authenticated && 98 const bool online = status_.sync_count > 0 && status_.authenticated &&
98 status_.server_reachable && status_.server_up; 99 status_.server_reachable && status_.server_up;
100
101 if (status_.syncing) {
rlarocque 2012/02/08 00:07:37 Why not make this a big series of if/else if branc
lipalani1 2012/02/08 19:41:50 Nothing functionally wrong with that. The reason i
102 status_.summary = sync_api::SyncManager::Status::SYNCING;
103 return;
104 }
105
106 // If it is not syncing check if it is online.
99 if (online) { 107 if (online) {
100 if (status_.syncing) 108 status_.summary = sync_api::SyncManager::Status::READY;
101 status_.summary = sync_api::SyncManager::Status::SYNCING; 109 return;
102 else 110 }
103 status_.summary = sync_api::SyncManager::Status::READY; 111
104 } else if (!status_.initial_sync_ended) { 112 // It is not online. Find out more details for the summary.
113 if (!status_.initial_sync_ended) {
105 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNUSABLE; 114 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNUSABLE;
106 } else if (unsynced_changes) { 115 } else if (unsynced_changes) {
107 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNSYNCED; 116 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNSYNCED;
117 } else if (status_.sync_count > 0) {
118 status_.summary = sync_api::SyncManager::Status::OFFLINE;
108 } else { 119 } else {
109 status_.summary = sync_api::SyncManager::Status::OFFLINE; 120 status_.summary = sync_api::SyncManager::Status::UNINITIALIZED;
110 } 121 }
111 } 122 }
112 123
113 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) { 124 void AllStatus::OnSyncEngineEvent(const SyncEngineEvent& event) {
114 ScopedStatusLock lock(this); 125 ScopedStatusLock lock(this);
115 switch (event.what_happened) { 126 switch (event.what_happened) {
116 case SyncEngineEvent::SYNC_CYCLE_BEGIN: 127 case SyncEngineEvent::SYNC_CYCLE_BEGIN:
117 case SyncEngineEvent::STATUS_CHANGED: 128 case SyncEngineEvent::STATUS_CHANGED:
118 case SyncEngineEvent::SYNC_CYCLE_ENDED: 129 case SyncEngineEvent::SYNC_CYCLE_ENDED:
119 status_ = CalcSyncing(event); 130 status_ = CalcSyncing(event);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 : allstatus_(allstatus) { 201 : allstatus_(allstatus) {
191 allstatus->mutex_.Acquire(); 202 allstatus->mutex_.Acquire();
192 } 203 }
193 204
194 ScopedStatusLock::~ScopedStatusLock() { 205 ScopedStatusLock::~ScopedStatusLock() {
195 allstatus_->CalcStatusChanges(); 206 allstatus_->CalcStatusChanges();
196 allstatus_->mutex_.Release(); 207 allstatus_->mutex_.Release();
197 } 208 }
198 209
199 } // namespace browser_sync 210 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698