OLD | NEW |
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 ++status.useless_sync_cycles; | 95 ++status.useless_sync_cycles; |
96 } else { | 96 } else { |
97 ++status.useful_sync_cycles; | 97 ++status.useful_sync_cycles; |
98 } | 98 } |
99 } | 99 } |
100 return status; | 100 return status; |
101 } | 101 } |
102 | 102 |
103 void AllStatus::CalcStatusChanges() { | 103 void AllStatus::CalcStatusChanges() { |
104 const bool unsynced_changes = status_.unsynced_count > 0; | 104 const bool unsynced_changes = status_.unsynced_count > 0; |
105 const bool online = status_.authenticated && | 105 // TODO(rlarocque): AllStatus currently has no way to inquire about the |
106 status_.server_reachable && status_.server_up && !status_.server_broken; | 106 // SyncScheduler's backoff state. We should fix that, then use it to update |
| 107 // the 'offline' state here. However, it's important to keep in mind that |
| 108 // there really is no such thing as offline according to our SyncScheduler. |
| 109 // The exponential backoff never gives up. |
| 110 const bool online = true; |
107 if (online) { | 111 if (online) { |
108 if (status_.syncer_stuck) | 112 if (status_.syncer_stuck) |
109 status_.summary = sync_api::SyncManager::Status::CONFLICT; | 113 status_.summary = sync_api::SyncManager::Status::CONFLICT; |
110 else if (status_.syncing) | 114 else if (status_.syncing) |
111 status_.summary = sync_api::SyncManager::Status::SYNCING; | 115 status_.summary = sync_api::SyncManager::Status::SYNCING; |
112 else | 116 else |
113 status_.summary = sync_api::SyncManager::Status::READY; | 117 status_.summary = sync_api::SyncManager::Status::READY; |
114 } else if (!status_.initial_sync_ended) { | 118 } else if (!status_.initial_sync_ended) { |
115 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNUSABLE; | 119 status_.summary = sync_api::SyncManager::Status::OFFLINE_UNUSABLE; |
116 } else if (unsynced_changes) { | 120 } else if (unsynced_changes) { |
(...skipping 19 matching lines...) Expand all Loading... |
136 case SyncEngineEvent::ACTIONABLE_ERROR: | 140 case SyncEngineEvent::ACTIONABLE_ERROR: |
137 status_ = CreateBlankStatus(); | 141 status_ = CreateBlankStatus(); |
138 status_.sync_protocol_error = event.snapshot->errors.sync_protocol_error; | 142 status_.sync_protocol_error = event.snapshot->errors.sync_protocol_error; |
139 break; | 143 break; |
140 default: | 144 default: |
141 LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened; | 145 LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened; |
142 break; | 146 break; |
143 } | 147 } |
144 } | 148 } |
145 | 149 |
146 void AllStatus::HandleServerConnectionEvent( | |
147 const ServerConnectionEvent& event) { | |
148 ScopedStatusLock lock(this); | |
149 status_.server_up = IsGoodReplyFromServer(event.connection_code); | |
150 status_.server_reachable = event.server_reachable; | |
151 | |
152 if (event.connection_code == HttpResponse::SERVER_CONNECTION_OK) { | |
153 status_.authenticated = true; | |
154 } else { | |
155 status_.authenticated = false; | |
156 } | |
157 } | |
158 | |
159 sync_api::SyncManager::Status AllStatus::status() const { | 150 sync_api::SyncManager::Status AllStatus::status() const { |
160 base::AutoLock lock(mutex_); | 151 base::AutoLock lock(mutex_); |
161 return status_; | 152 return status_; |
162 } | 153 } |
163 | 154 |
164 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { | 155 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { |
165 ScopedStatusLock lock(this); | 156 ScopedStatusLock lock(this); |
166 status_.notifications_enabled = notifications_enabled; | 157 status_.notifications_enabled = notifications_enabled; |
167 } | 158 } |
168 | 159 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 : allstatus_(allstatus) { | 191 : allstatus_(allstatus) { |
201 allstatus->mutex_.Acquire(); | 192 allstatus->mutex_.Acquire(); |
202 } | 193 } |
203 | 194 |
204 ScopedStatusLock::~ScopedStatusLock() { | 195 ScopedStatusLock::~ScopedStatusLock() { |
205 allstatus_->CalcStatusChanges(); | 196 allstatus_->CalcStatusChanges(); |
206 allstatus_->mutex_.Release(); | 197 allstatus_->mutex_.Release(); |
207 } | 198 } |
208 | 199 |
209 } // namespace browser_sync | 200 } // namespace browser_sync |
OLD | NEW |