| 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/json/json_writer.h" | 21 #include "base/json/json_writer.h" |
| 22 #include "base/logging.h" | 22 #include "base/logging.h" |
| 23 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
| 24 #include "base/message_loop.h" | 24 #include "base/message_loop.h" |
| 25 #include "base/observer_list.h" | 25 #include "base/observer_list.h" |
| 26 #include "base/sha1.h" | 26 #include "base/sha1.h" |
| 27 #include "base/string_number_conversions.h" | 27 #include "base/string_number_conversions.h" |
| 28 #include "base/string_util.h" | 28 #include "base/string_util.h" |
| 29 #include "base/task.h" | 29 #include "base/task.h" |
| 30 #include "base/time.h" | 30 #include "base/time.h" |
| 31 #include "base/tracked.h" |
| 31 #include "base/utf_string_conversions.h" | 32 #include "base/utf_string_conversions.h" |
| 32 #include "base/values.h" | 33 #include "base/values.h" |
| 33 #include "chrome/browser/sync/engine/all_status.h" | 34 #include "chrome/browser/sync/engine/all_status.h" |
| 34 #include "chrome/browser/sync/engine/change_reorder_buffer.h" | 35 #include "chrome/browser/sync/engine/change_reorder_buffer.h" |
| 35 #include "chrome/browser/sync/engine/model_safe_worker.h" | 36 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 36 #include "chrome/browser/sync/engine/nudge_source.h" | 37 #include "chrome/browser/sync/engine/nudge_source.h" |
| 37 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 38 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 38 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" | 39 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" |
| 39 #include "chrome/browser/sync/engine/sync_scheduler.h" | 40 #include "chrome/browser/sync/engine/sync_scheduler.h" |
| 40 #include "chrome/browser/sync/engine/syncer.h" | 41 #include "chrome/browser/sync/engine/syncer.h" |
| 41 #include "chrome/browser/sync/engine/http_post_provider_factory.h" | 42 #include "chrome/browser/sync/engine/http_post_provider_factory.h" |
| 42 #include "chrome/browser/sync/js_arg_list.h" | 43 #include "chrome/browser/sync/js_arg_list.h" |
| 43 #include "chrome/browser/sync/js_backend.h" | 44 #include "chrome/browser/sync/js_backend.h" |
| 44 #include "chrome/browser/sync/js_directory_change_listener.h" | 45 #include "chrome/browser/sync/js_transaction_observer.h" |
| 45 #include "chrome/browser/sync/js_event_details.h" | 46 #include "chrome/browser/sync/js_event_details.h" |
| 46 #include "chrome/browser/sync/js_event_router.h" | 47 #include "chrome/browser/sync/js_event_router.h" |
| 47 #include "chrome/browser/sync/notifier/sync_notifier.h" | 48 #include "chrome/browser/sync/notifier/sync_notifier.h" |
| 48 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" | 49 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" |
| 49 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 50 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
| 50 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 51 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
| 51 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 52 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 52 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 53 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
| 53 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 54 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
| 54 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 55 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
| 55 #include "chrome/browser/sync/protocol/proto_value_conversions.h" | 56 #include "chrome/browser/sync/protocol/proto_value_conversions.h" |
| 56 #include "chrome/browser/sync/protocol/service_constants.h" | 57 #include "chrome/browser/sync/protocol/service_constants.h" |
| 57 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | 58 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
| 58 #include "chrome/browser/sync/protocol/sync.pb.h" | 59 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 59 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 60 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
| 60 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 61 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
| 61 #include "chrome/browser/sync/sessions/sync_session.h" | 62 #include "chrome/browser/sync/sessions/sync_session.h" |
| 62 #include "chrome/browser/sync/sessions/sync_session_context.h" | 63 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| 63 #include "chrome/browser/sync/syncable/autofill_migration.h" | 64 #include "chrome/browser/sync/syncable/autofill_migration.h" |
| 64 #include "chrome/browser/sync/syncable/directory_change_listener.h" | 65 #include "chrome/browser/sync/syncable/directory_change_delegate.h" |
| 65 #include "chrome/browser/sync/syncable/directory_manager.h" | 66 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 66 #include "chrome/browser/sync/syncable/model_type_payload_map.h" | 67 #include "chrome/browser/sync/syncable/model_type_payload_map.h" |
| 67 #include "chrome/browser/sync/syncable/model_type.h" | 68 #include "chrome/browser/sync/syncable/model_type.h" |
| 68 #include "chrome/browser/sync/syncable/nigori_util.h" | 69 #include "chrome/browser/sync/syncable/nigori_util.h" |
| 69 #include "chrome/browser/sync/syncable/syncable.h" | 70 #include "chrome/browser/sync/syncable/syncable.h" |
| 70 #include "chrome/common/chrome_switches.h" | 71 #include "chrome/common/chrome_switches.h" |
| 71 #include "chrome/common/deprecated/event_sys.h" | 72 #include "chrome/common/deprecated/event_sys.h" |
| 72 #include "chrome/common/net/gaia/gaia_authenticator.h" | 73 #include "chrome/common/net/gaia/gaia_authenticator.h" |
| 73 #include "content/browser/browser_thread.h" | |
| 74 #include "net/base/network_change_notifier.h" | 74 #include "net/base/network_change_notifier.h" |
| 75 | 75 |
| 76 using base::TimeDelta; | 76 using base::TimeDelta; |
| 77 using browser_sync::AllStatus; | 77 using browser_sync::AllStatus; |
| 78 using browser_sync::Cryptographer; | 78 using browser_sync::Cryptographer; |
| 79 using browser_sync::KeyParams; | 79 using browser_sync::KeyParams; |
| 80 using browser_sync::ModelSafeRoutingInfo; | 80 using browser_sync::ModelSafeRoutingInfo; |
| 81 using browser_sync::ModelSafeWorker; | 81 using browser_sync::ModelSafeWorker; |
| 82 using browser_sync::ModelSafeWorkerRegistrar; | 82 using browser_sync::ModelSafeWorkerRegistrar; |
| 83 using browser_sync::ServerConnectionEvent; | 83 using browser_sync::ServerConnectionEvent; |
| (...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 << "SyncAPI InitByTagLookup referencing unusually typed object."; | 961 << "SyncAPI InitByTagLookup referencing unusually typed object."; |
| 962 return DecryptIfNecessary(); | 962 return DecryptIfNecessary(); |
| 963 } | 963 } |
| 964 | 964 |
| 965 ////////////////////////////////////////////////////////////////////////// | 965 ////////////////////////////////////////////////////////////////////////// |
| 966 // ReadTransaction member definitions | 966 // ReadTransaction member definitions |
| 967 ReadTransaction::ReadTransaction(UserShare* share) | 967 ReadTransaction::ReadTransaction(UserShare* share) |
| 968 : BaseTransaction(share), | 968 : BaseTransaction(share), |
| 969 transaction_(NULL), | 969 transaction_(NULL), |
| 970 close_transaction_(true) { | 970 close_transaction_(true) { |
| 971 transaction_ = new syncable::ReadTransaction(GetLookup(), __FILE__, __LINE__); | 971 transaction_ = new syncable::ReadTransaction(GetLookup(), FROM_HERE); |
| 972 } | 972 } |
| 973 | 973 |
| 974 ReadTransaction::ReadTransaction(UserShare* share, | 974 ReadTransaction::ReadTransaction(UserShare* share, |
| 975 syncable::BaseTransaction* trans) | 975 syncable::BaseTransaction* trans) |
| 976 : BaseTransaction(share), | 976 : BaseTransaction(share), |
| 977 transaction_(trans), | 977 transaction_(trans), |
| 978 close_transaction_(false) {} | 978 close_transaction_(false) {} |
| 979 | 979 |
| 980 ReadTransaction::~ReadTransaction() { | 980 ReadTransaction::~ReadTransaction() { |
| 981 if (close_transaction_) { | 981 if (close_transaction_) { |
| 982 delete transaction_; | 982 delete transaction_; |
| 983 } | 983 } |
| 984 } | 984 } |
| 985 | 985 |
| 986 syncable::BaseTransaction* ReadTransaction::GetWrappedTrans() const { | 986 syncable::BaseTransaction* ReadTransaction::GetWrappedTrans() const { |
| 987 return transaction_; | 987 return transaction_; |
| 988 } | 988 } |
| 989 | 989 |
| 990 ////////////////////////////////////////////////////////////////////////// | 990 ////////////////////////////////////////////////////////////////////////// |
| 991 // WriteTransaction member definitions | 991 // WriteTransaction member definitions |
| 992 WriteTransaction::WriteTransaction(UserShare* share) | 992 WriteTransaction::WriteTransaction(UserShare* share) |
| 993 : BaseTransaction(share), | 993 : BaseTransaction(share), |
| 994 transaction_(NULL) { | 994 transaction_(NULL) { |
| 995 transaction_ = new syncable::WriteTransaction(GetLookup(), syncable::SYNCAPI, | 995 transaction_ = new syncable::WriteTransaction(GetLookup(), syncable::SYNCAPI, |
| 996 __FILE__, __LINE__); | 996 FROM_HERE); |
| 997 } | 997 } |
| 998 | 998 |
| 999 WriteTransaction::~WriteTransaction() { | 999 WriteTransaction::~WriteTransaction() { |
| 1000 delete transaction_; | 1000 delete transaction_; |
| 1001 } | 1001 } |
| 1002 | 1002 |
| 1003 syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const { | 1003 syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const { |
| 1004 return transaction_; | 1004 return transaction_; |
| 1005 } | 1005 } |
| 1006 | 1006 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 | 1117 |
| 1118 ////////////////////////////////////////////////////////////////////////// | 1118 ////////////////////////////////////////////////////////////////////////// |
| 1119 // SyncManager's implementation: SyncManager::SyncInternal | 1119 // SyncManager's implementation: SyncManager::SyncInternal |
| 1120 class SyncManager::SyncInternal | 1120 class SyncManager::SyncInternal |
| 1121 : public net::NetworkChangeNotifier::IPAddressObserver, | 1121 : public net::NetworkChangeNotifier::IPAddressObserver, |
| 1122 public sync_notifier::SyncNotifierObserver, | 1122 public sync_notifier::SyncNotifierObserver, |
| 1123 public browser_sync::JsBackend, | 1123 public browser_sync::JsBackend, |
| 1124 public browser_sync::JsEventRouter, | 1124 public browser_sync::JsEventRouter, |
| 1125 public SyncEngineEventListener, | 1125 public SyncEngineEventListener, |
| 1126 public ServerConnectionEventListener, | 1126 public ServerConnectionEventListener, |
| 1127 public syncable::DirectoryChangeListener { | 1127 public syncable::DirectoryChangeDelegate { |
| 1128 static const int kDefaultNudgeDelayMilliseconds; | 1128 static const int kDefaultNudgeDelayMilliseconds; |
| 1129 static const int kPreferencesNudgeDelayMilliseconds; | 1129 static const int kPreferencesNudgeDelayMilliseconds; |
| 1130 public: | 1130 public: |
| 1131 SyncInternal(const std::string& name, SyncManager* sync_manager) | 1131 SyncInternal(const std::string& name, SyncManager* sync_manager) |
| 1132 : name_(name), | 1132 : name_(name), |
| 1133 sync_loop_(NULL), | 1133 sync_loop_(NULL), |
| 1134 parent_router_(NULL), | 1134 parent_router_(NULL), |
| 1135 sync_manager_(sync_manager), | 1135 sync_manager_(sync_manager), |
| 1136 registrar_(NULL), | 1136 registrar_(NULL), |
| 1137 initialized_(false), | 1137 initialized_(false), |
| 1138 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 1138 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 1139 js_directory_change_listener_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 1139 js_transaction_observer_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 1140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1141 // Pre-fill |notification_info_map_|. | 1140 // Pre-fill |notification_info_map_|. |
| 1142 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 1141 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 1143 i < syncable::MODEL_TYPE_COUNT; ++i) { | 1142 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 1144 notification_info_map_.insert( | 1143 notification_info_map_.insert( |
| 1145 std::make_pair(syncable::ModelTypeFromInt(i), NotificationInfo())); | 1144 std::make_pair(syncable::ModelTypeFromInt(i), NotificationInfo())); |
| 1146 } | 1145 } |
| 1147 | 1146 |
| 1148 // Bind message handlers. | 1147 // Bind message handlers. |
| 1149 BindJsMessageHandler( | 1148 BindJsMessageHandler( |
| 1150 "getNotificationState", | 1149 "getNotificationState", |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1164 BindJsMessageHandler( | 1163 BindJsMessageHandler( |
| 1165 "getChildNodeIds", | 1164 "getChildNodeIds", |
| 1166 &SyncManager::SyncInternal::GetChildNodeIds); | 1165 &SyncManager::SyncInternal::GetChildNodeIds); |
| 1167 BindJsMessageHandler( | 1166 BindJsMessageHandler( |
| 1168 "findNodesContainingString", | 1167 "findNodesContainingString", |
| 1169 &SyncManager::SyncInternal::FindNodesContainingString); | 1168 &SyncManager::SyncInternal::FindNodesContainingString); |
| 1170 } | 1169 } |
| 1171 | 1170 |
| 1172 virtual ~SyncInternal() { | 1171 virtual ~SyncInternal() { |
| 1173 CHECK(!sync_loop_); | 1172 CHECK(!sync_loop_); |
| 1174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1175 } | 1173 } |
| 1176 | 1174 |
| 1177 bool Init(const FilePath& database_location, | 1175 bool Init(const FilePath& database_location, |
| 1178 const std::string& sync_server_and_path, | 1176 const std::string& sync_server_and_path, |
| 1179 int port, | 1177 int port, |
| 1180 bool use_ssl, | 1178 bool use_ssl, |
| 1181 HttpPostProviderFactory* post_factory, | 1179 HttpPostProviderFactory* post_factory, |
| 1182 ModelSafeWorkerRegistrar* model_safe_worker_registrar, | 1180 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
| 1183 const char* user_agent, | 1181 const char* user_agent, |
| 1184 const SyncCredentials& credentials, | 1182 const SyncCredentials& credentials, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1215 | 1213 |
| 1216 // Try to set the current passphrase to |passphrase|, and record whether | 1214 // Try to set the current passphrase to |passphrase|, and record whether |
| 1217 // it is an explicit passphrase or implicitly using gaia in the Nigori | 1215 // it is an explicit passphrase or implicitly using gaia in the Nigori |
| 1218 // node. | 1216 // node. |
| 1219 void SetPassphrase(const std::string& passphrase, bool is_explicit); | 1217 void SetPassphrase(const std::string& passphrase, bool is_explicit); |
| 1220 | 1218 |
| 1221 // Call periodically from a database-safe thread to persist recent changes | 1219 // Call periodically from a database-safe thread to persist recent changes |
| 1222 // to the syncapi model. | 1220 // to the syncapi model. |
| 1223 void SaveChanges(); | 1221 void SaveChanges(); |
| 1224 | 1222 |
| 1225 // DirectoryChangeListener implementation. | 1223 // DirectoryChangeDelegate implementation. |
| 1226 // This listener is called upon completion of a syncable transaction, and | 1224 // This listener is called upon completion of a syncable transaction, and |
| 1227 // builds the list of sync-engine initiated changes that will be forwarded to | 1225 // builds the list of sync-engine initiated changes that will be forwarded to |
| 1228 // the SyncManager's Observers. | 1226 // the SyncManager's Observers. |
| 1229 virtual void HandleTransactionCompleteChangeEvent( | 1227 virtual void HandleTransactionCompleteChangeEvent( |
| 1230 const ModelTypeBitSet& models_with_changes); | 1228 const ModelTypeBitSet& models_with_changes); |
| 1231 virtual ModelTypeBitSet HandleTransactionEndingChangeEvent( | 1229 virtual ModelTypeBitSet HandleTransactionEndingChangeEvent( |
| 1232 syncable::BaseTransaction* trans); | 1230 syncable::BaseTransaction* trans); |
| 1233 virtual void HandleCalculateChangesChangeEventFromSyncApi( | 1231 virtual void HandleCalculateChangesChangeEventFromSyncApi( |
| 1234 const OriginalEntries& originals, | 1232 const OriginalEntries& originals, |
| 1235 const WriterTag& writer, | |
| 1236 syncable::BaseTransaction* trans); | 1233 syncable::BaseTransaction* trans); |
| 1237 virtual void HandleCalculateChangesChangeEventFromSyncer( | 1234 virtual void HandleCalculateChangesChangeEventFromSyncer( |
| 1238 const OriginalEntries& originals, | 1235 const OriginalEntries& originals, |
| 1239 const WriterTag& writer, | |
| 1240 syncable::BaseTransaction* trans); | 1236 syncable::BaseTransaction* trans); |
| 1241 | 1237 |
| 1242 // Listens for notifications from the ServerConnectionManager | 1238 // Listens for notifications from the ServerConnectionManager |
| 1243 void HandleServerConnectionEvent(const ServerConnectionEvent& event); | 1239 void HandleServerConnectionEvent(const ServerConnectionEvent& event); |
| 1244 | 1240 |
| 1245 // Open the directory named with username_for_share | 1241 // Open the directory named with username_for_share |
| 1246 bool OpenDirectory(); | 1242 bool OpenDirectory(); |
| 1247 | 1243 |
| 1248 // SyncNotifierObserver implementation. | 1244 // SyncNotifierObserver implementation. |
| 1249 virtual void OnNotificationStateChange( | 1245 virtual void OnNotificationStateChange( |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1584 // True if the SyncManager should be running in test mode (no sync | 1580 // True if the SyncManager should be running in test mode (no sync |
| 1585 // scheduler actually communicating with the server). | 1581 // scheduler actually communicating with the server). |
| 1586 bool setup_for_test_mode_; | 1582 bool setup_for_test_mode_; |
| 1587 | 1583 |
| 1588 ScopedRunnableMethodFactory<SyncManager::SyncInternal> method_factory_; | 1584 ScopedRunnableMethodFactory<SyncManager::SyncInternal> method_factory_; |
| 1589 | 1585 |
| 1590 // Map used to store the notification info to be displayed in | 1586 // Map used to store the notification info to be displayed in |
| 1591 // about:sync page. | 1587 // about:sync page. |
| 1592 NotificationInfoMap notification_info_map_; | 1588 NotificationInfoMap notification_info_map_; |
| 1593 | 1589 |
| 1594 browser_sync::JsDirectoryChangeListener js_directory_change_listener_; | 1590 browser_sync::JsTransactionObserver js_transaction_observer_; |
| 1595 | 1591 |
| 1596 JsMessageHandlerMap js_message_handlers_; | 1592 JsMessageHandlerMap js_message_handlers_; |
| 1597 }; | 1593 }; |
| 1598 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 1594 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
| 1599 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 1595 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; |
| 1600 | 1596 |
| 1601 SyncManager::Observer::~Observer() {} | 1597 SyncManager::Observer::~Observer() {} |
| 1602 | 1598 |
| 1603 SyncManager::SyncManager(const std::string& name) | 1599 SyncManager::SyncManager(const std::string& name) |
| 1604 : data_(new SyncInternal(name, ALLOW_THIS_IN_INITIALIZER_LIST(this))) {} | 1600 : data_(new SyncInternal(name, ALLOW_THIS_IN_INITIALIZER_LIST(this))) {} |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 // Start the sync scheduler. This won't actually result in any | 1838 // Start the sync scheduler. This won't actually result in any |
| 1843 // syncing until at least the DirectoryManager broadcasts the OPENED | 1839 // syncing until at least the DirectoryManager broadcasts the OPENED |
| 1844 // event, and a valid server connection is detected. | 1840 // event, and a valid server connection is detected. |
| 1845 if (scheduler()) // NULL during certain unittests. | 1841 if (scheduler()) // NULL during certain unittests. |
| 1846 scheduler()->Start(SyncScheduler::NORMAL_MODE, NULL); | 1842 scheduler()->Start(SyncScheduler::NORMAL_MODE, NULL); |
| 1847 } | 1843 } |
| 1848 | 1844 |
| 1849 bool SyncManager::SyncInternal::OpenDirectory() { | 1845 bool SyncManager::SyncInternal::OpenDirectory() { |
| 1850 DCHECK(!initialized_) << "Should only happen once"; | 1846 DCHECK(!initialized_) << "Should only happen once"; |
| 1851 | 1847 |
| 1852 bool share_opened = dir_manager()->Open(username_for_share()); | 1848 bool share_opened = dir_manager()->Open(username_for_share(), this); |
| 1853 DCHECK(share_opened); | 1849 DCHECK(share_opened); |
| 1854 if (!share_opened) { | 1850 if (!share_opened) { |
| 1855 ObserverList<SyncManager::Observer> temp_obs_list; | 1851 ObserverList<SyncManager::Observer> temp_obs_list; |
| 1856 CopyObservers(&temp_obs_list); | 1852 CopyObservers(&temp_obs_list); |
| 1857 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 1853 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
| 1858 OnStopSyncingPermanently()); | 1854 OnStopSyncingPermanently()); |
| 1859 | 1855 |
| 1860 LOG(ERROR) << "Could not open share for:" << username_for_share(); | 1856 LOG(ERROR) << "Could not open share for:" << username_for_share(); |
| 1861 return false; | 1857 return false; |
| 1862 } | 1858 } |
| 1863 | 1859 |
| 1864 // Database has to be initialized for the guid to be available. | 1860 // Database has to be initialized for the guid to be available. |
| 1865 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | 1861 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); |
| 1866 if (!lookup.good()) { | 1862 if (!lookup.good()) { |
| 1867 NOTREACHED(); | 1863 NOTREACHED(); |
| 1868 return false; | 1864 return false; |
| 1869 } | 1865 } |
| 1870 | 1866 |
| 1871 connection_manager()->set_client_id(lookup->cache_guid()); | 1867 connection_manager()->set_client_id(lookup->cache_guid()); |
| 1872 | 1868 |
| 1873 // Since we own |share_|, it's okay that we don't ever remove | |
| 1874 // ourselves as a listener. | |
| 1875 lookup->AddChangeListener(this); | |
| 1876 | |
| 1877 if (parent_router_) { | 1869 if (parent_router_) { |
| 1878 // Make sure we add the listener at most once. | 1870 // Make sure we add the observer at most once. |
| 1879 lookup->RemoveChangeListener(&js_directory_change_listener_); | 1871 lookup->RemoveTransactionObserver(&js_transaction_observer_); |
| 1880 lookup->AddChangeListener(&js_directory_change_listener_); | 1872 lookup->AddTransactionObserver(&js_transaction_observer_); |
| 1881 } | 1873 } |
| 1882 return true; | 1874 return true; |
| 1883 } | 1875 } |
| 1884 | 1876 |
| 1885 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) { | 1877 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) { |
| 1886 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1878 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1887 DCHECK(share_.name.empty()); | 1879 DCHECK(share_.name.empty()); |
| 1888 share_.name = credentials.email; | 1880 share_.name = credentials.email; |
| 1889 | 1881 |
| 1890 VLOG(1) << "Signing in user: " << username_for_share(); | 1882 VLOG(1) << "Signing in user: " << username_for_share(); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2321 &ordered_changes[0], ordered_changes.size())); | 2313 &ordered_changes[0], ordered_changes.size())); |
| 2322 models_with_changes.set(i, true); | 2314 models_with_changes.set(i, true); |
| 2323 } | 2315 } |
| 2324 change_buffers_[i].Clear(); | 2316 change_buffers_[i].Clear(); |
| 2325 } | 2317 } |
| 2326 return models_with_changes; | 2318 return models_with_changes; |
| 2327 } | 2319 } |
| 2328 | 2320 |
| 2329 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncApi( | 2321 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncApi( |
| 2330 const OriginalEntries& originals, | 2322 const OriginalEntries& originals, |
| 2331 const WriterTag& writer, | |
| 2332 syncable::BaseTransaction* trans) { | 2323 syncable::BaseTransaction* trans) { |
| 2333 // We have been notified about a user action changing a sync model. | 2324 // We have been notified about a user action changing a sync model. |
| 2334 DCHECK(writer == syncable::SYNCAPI || | |
| 2335 writer == syncable::UNITTEST); | |
| 2336 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << | 2325 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << |
| 2337 "CALCULATE_CHANGES called with unapplied old changes."; | 2326 "CALCULATE_CHANGES called with unapplied old changes."; |
| 2338 | 2327 |
| 2339 bool exists_unsynced_items = false; | 2328 bool exists_unsynced_items = false; |
| 2340 bool only_preference_changes = true; | 2329 bool only_preference_changes = true; |
| 2341 syncable::ModelTypeBitSet model_types; | 2330 syncable::ModelTypeBitSet model_types; |
| 2342 for (syncable::OriginalEntries::const_iterator i = originals.begin(); | 2331 for (syncable::OriginalEntries::const_iterator i = originals.begin(); |
| 2343 i != originals.end() && !exists_unsynced_items; | 2332 i != originals.end() && !exists_unsynced_items; |
| 2344 ++i) { | 2333 ++i) { |
| 2345 int64 id = i->ref(syncable::META_HANDLE); | 2334 int64 id = i->ref(syncable::META_HANDLE); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2399 NOTREACHED(); | 2388 NOTREACHED(); |
| 2400 return; | 2389 return; |
| 2401 } | 2390 } |
| 2402 } | 2391 } |
| 2403 buffer->SetSpecificsForId(id, original_specifics); | 2392 buffer->SetSpecificsForId(id, original_specifics); |
| 2404 } | 2393 } |
| 2405 } | 2394 } |
| 2406 | 2395 |
| 2407 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncer( | 2396 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncer( |
| 2408 const OriginalEntries& originals, | 2397 const OriginalEntries& originals, |
| 2409 const WriterTag& writer, | |
| 2410 syncable::BaseTransaction* trans) { | 2398 syncable::BaseTransaction* trans) { |
| 2411 // We only expect one notification per sync step, so change_buffers_ should | 2399 // We only expect one notification per sync step, so change_buffers_ should |
| 2412 // contain no pending entries. | 2400 // contain no pending entries. |
| 2413 DCHECK(writer == syncable::SYNCER || | |
| 2414 writer == syncable::UNITTEST); | |
| 2415 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << | 2401 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << |
| 2416 "CALCULATE_CHANGES called with unapplied old changes."; | 2402 "CALCULATE_CHANGES called with unapplied old changes."; |
| 2417 | 2403 |
| 2418 Cryptographer* crypto = dir_manager()->GetCryptographer(trans); | 2404 Cryptographer* crypto = dir_manager()->GetCryptographer(trans); |
| 2419 for (syncable::OriginalEntries::const_iterator i = originals.begin(); | 2405 for (syncable::OriginalEntries::const_iterator i = originals.begin(); |
| 2420 i != originals.end(); ++i) { | 2406 i != originals.end(); ++i) { |
| 2421 int64 id = i->ref(syncable::META_HANDLE); | 2407 int64 id = i->ref(syncable::META_HANDLE); |
| 2422 syncable::Entry e(trans, syncable::GET_BY_HANDLE, id); | 2408 syncable::Entry e(trans, syncable::GET_BY_HANDLE, id); |
| 2423 bool existed_before = !i->ref(syncable::IS_DEL); | 2409 bool existed_before = !i->ref(syncable::IS_DEL); |
| 2424 bool exists_now = e.good() && !e.Get(syncable::IS_DEL); | 2410 bool exists_now = e.good() && !e.Get(syncable::IS_DEL); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2604 | 2590 |
| 2605 // We might be called before OpenDirectory() or after shutdown. | 2591 // We might be called before OpenDirectory() or after shutdown. |
| 2606 if (!dir_manager()) { | 2592 if (!dir_manager()) { |
| 2607 return; | 2593 return; |
| 2608 } | 2594 } |
| 2609 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | 2595 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); |
| 2610 if (!lookup.good()) { | 2596 if (!lookup.good()) { |
| 2611 return; | 2597 return; |
| 2612 } | 2598 } |
| 2613 | 2599 |
| 2614 // Make sure we add the listener at most once. | 2600 // Make sure we add the observer at most once. |
| 2615 lookup->RemoveChangeListener(&js_directory_change_listener_); | 2601 lookup->RemoveTransactionObserver(&js_transaction_observer_); |
| 2616 lookup->AddChangeListener(&js_directory_change_listener_); | 2602 lookup->AddTransactionObserver(&js_transaction_observer_); |
| 2617 } | 2603 } |
| 2618 | 2604 |
| 2619 void SyncManager::SyncInternal::RemoveParentJsEventRouter() { | 2605 void SyncManager::SyncInternal::RemoveParentJsEventRouter() { |
| 2620 parent_router_ = NULL; | 2606 parent_router_ = NULL; |
| 2621 | 2607 |
| 2622 // We might be called before OpenDirectory() or after shutdown. | 2608 // We might be called before OpenDirectory() or after shutdown. |
| 2623 if (!dir_manager()) { | 2609 if (!dir_manager()) { |
| 2624 return; | 2610 return; |
| 2625 } | 2611 } |
| 2626 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | 2612 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); |
| 2627 if (!lookup.good()) { | 2613 if (!lookup.good()) { |
| 2628 return; | 2614 return; |
| 2629 } | 2615 } |
| 2630 | 2616 |
| 2631 lookup->RemoveChangeListener(&js_directory_change_listener_); | 2617 lookup->RemoveTransactionObserver(&js_transaction_observer_); |
| 2632 } | 2618 } |
| 2633 | 2619 |
| 2634 const browser_sync::JsEventRouter* | 2620 const browser_sync::JsEventRouter* |
| 2635 SyncManager::SyncInternal::GetParentJsEventRouter() const { | 2621 SyncManager::SyncInternal::GetParentJsEventRouter() const { |
| 2636 return parent_router_; | 2622 return parent_router_; |
| 2637 } | 2623 } |
| 2638 | 2624 |
| 2639 void SyncManager::SyncInternal::ProcessMessage( | 2625 void SyncManager::SyncInternal::ProcessMessage( |
| 2640 const std::string& name, const browser_sync::JsArgList& args, | 2626 const std::string& name, const browser_sync::JsArgList& args, |
| 2641 const browser_sync::JsEventHandler* sender) { | 2627 const browser_sync::JsEventHandler* sender) { |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3014 void SyncManager::TriggerOnIncomingNotificationForTest( | 3000 void SyncManager::TriggerOnIncomingNotificationForTest( |
| 3015 const syncable::ModelTypeBitSet& model_types) { | 3001 const syncable::ModelTypeBitSet& model_types) { |
| 3016 syncable::ModelTypePayloadMap model_types_with_payloads = | 3002 syncable::ModelTypePayloadMap model_types_with_payloads = |
| 3017 syncable::ModelTypePayloadMapFromBitSet(model_types, | 3003 syncable::ModelTypePayloadMapFromBitSet(model_types, |
| 3018 std::string()); | 3004 std::string()); |
| 3019 | 3005 |
| 3020 data_->OnIncomingNotification(model_types_with_payloads); | 3006 data_->OnIncomingNotification(model_types_with_payloads); |
| 3021 } | 3007 } |
| 3022 | 3008 |
| 3023 } // namespace sync_api | 3009 } // namespace sync_api |
| OLD | NEW |