Chromium Code Reviews| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sync/glue/sync_backend_host.h" | 7 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 void DoSetEncryptionPassphrase(const std::string& passphrase, | 146 void DoSetEncryptionPassphrase(const std::string& passphrase, |
| 147 bool is_explicit); | 147 bool is_explicit); |
| 148 | 148 |
| 149 // Called to decrypt the pending keys. | 149 // Called to decrypt the pending keys. |
| 150 void DoSetDecryptionPassphrase(const std::string& passphrase); | 150 void DoSetDecryptionPassphrase(const std::string& passphrase); |
| 151 | 151 |
| 152 // Called to turn on encryption of all sync data as well as | 152 // Called to turn on encryption of all sync data as well as |
| 153 // reencrypt everything. | 153 // reencrypt everything. |
| 154 void DoEnableEncryptEverything(); | 154 void DoEnableEncryptEverything(); |
| 155 | 155 |
| 156 // Called to refresh encryption with the most recent passphrase | 156 // Called to perform tasks which require the metadata to be present, including |
| 157 // and set of encrypted types. Also adds device information to the nigori | 157 // refreshing encryption with the most passphrase and requested types an |
| 158 // node. |done_callback| is called on the sync thread. | 158 // updating device information. |
| 159 void DoRefreshNigori(const base::Closure& done_callback); | 159 void DoInitialProcessMetadata(const base::Closure& done_callback); |
| 160 | 160 |
| 161 // The shutdown order is a bit complicated: | 161 // The shutdown order is a bit complicated: |
| 162 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do | 162 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do |
| 163 // a final SaveChanges, and close sqlite handles. | 163 // a final SaveChanges, and close sqlite handles. |
| 164 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is | 164 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is |
| 165 // a blocking call). This causes syncapi thread-exit handlers | 165 // a blocking call). This causes syncapi thread-exit handlers |
| 166 // to run and make use of cached pointers to various components | 166 // to run and make use of cached pointers to various components |
| 167 // owned implicitly by us. | 167 // owned implicitly by us. |
| 168 // 3) Destroy this Core. That will delete syncapi components in a | 168 // 3) Destroy this Core. That will delete syncapi components in a |
| 169 // safe order because the thread that was using them has exited | 169 // safe order because the thread that was using them has exited |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 | 624 |
| 625 registrar_.reset(); | 625 registrar_.reset(); |
| 626 chrome_sync_notification_bridge_.reset(); | 626 chrome_sync_notification_bridge_.reset(); |
| 627 core_ = NULL; // Releases reference to core_. | 627 core_ = NULL; // Releases reference to core_. |
| 628 } | 628 } |
| 629 | 629 |
| 630 void SyncBackendHost::ConfigureDataTypes( | 630 void SyncBackendHost::ConfigureDataTypes( |
| 631 syncer::ConfigureReason reason, | 631 syncer::ConfigureReason reason, |
| 632 syncer::ModelTypeSet types_to_add, | 632 syncer::ModelTypeSet types_to_add, |
| 633 syncer::ModelTypeSet types_to_remove, | 633 syncer::ModelTypeSet types_to_remove, |
| 634 NigoriState nigori_state, | |
| 635 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, | 634 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, |
| 636 const base::Callback<void()>& retry_callback) { | 635 const base::Callback<void()>& retry_callback) { |
| 637 // Only one configure is allowed at a time. This is guaranteed by our | 636 // Only one configure is allowed at a time. This is guaranteed by our |
| 638 // callers. The SyncBackendHost requests one configure as the backend is | 637 // callers. The SyncBackendHost requests one configure as the backend is |
| 639 // initializing and waits for it to complete. After initialization, all | 638 // initializing and waits for it to complete. After initialization, all |
| 640 // configurations will pass through the DataTypeManager, which is careful to | 639 // configurations will pass through the DataTypeManager, which is careful to |
| 641 // never send a new configure request until the current request succeeds. | 640 // never send a new configure request until the current request succeeds. |
| 642 | 641 |
| 643 DCHECK_GT(initialization_state_, NOT_INITIALIZED); | 642 DCHECK_GT(initialization_state_, NOT_INITIALIZED); |
| 644 | 643 |
| 645 syncer::ModelTypeSet types_to_add_with_nigori = types_to_add; | |
| 646 syncer::ModelTypeSet types_to_remove_with_nigori = types_to_remove; | |
| 647 if (nigori_state == WITH_NIGORI) { | |
| 648 types_to_add_with_nigori.Put(syncer::NIGORI); | |
| 649 types_to_remove_with_nigori.Remove(syncer::NIGORI); | |
| 650 } else { | |
| 651 types_to_add_with_nigori.Remove(syncer::NIGORI); | |
| 652 types_to_remove_with_nigori.Put(syncer::NIGORI); | |
| 653 } | |
| 654 | |
| 655 // The SyncBackendRegistrar's routing info will be updated by adding the | 644 // The SyncBackendRegistrar's routing info will be updated by adding the |
| 656 // types_to_add_with_nigori to the list then removing | 645 // types_to_add to the list then removing types_to_remove. Any types which |
| 657 // types_to_remove_with_nigori. Any types which are not in either of those | 646 // are not in either of those sets will remain untouched. |
| 658 // sets will remain untouched. | |
| 659 // | 647 // |
| 660 // Types which were not in the list previously are not fully downloaded, so we | 648 // Types which were not in the list previously are not fully downloaded, so we |
| 661 // must ask the syncer to download them. Any newly supported datatypes will | 649 // must ask the syncer to download them. Any newly supported datatypes will |
| 662 // not have been in that routing info list, so they will be among the types | 650 // not have been in that routing info list, so they will be among the types |
| 663 // downloaded if they are enabled. | 651 // downloaded if they are enabled. |
| 664 // | 652 // |
| 665 // The SyncBackendRegistrar's state was initially derived from the types | 653 // The SyncBackendRegistrar's state was initially derived from the types |
| 666 // marked initial_sync_ended when the sync database was loaded. Afterwards it | 654 // marked initial_sync_ended when the sync database was loaded. Afterwards it |
| 667 // is modified only by this function. We expect it to remain in sync with the | 655 // is modified only by this function. We expect it to remain in sync with the |
| 668 // backend because configuration requests are never aborted; they are retried | 656 // backend because configuration requests are never aborted; they are retried |
| 669 // until they succeed or the browser is closed. | 657 // until they succeed or the browser is closed. |
| 670 | 658 |
| 671 syncer::ModelTypeSet types_to_download = registrar_->ConfigureDataTypes( | 659 syncer::ModelTypeSet types_to_download = registrar_->ConfigureDataTypes( |
| 672 types_to_add_with_nigori, types_to_remove_with_nigori); | 660 types_to_add, types_to_remove); |
| 673 if (!types_to_download.Empty()) | 661 if (!types_to_download.Empty()) |
| 674 types_to_download.Put(syncer::NIGORI); | 662 types_to_download.Put(syncer::NIGORI); |
| 675 | 663 |
| 676 // TODO(sync): crbug.com/137550. | 664 // TODO(sync): crbug.com/137550. |
| 677 // It's dangerous to configure types that have progress markers. Types with | 665 // It's dangerous to configure types that have progress markers. Types with |
| 678 // progress markers can trigger a MIGRATION_DONE response. We are not | 666 // progress markers can trigger a MIGRATION_DONE response. We are not |
| 679 // prepared to handle a migration during a configure, so we must ensure that | 667 // prepared to handle a migration during a configure, so we must ensure that |
| 680 // all our types_to_download actually contain no data before we sync them. | 668 // all our types_to_download actually contain no data before we sync them. |
| 681 // | 669 // |
| 682 // The most common way to end up in this situation used to be types which had | 670 // The most common way to end up in this situation used to be types which had |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1156 const std::string& passphrase) { | 1144 const std::string& passphrase) { |
| 1157 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1145 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1158 sync_manager_->SetDecryptionPassphrase(passphrase); | 1146 sync_manager_->SetDecryptionPassphrase(passphrase); |
| 1159 } | 1147 } |
| 1160 | 1148 |
| 1161 void SyncBackendHost::Core::DoEnableEncryptEverything() { | 1149 void SyncBackendHost::Core::DoEnableEncryptEverything() { |
| 1162 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1150 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1163 sync_manager_->EnableEncryptEverything(); | 1151 sync_manager_->EnableEncryptEverything(); |
| 1164 } | 1152 } |
| 1165 | 1153 |
| 1166 void SyncBackendHost::Core::DoRefreshNigori( | 1154 void SyncBackendHost::Core::DoInitialProcessMetadata( |
| 1167 const base::Closure& done_callback) { | 1155 const base::Closure& done_callback) { |
| 1168 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1156 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1169 chrome::VersionInfo version_info; | 1157 chrome::VersionInfo version_info; |
| 1170 sync_manager_->RefreshNigori(version_info.CreateVersionString(), | 1158 sync_manager_->InitialProcessMetadata(version_info.CreateVersionString(), |
| 1171 done_callback); | 1159 done_callback); |
| 1172 } | 1160 } |
| 1173 | 1161 |
| 1174 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( | 1162 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( |
| 1175 const base::Closure& closure) { | 1163 const base::Closure& closure) { |
| 1176 if (sync_manager_.get()) { | 1164 if (sync_manager_.get()) { |
| 1177 sync_manager_->StopSyncingForShutdown(closure); | 1165 sync_manager_->StopSyncingForShutdown(closure); |
| 1178 } else { | 1166 } else { |
| 1179 sync_loop_->PostTask(FROM_HERE, closure); | 1167 sync_loop_->PostTask(FROM_HERE, closure); |
| 1180 } | 1168 } |
| 1181 } | 1169 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1318 | 1306 |
| 1319 // Run initialization state machine. | 1307 // Run initialization state machine. |
| 1320 switch (initialization_state_) { | 1308 switch (initialization_state_) { |
| 1321 case NOT_INITIALIZED: | 1309 case NOT_INITIALIZED: |
| 1322 // This configuration should result in a download request if the nigori | 1310 // This configuration should result in a download request if the nigori |
| 1323 // type's initial_sync_ended bit is unset. If the download request | 1311 // type's initial_sync_ended bit is unset. If the download request |
| 1324 // contains progress markers, there is a risk that the server will try to | 1312 // contains progress markers, there is a risk that the server will try to |
| 1325 // trigger migration. That would be disastrous, so we must rely on the | 1313 // trigger migration. That would be disastrous, so we must rely on the |
| 1326 // sync manager to ensure that this type never has both progress markers | 1314 // sync manager to ensure that this type never has both progress markers |
| 1327 // and !initial_sync_ended. | 1315 // and !initial_sync_ended. |
| 1328 initialization_state_ = DOWNLOADING_NIGORI; | 1316 initialization_state_ = DOWNLOADING_METADATA; |
| 1329 ConfigureDataTypes( | 1317 ConfigureDataTypes( |
| 1330 syncer::CONFIGURE_REASON_NEW_CLIENT, | 1318 syncer::CONFIGURE_REASON_NEW_CLIENT, |
| 1319 syncer::ModelTypeSet(syncer::ControlTypes()), | |
|
rlarocque
2012/08/11 01:31:52
ControlTypes was intended to be a group of types t
| |
| 1331 syncer::ModelTypeSet(), | 1320 syncer::ModelTypeSet(), |
| 1332 syncer::ModelTypeSet(), | |
| 1333 WITH_NIGORI, | |
| 1334 // Calls back into this function. | 1321 // Calls back into this function. |
| 1335 base::Bind( | 1322 base::Bind( |
| 1336 &SyncBackendHost:: | 1323 &SyncBackendHost:: |
| 1337 HandleNigoriConfigurationCompletedOnFrontendLoop, | 1324 HandleNigoriConfigurationCompletedOnFrontendLoop, |
| 1338 weak_ptr_factory_.GetWeakPtr(), js_backend), | 1325 weak_ptr_factory_.GetWeakPtr(), js_backend), |
| 1339 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, | 1326 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, |
| 1340 weak_ptr_factory_.GetWeakPtr())); | 1327 weak_ptr_factory_.GetWeakPtr())); |
| 1341 break; | 1328 break; |
| 1342 case DOWNLOADING_NIGORI: | 1329 case DOWNLOADING_METADATA: |
| 1343 initialization_state_ = REFRESHING_NIGORI; | 1330 initialization_state_ = PROCESSING_METADATA; |
| 1344 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() | 1331 // Updates encryption and other metadata. Will call |
| 1345 // if necessary. | 1332 // OnEncryptedTypesChanged() and OnEncryptionComplete() if necessary. |
| 1346 RefreshNigori( | 1333 InitialProcessMetadata( |
| 1347 base::Bind( | 1334 base::Bind( |
| 1348 &SyncBackendHost:: | 1335 &SyncBackendHost:: |
| 1349 HandleInitializationCompletedOnFrontendLoop, | 1336 HandleInitializationCompletedOnFrontendLoop, |
| 1350 weak_ptr_factory_.GetWeakPtr(), js_backend, true)); | 1337 weak_ptr_factory_.GetWeakPtr(), js_backend, true)); |
| 1351 break; | 1338 break; |
| 1352 case REFRESHING_NIGORI: | 1339 case PROCESSING_METADATA: |
| 1353 initialization_state_ = INITIALIZED; | 1340 initialization_state_ = INITIALIZED; |
| 1354 // Now that we've downloaded the nigori node, we can see if there are any | 1341 // Now that we've downloaded the nigori node, we can see if there are any |
| 1355 // experimental types to enable. This should be done before we inform | 1342 // experimental types to enable. This should be done before we inform |
| 1356 // the frontend to ensure they're visible in the customize screen. | 1343 // the frontend to ensure they're visible in the customize screen. |
| 1357 AddExperimentalTypes(); | 1344 AddExperimentalTypes(); |
| 1358 frontend_->OnBackendInitialized(js_backend, true); | 1345 frontend_->OnBackendInitialized(js_backend, true); |
| 1359 break; | 1346 break; |
| 1360 default: | 1347 default: |
| 1361 NOTREACHED(); | 1348 NOTREACHED(); |
| 1362 } | 1349 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1526 | 1513 |
| 1527 // Needed because MessageLoop::PostTask is overloaded. | 1514 // Needed because MessageLoop::PostTask is overloaded. |
| 1528 void PostClosure(MessageLoop* message_loop, | 1515 void PostClosure(MessageLoop* message_loop, |
| 1529 const tracked_objects::Location& from_here, | 1516 const tracked_objects::Location& from_here, |
| 1530 const base::Closure& callback) { | 1517 const base::Closure& callback) { |
| 1531 message_loop->PostTask(from_here, callback); | 1518 message_loop->PostTask(from_here, callback); |
| 1532 } | 1519 } |
| 1533 | 1520 |
| 1534 } // namespace | 1521 } // namespace |
| 1535 | 1522 |
| 1536 void SyncBackendHost::RefreshNigori(const base::Closure& done_callback) { | 1523 void SyncBackendHost::InitialProcessMetadata( |
| 1524 const base::Closure& done_callback) { | |
| 1537 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1525 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1538 base::Closure sync_thread_done_callback = | 1526 base::Closure sync_thread_done_callback = |
| 1539 base::Bind(&PostClosure, | 1527 base::Bind(&PostClosure, |
| 1540 MessageLoop::current(), FROM_HERE, done_callback); | 1528 MessageLoop::current(), FROM_HERE, done_callback); |
| 1541 sync_thread_.message_loop()->PostTask( | 1529 sync_thread_.message_loop()->PostTask( |
| 1542 FROM_HERE, | 1530 FROM_HERE, |
| 1543 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, | 1531 base::Bind(&SyncBackendHost::Core::DoInitialProcessMetadata, |
| 1544 core_.get(), sync_thread_done_callback)); | 1532 core_.get(), sync_thread_done_callback)); |
| 1545 } | 1533 } |
| 1546 | 1534 |
| 1547 #undef SDVLOG | 1535 #undef SDVLOG |
| 1548 | 1536 |
| 1549 #undef SLOG | 1537 #undef SLOG |
| 1550 | 1538 |
| 1551 } // namespace browser_sync | 1539 } // namespace browser_sync |
| OLD | NEW |