| 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/backend_migrator.h" | 5 #include "chrome/browser/sync/backend_migrator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
| 11 #include "chrome/browser/sync/engine/configure_reason.h" | 11 #include "chrome/browser/sync/engine/configure_reason.h" |
| 12 #include "chrome/browser/sync/glue/data_type_manager.h" | 12 #include "chrome/browser/sync/glue/data_type_manager.h" |
| 13 #include "chrome/browser/sync/sessions/session_state.h" | 13 #include "chrome/browser/sync/sessions/session_state.h" |
| 14 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "content/browser/browser_thread.h" | 15 #include "content/browser/browser_thread.h" |
| 15 #include "content/common/notification_details.h" | 16 #include "content/common/notification_details.h" |
| 16 #include "content/common/notification_source.h" | 17 #include "content/common/notification_source.h" |
| 17 | 18 |
| 18 using syncable::ModelTypeSet; | 19 using syncable::ModelTypeSet; |
| 19 | 20 |
| 20 namespace browser_sync { | 21 namespace browser_sync { |
| 21 | 22 |
| 22 using sessions::SyncSessionSnapshot; | 23 using sessions::SyncSessionSnapshot; |
| 23 | 24 |
| 24 BackendMigrator::BackendMigrator(ProfileSyncService* service, | 25 BackendMigrator::BackendMigrator(ProfileSyncService* service, |
| 25 DataTypeManager* manager) | 26 DataTypeManager* manager) |
| 26 : state_(IDLE), service_(service), manager_(manager), | 27 : state_(IDLE), service_(service), manager_(manager), |
| 27 restart_migration_(false), | 28 restart_migration_(false), |
| 28 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 29 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 29 registrar_.Add(this, NotificationType::SYNC_CONFIGURE_DONE, | 30 registrar_.Add(this, chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
| 30 Source<DataTypeManager>(manager_)); | 31 Source<DataTypeManager>(manager_)); |
| 31 service_->AddObserver(this); | 32 service_->AddObserver(this); |
| 32 } | 33 } |
| 33 | 34 |
| 34 BackendMigrator::~BackendMigrator() { | 35 BackendMigrator::~BackendMigrator() { |
| 35 service_->RemoveObserver(this); | 36 service_->RemoveObserver(this); |
| 36 } | 37 } |
| 37 | 38 |
| 38 bool BackendMigrator::HasStartedMigrating() const { | 39 bool BackendMigrator::HasStartedMigrating() const { |
| 39 return state_ >= DISABLING_TYPES; | 40 return state_ >= DISABLING_TYPES; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 state_ = REENABLING_TYPES; | 107 state_ = REENABLING_TYPES; |
| 107 ModelTypeSet full_set; | 108 ModelTypeSet full_set; |
| 108 service_->GetPreferredDataTypes(&full_set); | 109 service_->GetPreferredDataTypes(&full_set); |
| 109 VLOG(1) << "BackendMigrator re-enabling types."; | 110 VLOG(1) << "BackendMigrator re-enabling types."; |
| 110 | 111 |
| 111 // Don't use |to_migrate_| for the re-enabling because the user may have | 112 // Don't use |to_migrate_| for the re-enabling because the user may have |
| 112 // chosen to disable types during the migration. | 113 // chosen to disable types during the migration. |
| 113 manager_->Configure(full_set, sync_api::CONFIGURE_REASON_MIGRATION); | 114 manager_->Configure(full_set, sync_api::CONFIGURE_REASON_MIGRATION); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void BackendMigrator::Observe(NotificationType type, | 117 void BackendMigrator::Observe(int type, |
| 117 const NotificationSource& source, | 118 const NotificationSource& source, |
| 118 const NotificationDetails& details) { | 119 const NotificationDetails& details) { |
| 119 DCHECK_EQ(NotificationType::SYNC_CONFIGURE_DONE, type.value); | 120 DCHECK_EQ(chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, type); |
| 120 if (state_ == IDLE) | 121 if (state_ == IDLE) |
| 121 return; | 122 return; |
| 122 | 123 |
| 123 DataTypeManager::ConfigureResultWithErrorLocation* result = | 124 DataTypeManager::ConfigureResultWithErrorLocation* result = |
| 124 Details<DataTypeManager::ConfigureResultWithErrorLocation>( | 125 Details<DataTypeManager::ConfigureResultWithErrorLocation>( |
| 125 details).ptr(); | 126 details).ptr(); |
| 126 | 127 |
| 127 ModelTypeSet intersection; | 128 ModelTypeSet intersection; |
| 128 std::set_intersection(result->requested_types.begin(), | 129 std::set_intersection(result->requested_types.begin(), |
| 129 result->requested_types.end(), to_migrate_.begin(), to_migrate_.end(), | 130 result->requested_types.end(), to_migrate_.begin(), to_migrate_.end(), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 VLOG(1) << "BackendMigrator: Migration complete for: " << ss.str(); | 178 VLOG(1) << "BackendMigrator: Migration complete for: " << ss.str(); |
| 178 to_migrate_.clear(); | 179 to_migrate_.clear(); |
| 179 } | 180 } |
| 180 } | 181 } |
| 181 | 182 |
| 182 BackendMigrator::State BackendMigrator::state() const { | 183 BackendMigrator::State BackendMigrator::state() const { |
| 183 return state_; | 184 return state_; |
| 184 } | 185 } |
| 185 | 186 |
| 186 }; // namespace browser_sync | 187 }; // namespace browser_sync |
| OLD | NEW |