Chromium Code Reviews| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 #include "content/browser/browser_thread.h" | 65 #include "content/browser/browser_thread.h" |
| 66 #include "net/base/network_change_notifier.h" | 66 #include "net/base/network_change_notifier.h" |
| 67 | 67 |
| 68 using browser_sync::AllStatus; | 68 using browser_sync::AllStatus; |
| 69 using browser_sync::Cryptographer; | 69 using browser_sync::Cryptographer; |
| 70 using browser_sync::KeyParams; | 70 using browser_sync::KeyParams; |
| 71 using browser_sync::ModelSafeRoutingInfo; | 71 using browser_sync::ModelSafeRoutingInfo; |
| 72 using browser_sync::ModelSafeWorker; | 72 using browser_sync::ModelSafeWorker; |
| 73 using browser_sync::ModelSafeWorkerRegistrar; | 73 using browser_sync::ModelSafeWorkerRegistrar; |
| 74 using browser_sync::ServerConnectionEvent; | 74 using browser_sync::ServerConnectionEvent; |
| 75 using browser_sync::ServerConnectionEvent2; | |
| 76 using browser_sync::ServerConnectionEventListener; | |
| 75 using browser_sync::SyncEngineEvent; | 77 using browser_sync::SyncEngineEvent; |
| 76 using browser_sync::SyncEngineEventListener; | 78 using browser_sync::SyncEngineEventListener; |
| 77 using browser_sync::Syncer; | 79 using browser_sync::Syncer; |
| 78 using browser_sync::SyncerThread; | 80 using browser_sync::SyncerThread; |
| 79 using browser_sync::SyncerThreadAdapter; | 81 using browser_sync::SyncerThreadAdapter; |
| 80 using browser_sync::kNigoriTag; | 82 using browser_sync::kNigoriTag; |
| 81 using browser_sync::sessions::SyncSessionContext; | 83 using browser_sync::sessions::SyncSessionContext; |
| 82 using std::list; | 84 using std::list; |
| 83 using std::hex; | 85 using std::hex; |
| 84 using std::string; | 86 using std::string; |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1103 return unencrypted_; | 1105 return unencrypted_; |
| 1104 } | 1106 } |
| 1105 | 1107 |
| 1106 ////////////////////////////////////////////////////////////////////////// | 1108 ////////////////////////////////////////////////////////////////////////// |
| 1107 // SyncManager's implementation: SyncManager::SyncInternal | 1109 // SyncManager's implementation: SyncManager::SyncInternal |
| 1108 class SyncManager::SyncInternal | 1110 class SyncManager::SyncInternal |
| 1109 : public net::NetworkChangeNotifier::IPAddressObserver, | 1111 : public net::NetworkChangeNotifier::IPAddressObserver, |
| 1110 public sync_notifier::SyncNotifierObserver, | 1112 public sync_notifier::SyncNotifierObserver, |
| 1111 public browser_sync::ChannelEventHandler<syncable::DirectoryChangeEvent>, | 1113 public browser_sync::ChannelEventHandler<syncable::DirectoryChangeEvent>, |
| 1112 public browser_sync::JsBackend, | 1114 public browser_sync::JsBackend, |
| 1113 public SyncEngineEventListener { | 1115 public SyncEngineEventListener, |
| 1116 public ServerConnectionEventListener { | |
| 1114 static const int kDefaultNudgeDelayMilliseconds; | 1117 static const int kDefaultNudgeDelayMilliseconds; |
| 1115 static const int kPreferencesNudgeDelayMilliseconds; | 1118 static const int kPreferencesNudgeDelayMilliseconds; |
| 1116 public: | 1119 public: |
| 1117 explicit SyncInternal(SyncManager* sync_manager) | 1120 explicit SyncInternal(SyncManager* sync_manager) |
| 1118 : core_message_loop_(NULL), | 1121 : core_message_loop_(NULL), |
| 1119 parent_router_(NULL), | 1122 parent_router_(NULL), |
| 1120 sync_manager_(sync_manager), | 1123 sync_manager_(sync_manager), |
| 1121 registrar_(NULL), | 1124 registrar_(NULL), |
| 1122 initialized_(false), | 1125 initialized_(false), |
| 1123 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 1126 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1300 DCHECK(false) << "ScopedDirLookup failed when checking initial sync"; | 1303 DCHECK(false) << "ScopedDirLookup failed when checking initial sync"; |
| 1301 syncable::AutofillMigrationDebugInfo null_value = {0}; | 1304 syncable::AutofillMigrationDebugInfo null_value = {0}; |
| 1302 return null_value; | 1305 return null_value; |
| 1303 } | 1306 } |
| 1304 return lookup->get_autofill_migration_debug_info(); | 1307 return lookup->get_autofill_migration_debug_info(); |
| 1305 } | 1308 } |
| 1306 | 1309 |
| 1307 // SyncEngineEventListener implementation. | 1310 // SyncEngineEventListener implementation. |
| 1308 virtual void OnSyncEngineEvent(const SyncEngineEvent& event); | 1311 virtual void OnSyncEngineEvent(const SyncEngineEvent& event); |
| 1309 | 1312 |
| 1313 // ServerConnectionEventListener implementation. | |
| 1314 virtual void OnServerConnectionEvent(const ServerConnectionEvent2& event); | |
| 1315 | |
| 1310 // browser_sync::JsBackend implementation. | 1316 // browser_sync::JsBackend implementation. |
| 1311 virtual void SetParentJsEventRouter(browser_sync::JsEventRouter* router); | 1317 virtual void SetParentJsEventRouter(browser_sync::JsEventRouter* router); |
| 1312 virtual void RemoveParentJsEventRouter(); | 1318 virtual void RemoveParentJsEventRouter(); |
| 1313 virtual const browser_sync::JsEventRouter* GetParentJsEventRouter() const; | 1319 virtual const browser_sync::JsEventRouter* GetParentJsEventRouter() const; |
| 1314 virtual void ProcessMessage(const std::string& name, | 1320 virtual void ProcessMessage(const std::string& name, |
| 1315 const browser_sync::JsArgList& args, | 1321 const browser_sync::JsArgList& args, |
| 1316 const browser_sync::JsEventHandler* sender); | 1322 const browser_sync::JsEventHandler* sender); |
| 1317 | 1323 |
| 1318 private: | 1324 private: |
| 1319 // Helper to call OnAuthError when no authentication credentials are | 1325 // Helper to call OnAuthError when no authentication credentials are |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1601 | 1607 |
| 1602 void SyncManager::RequestClearServerData() { | 1608 void SyncManager::RequestClearServerData() { |
| 1603 if (data_->syncer_thread()) | 1609 if (data_->syncer_thread()) |
| 1604 data_->syncer_thread()->NudgeSyncer(0, SyncerThread::kClearPrivateData); | 1610 data_->syncer_thread()->NudgeSyncer(0, SyncerThread::kClearPrivateData); |
| 1605 } | 1611 } |
| 1606 | 1612 |
| 1607 void SyncManager::RequestConfig(const syncable::ModelTypeBitSet& types) { | 1613 void SyncManager::RequestConfig(const syncable::ModelTypeBitSet& types) { |
| 1608 if (!data_->syncer_thread()) | 1614 if (!data_->syncer_thread()) |
| 1609 return; | 1615 return; |
| 1610 // It is an error for this to be called if new_impl is null. | 1616 // It is an error for this to be called if new_impl is null. |
| 1617 StartConfigurationMode(NULL); | |
| 1618 data_->syncer_thread()->new_impl()->ScheduleConfig(types); | |
| 1619 } | |
| 1620 | |
| 1621 void SyncManager::StartConfigurationMode(ModeChangeCallback* callback) { | |
| 1622 if (!data_->syncer_thread()) | |
| 1623 return; | |
| 1624 // It is an error for this to be called if new_impl is null. | |
| 1611 data_->syncer_thread()->new_impl()->Start( | 1625 data_->syncer_thread()->new_impl()->Start( |
| 1612 browser_sync::s3::SyncerThread::CONFIGURATION_MODE); | 1626 browser_sync::s3::SyncerThread::CONFIGURATION_MODE, callback); |
| 1613 data_->syncer_thread()->new_impl()->ScheduleConfig(types); | |
| 1614 } | 1627 } |
| 1615 | 1628 |
| 1616 const std::string& SyncManager::GetAuthenticatedUsername() { | 1629 const std::string& SyncManager::GetAuthenticatedUsername() { |
| 1617 DCHECK(data_); | 1630 DCHECK(data_); |
| 1618 return data_->username_for_share(); | 1631 return data_->username_for_share(); |
| 1619 } | 1632 } |
| 1620 | 1633 |
| 1621 bool SyncManager::SyncInternal::Init( | 1634 bool SyncManager::SyncInternal::Init( |
| 1622 const FilePath& database_location, | 1635 const FilePath& database_location, |
| 1623 const std::string& sync_server_and_path, | 1636 const std::string& sync_server_and_path, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1639 setup_for_test_mode_ = setup_for_test_mode; | 1652 setup_for_test_mode_ = setup_for_test_mode; |
| 1640 | 1653 |
| 1641 sync_notifier_.reset(sync_notifier); | 1654 sync_notifier_.reset(sync_notifier); |
| 1642 sync_notifier_->AddObserver(this); | 1655 sync_notifier_->AddObserver(this); |
| 1643 | 1656 |
| 1644 share_.dir_manager.reset(new DirectoryManager(database_location)); | 1657 share_.dir_manager.reset(new DirectoryManager(database_location)); |
| 1645 | 1658 |
| 1646 connection_manager_.reset(new SyncAPIServerConnectionManager( | 1659 connection_manager_.reset(new SyncAPIServerConnectionManager( |
| 1647 sync_server_and_path, port, use_ssl, user_agent, post_factory)); | 1660 sync_server_and_path, port, use_ssl, user_agent, post_factory)); |
| 1648 | 1661 |
| 1649 connection_manager_hookup_.reset( | 1662 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 1650 NewEventListenerHookup(connection_manager()->channel(), this, | |
| 1651 &SyncManager::SyncInternal::HandleServerConnectionEvent)); | |
| 1652 | 1663 |
| 1653 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 1664 bool new_syncer_thread = CommandLine::ForCurrentProcess()->HasSwitch( |
| 1665 switches::kNewSyncerThread); | |
| 1666 | |
| 1667 if (new_syncer_thread) { | |
| 1668 connection_manager()->AddListener(this); | |
| 1669 } else { | |
| 1670 connection_manager_hookup_.reset( | |
| 1671 NewEventListenerHookup(connection_manager()->channel(), this, | |
| 1672 &SyncManager::SyncInternal::HandleServerConnectionEvent)); | |
| 1673 } | |
| 1674 | |
| 1654 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we | 1675 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we |
| 1655 // try to shut down sync. Fix this. | 1676 // try to shut down sync. Fix this. |
| 1656 core_message_loop_->PostTask(FROM_HERE, | 1677 core_message_loop_->PostTask(FROM_HERE, |
| 1657 method_factory_.NewRunnableMethod(&SyncInternal::CheckServerReachable)); | 1678 method_factory_.NewRunnableMethod(&SyncInternal::CheckServerReachable)); |
| 1658 | 1679 |
| 1659 // Test mode does not use a syncer context or syncer thread. | 1680 // Test mode does not use a syncer context or syncer thread. |
| 1660 if (!setup_for_test_mode_) { | 1681 if (!setup_for_test_mode_) { |
| 1661 // Build a SyncSessionContext and store the worker in it. | 1682 // Build a SyncSessionContext and store the worker in it. |
| 1662 VLOG(1) << "Sync is bringing up SyncSessionContext."; | 1683 VLOG(1) << "Sync is bringing up SyncSessionContext."; |
| 1663 std::vector<SyncEngineEventListener*> listeners; | 1684 std::vector<SyncEngineEventListener*> listeners; |
| 1664 listeners.push_back(&allstatus_); | 1685 listeners.push_back(&allstatus_); |
| 1665 listeners.push_back(this); | 1686 listeners.push_back(this); |
| 1666 SyncSessionContext* context = new SyncSessionContext( | 1687 SyncSessionContext* context = new SyncSessionContext( |
| 1667 connection_manager_.get(), | 1688 connection_manager_.get(), |
| 1668 dir_manager(), | 1689 dir_manager(), |
| 1669 model_safe_worker_registrar, | 1690 model_safe_worker_registrar, |
| 1670 listeners); | 1691 listeners); |
| 1671 context->set_account_name(credentials.email); | 1692 context->set_account_name(credentials.email); |
| 1672 // The SyncerThread takes ownership of |context|. | 1693 // The SyncerThread takes ownership of |context|. |
| 1673 syncer_thread_.reset(new SyncerThreadAdapter(context, | 1694 syncer_thread_.reset(new SyncerThreadAdapter(context, |
| 1674 CommandLine::ForCurrentProcess()->HasSwitch( | 1695 new_syncer_thread)); |
| 1675 switches::kNewSyncerThread))); | |
| 1676 } | 1696 } |
| 1677 | 1697 |
| 1678 bool signed_in = SignIn(credentials); | 1698 bool signed_in = SignIn(credentials); |
| 1679 | 1699 |
| 1680 // Do this once the directory is opened. | 1700 // Do this once the directory is opened. |
| 1681 BootstrapEncryption(restored_key_for_bootstrapping); | 1701 BootstrapEncryption(restored_key_for_bootstrapping); |
| 1682 return signed_in; | 1702 return signed_in; |
| 1683 } | 1703 } |
| 1684 | 1704 |
| 1685 void SyncManager::SyncInternal::BootstrapEncryption( | 1705 void SyncManager::SyncInternal::BootstrapEncryption( |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2119 kChromeOSNetworkChangeReactionDelayHackMsec); | 2139 kChromeOSNetworkChangeReactionDelayHackMsec); |
| 2120 #else | 2140 #else |
| 2121 OnIPAddressChangedImpl(); | 2141 OnIPAddressChangedImpl(); |
| 2122 #endif // defined(OS_CHROMEOS) | 2142 #endif // defined(OS_CHROMEOS) |
| 2123 } | 2143 } |
| 2124 | 2144 |
| 2125 void SyncManager::SyncInternal::OnIPAddressChangedImpl() { | 2145 void SyncManager::SyncInternal::OnIPAddressChangedImpl() { |
| 2126 // TODO(akalin): CheckServerReachable() can block, which may cause | 2146 // TODO(akalin): CheckServerReachable() can block, which may cause |
| 2127 // jank if we try to shut down sync. Fix this. | 2147 // jank if we try to shut down sync. Fix this. |
| 2128 connection_manager()->CheckServerReachable(); | 2148 connection_manager()->CheckServerReachable(); |
| 2129 sync_manager_->RequestNudge(); | 2149 sync_manager_->RequestNudge(); |
|
Nicolas Zea
2011/03/25 18:53:03
Do we make a new connection to the server on an ip
tim (not reviewing)
2011/03/28 20:02:25
We don't but see TODO(tim) in syncer_thread2.h tha
| |
| 2130 } | 2150 } |
| 2131 | 2151 |
| 2132 // Listen to model changes, filter out ones initiated by the sync API, and | 2152 // Listen to model changes, filter out ones initiated by the sync API, and |
| 2133 // saves the rest (hopefully just backend Syncer changes resulting from | 2153 // saves the rest (hopefully just backend Syncer changes resulting from |
| 2134 // ApplyUpdates) to data_->changelist. | 2154 // ApplyUpdates) to data_->changelist. |
| 2135 void SyncManager::SyncInternal::HandleChannelEvent( | 2155 void SyncManager::SyncInternal::HandleChannelEvent( |
| 2136 const syncable::DirectoryChangeEvent& event) { | 2156 const syncable::DirectoryChangeEvent& event) { |
| 2137 if (event.todo == syncable::DirectoryChangeEvent::TRANSACTION_COMPLETE) { | 2157 if (event.todo == syncable::DirectoryChangeEvent::TRANSACTION_COMPLETE) { |
| 2138 // Safe to perform slow I/O operations now, go ahead and commit. | 2158 // Safe to perform slow I/O operations now, go ahead and commit. |
| 2139 HandleTransactionCompleteChangeEvent(event); | 2159 HandleTransactionCompleteChangeEvent(event); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 2165 // Call commit | 2185 // Call commit |
| 2166 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 2186 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 2167 if (model_has_change_.test(i)) { | 2187 if (model_has_change_.test(i)) { |
| 2168 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2188 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2169 OnChangesComplete(syncable::ModelTypeFromInt(i))); | 2189 OnChangesComplete(syncable::ModelTypeFromInt(i))); |
| 2170 model_has_change_.reset(i); | 2190 model_has_change_.reset(i); |
| 2171 } | 2191 } |
| 2172 } | 2192 } |
| 2173 } | 2193 } |
| 2174 | 2194 |
| 2195 void SyncManager::SyncInternal::OnServerConnectionEvent( | |
| 2196 const ServerConnectionEvent2& event) { | |
| 2197 ServerConnectionEvent legacy; | |
| 2198 legacy.what_happened = ServerConnectionEvent::STATUS_CHANGED; | |
| 2199 legacy.connection_code = event.connection_code; | |
| 2200 legacy.server_reachable = event.server_reachable; | |
| 2201 HandleServerConnectionEvent(legacy); | |
| 2202 } | |
| 2203 | |
| 2175 void SyncManager::SyncInternal::HandleServerConnectionEvent( | 2204 void SyncManager::SyncInternal::HandleServerConnectionEvent( |
| 2176 const ServerConnectionEvent& event) { | 2205 const ServerConnectionEvent& event) { |
| 2177 allstatus_.HandleServerConnectionEvent(event); | 2206 allstatus_.HandleServerConnectionEvent(event); |
| 2178 if (event.what_happened == ServerConnectionEvent::STATUS_CHANGED) { | 2207 if (event.what_happened == ServerConnectionEvent::STATUS_CHANGED) { |
| 2179 if (event.connection_code == | 2208 if (event.connection_code == |
| 2180 browser_sync::HttpResponse::SERVER_CONNECTION_OK) { | 2209 browser_sync::HttpResponse::SERVER_CONNECTION_OK) { |
| 2181 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2210 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2182 OnAuthError(AuthError::None())); | 2211 OnAuthError(AuthError::None())); |
| 2183 } | 2212 } |
| 2184 | 2213 |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2678 void SyncManager::TriggerOnIncomingNotificationForTest( | 2707 void SyncManager::TriggerOnIncomingNotificationForTest( |
| 2679 const syncable::ModelTypeBitSet& model_types) { | 2708 const syncable::ModelTypeBitSet& model_types) { |
| 2680 syncable::ModelTypePayloadMap model_types_with_payloads = | 2709 syncable::ModelTypePayloadMap model_types_with_payloads = |
| 2681 syncable::ModelTypePayloadMapFromBitSet(model_types, | 2710 syncable::ModelTypePayloadMapFromBitSet(model_types, |
| 2682 std::string()); | 2711 std::string()); |
| 2683 | 2712 |
| 2684 data_->OnIncomingNotification(model_types_with_payloads); | 2713 data_->OnIncomingNotification(model_types_with_payloads); |
| 2685 } | 2714 } |
| 2686 | 2715 |
| 2687 } // namespace sync_api | 2716 } // namespace sync_api |
| OLD | NEW |