| 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 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 return unencrypted_; | 1094 return unencrypted_; |
| 1093 } | 1095 } |
| 1094 | 1096 |
| 1095 ////////////////////////////////////////////////////////////////////////// | 1097 ////////////////////////////////////////////////////////////////////////// |
| 1096 // SyncManager's implementation: SyncManager::SyncInternal | 1098 // SyncManager's implementation: SyncManager::SyncInternal |
| 1097 class SyncManager::SyncInternal | 1099 class SyncManager::SyncInternal |
| 1098 : public net::NetworkChangeNotifier::IPAddressObserver, | 1100 : public net::NetworkChangeNotifier::IPAddressObserver, |
| 1099 public sync_notifier::SyncNotifierObserver, | 1101 public sync_notifier::SyncNotifierObserver, |
| 1100 public browser_sync::ChannelEventHandler<syncable::DirectoryChangeEvent>, | 1102 public browser_sync::ChannelEventHandler<syncable::DirectoryChangeEvent>, |
| 1101 public browser_sync::JsBackend, | 1103 public browser_sync::JsBackend, |
| 1102 public SyncEngineEventListener { | 1104 public SyncEngineEventListener, |
| 1105 public ServerConnectionEventListener { |
| 1103 static const int kDefaultNudgeDelayMilliseconds; | 1106 static const int kDefaultNudgeDelayMilliseconds; |
| 1104 static const int kPreferencesNudgeDelayMilliseconds; | 1107 static const int kPreferencesNudgeDelayMilliseconds; |
| 1105 public: | 1108 public: |
| 1106 explicit SyncInternal(SyncManager* sync_manager) | 1109 explicit SyncInternal(SyncManager* sync_manager) |
| 1107 : core_message_loop_(NULL), | 1110 : core_message_loop_(NULL), |
| 1108 parent_router_(NULL), | 1111 parent_router_(NULL), |
| 1109 sync_manager_(sync_manager), | 1112 sync_manager_(sync_manager), |
| 1110 registrar_(NULL), | 1113 registrar_(NULL), |
| 1111 initialized_(false), | 1114 initialized_(false), |
| 1112 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 1115 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 DCHECK(false) << "ScopedDirLookup failed when checking initial sync"; | 1292 DCHECK(false) << "ScopedDirLookup failed when checking initial sync"; |
| 1290 syncable::AutofillMigrationDebugInfo null_value = {0}; | 1293 syncable::AutofillMigrationDebugInfo null_value = {0}; |
| 1291 return null_value; | 1294 return null_value; |
| 1292 } | 1295 } |
| 1293 return lookup->get_autofill_migration_debug_info(); | 1296 return lookup->get_autofill_migration_debug_info(); |
| 1294 } | 1297 } |
| 1295 | 1298 |
| 1296 // SyncEngineEventListener implementation. | 1299 // SyncEngineEventListener implementation. |
| 1297 virtual void OnSyncEngineEvent(const SyncEngineEvent& event); | 1300 virtual void OnSyncEngineEvent(const SyncEngineEvent& event); |
| 1298 | 1301 |
| 1302 // ServerConnectionEventListener implementation. |
| 1303 virtual void OnServerConnectionEvent(const ServerConnectionEvent2& event); |
| 1304 |
| 1299 // browser_sync::JsBackend implementation. | 1305 // browser_sync::JsBackend implementation. |
| 1300 virtual void SetParentJsEventRouter(browser_sync::JsEventRouter* router); | 1306 virtual void SetParentJsEventRouter(browser_sync::JsEventRouter* router); |
| 1301 virtual void RemoveParentJsEventRouter(); | 1307 virtual void RemoveParentJsEventRouter(); |
| 1302 virtual const browser_sync::JsEventRouter* GetParentJsEventRouter() const; | 1308 virtual const browser_sync::JsEventRouter* GetParentJsEventRouter() const; |
| 1303 virtual void ProcessMessage(const std::string& name, | 1309 virtual void ProcessMessage(const std::string& name, |
| 1304 const browser_sync::JsArgList& args, | 1310 const browser_sync::JsArgList& args, |
| 1305 const browser_sync::JsEventHandler* sender); | 1311 const browser_sync::JsEventHandler* sender); |
| 1306 | 1312 |
| 1307 private: | 1313 private: |
| 1308 // Helper to call OnAuthError when no authentication credentials are | 1314 // Helper to call OnAuthError when no authentication credentials are |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 | 1596 |
| 1591 void SyncManager::RequestClearServerData() { | 1597 void SyncManager::RequestClearServerData() { |
| 1592 if (data_->syncer_thread()) | 1598 if (data_->syncer_thread()) |
| 1593 data_->syncer_thread()->NudgeSyncer(0, SyncerThread::kClearPrivateData); | 1599 data_->syncer_thread()->NudgeSyncer(0, SyncerThread::kClearPrivateData); |
| 1594 } | 1600 } |
| 1595 | 1601 |
| 1596 void SyncManager::RequestConfig(const syncable::ModelTypeBitSet& types) { | 1602 void SyncManager::RequestConfig(const syncable::ModelTypeBitSet& types) { |
| 1597 if (!data_->syncer_thread()) | 1603 if (!data_->syncer_thread()) |
| 1598 return; | 1604 return; |
| 1599 // It is an error for this to be called if new_impl is null. | 1605 // It is an error for this to be called if new_impl is null. |
| 1606 StartConfigurationMode(NULL); |
| 1607 data_->syncer_thread()->new_impl()->ScheduleConfig(types); |
| 1608 } |
| 1609 |
| 1610 void SyncManager::StartConfigurationMode(ModeChangeCallback* callback) { |
| 1611 if (!data_->syncer_thread()) |
| 1612 return; |
| 1613 // It is an error for this to be called if new_impl is null. |
| 1600 data_->syncer_thread()->new_impl()->Start( | 1614 data_->syncer_thread()->new_impl()->Start( |
| 1601 browser_sync::s3::SyncerThread::CONFIGURATION_MODE); | 1615 browser_sync::s3::SyncerThread::CONFIGURATION_MODE, callback); |
| 1602 data_->syncer_thread()->new_impl()->ScheduleConfig(types); | |
| 1603 } | 1616 } |
| 1604 | 1617 |
| 1605 const std::string& SyncManager::GetAuthenticatedUsername() { | 1618 const std::string& SyncManager::GetAuthenticatedUsername() { |
| 1606 DCHECK(data_); | 1619 DCHECK(data_); |
| 1607 return data_->username_for_share(); | 1620 return data_->username_for_share(); |
| 1608 } | 1621 } |
| 1609 | 1622 |
| 1610 bool SyncManager::SyncInternal::Init( | 1623 bool SyncManager::SyncInternal::Init( |
| 1611 const FilePath& database_location, | 1624 const FilePath& database_location, |
| 1612 const std::string& sync_server_and_path, | 1625 const std::string& sync_server_and_path, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1628 setup_for_test_mode_ = setup_for_test_mode; | 1641 setup_for_test_mode_ = setup_for_test_mode; |
| 1629 | 1642 |
| 1630 sync_notifier_.reset(sync_notifier); | 1643 sync_notifier_.reset(sync_notifier); |
| 1631 sync_notifier_->AddObserver(this); | 1644 sync_notifier_->AddObserver(this); |
| 1632 | 1645 |
| 1633 share_.dir_manager.reset(new DirectoryManager(database_location)); | 1646 share_.dir_manager.reset(new DirectoryManager(database_location)); |
| 1634 | 1647 |
| 1635 connection_manager_.reset(new SyncAPIServerConnectionManager( | 1648 connection_manager_.reset(new SyncAPIServerConnectionManager( |
| 1636 sync_server_and_path, port, use_ssl, user_agent, post_factory)); | 1649 sync_server_and_path, port, use_ssl, user_agent, post_factory)); |
| 1637 | 1650 |
| 1638 connection_manager_hookup_.reset( | 1651 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 1639 NewEventListenerHookup(connection_manager()->channel(), this, | |
| 1640 &SyncManager::SyncInternal::HandleServerConnectionEvent)); | |
| 1641 | 1652 |
| 1642 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 1653 bool new_syncer_thread = CommandLine::ForCurrentProcess()->HasSwitch( |
| 1654 switches::kNewSyncerThread); |
| 1655 |
| 1656 if (new_syncer_thread) { |
| 1657 connection_manager()->AddListener(this); |
| 1658 } else { |
| 1659 connection_manager_hookup_.reset( |
| 1660 NewEventListenerHookup(connection_manager()->channel(), this, |
| 1661 &SyncManager::SyncInternal::HandleServerConnectionEvent)); |
| 1662 } |
| 1663 |
| 1643 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we | 1664 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we |
| 1644 // try to shut down sync. Fix this. | 1665 // try to shut down sync. Fix this. |
| 1645 core_message_loop_->PostTask(FROM_HERE, | 1666 core_message_loop_->PostTask(FROM_HERE, |
| 1646 method_factory_.NewRunnableMethod(&SyncInternal::CheckServerReachable)); | 1667 method_factory_.NewRunnableMethod(&SyncInternal::CheckServerReachable)); |
| 1647 | 1668 |
| 1648 // Test mode does not use a syncer context or syncer thread. | 1669 // Test mode does not use a syncer context or syncer thread. |
| 1649 if (!setup_for_test_mode_) { | 1670 if (!setup_for_test_mode_) { |
| 1650 // Build a SyncSessionContext and store the worker in it. | 1671 // Build a SyncSessionContext and store the worker in it. |
| 1651 VLOG(1) << "Sync is bringing up SyncSessionContext."; | 1672 VLOG(1) << "Sync is bringing up SyncSessionContext."; |
| 1652 std::vector<SyncEngineEventListener*> listeners; | 1673 std::vector<SyncEngineEventListener*> listeners; |
| 1653 listeners.push_back(&allstatus_); | 1674 listeners.push_back(&allstatus_); |
| 1654 listeners.push_back(this); | 1675 listeners.push_back(this); |
| 1655 SyncSessionContext* context = new SyncSessionContext( | 1676 SyncSessionContext* context = new SyncSessionContext( |
| 1656 connection_manager_.get(), | 1677 connection_manager_.get(), |
| 1657 dir_manager(), | 1678 dir_manager(), |
| 1658 model_safe_worker_registrar, | 1679 model_safe_worker_registrar, |
| 1659 listeners); | 1680 listeners); |
| 1660 context->set_account_name(credentials.email); | 1681 context->set_account_name(credentials.email); |
| 1661 // The SyncerThread takes ownership of |context|. | 1682 // The SyncerThread takes ownership of |context|. |
| 1662 syncer_thread_.reset(new SyncerThreadAdapter(context, | 1683 syncer_thread_.reset(new SyncerThreadAdapter(context, |
| 1663 CommandLine::ForCurrentProcess()->HasSwitch( | 1684 new_syncer_thread)); |
| 1664 switches::kNewSyncerThread))); | |
| 1665 } | 1685 } |
| 1666 | 1686 |
| 1667 bool signed_in = SignIn(credentials); | 1687 bool signed_in = SignIn(credentials); |
| 1668 | 1688 |
| 1669 // Do this once the directory is opened. | 1689 // Do this once the directory is opened. |
| 1670 BootstrapEncryption(restored_key_for_bootstrapping); | 1690 BootstrapEncryption(restored_key_for_bootstrapping); |
| 1671 return signed_in; | 1691 return signed_in; |
| 1672 } | 1692 } |
| 1673 | 1693 |
| 1674 void SyncManager::SyncInternal::BootstrapEncryption( | 1694 void SyncManager::SyncInternal::BootstrapEncryption( |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2154 // Call commit | 2174 // Call commit |
| 2155 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { | 2175 for (int i = 0; i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 2156 if (model_has_change_.test(i)) { | 2176 if (model_has_change_.test(i)) { |
| 2157 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2177 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2158 OnChangesComplete(syncable::ModelTypeFromInt(i))); | 2178 OnChangesComplete(syncable::ModelTypeFromInt(i))); |
| 2159 model_has_change_.reset(i); | 2179 model_has_change_.reset(i); |
| 2160 } | 2180 } |
| 2161 } | 2181 } |
| 2162 } | 2182 } |
| 2163 | 2183 |
| 2184 void SyncManager::SyncInternal::OnServerConnectionEvent( |
| 2185 const ServerConnectionEvent2& event) { |
| 2186 ServerConnectionEvent legacy; |
| 2187 legacy.what_happened = ServerConnectionEvent::STATUS_CHANGED; |
| 2188 legacy.connection_code = event.connection_code; |
| 2189 legacy.server_reachable = event.server_reachable; |
| 2190 HandleServerConnectionEvent(legacy); |
| 2191 } |
| 2192 |
| 2164 void SyncManager::SyncInternal::HandleServerConnectionEvent( | 2193 void SyncManager::SyncInternal::HandleServerConnectionEvent( |
| 2165 const ServerConnectionEvent& event) { | 2194 const ServerConnectionEvent& event) { |
| 2166 allstatus_.HandleServerConnectionEvent(event); | 2195 allstatus_.HandleServerConnectionEvent(event); |
| 2167 if (event.what_happened == ServerConnectionEvent::STATUS_CHANGED) { | 2196 if (event.what_happened == ServerConnectionEvent::STATUS_CHANGED) { |
| 2168 if (event.connection_code == | 2197 if (event.connection_code == |
| 2169 browser_sync::HttpResponse::SERVER_CONNECTION_OK) { | 2198 browser_sync::HttpResponse::SERVER_CONNECTION_OK) { |
| 2170 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2199 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 2171 OnAuthError(AuthError::None())); | 2200 OnAuthError(AuthError::None())); |
| 2172 } | 2201 } |
| 2173 | 2202 |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2667 void SyncManager::TriggerOnIncomingNotificationForTest( | 2696 void SyncManager::TriggerOnIncomingNotificationForTest( |
| 2668 const syncable::ModelTypeBitSet& model_types) { | 2697 const syncable::ModelTypeBitSet& model_types) { |
| 2669 syncable::ModelTypePayloadMap model_types_with_payloads = | 2698 syncable::ModelTypePayloadMap model_types_with_payloads = |
| 2670 syncable::ModelTypePayloadMapFromBitSet(model_types, | 2699 syncable::ModelTypePayloadMapFromBitSet(model_types, |
| 2671 std::string()); | 2700 std::string()); |
| 2672 | 2701 |
| 2673 data_->OnIncomingNotification(model_types_with_payloads); | 2702 data_->OnIncomingNotification(model_types_with_payloads); |
| 2674 } | 2703 } |
| 2675 | 2704 |
| 2676 } // namespace sync_api | 2705 } // namespace sync_api |
| OLD | NEW |