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/engine/syncapi.h" | 5 #include "chrome/browser/sync/engine/syncapi.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <bitset> | 8 #include <bitset> |
9 #include <iomanip> | 9 #include <iomanip> |
10 #include <list> | 10 #include <list> |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "base/sha1.h" | 21 #include "base/sha1.h" |
22 #include "base/string_number_conversions.h" | 22 #include "base/string_number_conversions.h" |
23 #include "base/string_util.h" | 23 #include "base/string_util.h" |
24 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
25 #include "base/task.h" | 25 #include "base/task.h" |
26 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
27 #include "base/values.h" | 27 #include "base/values.h" |
28 #include "chrome/browser/sync/engine/all_status.h" | 28 #include "chrome/browser/sync/engine/all_status.h" |
29 #include "chrome/browser/sync/engine/change_reorder_buffer.h" | 29 #include "chrome/browser/sync/engine/change_reorder_buffer.h" |
30 #include "chrome/browser/sync/engine/model_safe_worker.h" | 30 #include "chrome/browser/sync/engine/model_safe_worker.h" |
31 #include "chrome/browser/sync/engine/nudge_source.h" | |
31 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 32 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
32 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" | 33 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" |
33 #include "chrome/browser/sync/engine/syncer.h" | 34 #include "chrome/browser/sync/engine/syncer.h" |
34 #include "chrome/browser/sync/engine/syncer_thread.h" | 35 #include "chrome/browser/sync/engine/syncer_thread.h" |
35 #include "chrome/browser/sync/engine/syncer_thread2.h" | |
36 #include "chrome/browser/sync/engine/syncer_thread_adapter.h" | 36 #include "chrome/browser/sync/engine/syncer_thread_adapter.h" |
37 #include "chrome/browser/sync/engine/http_post_provider_factory.h" | 37 #include "chrome/browser/sync/engine/http_post_provider_factory.h" |
38 #include "chrome/browser/sync/js_arg_list.h" | 38 #include "chrome/browser/sync/js_arg_list.h" |
39 #include "chrome/browser/sync/js_backend.h" | 39 #include "chrome/browser/sync/js_backend.h" |
40 #include "chrome/browser/sync/js_event_router.h" | 40 #include "chrome/browser/sync/js_event_router.h" |
41 #include "chrome/browser/sync/notifier/sync_notifier.h" | 41 #include "chrome/browser/sync/notifier/sync_notifier.h" |
42 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" | 42 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" |
43 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 43 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
44 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 44 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
45 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 45 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
(...skipping 1611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1657 | 1657 |
1658 void SyncManager::EncryptDataTypes( | 1658 void SyncManager::EncryptDataTypes( |
1659 const syncable::ModelTypeSet& encrypted_types) { | 1659 const syncable::ModelTypeSet& encrypted_types) { |
1660 data_->EncryptDataTypes(encrypted_types); | 1660 data_->EncryptDataTypes(encrypted_types); |
1661 } | 1661 } |
1662 | 1662 |
1663 bool SyncManager::IsUsingExplicitPassphrase() { | 1663 bool SyncManager::IsUsingExplicitPassphrase() { |
1664 return data_ && data_->IsUsingExplicitPassphrase(); | 1664 return data_ && data_->IsUsingExplicitPassphrase(); |
1665 } | 1665 } |
1666 | 1666 |
1667 bool SyncManager::RequestPause() { | |
1668 if (data_->syncer_thread()) | |
1669 return data_->syncer_thread()->RequestPause(); | |
1670 return false; | |
1671 } | |
1672 | |
1673 bool SyncManager::RequestResume() { | |
1674 if (data_->syncer_thread()) | |
1675 return data_->syncer_thread()->RequestResume(); | |
1676 return false; | |
1677 } | |
1678 | |
1679 void SyncManager::RequestNudge(const tracked_objects::Location& location) { | 1667 void SyncManager::RequestNudge(const tracked_objects::Location& location) { |
1680 if (data_->syncer_thread()) | 1668 if (data_->syncer_thread()) |
1681 data_->syncer_thread()->NudgeSyncer(0, SyncerThread::kLocal, location); | 1669 data_->syncer_thread()->NudgeSyncer( |
1670 0, browser_sync::NUDGE_SOURCE_LOCAL, location); | |
1682 } | 1671 } |
1683 | 1672 |
1684 void SyncManager::RequestClearServerData() { | 1673 void SyncManager::RequestClearServerData() { |
1685 if (data_->syncer_thread()) | 1674 if (data_->syncer_thread()) |
1686 data_->syncer_thread()->NudgeSyncer(0, SyncerThread::kClearPrivateData, | 1675 data_->syncer_thread()->NudgeSyncer( |
1687 FROM_HERE); | 1676 0, browser_sync::CLEAR_USER_PRIVATE_DATA, FROM_HERE); |
tim (not reviewing)
2011/04/18 16:11:47
SyncerThread has a "ScheduleClear..." operation, y
lipalani1
2011/04/18 20:36:41
Done.
| |
1688 } | 1677 } |
1689 | 1678 |
1690 void SyncManager::RequestConfig(const syncable::ModelTypeBitSet& types) { | 1679 void SyncManager::RequestConfig(const syncable::ModelTypeBitSet& types) { |
1691 if (!data_->syncer_thread()) | 1680 if (!data_->syncer_thread()) |
1692 return; | 1681 return; |
1693 // It is an error for this to be called if new_impl is null. | |
1694 StartConfigurationMode(NULL); | 1682 StartConfigurationMode(NULL); |
1695 data_->syncer_thread()->new_impl()->ScheduleConfig(types); | 1683 data_->syncer_thread()->new_impl()->ScheduleConfig(types); |
1696 } | 1684 } |
1697 | 1685 |
1698 void SyncManager::StartConfigurationMode(ModeChangeCallback* callback) { | 1686 void SyncManager::StartConfigurationMode(ModeChangeCallback* callback) { |
1699 if (!data_->syncer_thread()) | 1687 if (!data_->syncer_thread()) |
1700 return; | 1688 return; |
1701 if (!data_->syncer_thread()->new_impl()) | 1689 if (!data_->syncer_thread()->new_impl()) |
1702 return; | 1690 return; |
1703 data_->syncer_thread()->new_impl()->Start( | 1691 data_->syncer_thread()->new_impl()->Start( |
1704 browser_sync::s3::SyncerThread::CONFIGURATION_MODE, callback); | 1692 browser_sync::SyncerThread::CONFIGURATION_MODE, callback); |
1705 } | 1693 } |
1706 | 1694 |
1707 const std::string& SyncManager::GetAuthenticatedUsername() { | 1695 const std::string& SyncManager::GetAuthenticatedUsername() { |
1708 DCHECK(data_); | 1696 DCHECK(data_); |
1709 return data_->username_for_share(); | 1697 return data_->username_for_share(); |
1710 } | 1698 } |
1711 | 1699 |
1712 bool SyncManager::SyncInternal::Init( | 1700 bool SyncManager::SyncInternal::Init( |
1713 const FilePath& database_location, | 1701 const FilePath& database_location, |
1714 const std::string& sync_server_and_path, | 1702 const std::string& sync_server_and_path, |
(...skipping 17 matching lines...) Expand all Loading... | |
1732 sync_notifier_ = sync_notifier; | 1720 sync_notifier_ = sync_notifier; |
1733 sync_notifier_->AddObserver(this); | 1721 sync_notifier_->AddObserver(this); |
1734 | 1722 |
1735 share_.dir_manager.reset(new DirectoryManager(database_location)); | 1723 share_.dir_manager.reset(new DirectoryManager(database_location)); |
1736 | 1724 |
1737 connection_manager_.reset(new SyncAPIServerConnectionManager( | 1725 connection_manager_.reset(new SyncAPIServerConnectionManager( |
1738 sync_server_and_path, port, use_ssl, user_agent, post_factory)); | 1726 sync_server_and_path, port, use_ssl, user_agent, post_factory)); |
1739 | 1727 |
1740 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 1728 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
1741 | 1729 |
1742 bool new_syncer_thread = CommandLine::ForCurrentProcess()->HasSwitch( | 1730 connection_manager()->AddListener(this); |
1743 switches::kNewSyncerThread); | |
1744 | |
1745 if (new_syncer_thread) { | |
1746 connection_manager()->AddListener(this); | |
1747 } else { | |
1748 connection_manager_hookup_.reset( | |
1749 NewEventListenerHookup(connection_manager()->channel(), this, | |
1750 &SyncManager::SyncInternal::HandleServerConnectionEvent)); | |
1751 } | |
1752 | 1731 |
1753 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we | 1732 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we |
1754 // try to shut down sync. Fix this. | 1733 // try to shut down sync. Fix this. |
1755 core_message_loop_->PostTask(FROM_HERE, | 1734 core_message_loop_->PostTask(FROM_HERE, |
1756 method_factory_.NewRunnableMethod(&SyncInternal::CheckServerReachable)); | 1735 method_factory_.NewRunnableMethod(&SyncInternal::CheckServerReachable)); |
1757 | 1736 |
1758 // Test mode does not use a syncer context or syncer thread. | 1737 // Test mode does not use a syncer context or syncer thread. |
1759 if (!setup_for_test_mode_) { | 1738 if (!setup_for_test_mode_) { |
1760 // Build a SyncSessionContext and store the worker in it. | 1739 // Build a SyncSessionContext and store the worker in it. |
1761 VLOG(1) << "Sync is bringing up SyncSessionContext."; | 1740 VLOG(1) << "Sync is bringing up SyncSessionContext."; |
1762 std::vector<SyncEngineEventListener*> listeners; | 1741 std::vector<SyncEngineEventListener*> listeners; |
1763 listeners.push_back(&allstatus_); | 1742 listeners.push_back(&allstatus_); |
1764 listeners.push_back(this); | 1743 listeners.push_back(this); |
1765 SyncSessionContext* context = new SyncSessionContext( | 1744 SyncSessionContext* context = new SyncSessionContext( |
1766 connection_manager_.get(), | 1745 connection_manager_.get(), |
1767 dir_manager(), | 1746 dir_manager(), |
1768 model_safe_worker_registrar, | 1747 model_safe_worker_registrar, |
1769 listeners); | 1748 listeners); |
1770 context->set_account_name(credentials.email); | 1749 context->set_account_name(credentials.email); |
1771 // The SyncerThread takes ownership of |context|. | 1750 // The SyncerThread takes ownership of |context|. |
1772 syncer_thread_.reset(new SyncerThreadAdapter(context, | 1751 syncer_thread_.reset(new SyncerThreadAdapter(context)); |
tim (not reviewing)
2011/04/18 16:11:47
Can we just yank SyncerThreadAdapter now too?
lipalani1
2011/04/18 20:36:41
Done.
| |
1773 new_syncer_thread)); | |
1774 } | 1752 } |
1775 | 1753 |
1776 bool signed_in = SignIn(credentials); | 1754 bool signed_in = SignIn(credentials); |
1777 | 1755 |
1778 // Do this once the directory is opened. | 1756 // Do this once the directory is opened. |
1779 BootstrapEncryption(restored_key_for_bootstrapping); | 1757 BootstrapEncryption(restored_key_for_bootstrapping); |
1780 return signed_in; | 1758 return signed_in; |
1781 } | 1759 } |
1782 | 1760 |
1783 void SyncManager::SyncInternal::BootstrapEncryption( | 1761 void SyncManager::SyncInternal::BootstrapEncryption( |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1875 | 1853 |
1876 // Database has to be initialized for the guid to be available. | 1854 // Database has to be initialized for the guid to be available. |
1877 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | 1855 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); |
1878 if (!lookup.good()) { | 1856 if (!lookup.good()) { |
1879 NOTREACHED(); | 1857 NOTREACHED(); |
1880 return false; | 1858 return false; |
1881 } | 1859 } |
1882 | 1860 |
1883 connection_manager()->set_client_id(lookup->cache_guid()); | 1861 connection_manager()->set_client_id(lookup->cache_guid()); |
1884 | 1862 |
1885 if (syncer_thread()) | |
1886 syncer_thread()->CreateSyncer(username_for_share()); | |
1887 | |
1888 MarkAndNotifyInitializationComplete(); | 1863 MarkAndNotifyInitializationComplete(); |
1889 dir_change_hookup_.reset(lookup->AddChangeObserver(this)); | 1864 dir_change_hookup_.reset(lookup->AddChangeObserver(this)); |
1890 return true; | 1865 return true; |
1891 } | 1866 } |
1892 | 1867 |
1893 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) { | 1868 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) { |
1894 DCHECK_EQ(MessageLoop::current(), core_message_loop_); | 1869 DCHECK_EQ(MessageLoop::current(), core_message_loop_); |
1895 DCHECK(share_.name.empty()); | 1870 DCHECK(share_.name.empty()); |
1896 share_.name = credentials.email; | 1871 share_.name = credentials.email; |
1897 | 1872 |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2412 model_types[model_type] = true; | 2387 model_types[model_type] = true; |
2413 if (model_type != syncable::PREFERENCES) | 2388 if (model_type != syncable::PREFERENCES) |
2414 only_preference_changes = false; | 2389 only_preference_changes = false; |
2415 } | 2390 } |
2416 } | 2391 } |
2417 if (exists_unsynced_items && syncer_thread()) { | 2392 if (exists_unsynced_items && syncer_thread()) { |
2418 int nudge_delay = only_preference_changes ? | 2393 int nudge_delay = only_preference_changes ? |
2419 kPreferencesNudgeDelayMilliseconds : kDefaultNudgeDelayMilliseconds; | 2394 kPreferencesNudgeDelayMilliseconds : kDefaultNudgeDelayMilliseconds; |
2420 syncer_thread()->NudgeSyncerWithDataTypes( | 2395 syncer_thread()->NudgeSyncerWithDataTypes( |
2421 nudge_delay, | 2396 nudge_delay, |
2422 SyncerThread::kLocal, | 2397 browser_sync::NUDGE_SOURCE_LOCAL, |
2423 model_types, | 2398 model_types, |
2424 FROM_HERE); | 2399 FROM_HERE); |
2425 } | 2400 } |
2426 } | 2401 } |
2427 | 2402 |
2428 void SyncManager::SyncInternal::SetExtraChangeRecordData(int64 id, | 2403 void SyncManager::SyncInternal::SetExtraChangeRecordData(int64 id, |
2429 syncable::ModelType type, ChangeReorderBuffer* buffer, | 2404 syncable::ModelType type, ChangeReorderBuffer* buffer, |
2430 Cryptographer* cryptographer, const syncable::EntryKernel& original, | 2405 Cryptographer* cryptographer, const syncable::EntryKernel& original, |
2431 bool existed_before, bool exists_now) { | 2406 bool existed_before, bool exists_now) { |
2432 // If this is a deletion and the datatype was encrypted, we need to decrypt it | 2407 // If this is a deletion and the datatype was encrypted, we need to decrypt it |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2568 (event.snapshot->syncer_status.num_successful_commits > 0); | 2543 (event.snapshot->syncer_status.num_successful_commits > 0); |
2569 if (new_notification) { | 2544 if (new_notification) { |
2570 core_message_loop_->PostTask( | 2545 core_message_loop_->PostTask( |
2571 FROM_HERE, | 2546 FROM_HERE, |
2572 NewRunnableMethod( | 2547 NewRunnableMethod( |
2573 this, | 2548 this, |
2574 &SyncManager::SyncInternal::SendNotification)); | 2549 &SyncManager::SyncInternal::SendNotification)); |
2575 } | 2550 } |
2576 } | 2551 } |
2577 | 2552 |
2578 if (event.what_happened == SyncEngineEvent::SYNCER_THREAD_PAUSED) { | |
2579 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | |
2580 OnPaused()); | |
2581 return; | |
2582 } | |
2583 | |
2584 if (event.what_happened == SyncEngineEvent::SYNCER_THREAD_RESUMED) { | |
2585 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | |
2586 OnResumed()); | |
2587 return; | |
2588 } | |
2589 | |
2590 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { | 2553 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { |
2591 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2554 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
2592 OnStopSyncingPermanently()); | 2555 OnStopSyncingPermanently()); |
2593 return; | 2556 return; |
2594 } | 2557 } |
2595 | 2558 |
2596 if (event.what_happened == SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED) { | 2559 if (event.what_happened == SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED) { |
2597 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2560 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
2598 OnClearServerDataSucceeded()); | 2561 OnClearServerDataSucceeded()); |
2599 return; | 2562 return; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2763 info->payload = it->second; | 2726 info->payload = it->second; |
2764 } | 2727 } |
2765 } | 2728 } |
2766 | 2729 |
2767 void SyncManager::SyncInternal::OnIncomingNotification( | 2730 void SyncManager::SyncInternal::OnIncomingNotification( |
2768 const syncable::ModelTypePayloadMap& type_payloads) { | 2731 const syncable::ModelTypePayloadMap& type_payloads) { |
2769 if (!type_payloads.empty()) { | 2732 if (!type_payloads.empty()) { |
2770 if (syncer_thread()) { | 2733 if (syncer_thread()) { |
2771 syncer_thread()->NudgeSyncerWithPayloads( | 2734 syncer_thread()->NudgeSyncerWithPayloads( |
2772 kSyncerThreadDelayMsec, | 2735 kSyncerThreadDelayMsec, |
2773 SyncerThread::kNotification, | 2736 browser_sync::NUDGE_SOURCE_NOTIFICATION, |
2774 type_payloads, FROM_HERE); | 2737 type_payloads, FROM_HERE); |
2775 } | 2738 } |
2776 allstatus_.IncrementNotificationsReceived(); | 2739 allstatus_.IncrementNotificationsReceived(); |
2777 UpdateNotificationInfo(type_payloads); | 2740 UpdateNotificationInfo(type_payloads); |
2778 } else { | 2741 } else { |
2779 LOG(WARNING) << "Sync received notification without any type information."; | 2742 LOG(WARNING) << "Sync received notification without any type information."; |
2780 } | 2743 } |
2781 | 2744 |
2782 if (parent_router_) { | 2745 if (parent_router_) { |
2783 ListValue args; | 2746 ListValue args; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2879 void SyncManager::TriggerOnIncomingNotificationForTest( | 2842 void SyncManager::TriggerOnIncomingNotificationForTest( |
2880 const syncable::ModelTypeBitSet& model_types) { | 2843 const syncable::ModelTypeBitSet& model_types) { |
2881 syncable::ModelTypePayloadMap model_types_with_payloads = | 2844 syncable::ModelTypePayloadMap model_types_with_payloads = |
2882 syncable::ModelTypePayloadMapFromBitSet(model_types, | 2845 syncable::ModelTypePayloadMapFromBitSet(model_types, |
2883 std::string()); | 2846 std::string()); |
2884 | 2847 |
2885 data_->OnIncomingNotification(model_types_with_payloads); | 2848 data_->OnIncomingNotification(model_types_with_payloads); |
2886 } | 2849 } |
2887 | 2850 |
2888 } // namespace sync_api | 2851 } // namespace sync_api |
OLD | NEW |