Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: chrome/browser/sync/engine/syncapi.cc

Issue 7190001: [Sync] Split DirectoryChangeListener for thread-safety (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix copyright Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/engine/syncapi.h ('k') | chrome/browser/sync/engine/syncapi_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 1215
1218 // Try to set the current passphrase to |passphrase|, and record whether 1216 // Try to set the current passphrase to |passphrase|, and record whether
1219 // it is an explicit passphrase or implicitly using gaia in the Nigori 1217 // it is an explicit passphrase or implicitly using gaia in the Nigori
1220 // node. 1218 // node.
1221 void SetPassphrase(const std::string& passphrase, bool is_explicit); 1219 void SetPassphrase(const std::string& passphrase, bool is_explicit);
1222 1220
1223 // Call periodically from a database-safe thread to persist recent changes 1221 // Call periodically from a database-safe thread to persist recent changes
1224 // to the syncapi model. 1222 // to the syncapi model.
1225 void SaveChanges(); 1223 void SaveChanges();
1226 1224
1227 // DirectoryChangeListener implementation. 1225 // DirectoryChangeDelegate implementation.
1228 // This listener is called upon completion of a syncable transaction, and 1226 // This listener is called upon completion of a syncable transaction, and
1229 // builds the list of sync-engine initiated changes that will be forwarded to 1227 // builds the list of sync-engine initiated changes that will be forwarded to
1230 // the SyncManager's Observers. 1228 // the SyncManager's Observers.
1231 virtual void HandleTransactionCompleteChangeEvent( 1229 virtual void HandleTransactionCompleteChangeEvent(
1232 const ModelTypeBitSet& models_with_changes); 1230 const ModelTypeBitSet& models_with_changes);
1233 virtual ModelTypeBitSet HandleTransactionEndingChangeEvent( 1231 virtual ModelTypeBitSet HandleTransactionEndingChangeEvent(
1234 syncable::BaseTransaction* trans); 1232 syncable::BaseTransaction* trans);
1235 virtual void HandleCalculateChangesChangeEventFromSyncApi( 1233 virtual void HandleCalculateChangesChangeEventFromSyncApi(
1236 const OriginalEntries& originals, 1234 const OriginalEntries& originals,
1237 const WriterTag& writer,
1238 syncable::BaseTransaction* trans); 1235 syncable::BaseTransaction* trans);
1239 virtual void HandleCalculateChangesChangeEventFromSyncer( 1236 virtual void HandleCalculateChangesChangeEventFromSyncer(
1240 const OriginalEntries& originals, 1237 const OriginalEntries& originals,
1241 const WriterTag& writer,
1242 syncable::BaseTransaction* trans); 1238 syncable::BaseTransaction* trans);
1243 1239
1244 // Listens for notifications from the ServerConnectionManager 1240 // Listens for notifications from the ServerConnectionManager
1245 void HandleServerConnectionEvent(const ServerConnectionEvent& event); 1241 void HandleServerConnectionEvent(const ServerConnectionEvent& event);
1246 1242
1247 // Open the directory named with username_for_share 1243 // Open the directory named with username_for_share
1248 bool OpenDirectory(); 1244 bool OpenDirectory();
1249 1245
1250 // SyncNotifierObserver implementation. 1246 // SyncNotifierObserver implementation.
1251 virtual void OnNotificationStateChange( 1247 virtual void OnNotificationStateChange(
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 // True if the SyncManager should be running in test mode (no sync 1582 // True if the SyncManager should be running in test mode (no sync
1587 // scheduler actually communicating with the server). 1583 // scheduler actually communicating with the server).
1588 bool setup_for_test_mode_; 1584 bool setup_for_test_mode_;
1589 1585
1590 ScopedRunnableMethodFactory<SyncManager::SyncInternal> method_factory_; 1586 ScopedRunnableMethodFactory<SyncManager::SyncInternal> method_factory_;
1591 1587
1592 // Map used to store the notification info to be displayed in 1588 // Map used to store the notification info to be displayed in
1593 // about:sync page. 1589 // about:sync page.
1594 NotificationInfoMap notification_info_map_; 1590 NotificationInfoMap notification_info_map_;
1595 1591
1596 browser_sync::JsDirectoryChangeListener js_directory_change_listener_; 1592 browser_sync::JsTransactionObserver js_transaction_observer_;
1597 1593
1598 JsMessageHandlerMap js_message_handlers_; 1594 JsMessageHandlerMap js_message_handlers_;
1599 }; 1595 };
1600 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; 1596 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200;
1601 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; 1597 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000;
1602 1598
1603 SyncManager::Observer::~Observer() {} 1599 SyncManager::Observer::~Observer() {}
1604 1600
1605 SyncManager::SyncManager(const std::string& name) 1601 SyncManager::SyncManager(const std::string& name)
1606 : data_(new SyncInternal(name, ALLOW_THIS_IN_INITIALIZER_LIST(this))) {} 1602 : data_(new SyncInternal(name, ALLOW_THIS_IN_INITIALIZER_LIST(this))) {}
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 // Start the sync scheduler. This won't actually result in any 1840 // Start the sync scheduler. This won't actually result in any
1845 // syncing until at least the DirectoryManager broadcasts the OPENED 1841 // syncing until at least the DirectoryManager broadcasts the OPENED
1846 // event, and a valid server connection is detected. 1842 // event, and a valid server connection is detected.
1847 if (scheduler()) // NULL during certain unittests. 1843 if (scheduler()) // NULL during certain unittests.
1848 scheduler()->Start(SyncScheduler::NORMAL_MODE, NULL); 1844 scheduler()->Start(SyncScheduler::NORMAL_MODE, NULL);
1849 } 1845 }
1850 1846
1851 bool SyncManager::SyncInternal::OpenDirectory() { 1847 bool SyncManager::SyncInternal::OpenDirectory() {
1852 DCHECK(!initialized_) << "Should only happen once"; 1848 DCHECK(!initialized_) << "Should only happen once";
1853 1849
1854 bool share_opened = dir_manager()->Open(username_for_share()); 1850 bool share_opened = dir_manager()->Open(username_for_share(), this);
1855 DCHECK(share_opened); 1851 DCHECK(share_opened);
1856 if (!share_opened) { 1852 if (!share_opened) {
1857 ObserverList<SyncManager::Observer> temp_obs_list; 1853 ObserverList<SyncManager::Observer> temp_obs_list;
1858 CopyObservers(&temp_obs_list); 1854 CopyObservers(&temp_obs_list);
1859 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, 1855 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list,
1860 OnStopSyncingPermanently()); 1856 OnStopSyncingPermanently());
1861 1857
1862 LOG(ERROR) << "Could not open share for:" << username_for_share(); 1858 LOG(ERROR) << "Could not open share for:" << username_for_share();
1863 return false; 1859 return false;
1864 } 1860 }
1865 1861
1866 // Database has to be initialized for the guid to be available. 1862 // Database has to be initialized for the guid to be available.
1867 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); 1863 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share());
1868 if (!lookup.good()) { 1864 if (!lookup.good()) {
1869 NOTREACHED(); 1865 NOTREACHED();
1870 return false; 1866 return false;
1871 } 1867 }
1872 1868
1873 connection_manager()->set_client_id(lookup->cache_guid()); 1869 connection_manager()->set_client_id(lookup->cache_guid());
1874 1870
1875 // Since we own |share_|, it's okay that we don't ever remove
1876 // ourselves as a listener.
1877 lookup->AddChangeListener(this);
1878
1879 if (parent_router_) { 1871 if (parent_router_) {
1880 // Make sure we add the listener at most once. 1872 // Make sure we add the observer at most once.
1881 lookup->RemoveChangeListener(&js_directory_change_listener_); 1873 lookup->RemoveTransactionObserver(&js_transaction_observer_);
1882 lookup->AddChangeListener(&js_directory_change_listener_); 1874 lookup->AddTransactionObserver(&js_transaction_observer_);
1883 } 1875 }
1884 return true; 1876 return true;
1885 } 1877 }
1886 1878
1887 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) { 1879 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) {
1888 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1880 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1889 DCHECK(share_.name.empty()); 1881 DCHECK(share_.name.empty());
1890 share_.name = credentials.email; 1882 share_.name = credentials.email;
1891 1883
1892 VLOG(1) << "Signing in user: " << username_for_share(); 1884 VLOG(1) << "Signing in user: " << username_for_share();
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 &ordered_changes[0], ordered_changes.size())); 2315 &ordered_changes[0], ordered_changes.size()));
2324 models_with_changes.set(i, true); 2316 models_with_changes.set(i, true);
2325 } 2317 }
2326 change_buffers_[i].Clear(); 2318 change_buffers_[i].Clear();
2327 } 2319 }
2328 return models_with_changes; 2320 return models_with_changes;
2329 } 2321 }
2330 2322
2331 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncApi( 2323 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncApi(
2332 const OriginalEntries& originals, 2324 const OriginalEntries& originals,
2333 const WriterTag& writer,
2334 syncable::BaseTransaction* trans) { 2325 syncable::BaseTransaction* trans) {
2335 // We have been notified about a user action changing a sync model. 2326 // We have been notified about a user action changing a sync model.
2336 DCHECK(writer == syncable::SYNCAPI ||
2337 writer == syncable::UNITTEST);
2338 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << 2327 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) <<
2339 "CALCULATE_CHANGES called with unapplied old changes."; 2328 "CALCULATE_CHANGES called with unapplied old changes.";
2340 2329
2341 bool exists_unsynced_items = false; 2330 bool exists_unsynced_items = false;
2342 bool only_preference_changes = true; 2331 bool only_preference_changes = true;
2343 syncable::ModelTypeBitSet model_types; 2332 syncable::ModelTypeBitSet model_types;
2344 for (syncable::OriginalEntries::const_iterator i = originals.begin(); 2333 for (syncable::OriginalEntries::const_iterator i = originals.begin();
2345 i != originals.end() && !exists_unsynced_items; 2334 i != originals.end() && !exists_unsynced_items;
2346 ++i) { 2335 ++i) {
2347 int64 id = i->ref(syncable::META_HANDLE); 2336 int64 id = i->ref(syncable::META_HANDLE);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 NOTREACHED(); 2390 NOTREACHED();
2402 return; 2391 return;
2403 } 2392 }
2404 } 2393 }
2405 buffer->SetSpecificsForId(id, original_specifics); 2394 buffer->SetSpecificsForId(id, original_specifics);
2406 } 2395 }
2407 } 2396 }
2408 2397
2409 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncer( 2398 void SyncManager::SyncInternal::HandleCalculateChangesChangeEventFromSyncer(
2410 const OriginalEntries& originals, 2399 const OriginalEntries& originals,
2411 const WriterTag& writer,
2412 syncable::BaseTransaction* trans) { 2400 syncable::BaseTransaction* trans) {
2413 // We only expect one notification per sync step, so change_buffers_ should 2401 // We only expect one notification per sync step, so change_buffers_ should
2414 // contain no pending entries. 2402 // contain no pending entries.
2415 DCHECK(writer == syncable::SYNCER ||
2416 writer == syncable::UNITTEST);
2417 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) << 2403 LOG_IF(WARNING, !ChangeBuffersAreEmpty()) <<
2418 "CALCULATE_CHANGES called with unapplied old changes."; 2404 "CALCULATE_CHANGES called with unapplied old changes.";
2419 2405
2420 Cryptographer* crypto = dir_manager()->GetCryptographer(trans); 2406 Cryptographer* crypto = dir_manager()->GetCryptographer(trans);
2421 for (syncable::OriginalEntries::const_iterator i = originals.begin(); 2407 for (syncable::OriginalEntries::const_iterator i = originals.begin();
2422 i != originals.end(); ++i) { 2408 i != originals.end(); ++i) {
2423 int64 id = i->ref(syncable::META_HANDLE); 2409 int64 id = i->ref(syncable::META_HANDLE);
2424 syncable::Entry e(trans, syncable::GET_BY_HANDLE, id); 2410 syncable::Entry e(trans, syncable::GET_BY_HANDLE, id);
2425 bool existed_before = !i->ref(syncable::IS_DEL); 2411 bool existed_before = !i->ref(syncable::IS_DEL);
2426 bool exists_now = e.good() && !e.Get(syncable::IS_DEL); 2412 bool exists_now = e.good() && !e.Get(syncable::IS_DEL);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
2606 2592
2607 // We might be called before OpenDirectory() or after shutdown. 2593 // We might be called before OpenDirectory() or after shutdown.
2608 if (!dir_manager()) { 2594 if (!dir_manager()) {
2609 return; 2595 return;
2610 } 2596 }
2611 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); 2597 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share());
2612 if (!lookup.good()) { 2598 if (!lookup.good()) {
2613 return; 2599 return;
2614 } 2600 }
2615 2601
2616 // Make sure we add the listener at most once. 2602 // Make sure we add the observer at most once.
2617 lookup->RemoveChangeListener(&js_directory_change_listener_); 2603 lookup->RemoveTransactionObserver(&js_transaction_observer_);
2618 lookup->AddChangeListener(&js_directory_change_listener_); 2604 lookup->AddTransactionObserver(&js_transaction_observer_);
2619 } 2605 }
2620 2606
2621 void SyncManager::SyncInternal::RemoveParentJsEventRouter() { 2607 void SyncManager::SyncInternal::RemoveParentJsEventRouter() {
2622 parent_router_ = NULL; 2608 parent_router_ = NULL;
2623 2609
2624 // We might be called before OpenDirectory() or after shutdown. 2610 // We might be called before OpenDirectory() or after shutdown.
2625 if (!dir_manager()) { 2611 if (!dir_manager()) {
2626 return; 2612 return;
2627 } 2613 }
2628 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); 2614 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share());
2629 if (!lookup.good()) { 2615 if (!lookup.good()) {
2630 return; 2616 return;
2631 } 2617 }
2632 2618
2633 lookup->RemoveChangeListener(&js_directory_change_listener_); 2619 lookup->RemoveTransactionObserver(&js_transaction_observer_);
2634 } 2620 }
2635 2621
2636 const browser_sync::JsEventRouter* 2622 const browser_sync::JsEventRouter*
2637 SyncManager::SyncInternal::GetParentJsEventRouter() const { 2623 SyncManager::SyncInternal::GetParentJsEventRouter() const {
2638 return parent_router_; 2624 return parent_router_;
2639 } 2625 }
2640 2626
2641 void SyncManager::SyncInternal::ProcessMessage( 2627 void SyncManager::SyncInternal::ProcessMessage(
2642 const std::string& name, const browser_sync::JsArgList& args, 2628 const std::string& name, const browser_sync::JsArgList& args,
2643 const browser_sync::JsEventHandler* sender) { 2629 const browser_sync::JsEventHandler* sender) {
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
3016 void SyncManager::TriggerOnIncomingNotificationForTest( 3002 void SyncManager::TriggerOnIncomingNotificationForTest(
3017 const syncable::ModelTypeBitSet& model_types) { 3003 const syncable::ModelTypeBitSet& model_types) {
3018 syncable::ModelTypePayloadMap model_types_with_payloads = 3004 syncable::ModelTypePayloadMap model_types_with_payloads =
3019 syncable::ModelTypePayloadMapFromBitSet(model_types, 3005 syncable::ModelTypePayloadMapFromBitSet(model_types,
3020 std::string()); 3006 std::string());
3021 3007
3022 data_->OnIncomingNotification(model_types_with_payloads); 3008 data_->OnIncomingNotification(model_types_with_payloads);
3023 } 3009 }
3024 3010
3025 } // namespace sync_api 3011 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncapi.h ('k') | chrome/browser/sync/engine/syncapi_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698