Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / migration_watcher.cc
blob14e18d64669f4c8eecf913d56244f1bb9048aade
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/sync/test/integration/migration_watcher.h"
7 #include "chrome/browser/sync/profile_sync_service.h"
8 #include "chrome/browser/sync/test/integration/migration_waiter.h"
9 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
11 MigrationWatcher::MigrationWatcher(ProfileSyncServiceHarness* harness)
12 : harness_(harness), migration_waiter_(NULL) {
13 browser_sync::BackendMigrator* migrator =
14 harness_->service()->GetBackendMigratorForTest();
15 // PSS must have a migrator after sync is setup and initial data type
16 // configuration is complete.
17 migrator->AddMigrationObserver(this);
20 MigrationWatcher::~MigrationWatcher() {
21 DCHECK(!migration_waiter_);
24 bool MigrationWatcher::HasPendingBackendMigration() const {
25 browser_sync::BackendMigrator* migrator =
26 harness_->service()->GetBackendMigratorForTest();
27 return migrator && migrator->state() != browser_sync::BackendMigrator::IDLE;
30 syncer::ModelTypeSet MigrationWatcher::GetMigratedTypes() const {
31 return migrated_types_;
34 void MigrationWatcher::OnMigrationStateChange() {
35 if (HasPendingBackendMigration()) {
36 // A new bunch of data types are in the process of being migrated. Merge
37 // them into |pending_types_|.
38 pending_types_.PutAll(harness_->service()
39 ->GetBackendMigratorForTest()
40 ->GetPendingMigrationTypesForTest());
41 DVLOG(1) << harness_->profile_debug_name()
42 << ": new pending migration types "
43 << syncer::ModelTypeSetToString(pending_types_);
44 } else {
45 // Migration just finished for a bunch of data types. Merge them into
46 // |migrated_types_|.
47 migrated_types_.PutAll(pending_types_);
48 pending_types_.Clear();
49 DVLOG(1) << harness_->profile_debug_name() << ": new migrated types "
50 << syncer::ModelTypeSetToString(migrated_types_);
53 // Manually trigger a check of the exit condition.
54 if (migration_waiter_)
55 migration_waiter_->OnMigrationStateChange();
58 void MigrationWatcher::set_migration_waiter(MigrationWaiter* waiter) {
59 DCHECK(!migration_waiter_);
60 migration_waiter_ = waiter;
63 void MigrationWatcher::clear_migration_waiter() {
64 DCHECK(migration_waiter_);
65 migration_waiter_ = NULL;