| OLD | NEW |
| 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.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 } | 457 } |
| 458 | 458 |
| 459 registrar_.Remove( | 459 registrar_.Remove( |
| 460 this, | 460 this, |
| 461 chrome::NOTIFICATION_SYNC_CONFIGURE_START, | 461 chrome::NOTIFICATION_SYNC_CONFIGURE_START, |
| 462 content::Source<DataTypeManager>(data_type_manager_.get())); | 462 content::Source<DataTypeManager>(data_type_manager_.get())); |
| 463 registrar_.Remove( | 463 registrar_.Remove( |
| 464 this, | 464 this, |
| 465 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, | 465 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
| 466 content::Source<DataTypeManager>(data_type_manager_.get())); | 466 content::Source<DataTypeManager>(data_type_manager_.get())); |
| 467 registrar_.Remove( |
| 468 this, |
| 469 chrome::NOTIFICATION_SYNC_CONFIGURE_BLOCKED, |
| 470 content::Source<DataTypeManager>(data_type_manager_.get())); |
| 467 data_type_manager_.reset(); | 471 data_type_manager_.reset(); |
| 468 } | 472 } |
| 469 | 473 |
| 470 // Shutdown the migrator before the backend to ensure it doesn't pull a null | 474 // Shutdown the migrator before the backend to ensure it doesn't pull a null |
| 471 // snapshot. | 475 // snapshot. |
| 472 migrator_.reset(); | 476 migrator_.reset(); |
| 473 sync_js_controller_.AttachJsBackend(WeakHandle<JsBackend>()); | 477 sync_js_controller_.AttachJsBackend(WeakHandle<JsBackend>()); |
| 474 | 478 |
| 475 // Move aside the backend so nobody else tries to use it while we are | 479 // Move aside the backend so nobody else tries to use it while we are |
| 476 // shutting it down. | 480 // shutting it down. |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 NOTREACHED(); | 1128 NOTREACHED(); |
| 1125 return; | 1129 return; |
| 1126 } | 1130 } |
| 1127 | 1131 |
| 1128 UpdateSelectedTypesHistogram(sync_everything, chosen_types); | 1132 UpdateSelectedTypesHistogram(sync_everything, chosen_types); |
| 1129 sync_prefs_.SetKeepEverythingSynced(sync_everything); | 1133 sync_prefs_.SetKeepEverythingSynced(sync_everything); |
| 1130 | 1134 |
| 1131 failed_datatypes_handler_.OnUserChoseDatatypes(); | 1135 failed_datatypes_handler_.OnUserChoseDatatypes(); |
| 1132 ChangePreferredDataTypes(chosen_types); | 1136 ChangePreferredDataTypes(chosen_types); |
| 1133 AcknowledgeSyncedTypes(); | 1137 AcknowledgeSyncedTypes(); |
| 1138 NotifyObservers(); |
| 1134 } | 1139 } |
| 1135 | 1140 |
| 1136 void ProfileSyncService::ChangePreferredDataTypes( | 1141 void ProfileSyncService::ChangePreferredDataTypes( |
| 1137 syncable::ModelTypeSet preferred_types) { | 1142 syncable::ModelTypeSet preferred_types) { |
| 1138 | 1143 |
| 1139 DVLOG(1) << "ChangePreferredDataTypes invoked"; | 1144 DVLOG(1) << "ChangePreferredDataTypes invoked"; |
| 1140 const syncable::ModelTypeSet registered_types = GetRegisteredDataTypes(); | 1145 const syncable::ModelTypeSet registered_types = GetRegisteredDataTypes(); |
| 1141 const syncable::ModelTypeSet registered_preferred_types = | 1146 const syncable::ModelTypeSet registered_preferred_types = |
| 1142 Intersection(registered_types, preferred_types); | 1147 Intersection(registered_types, preferred_types); |
| 1143 sync_prefs_.SetPreferredDataTypes(registered_types, | 1148 sync_prefs_.SetPreferredDataTypes(registered_types, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 restart = true; | 1194 restart = true; |
| 1190 data_type_manager_.reset( | 1195 data_type_manager_.reset( |
| 1191 factory_->CreateDataTypeManager(backend_.get(), | 1196 factory_->CreateDataTypeManager(backend_.get(), |
| 1192 &data_type_controllers_)); | 1197 &data_type_controllers_)); |
| 1193 registrar_.Add(this, | 1198 registrar_.Add(this, |
| 1194 chrome::NOTIFICATION_SYNC_CONFIGURE_START, | 1199 chrome::NOTIFICATION_SYNC_CONFIGURE_START, |
| 1195 content::Source<DataTypeManager>(data_type_manager_.get())); | 1200 content::Source<DataTypeManager>(data_type_manager_.get())); |
| 1196 registrar_.Add(this, | 1201 registrar_.Add(this, |
| 1197 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, | 1202 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
| 1198 content::Source<DataTypeManager>(data_type_manager_.get())); | 1203 content::Source<DataTypeManager>(data_type_manager_.get())); |
| 1204 registrar_.Add(this, |
| 1205 chrome::NOTIFICATION_SYNC_CONFIGURE_BLOCKED, |
| 1206 content::Source<DataTypeManager>(data_type_manager_.get())); |
| 1199 | 1207 |
| 1200 // We create the migrator at the same time. | 1208 // We create the migrator at the same time. |
| 1201 migrator_.reset( | 1209 migrator_.reset( |
| 1202 new browser_sync::BackendMigrator( | 1210 new browser_sync::BackendMigrator( |
| 1203 profile_->GetDebugName(), GetUserShare(), | 1211 profile_->GetDebugName(), GetUserShare(), |
| 1204 this, data_type_manager_.get(), | 1212 this, data_type_manager_.get(), |
| 1205 base::Bind(&ProfileSyncService::StartSyncingWithServer, | 1213 base::Bind(&ProfileSyncService::StartSyncingWithServer, |
| 1206 base::Unretained(this)))); | 1214 base::Unretained(this)))); |
| 1207 } | 1215 } |
| 1208 | 1216 |
| 1209 const syncable::ModelTypeSet types = GetPreferredDataTypes(); | 1217 const syncable::ModelTypeSet types = GetPreferredDataTypes(); |
| 1210 if (IsPassphraseRequiredForDecryption()) { | 1218 if (IsPassphraseRequiredForDecryption()) { |
| 1211 // We need a passphrase still. We don't bother to attempt to configure | 1219 // We need a passphrase still. We don't bother to attempt to configure |
| 1212 // until we receive an OnPassphraseAccepted (which triggers a configure). | 1220 // until we receive an OnPassphraseAccepted (which triggers a configure). |
| 1213 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " | 1221 DVLOG(1) << "ProfileSyncService::ConfigureDataTypeManager bailing out " |
| 1214 << "because a passphrase required"; | 1222 << "because a passphrase required"; |
| 1223 NotifyObservers(); |
| 1215 return; | 1224 return; |
| 1216 } | 1225 } |
| 1217 sync_api::ConfigureReason reason = sync_api::CONFIGURE_REASON_UNKNOWN; | 1226 sync_api::ConfigureReason reason = sync_api::CONFIGURE_REASON_UNKNOWN; |
| 1218 if (!HasSyncSetupCompleted()) { | 1227 if (!HasSyncSetupCompleted()) { |
| 1219 reason = sync_api::CONFIGURE_REASON_NEW_CLIENT; | 1228 reason = sync_api::CONFIGURE_REASON_NEW_CLIENT; |
| 1220 } else if (restart == false || | 1229 } else if (restart == false || |
| 1221 sync_api::InitialSyncEndedForTypes(types, GetUserShare())) { | 1230 sync_api::InitialSyncEndedForTypes(types, GetUserShare())) { |
| 1222 reason = sync_api::CONFIGURE_REASON_RECONFIGURATION; | 1231 reason = sync_api::CONFIGURE_REASON_RECONFIGURATION; |
| 1223 } else { | 1232 } else { |
| 1224 DCHECK(restart); | 1233 DCHECK(restart); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 DisableForUser(); | 1395 DisableForUser(); |
| 1387 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { | 1396 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { |
| 1388 StartUp(); | 1397 StartUp(); |
| 1389 } | 1398 } |
| 1390 } | 1399 } |
| 1391 | 1400 |
| 1392 void ProfileSyncService::Observe(int type, | 1401 void ProfileSyncService::Observe(int type, |
| 1393 const content::NotificationSource& source, | 1402 const content::NotificationSource& source, |
| 1394 const content::NotificationDetails& details) { | 1403 const content::NotificationDetails& details) { |
| 1395 switch (type) { | 1404 switch (type) { |
| 1396 case chrome::NOTIFICATION_SYNC_CONFIGURE_START: { | 1405 case chrome::NOTIFICATION_SYNC_CONFIGURE_START: |
| 1406 case chrome::NOTIFICATION_SYNC_CONFIGURE_BLOCKED: |
| 1397 NotifyObservers(); | 1407 NotifyObservers(); |
| 1398 // TODO(sync): Maybe toast? | 1408 // TODO(sync): Maybe toast? |
| 1399 break; | 1409 break; |
| 1400 } | |
| 1401 case chrome::NOTIFICATION_SYNC_CONFIGURE_DONE: { | 1410 case chrome::NOTIFICATION_SYNC_CONFIGURE_DONE: { |
| 1402 // We should have cleared our cached passphrase before we get here (in | 1411 // We should have cleared our cached passphrase before we get here (in |
| 1403 // OnBackendInitialized()). | 1412 // OnBackendInitialized()). |
| 1404 DCHECK(cached_passphrase_.empty()); | 1413 DCHECK(cached_passphrase_.empty()); |
| 1405 | 1414 |
| 1406 DataTypeManager::ConfigureResult* result = | 1415 DataTypeManager::ConfigureResult* result = |
| 1407 content::Details<DataTypeManager::ConfigureResult>(details).ptr(); | 1416 content::Details<DataTypeManager::ConfigureResult>(details).ptr(); |
| 1408 | 1417 |
| 1409 configure_status_ = result->status; | 1418 configure_status_ = result->status; |
| 1410 DVLOG(1) << "PSS SYNC_CONFIGURE_DONE called with status: " | 1419 DVLOG(1) << "PSS SYNC_CONFIGURE_DONE called with status: " |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1658 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. | 1667 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. |
| 1659 ProfileSyncService* old_this = this; | 1668 ProfileSyncService* old_this = this; |
| 1660 this->~ProfileSyncService(); | 1669 this->~ProfileSyncService(); |
| 1661 new(old_this) ProfileSyncService( | 1670 new(old_this) ProfileSyncService( |
| 1662 new ProfileSyncComponentsFactoryImpl(profile, | 1671 new ProfileSyncComponentsFactoryImpl(profile, |
| 1663 CommandLine::ForCurrentProcess()), | 1672 CommandLine::ForCurrentProcess()), |
| 1664 profile, | 1673 profile, |
| 1665 signin, | 1674 signin, |
| 1666 behavior); | 1675 behavior); |
| 1667 } | 1676 } |
| OLD | NEW |