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

Side by Side Diff: chrome/browser/sync/profile_sync_service_harness.cc

Issue 9251035: Delete lots of sync ServerConnectionManager code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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/profile_sync_service_harness.h" 5 #include "chrome/browser/sync/profile_sync_service_harness.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <iterator> 8 #include <iterator>
9 #include <ostream> 9 #include <ostream>
10 #include <set> 10 #include <set>
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 SignalStateCompleteWithNextState(FULLY_SYNCED); 272 SignalStateCompleteWithNextState(FULLY_SYNCED);
273 break; 273 break;
274 } 274 }
275 if (service()->passphrase_required_reason() == 275 if (service()->passphrase_required_reason() ==
276 sync_api::REASON_SET_PASSPHRASE_FAILED) { 276 sync_api::REASON_SET_PASSPHRASE_FAILED) {
277 // A passphrase is required for decryption and we don't have it. Do not 277 // A passphrase is required for decryption and we don't have it. Do not
278 // wait any more. 278 // wait any more.
279 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED); 279 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED);
280 break; 280 break;
281 } 281 }
282 if (!GetStatus().server_reachable) {
283 // The client cannot reach the sync server because the network is
284 // disabled. There is no need to wait anymore.
285 SignalStateCompleteWithNextState(SERVER_UNREACHABLE);
286 break;
287 }
288 break; 282 break;
289 } 283 }
290 case WAITING_FOR_DATA_SYNC: { 284 case WAITING_FOR_DATA_SYNC: {
291 if (IsDataSynced()) { 285 if (IsDataSynced()) {
292 SignalStateCompleteWithNextState(FULLY_SYNCED); 286 SignalStateCompleteWithNextState(FULLY_SYNCED);
293 break; 287 break;
294 } 288 }
295 break; 289 break;
296 } 290 }
297 case WAITING_FOR_UPDATES: { 291 case WAITING_FOR_UPDATES: {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // The correctness of this if condition may depend on the ordering of its 324 // The correctness of this if condition may depend on the ordering of its
331 // sub-expressions. See crbug.com/98607, crbug.com/95619. 325 // sub-expressions. See crbug.com/98607, crbug.com/95619.
332 // TODO(rlarocque): Figure out a less brittle way of detecting this. 326 // TODO(rlarocque): Figure out a less brittle way of detecting this.
333 if (IsTypeEncrypted(waiting_for_encryption_type_) && 327 if (IsTypeEncrypted(waiting_for_encryption_type_) &&
334 IsFullySynced() && 328 IsFullySynced() &&
335 GetLastSessionSnapshot()->num_conflicting_updates == 0) { 329 GetLastSessionSnapshot()->num_conflicting_updates == 0) {
336 // Encryption is now complete for the the type in which we were waiting. 330 // Encryption is now complete for the the type in which we were waiting.
337 SignalStateCompleteWithNextState(FULLY_SYNCED); 331 SignalStateCompleteWithNextState(FULLY_SYNCED);
338 break; 332 break;
339 } 333 }
340 if (!GetStatus().server_reachable) {
341 // The client cannot reach the sync server because the network is
342 // disabled. There is no need to wait anymore.
343 SignalStateCompleteWithNextState(SERVER_UNREACHABLE);
344 break;
345 }
346 break; 334 break;
347 } 335 }
348 case WAITING_FOR_SYNC_CONFIGURATION: { 336 case WAITING_FOR_SYNC_CONFIGURATION: {
349 DVLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_CONFIGURATION"); 337 DVLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_CONFIGURATION");
350 if (service()->ShouldPushChanges()) { 338 if (service()->ShouldPushChanges()) {
351 // The Datatype manager is configured and sync is fully initialized. 339 // The Datatype manager is configured and sync is fully initialized.
352 SignalStateCompleteWithNextState(FULLY_SYNCED); 340 SignalStateCompleteWithNextState(FULLY_SYNCED);
353 } 341 }
354 break; 342 break;
355 } 343 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 case WAITING_FOR_ACTIONABLE_ERROR: { 381 case WAITING_FOR_ACTIONABLE_ERROR: {
394 DVLOG(1) << GetClientInfoString("WAITING_FOR_ACTIONABLE_ERROR"); 382 DVLOG(1) << GetClientInfoString("WAITING_FOR_ACTIONABLE_ERROR");
395 ProfileSyncService::Status status = GetStatus(); 383 ProfileSyncService::Status status = GetStatus();
396 if (status.sync_protocol_error.action != browser_sync::UNKNOWN_ACTION && 384 if (status.sync_protocol_error.action != browser_sync::UNKNOWN_ACTION &&
397 service_->unrecoverable_error_detected() == true) { 385 service_->unrecoverable_error_detected() == true) {
398 // An actionable error has been detected. 386 // An actionable error has been detected.
399 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); 387 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING);
400 } 388 }
401 break; 389 break;
402 } 390 }
403 case SERVER_UNREACHABLE: {
404 DVLOG(1) << GetClientInfoString("SERVER_UNREACHABLE");
405 if (GetStatus().server_reachable) {
406 // The client was offline due to the network being disabled, but is now
407 // back online. Wait for the pending sync cycle to complete.
408 SignalStateCompleteWithNextState(WAITING_FOR_FULL_SYNC);
409 }
410 break;
411 }
412 case SET_PASSPHRASE_FAILED: { 391 case SET_PASSPHRASE_FAILED: {
413 // A passphrase is required for decryption. There is nothing the sync 392 // A passphrase is required for decryption. There is nothing the sync
414 // client can do until SetPassphrase() is called. 393 // client can do until SetPassphrase() is called.
415 DVLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED"); 394 DVLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED");
416 break; 395 break;
417 } 396 }
418 case FULLY_SYNCED: { 397 case FULLY_SYNCED: {
419 // The client is online and fully synced. There is nothing to do. 398 // The client is online and fully synced. There is nothing to do.
420 DVLOG(1) << GetClientInfoString("FULLY_SYNCED"); 399 DVLOG(1) << GetClientInfoString("FULLY_SYNCED");
421 break; 400 break;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, 511 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs,
533 "Waiting for sync configuration."); 512 "Waiting for sync configuration.");
534 } 513 }
535 514
536 bool ProfileSyncServiceHarness::AwaitDataSyncCompletion( 515 bool ProfileSyncServiceHarness::AwaitDataSyncCompletion(
537 const std::string& reason) { 516 const std::string& reason) {
538 DVLOG(1) << GetClientInfoString("AwaitDataSyncCompletion"); 517 DVLOG(1) << GetClientInfoString("AwaitDataSyncCompletion");
539 518
540 CHECK(service()->sync_initialized()); 519 CHECK(service()->sync_initialized());
541 CHECK_NE(wait_state_, SYNC_DISABLED); 520 CHECK_NE(wait_state_, SYNC_DISABLED);
542 CHECK_NE(wait_state_, SERVER_UNREACHABLE);
543 521
544 if (IsDataSynced()) { 522 if (IsDataSynced()) {
545 // Client is already synced; don't wait. 523 // Client is already synced; don't wait.
546 return true; 524 return true;
547 } 525 }
548 526
549 wait_state_ = WAITING_FOR_DATA_SYNC; 527 wait_state_ = WAITING_FOR_DATA_SYNC;
550 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); 528 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
551 if (wait_state_ == FULLY_SYNCED) { 529 if (wait_state_ == FULLY_SYNCED) {
552 return true; 530 return true;
(...skipping 10 matching lines...) Expand all
563 if (wait_state_ == SYNC_DISABLED) { 541 if (wait_state_ == SYNC_DISABLED) {
564 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; 542 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << ".";
565 return false; 543 return false;
566 } 544 }
567 545
568 if (IsFullySynced()) { 546 if (IsFullySynced()) {
569 // Client is already synced; don't wait. 547 // Client is already synced; don't wait.
570 return true; 548 return true;
571 } 549 }
572 550
573 if (wait_state_ == SERVER_UNREACHABLE) {
574 // Client was offline; wait for it to go online, and then wait for sync.
575 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
576 DCHECK_EQ(wait_state_, WAITING_FOR_FULL_SYNC);
577 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
578 }
579
580 DCHECK(service()->sync_initialized()); 551 DCHECK(service()->sync_initialized());
581 wait_state_ = WAITING_FOR_FULL_SYNC; 552 wait_state_ = WAITING_FOR_FULL_SYNC;
582 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); 553 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
583 if (wait_state_ == FULLY_SYNCED) { 554 if (wait_state_ == FULLY_SYNCED) {
584 // Client is online; sync was successful. 555 // Client is online; sync was successful.
585 return true; 556 return true;
586 } else if (wait_state_ == SERVER_UNREACHABLE) {
587 // Client is offline; sync was unsuccessful.
588 LOG(ERROR) << "Client went offline after waiting for sync to finish";
589 return false;
590 } else { 557 } else {
591 LOG(ERROR) << "Invalid wait state: " << wait_state_; 558 LOG(ERROR) << "Invalid wait state: " << wait_state_;
592 return false; 559 return false;
593 } 560 }
594 } 561 }
595 562
596 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) { 563 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) {
597 DCHECK(service()->HasSyncSetupCompleted()); 564 DCHECK(service()->HasSyncSetupCompleted());
598 DCHECK_NE(wait_state_, SYNC_DISABLED); 565 DCHECK_NE(wait_state_, SYNC_DISABLED);
599 wait_state_ = WAITING_FOR_SYNC_DISABLED; 566 wait_state_ = WAITING_FOR_SYNC_DISABLED;
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 return service_->GetPreferredDataTypes().Has(type); 1062 return service_->GetPreferredDataTypes().Has(type);
1096 } 1063 }
1097 1064
1098 std::string ProfileSyncServiceHarness::GetServiceStatus() { 1065 std::string ProfileSyncServiceHarness::GetServiceStatus() {
1099 DictionaryValue value; 1066 DictionaryValue value;
1100 sync_ui_util::ConstructAboutInformation(service_, &value); 1067 sync_ui_util::ConstructAboutInformation(service_, &value);
1101 std::string service_status; 1068 std::string service_status;
1102 base::JSONWriter::Write(&value, true, &service_status); 1069 base::JSONWriter::Write(&value, true, &service_status);
1103 return service_status; 1070 return service_status;
1104 } 1071 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698