| 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/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return profile_->HasProfileSyncService(); | 125 return profile_->HasProfileSyncService(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool ProfileSyncServiceHarness::SetupSync() { | 128 bool ProfileSyncServiceHarness::SetupSync() { |
| 129 syncable::ModelTypeSet synced_datatypes; | 129 syncable::ModelTypeSet synced_datatypes; |
| 130 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 130 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 131 i < syncable::MODEL_TYPE_COUNT; ++i) { | 131 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 132 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); | 132 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); |
| 133 } | 133 } |
| 134 bool result = SetupSync(synced_datatypes); | 134 bool result = SetupSync(synced_datatypes); |
| 135 VLOG(0) << "Client " << id_ << " PSH: Set up sync completed"; | 135 if (result) { |
| 136 // TODO(lipalani): Change VLOG(0) to VLOG(1) -- See http://crbug.com/80706. |
| 137 VLOG(0) << "Client " << id_ << ": SetupSync() successful."; |
| 138 } |
| 136 return result; | 139 return result; |
| 137 } | 140 } |
| 138 | 141 |
| 139 bool ProfileSyncServiceHarness::SetupSync( | 142 bool ProfileSyncServiceHarness::SetupSync( |
| 140 const syncable::ModelTypeSet& synced_datatypes) { | 143 const syncable::ModelTypeSet& synced_datatypes) { |
| 141 // Initialize the sync client's profile sync service object. | 144 // Initialize the sync client's profile sync service object. |
| 142 service_ = profile_->GetProfileSyncService(""); | 145 service_ = profile_->GetProfileSyncService(""); |
| 143 if (service_ == NULL) { | 146 if (service_ == NULL) { |
| 144 LOG(ERROR) << "SetupSync(): service_ is null."; | 147 LOG(ERROR) << "SetupSync(): service_ is null."; |
| 145 return false; | 148 return false; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 169 // Wait for initial sync cycle to be completed. | 172 // Wait for initial sync cycle to be completed. |
| 170 DCHECK_EQ(wait_state_, WAITING_FOR_INITIAL_SYNC); | 173 DCHECK_EQ(wait_state_, WAITING_FOR_INITIAL_SYNC); |
| 171 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 174 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 172 "Waiting for initial sync cycle to complete.")) { | 175 "Waiting for initial sync cycle to complete.")) { |
| 173 LOG(ERROR) << "Initial sync cycle did not complete after " | 176 LOG(ERROR) << "Initial sync cycle did not complete after " |
| 174 << kLiveSyncOperationTimeoutMs / 1000 | 177 << kLiveSyncOperationTimeoutMs / 1000 |
| 175 << " seconds."; | 178 << " seconds."; |
| 176 return false; | 179 return false; |
| 177 } | 180 } |
| 178 | 181 |
| 182 if (wait_state_ == PASSPHRASE_REQUIRED_FOR_DECRYPTION) { |
| 183 // A passphrase is required for decryption. Sync cannot proceed until |
| 184 // SetPassphrase is called. |
| 185 return false; |
| 186 } |
| 187 |
| 179 // Indicate to the browser that sync setup is complete. | 188 // Indicate to the browser that sync setup is complete. |
| 180 service()->SetSyncSetupCompleted(); | 189 service()->SetSyncSetupCompleted(); |
| 181 | 190 |
| 182 return true; | 191 return true; |
| 183 } | 192 } |
| 184 | 193 |
| 185 void ProfileSyncServiceHarness::SignalStateCompleteWithNextState( | 194 void ProfileSyncServiceHarness::SignalStateCompleteWithNextState( |
| 186 WaitState next_state) { | 195 WaitState next_state) { |
| 187 wait_state_ = next_state; | 196 wait_state_ = next_state; |
| 188 SignalStateComplete(); | 197 SignalStateComplete(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 201 // The sync backend is initialized. | 210 // The sync backend is initialized. |
| 202 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); | 211 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); |
| 203 } | 212 } |
| 204 break; | 213 break; |
| 205 } | 214 } |
| 206 case WAITING_FOR_INITIAL_SYNC: { | 215 case WAITING_FOR_INITIAL_SYNC: { |
| 207 LogClientInfo("WAITING_FOR_INITIAL_SYNC"); | 216 LogClientInfo("WAITING_FOR_INITIAL_SYNC"); |
| 208 if (IsSynced()) { | 217 if (IsSynced()) { |
| 209 // The first sync cycle is now complete. We can start running tests. | 218 // The first sync cycle is now complete. We can start running tests. |
| 210 SignalStateCompleteWithNextState(FULLY_SYNCED); | 219 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 220 break; |
| 221 } |
| 222 if (service()->observed_passphrase_required() && |
| 223 service()->observed_passphrase_failed() && |
| 224 service()->passphrase_required_for_decryption()) { |
| 225 // A passphrase is required for decryption and we don't have it. Do not |
| 226 // wait any more. |
| 227 SignalStateCompleteWithNextState(PASSPHRASE_REQUIRED_FOR_DECRYPTION); |
| 228 break; |
| 211 } | 229 } |
| 212 break; | 230 break; |
| 213 } | 231 } |
| 214 case WAITING_FOR_SYNC_TO_FINISH: { | 232 case WAITING_FOR_SYNC_TO_FINISH: { |
| 215 LogClientInfo("WAITING_FOR_SYNC_TO_FINISH"); | 233 LogClientInfo("WAITING_FOR_SYNC_TO_FINISH"); |
| 216 if (!IsSynced()) { | 234 if (IsSynced()) { |
| 217 // The client is not yet fully synced. Continue waiting. | 235 // The sync cycle we were waiting for is complete. |
| 218 if (!GetStatus().server_reachable) { | 236 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 219 // The client cannot reach the sync server because the network is | |
| 220 // disabled. There is no need to wait anymore. | |
| 221 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | |
| 222 } | |
| 223 break; | 237 break; |
| 224 } | 238 } |
| 225 SignalStateCompleteWithNextState(FULLY_SYNCED); | 239 if (service()->observed_passphrase_required() && |
| 240 service()->observed_passphrase_failed() && |
| 241 service()->passphrase_required_for_decryption()) { |
| 242 // A passphrase is required for decryption and we don't have it. Do not |
| 243 // wait any more. |
| 244 SignalStateCompleteWithNextState(PASSPHRASE_REQUIRED_FOR_DECRYPTION); |
| 245 break; |
| 246 } |
| 247 if (!GetStatus().server_reachable) { |
| 248 // The client cannot reach the sync server because the network is |
| 249 // disabled. There is no need to wait anymore. |
| 250 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); |
| 251 break; |
| 252 } |
| 226 break; | 253 break; |
| 227 } | 254 } |
| 228 case WAITING_FOR_UPDATES: { | 255 case WAITING_FOR_UPDATES: { |
| 229 LogClientInfo("WAITING_FOR_UPDATES"); | 256 LogClientInfo("WAITING_FOR_UPDATES"); |
| 230 DCHECK(timestamp_match_partner_); | 257 DCHECK(timestamp_match_partner_); |
| 231 if (!MatchesOtherClient(timestamp_match_partner_)) { | 258 if (!MatchesOtherClient(timestamp_match_partner_)) { |
| 232 // The client is not yet fully synced; keep waiting until we converge. | 259 // The client is not yet fully synced; keep waiting until we converge. |
| 233 break; | 260 break; |
| 234 } | 261 } |
| 235 timestamp_match_partner_->service()->RemoveObserver(this); | 262 timestamp_match_partner_->service()->RemoveObserver(this); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 265 } | 292 } |
| 266 case SERVER_UNREACHABLE: { | 293 case SERVER_UNREACHABLE: { |
| 267 LogClientInfo("SERVER_UNREACHABLE"); | 294 LogClientInfo("SERVER_UNREACHABLE"); |
| 268 if (GetStatus().server_reachable) { | 295 if (GetStatus().server_reachable) { |
| 269 // The client was offline due to the network being disabled, but is now | 296 // The client was offline due to the network being disabled, but is now |
| 270 // back online. Wait for the pending sync cycle to complete. | 297 // back online. Wait for the pending sync cycle to complete. |
| 271 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); | 298 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); |
| 272 } | 299 } |
| 273 break; | 300 break; |
| 274 } | 301 } |
| 302 case PASSPHRASE_REQUIRED_FOR_DECRYPTION: { |
| 303 // A passphrase is required for decryption. There is nothing the sync |
| 304 // client can do until SetPassphrase() is called. |
| 305 LogClientInfo("PASSPHRASE_REQUIRED_FOR_DECRYPTION"); |
| 306 break; |
| 307 } |
| 275 case FULLY_SYNCED: { | 308 case FULLY_SYNCED: { |
| 276 // The client is online and fully synced. There is nothing to do. | 309 // The client is online and fully synced. There is nothing to do. |
| 277 LogClientInfo("FULLY_SYNCED"); | 310 LogClientInfo("FULLY_SYNCED"); |
| 278 break; | 311 break; |
| 279 } | 312 } |
| 280 case SYNC_DISABLED: { | 313 case SYNC_DISABLED: { |
| 281 // Syncing is disabled for the client. There is nothing to do. | 314 // Syncing is disabled for the client. There is nothing to do. |
| 282 LogClientInfo("SYNC_DISABLED"); | 315 LogClientInfo("SYNC_DISABLED"); |
| 283 break; | 316 break; |
| 284 } | 317 } |
| 285 default: | 318 default: |
| 286 // Invalid state during observer callback which may be triggered by other | 319 // Invalid state during observer callback which may be triggered by other |
| 287 // classes using the the UI message loop. Defer to their handling. | 320 // classes using the the UI message loop. Defer to their handling. |
| 288 break; | 321 break; |
| 289 } | 322 } |
| 290 return original_wait_state != wait_state_; | 323 return original_wait_state != wait_state_; |
| 291 } | 324 } |
| 292 | 325 |
| 293 void ProfileSyncServiceHarness::OnStateChanged() { | 326 void ProfileSyncServiceHarness::OnStateChanged() { |
| 294 RunStateChangeMachine(); | 327 RunStateChangeMachine(); |
| 295 } | 328 } |
| 296 | 329 |
| 297 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { | 330 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { |
| 298 LogClientInfo("AwaitPassphraseAccepted"); | 331 LogClientInfo("AwaitPassphraseAccepted"); |
| 299 if (wait_state_ == SYNC_DISABLED) { | 332 if (wait_state_ == SYNC_DISABLED) { |
| 300 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 333 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; |
| 301 return false; | 334 return false; |
| 302 } | 335 } |
| 303 | 336 |
| 304 // TODO(atwilson): After ProfileSyncService::OnPassphraseAccepted() is | 337 if (service()->ShouldPushChanges() && |
| 305 // fixed, add an extra check to make sure that the value of | 338 !service()->observed_passphrase_required()) { |
| 306 // service()->observed_passphrase_required() is false. | |
| 307 if (service()->ShouldPushChanges()) { | |
| 308 // Passphrase is already accepted; don't wait. | 339 // Passphrase is already accepted; don't wait. |
| 309 return true; | 340 return true; |
| 310 } | 341 } |
| 311 | 342 |
| 312 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; | 343 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; |
| 313 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 344 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 314 "Waiting for passphrase accepted."); | 345 "Waiting for passphrase accepted."); |
| 315 } | 346 } |
| 316 | 347 |
| 317 bool ProfileSyncServiceHarness::AwaitBackendInitialized() { | 348 bool ProfileSyncServiceHarness::AwaitBackendInitialized() { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 } | 637 } |
| 607 | 638 |
| 608 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( | 639 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( |
| 609 syncable::ModelType model_type) { | 640 syncable::ModelType model_type) { |
| 610 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 641 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 611 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; | 642 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; |
| 612 return snap->download_progress_markers[model_type]; | 643 return snap->download_progress_markers[model_type]; |
| 613 } | 644 } |
| 614 | 645 |
| 615 void ProfileSyncServiceHarness::LogClientInfo(const std::string& message) { | 646 void ProfileSyncServiceHarness::LogClientInfo(const std::string& message) { |
| 616 // TODO(lipalani): Change VLOG(0) to VLOG(1) | 647 // TODO(lipalani): Change VLOG(0) to VLOG(1) -- See http://crbug.com/80706. |
| 617 // http://crbug.com/80706 | |
| 618 if (service()) { | 648 if (service()) { |
| 619 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 649 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 620 if (snap) { | 650 if (snap) { |
| 621 VLOG(0) << "Client " << id_ << ": " << message | 651 VLOG(0) << "Client " << id_ << ": " << message |
| 622 << ": num_updates_downloaded : " | 652 << ": num_updates_downloaded : " |
| 623 << snap->syncer_status.num_updates_downloaded_total | 653 << snap->syncer_status.num_updates_downloaded_total |
| 624 << ", has_more_to_sync: " << snap->has_more_to_sync | 654 << ", has_more_to_sync: " << snap->has_more_to_sync |
| 625 << ", unsynced_count: " << snap->unsynced_count | 655 << ", unsynced_count: " << snap->unsynced_count |
| 626 << ", num_conflicting_updates: " << snap->num_conflicting_updates | 656 << ", num_conflicting_updates: " << snap->num_conflicting_updates |
| 627 << ", has_unsynced_items: " | 657 << ", has_unsynced_items: " |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 } | 698 } |
| 669 | 699 |
| 670 bool ProfileSyncServiceHarness::IsTypeEncrypted(syncable::ModelType type) { | 700 bool ProfileSyncServiceHarness::IsTypeEncrypted(syncable::ModelType type) { |
| 671 syncable::ModelTypeSet encrypted_types; | 701 syncable::ModelTypeSet encrypted_types; |
| 672 service_->GetEncryptedDataTypes(&encrypted_types); | 702 service_->GetEncryptedDataTypes(&encrypted_types); |
| 673 if (encrypted_types.count(type) == 0) { | 703 if (encrypted_types.count(type) == 0) { |
| 674 return false; | 704 return false; |
| 675 } | 705 } |
| 676 return true; | 706 return true; |
| 677 } | 707 } |
| OLD | NEW |