OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "chrome/browser/browser.h" | 6 #include "chrome/browser/browser.h" |
7 #include "chrome/browser/pref_service.h" | 7 #include "chrome/browser/pref_service.h" |
8 #include "chrome/browser/profile.h" | 8 #include "chrome/browser/profile.h" |
9 #include "chrome/browser/sync/glue/sync_backend_host.h" | 9 #include "chrome/browser/sync/glue/sync_backend_host.h" |
10 #include "chrome/browser/sync/sessions/session_state.h" | 10 #include "chrome/browser/sync/sessions/session_state.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 case WAITING_FOR_SYNC_TO_FINISH: { | 133 case WAITING_FOR_SYNC_TO_FINISH: { |
134 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 134 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
135 DCHECK(snap) << "Should have been at least one sync session by now"; | 135 DCHECK(snap) << "Should have been at least one sync session by now"; |
136 // TODO(rsimha): In an ideal world, snap->has_more_to_sync == false should | 136 // TODO(rsimha): In an ideal world, snap->has_more_to_sync == false should |
137 // be a sufficient condition for sync to have completed. However, the | 137 // be a sufficient condition for sync to have completed. However, the |
138 // additional check of snap->unsynced_count is required due to | 138 // additional check of snap->unsynced_count is required due to |
139 // http://crbug.com/48989. | 139 // http://crbug.com/48989. |
140 if (snap->has_more_to_sync || snap->unsynced_count != 0) { | 140 if (snap->has_more_to_sync || snap->unsynced_count != 0) { |
141 break; | 141 break; |
142 } | 142 } |
143 | |
144 EXPECT_LE(last_timestamp_, snap->max_local_timestamp); | 143 EXPECT_LE(last_timestamp_, snap->max_local_timestamp); |
145 last_timestamp_ = snap->max_local_timestamp; | 144 last_timestamp_ = snap->max_local_timestamp; |
146 SignalStateCompleteWithNextState(FULLY_SYNCED); | 145 SignalStateCompleteWithNextState(FULLY_SYNCED); |
147 break; | 146 break; |
148 } | 147 } |
149 case WAITING_FOR_UPDATES: { | 148 case WAITING_FOR_UPDATES: { |
150 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 149 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
151 DCHECK(snap) << "Should have been at least one sync session by now"; | 150 DCHECK(snap) << "Should have been at least one sync session by now"; |
152 if (snap->max_local_timestamp < min_timestamp_needed_) | 151 if (snap->max_local_timestamp < min_timestamp_needed_) { |
153 break; | 152 break; |
154 | 153 } |
| 154 EXPECT_LE(last_timestamp_, snap->max_local_timestamp); |
| 155 last_timestamp_ = snap->max_local_timestamp; |
155 SignalStateCompleteWithNextState(FULLY_SYNCED); | 156 SignalStateCompleteWithNextState(FULLY_SYNCED); |
156 break; | 157 break; |
157 } | 158 } |
158 case FULLY_SYNCED: | 159 case FULLY_SYNCED: |
159 default: | 160 default: |
160 // Invalid state during observer callback which may be triggered by other | 161 // Invalid state during observer callback which may be triggered by other |
161 // classes using the the UI message loop. Defer to their handling. | 162 // classes using the the UI message loop. Defer to their handling. |
162 break; | 163 break; |
163 } | 164 } |
164 last_status_ = status; | 165 last_status_ = status; |
165 return state != wait_state_; | 166 return state != wait_state_; |
166 } | 167 } |
167 | 168 |
168 void ProfileSyncServiceTestHarness::OnStateChanged() { | 169 void ProfileSyncServiceTestHarness::OnStateChanged() { |
169 RunStateChangeMachine(); | 170 RunStateChangeMachine(); |
170 } | 171 } |
171 | 172 |
172 bool ProfileSyncServiceTestHarness::AwaitSyncCycleCompletion( | 173 bool ProfileSyncServiceTestHarness::AwaitSyncCycleCompletion( |
173 const std::string& reason) { | 174 const std::string& reason) { |
174 if (service()->backend()->HasUnsyncedItems()) { | 175 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 176 DCHECK(snap) << "Should have been at least one sync session by now"; |
| 177 // TODO(rsimha): Remove additional checks of snap->has_more_to_sync and |
| 178 // snap->unsynced_count once http://crbug.com/48989 is fixed. |
| 179 if (service()->backend()->HasUnsyncedItems() || |
| 180 snap->has_more_to_sync || |
| 181 snap->unsynced_count != 0) { |
175 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; | 182 wait_state_ = WAITING_FOR_SYNC_TO_FINISH; |
176 return AwaitStatusChangeWithTimeout(60, reason); | 183 return AwaitStatusChangeWithTimeout(60, reason); |
177 } else { | 184 } else { |
| 185 EXPECT_LE(last_timestamp_, snap->max_local_timestamp); |
| 186 last_timestamp_ = snap->max_local_timestamp; |
178 return true; | 187 return true; |
179 } | 188 } |
180 } | 189 } |
181 | 190 |
182 bool ProfileSyncServiceTestHarness::AwaitMutualSyncCycleCompletion( | 191 bool ProfileSyncServiceTestHarness::AwaitMutualSyncCycleCompletion( |
183 ProfileSyncServiceTestHarness* partner) { | 192 ProfileSyncServiceTestHarness* partner) { |
184 bool success = AwaitSyncCycleCompletion( | 193 bool success = AwaitSyncCycleCompletion( |
185 "Sync cycle completion on active client."); | 194 "Sync cycle completion on active client."); |
186 if (!success) | 195 if (!success) |
187 return false; | 196 return false; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 } | 287 } |
279 | 288 |
280 return true; | 289 return true; |
281 } | 290 } |
282 | 291 |
283 const SyncSessionSnapshot* | 292 const SyncSessionSnapshot* |
284 ProfileSyncServiceTestHarness::GetLastSessionSnapshot() const { | 293 ProfileSyncServiceTestHarness::GetLastSessionSnapshot() const { |
285 EXPECT_FALSE(service_ == NULL) << "Sync service has not yet been set up."; | 294 EXPECT_FALSE(service_ == NULL) << "Sync service has not yet been set up."; |
286 return service_->backend()->GetLastSessionSnapshot(); | 295 return service_->backend()->GetLastSessionSnapshot(); |
287 } | 296 } |
OLD | NEW |