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 "chrome/browser/sync/profile_sync_service_harness.h" | 5 #include "chrome/browser/sync/profile_sync_service_harness.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/net/gaia/token_service.h" | 13 #include "chrome/browser/net/gaia/token_service.h" |
14 #include "chrome/browser/sync/glue/sync_backend_host.h" | 14 #include "chrome/browser/sync/glue/sync_backend_host.h" |
15 #include "chrome/browser/sync/sessions/session_state.h" | 15 #include "chrome/browser/sync/sessions/session_state.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/common/net/gaia/gaia_constants.h" | 17 #include "chrome/common/net/gaia/gaia_constants.h" |
18 #include "chrome/common/net/gaia/google_service_auth_error.h" | 18 #include "chrome/common/net/gaia/google_service_auth_error.h" |
19 #include "chrome/common/notification_source.h" | 19 #include "chrome/common/notification_source.h" |
20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
21 | 21 |
22 // The default value for min_timestamp_needed_ when we're not in the | 22 // The default value for min_timestamp_needed_ when we're not in the |
23 // WAITING_FOR_UPDATES state. | 23 // WAITING_FOR_UPDATES state. |
24 static const int kMinTimestampNeededNone = -1; | 24 static const int kMinTimestampNeededNone = -1; |
Raghu Simha
2011/01/11 18:53:04
I believe you can now get rid of this constant.
ncarter (slow)
2011/01/13 00:06:13
Done.
| |
25 | 25 |
26 // The amount of time for which we wait for a live sync operation to complete. | 26 // The amount of time for which we wait for a live sync operation to complete. |
27 static const int kLiveSyncOperationTimeoutMs = 30000; | 27 static const int kLiveSyncOperationTimeoutMs = 30000; |
28 | 28 |
29 // Simple class to implement a timeout using PostDelayedTask. If it is not | 29 // Simple class to implement a timeout using PostDelayedTask. If it is not |
30 // aborted before picked up by a message queue, then it asserts with the message | 30 // aborted before picked up by a message queue, then it asserts with the message |
31 // provided. This class is not thread safe. | 31 // provided. This class is not thread safe. |
32 class StateChangeTimeoutEvent | 32 class StateChangeTimeoutEvent |
33 : public base::RefCountedThreadSafe<StateChangeTimeoutEvent> { | 33 : public base::RefCountedThreadSafe<StateChangeTimeoutEvent> { |
34 public: | 34 public: |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 LogClientInfo("WAITING_FOR_SYNC_TO_FINISH"); | 253 LogClientInfo("WAITING_FOR_SYNC_TO_FINISH"); |
254 if (!IsSynced()) { | 254 if (!IsSynced()) { |
255 // The client is not yet fully synced. Continue waiting. | 255 // The client is not yet fully synced. Continue waiting. |
256 if (!GetStatus().server_reachable) { | 256 if (!GetStatus().server_reachable) { |
257 // The client cannot reach the sync server because the network is | 257 // The client cannot reach the sync server because the network is |
258 // disabled. There is no need to wait anymore. | 258 // disabled. There is no need to wait anymore. |
259 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | 259 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); |
260 } | 260 } |
261 break; | 261 break; |
262 } | 262 } |
263 GetUpdatedTimestamp(); | |
264 SignalStateCompleteWithNextState(FULLY_SYNCED); | 263 SignalStateCompleteWithNextState(FULLY_SYNCED); |
265 break; | 264 break; |
266 } | 265 } |
267 case WAITING_FOR_UPDATES: { | 266 case WAITING_FOR_UPDATES: { |
268 LogClientInfo("WAITING_FOR_UPDATES"); | 267 LogClientInfo("WAITING_FOR_UPDATES"); |
269 DCHECK(timestamp_match_partner_); | 268 DCHECK(timestamp_match_partner_); |
270 if (!MatchesOtherClient(timestamp_match_partner_)) { | 269 if (!MatchesOtherClient(timestamp_match_partner_)) { |
271 // The client is not yet fully synced; keep waiting until we converge. | 270 // The client is not yet fully synced; keep waiting until we converge. |
272 break; | 271 break; |
273 } | 272 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 } else if (wait_state_ == SERVER_UNREACHABLE) { | 341 } else if (wait_state_ == SERVER_UNREACHABLE) { |
343 // Client is offline; sync was unsuccessful. | 342 // Client is offline; sync was unsuccessful. |
344 return false; | 343 return false; |
345 } else { | 344 } else { |
346 LOG(ERROR) << "Invalid wait state:" << wait_state_; | 345 LOG(ERROR) << "Invalid wait state:" << wait_state_; |
347 return false; | 346 return false; |
348 } | 347 } |
349 } | 348 } |
350 } else { | 349 } else { |
351 // Client is already synced; don't wait. | 350 // Client is already synced; don't wait. |
352 GetUpdatedTimestamp(); | |
353 return true; | 351 return true; |
354 } | 352 } |
355 } | 353 } |
356 | 354 |
357 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( | 355 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
358 ProfileSyncServiceHarness* partner) { | 356 ProfileSyncServiceHarness* partner) { |
359 LogClientInfo("AwaitMutualSyncCycleCompletion"); | 357 LogClientInfo("AwaitMutualSyncCycleCompletion"); |
360 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) | 358 if (!AwaitSyncCycleCompletion("Sync cycle completion on active client.")) |
361 return false; | 359 return false; |
362 return partner->WaitUntilTimestampMatches(this, | 360 return partner->WaitUntilTimestampMatches(this, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 | 466 |
469 // Only look for a match if we have at least one enabled datatype in | 467 // Only look for a match if we have at least one enabled datatype in |
470 // common with the partner client. | 468 // common with the partner client. |
471 syncable::ModelTypeSet types, other_types, intersection_types; | 469 syncable::ModelTypeSet types, other_types, intersection_types; |
472 service()->GetPreferredDataTypes(&types); | 470 service()->GetPreferredDataTypes(&types); |
473 partner->service()->GetPreferredDataTypes(&other_types); | 471 partner->service()->GetPreferredDataTypes(&other_types); |
474 std::set_intersection(types.begin(), types.end(), other_types.begin(), | 472 std::set_intersection(types.begin(), types.end(), other_types.begin(), |
475 other_types.end(), | 473 other_types.end(), |
476 inserter(intersection_types, | 474 inserter(intersection_types, |
477 intersection_types.begin())); | 475 intersection_types.begin())); |
478 if (intersection_types.empty()) { | 476 for (syncable::ModelTypeSet::iterator i = intersection_types.begin(); |
479 return true; | 477 i != intersection_types.end(); |
478 ++i) { | |
479 if (!partner->IsSynced() || | |
480 partner->GetUpdatedTimestamp(*i) != GetUpdatedTimestamp(*i)) { | |
481 return false; | |
482 } | |
480 } | 483 } |
481 return partner->IsSynced() && | 484 return true; |
482 partner->GetUpdatedTimestamp() == GetUpdatedTimestamp(); | |
483 } | 485 } |
484 | 486 |
485 const SyncSessionSnapshot* | 487 const SyncSessionSnapshot* |
486 ProfileSyncServiceHarness::GetLastSessionSnapshot() const { | 488 ProfileSyncServiceHarness::GetLastSessionSnapshot() const { |
487 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; | 489 DCHECK(service_ != NULL) << "Sync service has not yet been set up."; |
488 if (service_->backend()) { | 490 if (service_->backend()) { |
489 return service_->backend()->GetLastSessionSnapshot(); | 491 return service_->backend()->GetLastSessionSnapshot(); |
490 } | 492 } |
491 return NULL; | 493 return NULL; |
492 } | 494 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 void ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { | 564 void ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { |
563 LogClientInfo("DisableSyncForAllDatatypes"); | 565 LogClientInfo("DisableSyncForAllDatatypes"); |
564 DCHECK(service() != NULL) << "EnableSyncForAllDatatypes(): service() is " | 566 DCHECK(service() != NULL) << "EnableSyncForAllDatatypes(): service() is " |
565 "null."; | 567 "null."; |
566 service()->DisableForUser(); | 568 service()->DisableForUser(); |
567 wait_state_ = SYNC_DISABLED; | 569 wait_state_ = SYNC_DISABLED; |
568 VLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all datatypes on " | 570 VLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all datatypes on " |
569 "Client " << id_; | 571 "Client " << id_; |
570 } | 572 } |
571 | 573 |
572 int64 ProfileSyncServiceHarness::GetUpdatedTimestamp() { | 574 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( |
575 syncable::ModelType model_type) { | |
573 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 576 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
574 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; | 577 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; |
575 return snap->max_local_timestamp; | 578 return snap->download_progress_markers[model_type]; |
576 } | 579 } |
577 | 580 |
578 void ProfileSyncServiceHarness::LogClientInfo(std::string message) { | 581 void ProfileSyncServiceHarness::LogClientInfo(std::string message) { |
579 if (service()) { | 582 if (service()) { |
580 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 583 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
581 if (snap) { | 584 if (snap) { |
582 VLOG(1) << "Client " << id_ << ": " << message | 585 VLOG(1) << "Client " << id_ << ": " << message |
583 << ": max_local_timestamp: " << snap->max_local_timestamp | 586 << ": num_updates_downloaded : " |
587 << snap->syncer_status.num_updates_downloaded | |
584 << ", has_more_to_sync: " << snap->has_more_to_sync | 588 << ", has_more_to_sync: " << snap->has_more_to_sync |
585 << ", unsynced_count: " << snap->unsynced_count | 589 << ", unsynced_count: " << snap->unsynced_count |
586 << ", num_conflicting_updates: " << snap->num_conflicting_updates | 590 << ", num_conflicting_updates: " << snap->num_conflicting_updates |
587 << ", has_unsynced_items: " | 591 << ", has_unsynced_items: " |
588 << service()->backend()->HasUnsyncedItems() | 592 << service()->backend()->HasUnsyncedItems() |
589 << ", observed_passphrase_required: " | 593 << ", observed_passphrase_required: " |
590 << service()->observed_passphrase_required() | 594 << service()->observed_passphrase_required() |
591 << ", notifications_enabled: " | 595 << ", notifications_enabled: " |
592 << GetStatus().notifications_enabled | 596 << GetStatus().notifications_enabled |
593 << ", service_is_pushing_changes: " << ServiceIsPushingChanges(); | 597 << ", service_is_pushing_changes: " << ServiceIsPushingChanges(); |
594 } else { | 598 } else { |
595 VLOG(1) << "Client " << id_ << ": " << message | 599 VLOG(1) << "Client " << id_ << ": " << message |
596 << ": Sync session snapshot not available."; | 600 << ": Sync session snapshot not available."; |
597 } | 601 } |
598 } else { | 602 } else { |
599 VLOG(1) << "Client " << id_ << ": " << message | 603 VLOG(1) << "Client " << id_ << ": " << message |
600 << ": Sync service not available."; | 604 << ": Sync service not available."; |
601 } | 605 } |
602 } | 606 } |
OLD | NEW |