Chromium Code Reviews| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 return profile_->HasProfileSyncService(); | 127 return profile_->HasProfileSyncService(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool ProfileSyncServiceHarness::SetupSync() { | 130 bool ProfileSyncServiceHarness::SetupSync() { |
| 131 syncable::ModelTypeSet synced_datatypes; | 131 syncable::ModelTypeSet synced_datatypes; |
| 132 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 132 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 133 i < syncable::MODEL_TYPE_COUNT; ++i) { | 133 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 134 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); | 134 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); |
| 135 } | 135 } |
| 136 bool result = SetupSync(synced_datatypes); | 136 bool result = SetupSync(synced_datatypes); |
| 137 VLOG(0) << "Client " << id_ << ": Set up sync completed with result " | 137 // TODO(lipalani): Change VLOG(0) to VLOG(1) -- See http://crbug.com/80706. |
| 138 << result; | 138 VLOG(0) << "Client " << id_ << ": SetupSync completed with result " |
| 139 << result << "."; | |
| 139 if (result == false) { | 140 if (result == false) { |
| 140 std::string pss_status = GetServiceStatus(); | 141 std::string pss_status = GetServiceStatus(); |
| 141 VLOG(0) << pss_status; | 142 LOG(ERROR) << "SetupSync() failed. service_ details:\n" << pss_status; |
| 142 } | 143 } |
| 143 return result; | 144 return result; |
| 144 } | 145 } |
| 145 | 146 |
| 146 bool ProfileSyncServiceHarness::SetupSync( | 147 bool ProfileSyncServiceHarness::SetupSync( |
| 147 const syncable::ModelTypeSet& synced_datatypes) { | 148 const syncable::ModelTypeSet& synced_datatypes) { |
| 148 // Initialize the sync client's profile sync service object. | 149 // Initialize the sync client's profile sync service object. |
| 149 service_ = profile_->GetProfileSyncService(""); | 150 service_ = profile_->GetProfileSyncService(""); |
| 150 if (service_ == NULL) { | 151 if (service_ == NULL) { |
| 151 LOG(ERROR) << "SetupSync(): service_ is null."; | 152 LOG(ERROR) << "SetupSync(): service_ is null."; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 176 // Wait for initial sync cycle to be completed. | 177 // Wait for initial sync cycle to be completed. |
| 177 DCHECK_EQ(wait_state_, WAITING_FOR_INITIAL_SYNC); | 178 DCHECK_EQ(wait_state_, WAITING_FOR_INITIAL_SYNC); |
| 178 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 179 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 179 "Waiting for initial sync cycle to complete.")) { | 180 "Waiting for initial sync cycle to complete.")) { |
| 180 LOG(ERROR) << "Initial sync cycle did not complete after " | 181 LOG(ERROR) << "Initial sync cycle did not complete after " |
| 181 << kLiveSyncOperationTimeoutMs / 1000 | 182 << kLiveSyncOperationTimeoutMs / 1000 |
| 182 << " seconds."; | 183 << " seconds."; |
| 183 return false; | 184 return false; |
| 184 } | 185 } |
| 185 | 186 |
| 187 if (wait_state_ == PASSPHRASE_REQUIRED_FOR_DECRYPTION) { | |
| 188 // A passphrase is required for decryption. Sync cannot proceed until | |
| 189 // SetPassphrase is called. | |
| 190 return false; | |
| 191 } | |
| 192 | |
| 186 // Indicate to the browser that sync setup is complete. | 193 // Indicate to the browser that sync setup is complete. |
| 187 service()->SetSyncSetupCompleted(); | 194 service()->SetSyncSetupCompleted(); |
| 188 | 195 |
| 189 return true; | 196 return true; |
| 190 } | 197 } |
| 191 | 198 |
| 192 void ProfileSyncServiceHarness::SignalStateCompleteWithNextState( | 199 void ProfileSyncServiceHarness::SignalStateCompleteWithNextState( |
| 193 WaitState next_state) { | 200 WaitState next_state) { |
| 194 wait_state_ = next_state; | 201 wait_state_ = next_state; |
| 195 SignalStateComplete(); | 202 SignalStateComplete(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 208 // The sync backend is initialized. | 215 // The sync backend is initialized. |
| 209 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); | 216 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); |
| 210 } | 217 } |
| 211 break; | 218 break; |
| 212 } | 219 } |
| 213 case WAITING_FOR_INITIAL_SYNC: { | 220 case WAITING_FOR_INITIAL_SYNC: { |
| 214 LogClientInfo("WAITING_FOR_INITIAL_SYNC"); | 221 LogClientInfo("WAITING_FOR_INITIAL_SYNC"); |
| 215 if (IsSynced()) { | 222 if (IsSynced()) { |
| 216 // The first sync cycle is now complete. We can start running tests. | 223 // The first sync cycle is now complete. We can start running tests. |
| 217 SignalStateCompleteWithNextState(FULLY_SYNCED); | 224 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 225 break; | |
| 226 } | |
| 227 if (service()->observed_passphrase_required() && | |
| 228 service()->passphrase_required_reason() == | |
| 229 sync_api::REASON_SET_PASSPHRASE_FAILED) { | |
| 230 // A passphrase is required for decryption and we don't have it. Do not | |
| 231 // wait any more. | |
| 232 SignalStateCompleteWithNextState(PASSPHRASE_REQUIRED_FOR_DECRYPTION); | |
|
tim (not reviewing)
2011/04/29 23:02:13
It's a bit unintuitive now that we say if REASON_S
Raghu Simha
2011/04/30 00:43:06
Changed to SET_PASSPHRASE_FAILED.
| |
| 233 break; | |
| 218 } | 234 } |
| 219 break; | 235 break; |
| 220 } | 236 } |
| 221 case WAITING_FOR_SYNC_TO_FINISH: { | 237 case WAITING_FOR_SYNC_TO_FINISH: { |
| 222 LogClientInfo("WAITING_FOR_SYNC_TO_FINISH"); | 238 LogClientInfo("WAITING_FOR_SYNC_TO_FINISH"); |
| 223 if (!IsSynced()) { | 239 if (IsSynced()) { |
| 224 // The client is not yet fully synced. Continue waiting. | 240 // The sync cycle we were waiting for is complete. |
| 225 if (!GetStatus().server_reachable) { | 241 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 226 // The client cannot reach the sync server because the network is | |
| 227 // disabled. There is no need to wait anymore. | |
| 228 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | |
| 229 } | |
| 230 break; | 242 break; |
| 231 } | 243 } |
| 232 SignalStateCompleteWithNextState(FULLY_SYNCED); | 244 if (service()->observed_passphrase_required() && |
| 245 service()->passphrase_required_reason() == | |
| 246 sync_api::REASON_SET_PASSPHRASE_FAILED) { | |
| 247 // A passphrase is required for decryption and we don't have it. Do not | |
| 248 // wait any more. | |
| 249 SignalStateCompleteWithNextState(PASSPHRASE_REQUIRED_FOR_DECRYPTION); | |
| 250 break; | |
| 251 } | |
| 252 if (!GetStatus().server_reachable) { | |
| 253 // The client cannot reach the sync server because the network is | |
| 254 // disabled. There is no need to wait anymore. | |
| 255 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | |
| 256 break; | |
| 257 } | |
| 233 break; | 258 break; |
| 234 } | 259 } |
| 235 case WAITING_FOR_UPDATES: { | 260 case WAITING_FOR_UPDATES: { |
| 236 LogClientInfo("WAITING_FOR_UPDATES"); | 261 LogClientInfo("WAITING_FOR_UPDATES"); |
| 237 DCHECK(timestamp_match_partner_); | 262 DCHECK(timestamp_match_partner_); |
| 238 if (!MatchesOtherClient(timestamp_match_partner_)) { | 263 if (!MatchesOtherClient(timestamp_match_partner_)) { |
| 239 // The client is not yet fully synced; keep waiting until we converge. | 264 // The client is not yet fully synced; keep waiting until we converge. |
| 240 break; | 265 break; |
| 241 } | 266 } |
| 242 timestamp_match_partner_->service()->RemoveObserver(this); | 267 timestamp_match_partner_->service()->RemoveObserver(this); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 272 } | 297 } |
| 273 case SERVER_UNREACHABLE: { | 298 case SERVER_UNREACHABLE: { |
| 274 LogClientInfo("SERVER_UNREACHABLE"); | 299 LogClientInfo("SERVER_UNREACHABLE"); |
| 275 if (GetStatus().server_reachable) { | 300 if (GetStatus().server_reachable) { |
| 276 // The client was offline due to the network being disabled, but is now | 301 // The client was offline due to the network being disabled, but is now |
| 277 // back online. Wait for the pending sync cycle to complete. | 302 // back online. Wait for the pending sync cycle to complete. |
| 278 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); | 303 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); |
| 279 } | 304 } |
| 280 break; | 305 break; |
| 281 } | 306 } |
| 307 case PASSPHRASE_REQUIRED_FOR_DECRYPTION: { | |
| 308 // A passphrase is required for decryption. There is nothing the sync | |
| 309 // client can do until SetPassphrase() is called. | |
| 310 LogClientInfo("PASSPHRASE_REQUIRED_FOR_DECRYPTION"); | |
| 311 break; | |
| 312 } | |
| 282 case FULLY_SYNCED: { | 313 case FULLY_SYNCED: { |
| 283 // The client is online and fully synced. There is nothing to do. | 314 // The client is online and fully synced. There is nothing to do. |
| 284 LogClientInfo("FULLY_SYNCED"); | 315 LogClientInfo("FULLY_SYNCED"); |
| 285 break; | 316 break; |
| 286 } | 317 } |
| 287 case SYNC_DISABLED: { | 318 case SYNC_DISABLED: { |
| 288 // Syncing is disabled for the client. There is nothing to do. | 319 // Syncing is disabled for the client. There is nothing to do. |
| 289 LogClientInfo("SYNC_DISABLED"); | 320 LogClientInfo("SYNC_DISABLED"); |
| 290 break; | 321 break; |
| 291 } | 322 } |
| 292 default: | 323 default: |
| 293 // Invalid state during observer callback which may be triggered by other | 324 // Invalid state during observer callback which may be triggered by other |
| 294 // classes using the the UI message loop. Defer to their handling. | 325 // classes using the the UI message loop. Defer to their handling. |
| 295 break; | 326 break; |
| 296 } | 327 } |
| 297 return original_wait_state != wait_state_; | 328 return original_wait_state != wait_state_; |
| 298 } | 329 } |
| 299 | 330 |
| 300 void ProfileSyncServiceHarness::OnStateChanged() { | 331 void ProfileSyncServiceHarness::OnStateChanged() { |
| 301 RunStateChangeMachine(); | 332 RunStateChangeMachine(); |
| 302 } | 333 } |
| 303 | 334 |
| 304 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { | 335 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { |
| 305 LogClientInfo("AwaitPassphraseAccepted"); | 336 LogClientInfo("AwaitPassphraseAccepted"); |
| 306 if (wait_state_ == SYNC_DISABLED) { | 337 if (wait_state_ == SYNC_DISABLED) { |
| 307 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 338 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; |
| 308 return false; | 339 return false; |
| 309 } | 340 } |
| 310 | 341 |
| 311 // TODO(atwilson): After ProfileSyncService::OnPassphraseAccepted() is | 342 if (service()->ShouldPushChanges() && |
| 312 // fixed, add an extra check to make sure that the value of | 343 !service()->observed_passphrase_required()) { |
| 313 // service()->observed_passphrase_required() is false. | |
| 314 if (service()->ShouldPushChanges()) { | |
| 315 // Passphrase is already accepted; don't wait. | 344 // Passphrase is already accepted; don't wait. |
| 316 return true; | 345 return true; |
| 317 } | 346 } |
| 318 | 347 |
| 319 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; | 348 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; |
| 320 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 349 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 321 "Waiting for passphrase accepted."); | 350 "Waiting for passphrase accepted."); |
| 322 } | 351 } |
| 323 | 352 |
| 324 bool ProfileSyncServiceHarness::AwaitBackendInitialized() { | 353 bool ProfileSyncServiceHarness::AwaitBackendInitialized() { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 } | 642 } |
| 614 | 643 |
| 615 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( | 644 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( |
| 616 syncable::ModelType model_type) { | 645 syncable::ModelType model_type) { |
| 617 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 646 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 618 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; | 647 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; |
| 619 return snap->download_progress_markers[model_type]; | 648 return snap->download_progress_markers[model_type]; |
| 620 } | 649 } |
| 621 | 650 |
| 622 void ProfileSyncServiceHarness::LogClientInfo(const std::string& message) { | 651 void ProfileSyncServiceHarness::LogClientInfo(const std::string& message) { |
| 623 // TODO(lipalani): Change VLOG(0) to VLOG(1) | 652 // TODO(lipalani): Change VLOG(0) to VLOG(1) -- See http://crbug.com/80706. |
| 624 // http://crbug.com/80706 | |
| 625 if (service()) { | 653 if (service()) { |
| 626 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 654 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 627 if (snap) { | 655 if (snap) { |
| 628 VLOG(0) << "Client " << id_ << ": " << message | 656 VLOG(0) << "Client " << id_ << ": " << message |
| 629 << ": num_updates_downloaded : " | 657 << ": num_updates_downloaded : " |
| 630 << snap->syncer_status.num_updates_downloaded_total | 658 << snap->syncer_status.num_updates_downloaded_total |
| 631 << ", has_more_to_sync: " << snap->has_more_to_sync | 659 << ", has_more_to_sync: " << snap->has_more_to_sync |
| 632 << ", unsynced_count: " << snap->unsynced_count | 660 << ", unsynced_count: " << snap->unsynced_count |
| 633 << ", num_conflicting_updates: " << snap->num_conflicting_updates | 661 << ", num_conflicting_updates: " << snap->num_conflicting_updates |
| 634 << ", has_unsynced_items: " | 662 << ", has_unsynced_items: " |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 return true; | 711 return true; |
| 684 } | 712 } |
| 685 | 713 |
| 686 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 714 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 687 DictionaryValue value; | 715 DictionaryValue value; |
| 688 sync_ui_util::ConstructAboutInformation(service_, &value); | 716 sync_ui_util::ConstructAboutInformation(service_, &value); |
| 689 std::string service_status; | 717 std::string service_status; |
| 690 base::JSONWriter::Write(&value, true, &service_status); | 718 base::JSONWriter::Write(&value, true, &service_status); |
| 691 return service_status; | 719 return service_status; |
| 692 } | 720 } |
| OLD | NEW |