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

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

Issue 9348036: Trim code from sync's ServerConnectionManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: small updates Created 8 years, 10 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 267 }
268 break; 268 break;
269 } 269 }
270 case WAITING_FOR_FULL_SYNC: { 270 case WAITING_FOR_FULL_SYNC: {
271 DVLOG(1) << GetClientInfoString("WAITING_FOR_FULL_SYNC"); 271 DVLOG(1) << GetClientInfoString("WAITING_FOR_FULL_SYNC");
272 if (IsFullySynced()) { 272 if (IsFullySynced()) {
273 // The sync cycle we were waiting for is complete. 273 // The sync cycle we were waiting for is complete.
274 SignalStateCompleteWithNextState(FULLY_SYNCED); 274 SignalStateCompleteWithNextState(FULLY_SYNCED);
275 break; 275 break;
276 } 276 }
277 if (!GetStatus().server_reachable) {
278 // The client cannot reach the sync server because the network is
279 // disabled. There is no need to wait anymore.
280 SignalStateCompleteWithNextState(SERVER_UNREACHABLE);
281 break;
282 }
283 break; 277 break;
284 } 278 }
285 case WAITING_FOR_DATA_SYNC: { 279 case WAITING_FOR_DATA_SYNC: {
286 if (IsDataSynced()) { 280 if (IsDataSynced()) {
287 SignalStateCompleteWithNextState(FULLY_SYNCED); 281 SignalStateCompleteWithNextState(FULLY_SYNCED);
288 break; 282 break;
289 } 283 }
290 break; 284 break;
291 } 285 }
292 case WAITING_FOR_UPDATES: { 286 case WAITING_FOR_UPDATES: {
(...skipping 30 matching lines...) Expand all
323 // The correctness of this if condition may depend on the ordering of its 317 // The correctness of this if condition may depend on the ordering of its
324 // sub-expressions. See crbug.com/98607, crbug.com/95619. 318 // sub-expressions. See crbug.com/98607, crbug.com/95619.
325 // TODO(rlarocque): Figure out a less brittle way of detecting this. 319 // TODO(rlarocque): Figure out a less brittle way of detecting this.
326 if (IsTypeEncrypted(waiting_for_encryption_type_) && 320 if (IsTypeEncrypted(waiting_for_encryption_type_) &&
327 IsFullySynced() && 321 IsFullySynced() &&
328 GetLastSessionSnapshot()->num_conflicting_updates == 0) { 322 GetLastSessionSnapshot()->num_conflicting_updates == 0) {
329 // Encryption is now complete for the the type in which we were waiting. 323 // Encryption is now complete for the the type in which we were waiting.
330 SignalStateCompleteWithNextState(FULLY_SYNCED); 324 SignalStateCompleteWithNextState(FULLY_SYNCED);
331 break; 325 break;
332 } 326 }
333 if (!GetStatus().server_reachable) {
334 // The client cannot reach the sync server because the network is
335 // disabled. There is no need to wait anymore.
336 SignalStateCompleteWithNextState(SERVER_UNREACHABLE);
337 break;
338 }
339 break; 327 break;
340 } 328 }
341 case WAITING_FOR_SYNC_CONFIGURATION: { 329 case WAITING_FOR_SYNC_CONFIGURATION: {
342 DVLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_CONFIGURATION"); 330 DVLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_CONFIGURATION");
343 if (service()->ShouldPushChanges()) { 331 if (service()->ShouldPushChanges()) {
344 // The Datatype manager is configured and sync is fully initialized. 332 // The Datatype manager is configured and sync is fully initialized.
345 SignalStateCompleteWithNextState(FULLY_SYNCED); 333 SignalStateCompleteWithNextState(FULLY_SYNCED);
346 } 334 }
347 break; 335 break;
348 } 336 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 case WAITING_FOR_ACTIONABLE_ERROR: { 374 case WAITING_FOR_ACTIONABLE_ERROR: {
387 DVLOG(1) << GetClientInfoString("WAITING_FOR_ACTIONABLE_ERROR"); 375 DVLOG(1) << GetClientInfoString("WAITING_FOR_ACTIONABLE_ERROR");
388 ProfileSyncService::Status status = GetStatus(); 376 ProfileSyncService::Status status = GetStatus();
389 if (status.sync_protocol_error.action != browser_sync::UNKNOWN_ACTION && 377 if (status.sync_protocol_error.action != browser_sync::UNKNOWN_ACTION &&
390 service_->unrecoverable_error_detected() == true) { 378 service_->unrecoverable_error_detected() == true) {
391 // An actionable error has been detected. 379 // An actionable error has been detected.
392 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); 380 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING);
393 } 381 }
394 break; 382 break;
395 } 383 }
396 case SERVER_UNREACHABLE: {
397 DVLOG(1) << GetClientInfoString("SERVER_UNREACHABLE");
398 if (GetStatus().server_reachable) {
399 // The client was offline due to the network being disabled, but is now
400 // back online. Wait for the pending sync cycle to complete.
401 SignalStateCompleteWithNextState(WAITING_FOR_FULL_SYNC);
402 }
403 break;
404 }
405 case SET_PASSPHRASE_FAILED: { 384 case SET_PASSPHRASE_FAILED: {
406 // A passphrase is required for decryption. There is nothing the sync 385 // A passphrase is required for decryption. There is nothing the sync
407 // client can do until SetPassphrase() is called. 386 // client can do until SetPassphrase() is called.
408 DVLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED"); 387 DVLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED");
409 break; 388 break;
410 } 389 }
411 case FULLY_SYNCED: { 390 case FULLY_SYNCED: {
412 // The client is online and fully synced. There is nothing to do. 391 // The client is online and fully synced. There is nothing to do.
413 DVLOG(1) << GetClientInfoString("FULLY_SYNCED"); 392 DVLOG(1) << GetClientInfoString("FULLY_SYNCED");
414 break; 393 break;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, 504 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs,
526 "Waiting for sync configuration."); 505 "Waiting for sync configuration.");
527 } 506 }
528 507
529 bool ProfileSyncServiceHarness::AwaitDataSyncCompletion( 508 bool ProfileSyncServiceHarness::AwaitDataSyncCompletion(
530 const std::string& reason) { 509 const std::string& reason) {
531 DVLOG(1) << GetClientInfoString("AwaitDataSyncCompletion"); 510 DVLOG(1) << GetClientInfoString("AwaitDataSyncCompletion");
532 511
533 CHECK(service()->sync_initialized()); 512 CHECK(service()->sync_initialized());
534 CHECK_NE(wait_state_, SYNC_DISABLED); 513 CHECK_NE(wait_state_, SYNC_DISABLED);
535 CHECK_NE(wait_state_, SERVER_UNREACHABLE);
536 514
537 if (IsDataSynced()) { 515 if (IsDataSynced()) {
538 // Client is already synced; don't wait. 516 // Client is already synced; don't wait.
539 return true; 517 return true;
540 } 518 }
541 519
542 wait_state_ = WAITING_FOR_DATA_SYNC; 520 wait_state_ = WAITING_FOR_DATA_SYNC;
543 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); 521 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
544 if (wait_state_ == FULLY_SYNCED) { 522 if (wait_state_ == FULLY_SYNCED) {
545 return true; 523 return true;
(...skipping 10 matching lines...) Expand all
556 if (wait_state_ == SYNC_DISABLED) { 534 if (wait_state_ == SYNC_DISABLED) {
557 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; 535 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << ".";
558 return false; 536 return false;
559 } 537 }
560 538
561 if (IsFullySynced()) { 539 if (IsFullySynced()) {
562 // Client is already synced; don't wait. 540 // Client is already synced; don't wait.
563 return true; 541 return true;
564 } 542 }
565 543
566 if (wait_state_ == SERVER_UNREACHABLE) {
567 // Client was offline; wait for it to go online, and then wait for sync.
568 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
569 DCHECK_EQ(wait_state_, WAITING_FOR_FULL_SYNC);
570 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
571 }
572
573 DCHECK(service()->sync_initialized()); 544 DCHECK(service()->sync_initialized());
574 wait_state_ = WAITING_FOR_FULL_SYNC; 545 wait_state_ = WAITING_FOR_FULL_SYNC;
575 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); 546 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason);
576 if (wait_state_ == FULLY_SYNCED) { 547 if (wait_state_ == FULLY_SYNCED) {
577 // Client is online; sync was successful. 548 // Client is online; sync was successful.
578 return true; 549 return true;
579 } else if (wait_state_ == SERVER_UNREACHABLE) {
580 // Client is offline; sync was unsuccessful.
581 LOG(ERROR) << "Client went offline after waiting for sync to finish";
582 return false;
583 } else { 550 } else {
584 LOG(ERROR) << "Invalid wait state: " << wait_state_; 551 LOG(ERROR) << "Invalid wait state: " << wait_state_;
585 return false; 552 return false;
586 } 553 }
587 } 554 }
588 555
589 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) { 556 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) {
590 DCHECK(service()->HasSyncSetupCompleted()); 557 DCHECK(service()->HasSyncSetupCompleted());
591 DCHECK_NE(wait_state_, SYNC_DISABLED); 558 DCHECK_NE(wait_state_, SYNC_DISABLED);
592 wait_state_ = WAITING_FOR_SYNC_DISABLED; 559 wait_state_ = WAITING_FOR_SYNC_DISABLED;
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 return state_map.size(); 1074 return state_map.size();
1108 } 1075 }
1109 1076
1110 std::string ProfileSyncServiceHarness::GetServiceStatus() { 1077 std::string ProfileSyncServiceHarness::GetServiceStatus() {
1111 DictionaryValue value; 1078 DictionaryValue value;
1112 sync_ui_util::ConstructAboutInformation(service_, &value); 1079 sync_ui_util::ConstructAboutInformation(service_, &value);
1113 std::string service_status; 1080 std::string service_status;
1114 base::JSONWriter::Write(&value, true, &service_status); 1081 base::JSONWriter::Write(&value, true, &service_status);
1115 return service_status; 1082 return service_status;
1116 } 1083 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698