OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 20 matching lines...) Expand all Loading... | |
31 #include "chrome/browser/sync/engine/model_safe_worker.h" | 31 #include "chrome/browser/sync/engine/model_safe_worker.h" |
32 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 32 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
33 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" | 33 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" |
34 #include "chrome/browser/sync/engine/syncer.h" | 34 #include "chrome/browser/sync/engine/syncer.h" |
35 #include "chrome/browser/sync/engine/syncer_thread.h" | 35 #include "chrome/browser/sync/engine/syncer_thread.h" |
36 #include "chrome/browser/sync/engine/syncer_thread2.h" | 36 #include "chrome/browser/sync/engine/syncer_thread2.h" |
37 #include "chrome/browser/sync/engine/syncer_thread_adapter.h" | 37 #include "chrome/browser/sync/engine/syncer_thread_adapter.h" |
38 #include "chrome/browser/sync/js_arg_list.h" | 38 #include "chrome/browser/sync/js_arg_list.h" |
39 #include "chrome/browser/sync/js_backend.h" | 39 #include "chrome/browser/sync/js_backend.h" |
40 #include "chrome/browser/sync/js_event_router.h" | 40 #include "chrome/browser/sync/js_event_router.h" |
41 #include "chrome/browser/sync/notifier/server_notifier_thread.h" | 41 #include "chrome/browser/sync/notifier/sync_notifier.h" |
42 #include "chrome/browser/sync/notifier/state_writer.h" | 42 #include "chrome/browser/sync/notifier/sync_notifier_factory.h" |
43 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" | |
43 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 44 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
44 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 45 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
45 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 46 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
46 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 47 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
47 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 48 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
48 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 49 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
49 #include "chrome/browser/sync/protocol/proto_value_conversions.h" | 50 #include "chrome/browser/sync/protocol/proto_value_conversions.h" |
50 #include "chrome/browser/sync/protocol/service_constants.h" | 51 #include "chrome/browser/sync/protocol/service_constants.h" |
51 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | 52 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
52 #include "chrome/browser/sync/protocol/sync.pb.h" | 53 #include "chrome/browser/sync/protocol/sync.pb.h" |
53 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 54 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
54 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 55 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
55 #include "chrome/browser/sync/sessions/sync_session.h" | 56 #include "chrome/browser/sync/sessions/sync_session.h" |
56 #include "chrome/browser/sync/sessions/sync_session_context.h" | 57 #include "chrome/browser/sync/sessions/sync_session_context.h" |
57 #include "chrome/browser/sync/syncable/autofill_migration.h" | 58 #include "chrome/browser/sync/syncable/autofill_migration.h" |
58 #include "chrome/browser/sync/syncable/directory_manager.h" | 59 #include "chrome/browser/sync/syncable/directory_manager.h" |
59 #include "chrome/browser/sync/syncable/nigori_util.h" | 60 #include "chrome/browser/sync/syncable/nigori_util.h" |
60 #include "chrome/browser/sync/syncable/syncable.h" | 61 #include "chrome/browser/sync/syncable/syncable.h" |
61 #include "chrome/browser/sync/util/crypto_helpers.h" | 62 #include "chrome/browser/sync/util/crypto_helpers.h" |
62 #include "chrome/common/chrome_switches.h" | 63 #include "chrome/common/chrome_switches.h" |
63 #include "chrome/common/deprecated/event_sys.h" | 64 #include "chrome/common/deprecated/event_sys.h" |
64 #include "chrome/common/net/gaia/gaia_authenticator.h" | 65 #include "chrome/common/net/gaia/gaia_authenticator.h" |
65 #include "content/browser/browser_thread.h" | 66 #include "content/browser/browser_thread.h" |
66 #include "jingle/notifier/listener/mediator_thread_impl.h" | |
67 #include "jingle/notifier/listener/notification_constants.h" | |
68 #include "jingle/notifier/listener/talk_mediator.h" | |
69 #include "jingle/notifier/listener/talk_mediator_impl.h" | |
70 #include "net/base/network_change_notifier.h" | 67 #include "net/base/network_change_notifier.h" |
71 | 68 |
72 using browser_sync::AllStatus; | 69 using browser_sync::AllStatus; |
73 using browser_sync::Cryptographer; | 70 using browser_sync::Cryptographer; |
74 using browser_sync::KeyParams; | 71 using browser_sync::KeyParams; |
75 using browser_sync::ModelSafeRoutingInfo; | 72 using browser_sync::ModelSafeRoutingInfo; |
76 using browser_sync::ModelSafeWorker; | 73 using browser_sync::ModelSafeWorker; |
77 using browser_sync::ModelSafeWorkerRegistrar; | 74 using browser_sync::ModelSafeWorkerRegistrar; |
78 using browser_sync::ServerConnectionEvent; | 75 using browser_sync::ServerConnectionEvent; |
79 using browser_sync::SyncEngineEvent; | 76 using browser_sync::SyncEngineEvent; |
80 using browser_sync::SyncEngineEventListener; | 77 using browser_sync::SyncEngineEventListener; |
81 using browser_sync::Syncer; | 78 using browser_sync::Syncer; |
82 using browser_sync::SyncerThread; | 79 using browser_sync::SyncerThread; |
83 using browser_sync::SyncerThreadAdapter; | 80 using browser_sync::SyncerThreadAdapter; |
84 using browser_sync::kNigoriTag; | 81 using browser_sync::kNigoriTag; |
85 using browser_sync::sessions::SyncSessionContext; | 82 using browser_sync::sessions::SyncSessionContext; |
86 using notifier::TalkMediator; | |
87 using notifier::TalkMediatorImpl; | |
88 using std::list; | 83 using std::list; |
89 using std::hex; | 84 using std::hex; |
90 using std::string; | 85 using std::string; |
91 using std::vector; | 86 using std::vector; |
92 using syncable::Directory; | 87 using syncable::Directory; |
93 using syncable::DirectoryManager; | 88 using syncable::DirectoryManager; |
94 using syncable::Entry; | 89 using syncable::Entry; |
95 using syncable::SPECIFICS; | 90 using syncable::SPECIFICS; |
91 using sync_notifier::SyncNotifierFactory; | |
96 using sync_pb::AutofillProfileSpecifics; | 92 using sync_pb::AutofillProfileSpecifics; |
97 | 93 |
98 typedef GoogleServiceAuthError AuthError; | 94 typedef GoogleServiceAuthError AuthError; |
99 | 95 |
100 static const int kThreadExitTimeoutMsec = 60000; | 96 static const int kThreadExitTimeoutMsec = 60000; |
101 static const int kSSLPort = 443; | 97 static const int kSSLPort = 443; |
102 static const int kSyncerThreadDelayMsec = 250; | 98 static const int kSyncerThreadDelayMsec = 250; |
103 | 99 |
104 #if defined(OS_CHROMEOS) | 100 #if defined(OS_CHROMEOS) |
105 static const int kChromeOSNetworkChangeReactionDelayHackMsec = 5000; | 101 static const int kChromeOSNetworkChangeReactionDelayHackMsec = 5000; |
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1106 | 1102 |
1107 const sync_pb::PasswordSpecificsData& | 1103 const sync_pb::PasswordSpecificsData& |
1108 SyncManager::ExtraPasswordChangeRecordData::unencrypted() const { | 1104 SyncManager::ExtraPasswordChangeRecordData::unencrypted() const { |
1109 return unencrypted_; | 1105 return unencrypted_; |
1110 } | 1106 } |
1111 | 1107 |
1112 ////////////////////////////////////////////////////////////////////////// | 1108 ////////////////////////////////////////////////////////////////////////// |
1113 // SyncManager's implementation: SyncManager::SyncInternal | 1109 // SyncManager's implementation: SyncManager::SyncInternal |
1114 class SyncManager::SyncInternal | 1110 class SyncManager::SyncInternal |
1115 : public net::NetworkChangeNotifier::IPAddressObserver, | 1111 : public net::NetworkChangeNotifier::IPAddressObserver, |
1116 public TalkMediator::Delegate, | 1112 public sync_notifier::SyncNotifierObserver, |
1117 public sync_notifier::StateWriter, | |
1118 public browser_sync::ChannelEventHandler<syncable::DirectoryChangeEvent>, | 1113 public browser_sync::ChannelEventHandler<syncable::DirectoryChangeEvent>, |
1119 public browser_sync::JsBackend, | 1114 public browser_sync::JsBackend, |
1120 public SyncEngineEventListener { | 1115 public SyncEngineEventListener { |
1121 static const int kDefaultNudgeDelayMilliseconds; | 1116 static const int kDefaultNudgeDelayMilliseconds; |
1122 static const int kPreferencesNudgeDelayMilliseconds; | 1117 static const int kPreferencesNudgeDelayMilliseconds; |
1123 public: | 1118 public: |
1124 explicit SyncInternal(SyncManager* sync_manager) | 1119 explicit SyncInternal(SyncManager* sync_manager) |
1125 : core_message_loop_(NULL), | 1120 : core_message_loop_(NULL), |
1126 parent_router_(NULL), | 1121 parent_router_(NULL), |
1127 sync_manager_(sync_manager), | 1122 sync_manager_(sync_manager), |
1128 registrar_(NULL), | 1123 registrar_(NULL), |
1129 notification_pending_(false), | 1124 notification_pending_(false), |
1130 initialized_(false), | 1125 initialized_(false), |
1131 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 1126 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
1132 server_notifier_thread_(NULL) { | |
1133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1134 } | 1128 } |
1135 | 1129 |
1136 virtual ~SyncInternal() { | 1130 virtual ~SyncInternal() { |
1137 DCHECK(!core_message_loop_); | 1131 DCHECK(!core_message_loop_); |
1138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1139 } | 1133 } |
1140 | 1134 |
1141 bool Init(const FilePath& database_location, | 1135 bool Init(const FilePath& database_location, |
1142 const std::string& sync_server_and_path, | 1136 const std::string& sync_server_and_path, |
1143 int port, | 1137 int port, |
1144 bool use_ssl, | 1138 bool use_ssl, |
1145 HttpPostProviderFactory* post_factory, | 1139 HttpPostProviderFactory* post_factory, |
1146 ModelSafeWorkerRegistrar* model_safe_worker_registrar, | 1140 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
1147 const char* user_agent, | 1141 const char* user_agent, |
1148 const SyncCredentials& credentials, | 1142 const SyncCredentials& credentials, |
1149 const notifier::NotifierOptions& notifier_options, | |
1150 const std::string& restored_key_for_bootstrapping, | 1143 const std::string& restored_key_for_bootstrapping, |
1151 bool setup_for_test_mode); | 1144 bool setup_for_test_mode); |
1152 | 1145 |
1153 // Sign into sync with given credentials. | 1146 // Sign into sync with given credentials. |
1154 // We do not verify the tokens given. After this call, the tokens are set | 1147 // We do not verify the tokens given. After this call, the tokens are set |
1155 // and the sync DB is open. True if successful, false if something | 1148 // and the sync DB is open. True if successful, false if something |
1156 // went wrong. | 1149 // went wrong. |
1157 bool SignIn(const SyncCredentials& credentials); | 1150 bool SignIn(const SyncCredentials& credentials); |
1158 | 1151 |
1159 // Update tokens that we're using in Sync. Email must stay the same. | 1152 // Update tokens that we're using in Sync. Email must stay the same. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1193 const syncable::DirectoryChangeEvent& event); | 1186 const syncable::DirectoryChangeEvent& event); |
1194 void HandleCalculateChangesChangeEventFromSyncer( | 1187 void HandleCalculateChangesChangeEventFromSyncer( |
1195 const syncable::DirectoryChangeEvent& event); | 1188 const syncable::DirectoryChangeEvent& event); |
1196 | 1189 |
1197 // Listens for notifications from the ServerConnectionManager | 1190 // Listens for notifications from the ServerConnectionManager |
1198 void HandleServerConnectionEvent(const ServerConnectionEvent& event); | 1191 void HandleServerConnectionEvent(const ServerConnectionEvent& event); |
1199 | 1192 |
1200 // Open the directory named with username_for_share | 1193 // Open the directory named with username_for_share |
1201 bool OpenDirectory(); | 1194 bool OpenDirectory(); |
1202 | 1195 |
1203 // Login to the talk mediator with the given credentials. | 1196 // SyncNotifierObserver implementation. |
1204 void TalkMediatorLogin( | |
1205 const std::string& email, const std::string& token); | |
1206 | |
1207 // TalkMediator::Delegate implementation. | |
1208 virtual void OnNotificationStateChange( | 1197 virtual void OnNotificationStateChange( |
1209 bool notifications_enabled); | 1198 bool notifications_enabled); |
1210 | 1199 |
1211 virtual void OnIncomingNotification( | 1200 virtual void OnIncomingNotification( |
1212 const IncomingNotificationData& notification_data); | 1201 const browser_sync::sessions::TypePayloadMap& type_payloads); |
1213 | 1202 |
1214 virtual void OnOutgoingNotification(); | 1203 virtual void StoreState(const std::string& cookie); |
1215 | |
1216 // sync_notifier::StateWriter implementation. | |
1217 virtual void WriteState(const std::string& state); | |
1218 | 1204 |
1219 void AddObserver(SyncManager::Observer* observer); | 1205 void AddObserver(SyncManager::Observer* observer); |
1220 | 1206 |
1221 void RemoveObserver(SyncManager::Observer* observer); | 1207 void RemoveObserver(SyncManager::Observer* observer); |
1222 | 1208 |
1223 // Accessors for the private members. | 1209 // Accessors for the private members. |
1224 DirectoryManager* dir_manager() { return share_.dir_manager.get(); } | 1210 DirectoryManager* dir_manager() { return share_.dir_manager.get(); } |
1225 SyncAPIServerConnectionManager* connection_manager() { | 1211 SyncAPIServerConnectionManager* connection_manager() { |
1226 return connection_manager_.get(); | 1212 return connection_manager_.get(); |
1227 } | 1213 } |
1228 SyncerThreadAdapter* syncer_thread() { return syncer_thread_.get(); } | 1214 SyncerThreadAdapter* syncer_thread() { return syncer_thread_.get(); } |
1229 TalkMediator* talk_mediator() { return talk_mediator_.get(); } | |
1230 UserShare* GetUserShare() { return &share_; } | 1215 UserShare* GetUserShare() { return &share_; } |
1231 | 1216 |
1232 // Return the currently active (validated) username for use with syncable | 1217 // Return the currently active (validated) username for use with syncable |
1233 // types. | 1218 // types. |
1234 const std::string& username_for_share() const { | 1219 const std::string& username_for_share() const { |
1235 return share_.name; | 1220 return share_.name; |
1236 } | 1221 } |
1237 | 1222 |
1238 Status GetStatus(); | 1223 Status GetStatus(); |
1239 | 1224 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1327 | 1312 |
1328 // browser_sync::JsBackend implementation. | 1313 // browser_sync::JsBackend implementation. |
1329 virtual void SetParentJsEventRouter(browser_sync::JsEventRouter* router); | 1314 virtual void SetParentJsEventRouter(browser_sync::JsEventRouter* router); |
1330 virtual void RemoveParentJsEventRouter(); | 1315 virtual void RemoveParentJsEventRouter(); |
1331 virtual const browser_sync::JsEventRouter* GetParentJsEventRouter() const; | 1316 virtual const browser_sync::JsEventRouter* GetParentJsEventRouter() const; |
1332 virtual void ProcessMessage(const std::string& name, | 1317 virtual void ProcessMessage(const std::string& name, |
1333 const browser_sync::JsArgList& args, | 1318 const browser_sync::JsArgList& args, |
1334 const browser_sync::JsEventHandler* sender); | 1319 const browser_sync::JsEventHandler* sender); |
1335 | 1320 |
1336 private: | 1321 private: |
1337 // Helper to handle the details of initializing the TalkMediator. | |
1338 // Must be called only after OpenDirectory() is called. | |
1339 void InitializeTalkMediator(); | |
1340 | |
1341 // Helper to call OnAuthError when no authentication credentials are | 1322 // Helper to call OnAuthError when no authentication credentials are |
1342 // available. | 1323 // available. |
1343 void RaiseAuthNeededEvent(); | 1324 void RaiseAuthNeededEvent(); |
1344 | 1325 |
1345 // Helper to set initialized_ to true and raise an event to clients to notify | 1326 // Helper to set initialized_ to true and raise an event to clients to notify |
1346 // that initialization is complete and it is safe to send us changes. If | 1327 // that initialization is complete and it is safe to send us changes. If |
1347 // already initialized, this is a no-op. | 1328 // already initialized, this is a no-op. |
1348 void MarkAndNotifyInitializationComplete(); | 1329 void MarkAndNotifyInitializationComplete(); |
1349 | 1330 |
1350 // If there's a pending notification to be sent, either from the | 1331 // If there's a pending notification to be sent, either from the |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1460 | 1441 |
1461 browser_sync::JsEventRouter* parent_router_; | 1442 browser_sync::JsEventRouter* parent_router_; |
1462 | 1443 |
1463 // The ServerConnectionManager used to abstract communication between the | 1444 // The ServerConnectionManager used to abstract communication between the |
1464 // client (the Syncer) and the sync server. | 1445 // client (the Syncer) and the sync server. |
1465 scoped_ptr<SyncAPIServerConnectionManager> connection_manager_; | 1446 scoped_ptr<SyncAPIServerConnectionManager> connection_manager_; |
1466 | 1447 |
1467 // The thread that runs the Syncer. Needs to be explicitly Start()ed. | 1448 // The thread that runs the Syncer. Needs to be explicitly Start()ed. |
1468 scoped_ptr<SyncerThreadAdapter> syncer_thread_; | 1449 scoped_ptr<SyncerThreadAdapter> syncer_thread_; |
1469 | 1450 |
1470 // Notification (xmpp) handler. | 1451 // SyncNotifier to setup notifications. |
akalin
2011/03/11 04:17:14
Change comment to something like:
// The SyncNoti
Agrawal
2011/03/11 21:42:20
Done.
| |
1471 scoped_ptr<TalkMediator> talk_mediator_; | 1452 scoped_ptr<sync_notifier::SyncNotifier> sync_notifier_; |
1472 | 1453 |
1473 // A multi-purpose status watch object that aggregates stats from various | 1454 // A multi-purpose status watch object that aggregates stats from various |
1474 // sync components. | 1455 // sync components. |
1475 AllStatus allstatus_; | 1456 AllStatus allstatus_; |
1476 | 1457 |
1477 // Each element of this array is a store of change records produced by | 1458 // Each element of this array is a store of change records produced by |
1478 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are | 1459 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are |
1479 // segregated by model type, and are stored here to be processed and | 1460 // segregated by model type, and are stored here to be processed and |
1480 // forwarded to the observer slightly later, at the TRANSACTION_ENDING | 1461 // forwarded to the observer slightly later, at the TRANSACTION_ENDING |
1481 // step by HandleTransactionEndingChangeEvent. The list is cleared in the | 1462 // step by HandleTransactionEndingChangeEvent. The list is cleared in the |
(...skipping 26 matching lines...) Expand all Loading... | |
1508 | 1489 |
1509 // Set to true once Init has been called, and we know of an authenticated | 1490 // Set to true once Init has been called, and we know of an authenticated |
1510 // valid) username either from a fresh authentication attempt (as in | 1491 // valid) username either from a fresh authentication attempt (as in |
1511 // first-use case) or from a previous attempt stored in our UserSettings | 1492 // first-use case) or from a previous attempt stored in our UserSettings |
1512 // (as in the steady-state), and the syncable::Directory has been opened, | 1493 // (as in the steady-state), and the syncable::Directory has been opened, |
1513 // meaning we are ready to accept changes. Protected by initialized_mutex_ | 1494 // meaning we are ready to accept changes. Protected by initialized_mutex_ |
1514 // as it can get read/set by both the SyncerThread and the AuthWatcherThread. | 1495 // as it can get read/set by both the SyncerThread and the AuthWatcherThread. |
1515 bool initialized_; | 1496 bool initialized_; |
1516 mutable base::Lock initialized_mutex_; | 1497 mutable base::Lock initialized_mutex_; |
1517 | 1498 |
1518 notifier::NotifierOptions notifier_options_; | |
1519 | |
1520 // True if the SyncManager should be running in test mode (no syncer thread | 1499 // True if the SyncManager should be running in test mode (no syncer thread |
1521 // actually communicating with the server). | 1500 // actually communicating with the server). |
1522 bool setup_for_test_mode_; | 1501 bool setup_for_test_mode_; |
1523 | 1502 |
1524 syncable::ModelTypeSet enabled_types_; | |
1525 | |
1526 ScopedRunnableMethodFactory<SyncManager::SyncInternal> method_factory_; | 1503 ScopedRunnableMethodFactory<SyncManager::SyncInternal> method_factory_; |
1527 | |
1528 sync_notifier::ServerNotifierThread* server_notifier_thread_; | |
1529 }; | 1504 }; |
1530 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 1505 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
1531 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 1506 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; |
1532 | 1507 |
1533 SyncManager::Observer::~Observer() {} | 1508 SyncManager::Observer::~Observer() {} |
1534 | 1509 |
1535 SyncManager::SyncManager() { | 1510 SyncManager::SyncManager() { |
1536 data_ = new SyncInternal(this); | 1511 data_ = new SyncInternal(this); |
1537 } | 1512 } |
1538 | 1513 |
1539 bool SyncManager::Init(const FilePath& database_location, | 1514 bool SyncManager::Init(const FilePath& database_location, |
1540 const char* sync_server_and_path, | 1515 const char* sync_server_and_path, |
1541 int sync_server_port, | 1516 int sync_server_port, |
1542 bool use_ssl, | 1517 bool use_ssl, |
1543 HttpPostProviderFactory* post_factory, | 1518 HttpPostProviderFactory* post_factory, |
1544 ModelSafeWorkerRegistrar* registrar, | 1519 ModelSafeWorkerRegistrar* registrar, |
1545 const char* user_agent, | 1520 const char* user_agent, |
1546 const SyncCredentials& credentials, | 1521 const SyncCredentials& credentials, |
1547 const notifier::NotifierOptions& notifier_options, | |
1548 const std::string& restored_key_for_bootstrapping, | 1522 const std::string& restored_key_for_bootstrapping, |
1549 bool setup_for_test_mode) { | 1523 bool setup_for_test_mode) { |
1550 DCHECK(post_factory); | 1524 DCHECK(post_factory); |
1551 VLOG(1) << "SyncManager starting Init..."; | 1525 VLOG(1) << "SyncManager starting Init..."; |
1552 string server_string(sync_server_and_path); | 1526 string server_string(sync_server_and_path); |
1553 return data_->Init(database_location, | 1527 return data_->Init(database_location, |
1554 server_string, | 1528 server_string, |
1555 sync_server_port, | 1529 sync_server_port, |
1556 use_ssl, | 1530 use_ssl, |
1557 post_factory, | 1531 post_factory, |
1558 registrar, | 1532 registrar, |
1559 user_agent, | 1533 user_agent, |
1560 credentials, | 1534 credentials, |
1561 notifier_options, | |
1562 restored_key_for_bootstrapping, | 1535 restored_key_for_bootstrapping, |
1563 setup_for_test_mode); | 1536 setup_for_test_mode); |
1564 } | 1537 } |
1565 | 1538 |
1566 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) { | 1539 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) { |
1567 data_->UpdateCredentials(credentials); | 1540 data_->UpdateCredentials(credentials); |
1568 } | 1541 } |
1569 | 1542 |
1570 void SyncManager::UpdateEnabledTypes(const syncable::ModelTypeSet& types) { | 1543 void SyncManager::UpdateEnabledTypes(const syncable::ModelTypeSet& types) { |
1571 data_->UpdateEnabledTypes(types); | 1544 data_->UpdateEnabledTypes(types); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1653 | 1626 |
1654 bool SyncManager::SyncInternal::Init( | 1627 bool SyncManager::SyncInternal::Init( |
1655 const FilePath& database_location, | 1628 const FilePath& database_location, |
1656 const std::string& sync_server_and_path, | 1629 const std::string& sync_server_and_path, |
1657 int port, | 1630 int port, |
1658 bool use_ssl, | 1631 bool use_ssl, |
1659 HttpPostProviderFactory* post_factory, | 1632 HttpPostProviderFactory* post_factory, |
1660 ModelSafeWorkerRegistrar* model_safe_worker_registrar, | 1633 ModelSafeWorkerRegistrar* model_safe_worker_registrar, |
1661 const char* user_agent, | 1634 const char* user_agent, |
1662 const SyncCredentials& credentials, | 1635 const SyncCredentials& credentials, |
1663 const notifier::NotifierOptions& notifier_options, | |
1664 const std::string& restored_key_for_bootstrapping, | 1636 const std::string& restored_key_for_bootstrapping, |
1665 bool setup_for_test_mode) { | 1637 bool setup_for_test_mode) { |
1666 | 1638 |
1667 VLOG(1) << "Starting SyncInternal initialization."; | 1639 VLOG(1) << "Starting SyncInternal initialization."; |
1668 | 1640 |
1669 core_message_loop_ = MessageLoop::current(); | 1641 core_message_loop_ = MessageLoop::current(); |
1670 DCHECK(core_message_loop_); | 1642 DCHECK(core_message_loop_); |
1671 notifier_options_ = notifier_options; | |
1672 registrar_ = model_safe_worker_registrar; | 1643 registrar_ = model_safe_worker_registrar; |
1673 setup_for_test_mode_ = setup_for_test_mode; | 1644 setup_for_test_mode_ = setup_for_test_mode; |
1674 | 1645 |
1675 share_.dir_manager.reset(new DirectoryManager(database_location)); | 1646 share_.dir_manager.reset(new DirectoryManager(database_location)); |
1676 | 1647 |
1677 connection_manager_.reset(new SyncAPIServerConnectionManager( | 1648 connection_manager_.reset(new SyncAPIServerConnectionManager( |
1678 sync_server_and_path, port, use_ssl, user_agent, post_factory)); | 1649 sync_server_and_path, port, use_ssl, user_agent, post_factory)); |
1679 | 1650 |
1680 connection_manager_hookup_.reset( | 1651 connection_manager_hookup_.reset( |
1681 NewEventListenerHookup(connection_manager()->channel(), this, | 1652 NewEventListenerHookup(connection_manager()->channel(), this, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1778 } | 1749 } |
1779 | 1750 |
1780 // Notify that initialization is complete. | 1751 // Notify that initialization is complete. |
1781 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1752 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
1782 OnInitializationComplete()); | 1753 OnInitializationComplete()); |
1783 } | 1754 } |
1784 | 1755 |
1785 void SyncManager::SyncInternal::SendPendingXMPPNotification( | 1756 void SyncManager::SyncInternal::SendPendingXMPPNotification( |
1786 bool new_pending_notification) { | 1757 bool new_pending_notification) { |
1787 DCHECK_EQ(MessageLoop::current(), core_message_loop_); | 1758 DCHECK_EQ(MessageLoop::current(), core_message_loop_); |
1788 DCHECK_NE(notifier_options_.notification_method, | |
1789 notifier::NOTIFICATION_SERVER); | |
1790 notification_pending_ = notification_pending_ || new_pending_notification; | 1759 notification_pending_ = notification_pending_ || new_pending_notification; |
1791 if (!notification_pending_) { | 1760 if (!notification_pending_) { |
1792 VLOG(1) << "Not sending notification: no pending notification"; | 1761 VLOG(1) << "Not sending notification: no pending notification"; |
1793 return; | 1762 return; |
1794 } | 1763 } |
1795 if (!talk_mediator()) { | 1764 allstatus_.IncrementNotificationsSent(); |
akalin
2011/03/11 04:17:14
Restore this check, but instead check sync_notifie
Agrawal
2011/03/11 21:42:20
Done.
| |
1796 VLOG(1) << "Not sending notification: shutting down (talk_mediator_ is " | 1765 // Since this is used only in tests, we assume that the notification |
akalin
2011/03/11 04:17:14
no need for this comment
Agrawal
2011/03/11 21:42:20
Done.
| |
1797 "NULL)"; | 1766 // will always be sent. |
1798 return; | 1767 sync_notifier_->SendNotification(); |
1799 } | 1768 notification_pending_ = false; |
akalin
2011/03/11 04:17:14
I think you can get rid of notification_pending_ e
Agrawal
2011/03/11 21:42:20
Done.
| |
1800 VLOG(1) << "Sending XMPP notification..."; | |
1801 OutgoingNotificationData notification_data; | |
1802 notification_data.service_id = browser_sync::kSyncServiceId; | |
1803 notification_data.service_url = browser_sync::kSyncServiceUrl; | |
1804 notification_data.send_content = true; | |
1805 notification_data.priority = browser_sync::kSyncPriority; | |
1806 notification_data.write_to_cache_only = true; | |
1807 notification_data.service_specific_data = | |
1808 browser_sync::kSyncServiceSpecificData; | |
1809 notification_data.require_subscription = true; | |
1810 bool success = talk_mediator()->SendNotification(notification_data); | |
1811 if (success) { | |
1812 notification_pending_ = false; | |
1813 VLOG(1) << "Sent XMPP notification"; | |
1814 } else { | |
1815 VLOG(1) << "Could not send XMPP notification"; | |
1816 } | |
1817 } | 1769 } |
1818 | 1770 |
1819 bool SyncManager::SyncInternal::OpenDirectory() { | 1771 bool SyncManager::SyncInternal::OpenDirectory() { |
1820 DCHECK(!initialized()) << "Should only happen once"; | 1772 DCHECK(!initialized()) << "Should only happen once"; |
1821 | 1773 |
1822 bool share_opened = dir_manager()->Open(username_for_share()); | 1774 bool share_opened = dir_manager()->Open(username_for_share()); |
1823 DCHECK(share_opened); | 1775 DCHECK(share_opened); |
1824 if (!share_opened) { | 1776 if (!share_opened) { |
1825 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1777 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
1826 OnStopSyncingPermanently()); | 1778 OnStopSyncingPermanently()); |
(...skipping 21 matching lines...) Expand all Loading... | |
1848 | 1800 |
1849 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) { | 1801 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) { |
1850 DCHECK_EQ(MessageLoop::current(), core_message_loop_); | 1802 DCHECK_EQ(MessageLoop::current(), core_message_loop_); |
1851 DCHECK(share_.name.empty()); | 1803 DCHECK(share_.name.empty()); |
1852 share_.name = credentials.email; | 1804 share_.name = credentials.email; |
1853 | 1805 |
1854 VLOG(1) << "Signing in user: " << username_for_share(); | 1806 VLOG(1) << "Signing in user: " << username_for_share(); |
1855 if (!OpenDirectory()) | 1807 if (!OpenDirectory()) |
1856 return false; | 1808 return false; |
1857 | 1809 |
1810 // Initialize the sync notifier. This should be done only after OpenDirectory | |
1811 // is called, as we also need to set the state. | |
1812 SyncNotifierFactory sync_notifier_factory; | |
akalin
2011/03/11 04:17:14
Add a TODO to make sync_notifier_factory be a para
Agrawal
2011/03/11 21:42:20
Done.
| |
1813 sync_notifier_.reset(sync_notifier_factory.CreateSyncNotifier( | |
1814 *CommandLine::ForCurrentProcess())); | |
1815 sync_notifier_->AddObserver(this); | |
1816 | |
1817 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | |
1818 std::string state; | |
1819 if (lookup.good()) | |
akalin
2011/03/11 04:17:14
add braces
Agrawal
2011/03/11 21:42:20
Done.
| |
1820 state = lookup->GetAndClearNotificationState(); | |
1821 else | |
akalin
2011/03/11 04:17:14
here too
Agrawal
2011/03/11 21:42:20
Done.
| |
1822 LOG(ERROR) << "Could not read notification state"; | |
1823 if (VLOG_IS_ON(1)) { | |
1824 std::string encoded_state; | |
1825 base::Base64Encode(state, &encoded_state); | |
1826 VLOG(1) << "Read notification state: " << encoded_state; | |
1827 } | |
1828 sync_notifier_->SetState(state); | |
1829 | |
1858 if (!setup_for_test_mode_) { | 1830 if (!setup_for_test_mode_) { |
1859 UpdateCredentials(credentials); | 1831 UpdateCredentials(credentials); |
1860 } | 1832 } |
1861 return true; | 1833 return true; |
1862 } | 1834 } |
1863 | 1835 |
1864 void SyncManager::SyncInternal::UpdateCredentials( | 1836 void SyncManager::SyncInternal::UpdateCredentials( |
1865 const SyncCredentials& credentials) { | 1837 const SyncCredentials& credentials) { |
1866 DCHECK_EQ(MessageLoop::current(), core_message_loop_); | 1838 DCHECK_EQ(MessageLoop::current(), core_message_loop_); |
1867 DCHECK_EQ(credentials.email, share_.name); | 1839 DCHECK_EQ(credentials.email, share_.name); |
1840 DCHECK(!credentials.email.empty()); | |
1841 DCHECK(!credentials.sync_token.empty()); | |
1868 connection_manager()->set_auth_token(credentials.sync_token); | 1842 connection_manager()->set_auth_token(credentials.sync_token); |
1869 TalkMediatorLogin(credentials.email, credentials.sync_token); | 1843 sync_notifier_->UpdateCredentials( |
1844 credentials.email, credentials.sync_token); | |
1870 CheckServerReachable(); | 1845 CheckServerReachable(); |
1871 } | 1846 } |
1872 | 1847 |
1873 void SyncManager::SyncInternal::UpdateEnabledTypes( | 1848 void SyncManager::SyncInternal::UpdateEnabledTypes( |
1874 const syncable::ModelTypeSet& types) { | 1849 const syncable::ModelTypeSet& types) { |
1875 DCHECK_EQ(MessageLoop::current(), core_message_loop_); | 1850 DCHECK_EQ(MessageLoop::current(), core_message_loop_); |
1876 | 1851 |
1877 enabled_types_ = types; | 1852 sync_notifier_->UpdateEnabledTypes(types); |
1878 if (server_notifier_thread_ != NULL) { | |
1879 server_notifier_thread_->UpdateEnabledTypes(types); | |
1880 } | |
1881 } | |
1882 | |
1883 void SyncManager::SyncInternal::InitializeTalkMediator() { | |
1884 if (notifier_options_.notification_method == | |
1885 notifier::NOTIFICATION_SERVER) { | |
1886 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | |
1887 std::string state; | |
1888 if (lookup.good()) | |
1889 state = lookup->GetAndClearNotificationState(); | |
1890 else | |
1891 LOG(ERROR) << "Could not read notification state"; | |
1892 if (VLOG_IS_ON(1)) { | |
1893 std::string encoded_state; | |
1894 base::Base64Encode(state, &encoded_state); | |
1895 VLOG(1) << "Read notification state: " << encoded_state; | |
1896 } | |
1897 | |
1898 // |talk_mediator_| takes ownership of |sync_notifier_thread_| | |
1899 // but it is. guaranteed that |sync_notifier_thread_| is destroyed only | |
1900 // when |talk_mediator_| is (see the comments in talk_mediator.h). | |
1901 server_notifier_thread_ = new sync_notifier::ServerNotifierThread( | |
1902 notifier_options_, state, this); | |
1903 talk_mediator_.reset( | |
1904 new TalkMediatorImpl(server_notifier_thread_, | |
1905 notifier_options_.invalidate_xmpp_login, | |
1906 notifier_options_.allow_insecure_connection)); | |
1907 | |
1908 // Since we may be initialized more than once, make sure that any | |
1909 // newly created server notifier thread has the latest enabled types. | |
1910 server_notifier_thread_->UpdateEnabledTypes(enabled_types_); | |
1911 } else { | |
1912 notifier::MediatorThread* mediator_thread = | |
1913 new notifier::MediatorThreadImpl(notifier_options_); | |
1914 talk_mediator_.reset( | |
1915 new TalkMediatorImpl(mediator_thread, | |
1916 notifier_options_.invalidate_xmpp_login, | |
1917 notifier_options_.allow_insecure_connection)); | |
1918 talk_mediator_->AddSubscribedServiceUrl(browser_sync::kSyncServiceUrl); | |
1919 server_notifier_thread_ = NULL; | |
1920 } | |
1921 talk_mediator()->SetDelegate(this); | |
1922 } | 1853 } |
1923 | 1854 |
1924 void SyncManager::SyncInternal::RaiseAuthNeededEvent() { | 1855 void SyncManager::SyncInternal::RaiseAuthNeededEvent() { |
1925 FOR_EACH_OBSERVER( | 1856 FOR_EACH_OBSERVER( |
1926 SyncManager::Observer, observers_, | 1857 SyncManager::Observer, observers_, |
1927 OnAuthError(AuthError(AuthError::INVALID_GAIA_CREDENTIALS))); | 1858 OnAuthError(AuthError(AuthError::INVALID_GAIA_CREDENTIALS))); |
1928 } | 1859 } |
1929 | 1860 |
1930 void SyncManager::SyncInternal::SetUsingExplicitPassphrasePrefForMigration() { | 1861 void SyncManager::SyncInternal::SetUsingExplicitPassphrasePrefForMigration() { |
1931 WriteTransaction trans(&share_); | 1862 WriteTransaction trans(&share_); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2129 return data_; | 2060 return data_; |
2130 } | 2061 } |
2131 | 2062 |
2132 void SyncManager::Shutdown() { | 2063 void SyncManager::Shutdown() { |
2133 data_->Shutdown(); | 2064 data_->Shutdown(); |
2134 } | 2065 } |
2135 | 2066 |
2136 void SyncManager::SyncInternal::Shutdown() { | 2067 void SyncManager::SyncInternal::Shutdown() { |
2137 method_factory_.RevokeAll(); | 2068 method_factory_.RevokeAll(); |
2138 | 2069 |
2139 // We NULL out talk_mediator_ so that any tasks pumped below do not | |
2140 // trigger further XMPP actions. | |
2141 // | |
2142 // TODO(akalin): NULL the other member variables defensively, too. | |
2143 scoped_ptr<TalkMediator> talk_mediator(talk_mediator_.release()); | |
2144 | |
2145 if (syncer_thread()) { | 2070 if (syncer_thread()) { |
2146 if (!syncer_thread()->Stop(kThreadExitTimeoutMsec)) { | 2071 if (!syncer_thread()->Stop(kThreadExitTimeoutMsec)) { |
2147 LOG(FATAL) << "Unable to stop the syncer, it won't be happy..."; | 2072 LOG(FATAL) << "Unable to stop the syncer, it won't be happy..."; |
2148 } | 2073 } |
2149 syncer_thread_.reset(); | 2074 syncer_thread_.reset(); |
2150 } | 2075 } |
2151 | 2076 |
2152 // Shutdown the xmpp buzz connection. | 2077 // Notify the notifier of shutdown. |
2153 if (talk_mediator.get()) { | 2078 if (sync_notifier_.get()) { |
2154 VLOG(1) << "P2P: Mediator logout started."; | 2079 sync_notifier_->RemoveObserver(this); |
2155 talk_mediator->Logout(); | 2080 sync_notifier_.reset(); |
2156 VLOG(1) << "P2P: Mediator logout completed."; | |
2157 talk_mediator.reset(); | |
2158 | |
2159 // |server_notifier_thread_| is owned by |talk_mediator|. We NULL | |
2160 // it out here so as to not have a dangling pointer. | |
2161 server_notifier_thread_= NULL; | |
2162 VLOG(1) << "P2P: Mediator destroyed."; | |
2163 } | 2081 } |
2164 | 2082 |
2165 // Pump any messages the auth watcher, syncer thread, or talk | 2083 // Pump any messages the auth watcher, syncer thread, or talk |
2166 // mediator posted before they shut down. (See OnSyncEngineEvent(), | 2084 // mediator posted before they shut down. (See OnSyncEngineEvent(), |
2167 // and HandleTalkMediatorEvent() for the | 2085 // and HandleTalkMediatorEvent() for the |
2168 // events that may be posted.) | 2086 // events that may be posted.) |
2169 { | 2087 { |
2170 CHECK(core_message_loop_); | 2088 CHECK(core_message_loop_); |
2171 bool old_state = core_message_loop_->NestableTasksAllowed(); | 2089 bool old_state = core_message_loop_->NestableTasksAllowed(); |
2172 core_message_loop_->SetNestableTasksAllowed(true); | 2090 core_message_loop_->SetNestableTasksAllowed(true); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2480 } | 2398 } |
2481 | 2399 |
2482 if (!initialized()) | 2400 if (!initialized()) |
2483 return; | 2401 return; |
2484 | 2402 |
2485 if (!event.snapshot->has_more_to_sync) { | 2403 if (!event.snapshot->has_more_to_sync) { |
2486 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2404 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
2487 OnSyncCycleCompleted(event.snapshot)); | 2405 OnSyncCycleCompleted(event.snapshot)); |
2488 } | 2406 } |
2489 | 2407 |
2490 if (notifier_options_.notification_method != | 2408 // This is here for tests, which are still using p2p notifications. |
2491 notifier::NOTIFICATION_SERVER) { | 2409 // SendNotification does not do anything if we are using server based |
2492 // TODO(chron): Consider changing this back to track has_more_to_sync | 2410 // notifications. |
2493 // only notify peers if a successful commit has occurred. | 2411 // TODO(chron): Consider changing this back to track has_more_to_sync |
2494 bool new_pending_notification = | 2412 // only notify peers if a successful commit has occurred. |
2495 (event.snapshot->syncer_status.num_successful_commits > 0); | 2413 bool new_pending_notification = |
2496 core_message_loop_->PostTask( | 2414 (event.snapshot->syncer_status.num_successful_commits > 0); |
2497 FROM_HERE, | 2415 core_message_loop_->PostTask( |
akalin
2011/03/11 04:17:14
this can change to:
bool new_notification ...;
if
Agrawal
2011/03/11 21:42:20
Thanks. Got rid of the argument (new_pending_notif
| |
2498 NewRunnableMethod( | 2416 FROM_HERE, |
2499 this, | 2417 NewRunnableMethod( |
2500 &SyncManager::SyncInternal::SendPendingXMPPNotification, | 2418 this, |
2501 new_pending_notification)); | 2419 &SyncManager::SyncInternal::SendPendingXMPPNotification, |
2502 } | 2420 new_pending_notification)); |
2503 } | 2421 } |
2504 | 2422 |
2505 if (event.what_happened == SyncEngineEvent::SYNCER_THREAD_PAUSED) { | 2423 if (event.what_happened == SyncEngineEvent::SYNCER_THREAD_PAUSED) { |
2506 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2424 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
2507 OnPaused()); | 2425 OnPaused()); |
2508 return; | 2426 return; |
2509 } | 2427 } |
2510 | 2428 |
2511 if (event.what_happened == SyncEngineEvent::SYNCER_THREAD_RESUMED) { | 2429 if (event.what_happened == SyncEngineEvent::SYNCER_THREAD_RESUMED) { |
2512 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 2430 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2639 if (syncer_thread()) { | 2557 if (syncer_thread()) { |
2640 syncer_thread()->SetNotificationsEnabled(notifications_enabled); | 2558 syncer_thread()->SetNotificationsEnabled(notifications_enabled); |
2641 } | 2559 } |
2642 if (parent_router_) { | 2560 if (parent_router_) { |
2643 ListValue args; | 2561 ListValue args; |
2644 args.Append(Value::CreateBooleanValue(notifications_enabled)); | 2562 args.Append(Value::CreateBooleanValue(notifications_enabled)); |
2645 // TODO(akalin): Tidy up grammar in event names. | 2563 // TODO(akalin): Tidy up grammar in event names. |
2646 parent_router_->RouteJsEvent("onSyncNotificationStateChange", | 2564 parent_router_->RouteJsEvent("onSyncNotificationStateChange", |
2647 browser_sync::JsArgList(args), NULL); | 2565 browser_sync::JsArgList(args), NULL); |
2648 } | 2566 } |
2649 if ((notifier_options_.notification_method != | |
2650 notifier::NOTIFICATION_SERVER) && notifications_enabled) { | |
2651 // Nudge the syncer thread when notifications are enabled, in case there is | |
2652 // any data that has not yet been synced. If we are listening to | |
2653 // server-issued notifications, we are already guaranteed to receive a | |
2654 // notification on a successful connection. | |
2655 if (syncer_thread()) { | |
2656 syncer_thread()->NudgeSyncer(0, SyncerThread::kLocal); | |
2657 } | |
2658 | |
2659 // Send a notification as soon as subscriptions are on | |
2660 // (see http://code.google.com/p/chromium/issues/detail?id=38563 ). | |
2661 core_message_loop_->PostTask( | |
2662 FROM_HERE, | |
2663 NewRunnableMethod( | |
2664 this, | |
2665 &SyncManager::SyncInternal::SendPendingXMPPNotification, | |
2666 true)); | |
2667 } | |
2668 } | |
2669 | |
2670 void SyncManager::SyncInternal::TalkMediatorLogin( | |
2671 const std::string& email, const std::string& token) { | |
2672 DCHECK_EQ(MessageLoop::current(), core_message_loop_); | |
2673 DCHECK(!email.empty()); | |
2674 DCHECK(!token.empty()); | |
2675 InitializeTalkMediator(); | |
2676 talk_mediator()->SetAuthToken(email, token, SYNC_SERVICE_NAME); | |
2677 talk_mediator()->Login(); | |
2678 } | 2567 } |
2679 | 2568 |
2680 void SyncManager::SyncInternal::OnIncomingNotification( | 2569 void SyncManager::SyncInternal::OnIncomingNotification( |
2681 const IncomingNotificationData& notification_data) { | 2570 const browser_sync::sessions::TypePayloadMap& type_payloads) { |
2682 browser_sync::sessions::TypePayloadMap model_types_with_payloads; | 2571 if (!type_payloads.empty()) { |
2683 | |
2684 // Check if the service url is a sync URL. An empty service URL is | |
2685 // treated as a legacy sync notification. If we're listening to | |
2686 // server-issued notifications, no need to check the service_url. | |
2687 if (notifier_options_.notification_method == | |
2688 notifier::NOTIFICATION_SERVER) { | |
2689 VLOG(1) << "Sync received server notification from " << | |
2690 notification_data.service_url << ": " << | |
2691 notification_data.service_specific_data; | |
2692 syncable::ModelTypeBitSet model_types; | |
2693 const std::string& model_type_list = notification_data.service_url; | |
2694 const std::string& notification_payload = | |
2695 notification_data.service_specific_data; | |
2696 | |
2697 if (!syncable::ModelTypeBitSetFromString(model_type_list, &model_types)) { | |
2698 LOG(DFATAL) << "Could not extract model types from server data."; | |
2699 model_types.set(); | |
2700 } | |
2701 | |
2702 model_types_with_payloads = | |
2703 browser_sync::sessions::MakeTypePayloadMapFromBitSet(model_types, | |
2704 notification_payload); | |
2705 } else if (notification_data.service_url.empty() || | |
2706 (notification_data.service_url == | |
2707 browser_sync::kSyncLegacyServiceUrl) || | |
2708 (notification_data.service_url == | |
2709 browser_sync::kSyncServiceUrl)) { | |
2710 VLOG(1) << "Sync received P2P notification."; | |
2711 | |
2712 // Catch for sync integration tests (uses p2p). Just set all enabled | |
2713 // datatypes. | |
2714 ModelSafeRoutingInfo routes; | |
2715 registrar_->GetModelSafeRoutingInfo(&routes); | |
2716 model_types_with_payloads = | |
2717 browser_sync::sessions::MakeTypePayloadMapFromRoutingInfo(routes, | |
2718 std::string()); | |
2719 } else { | |
2720 LOG(WARNING) << "Notification fron unexpected source: " | |
2721 << notification_data.service_url; | |
2722 } | |
2723 | |
2724 if (!model_types_with_payloads.empty()) { | |
2725 if (syncer_thread()) { | 2572 if (syncer_thread()) { |
2726 syncer_thread()->NudgeSyncerWithPayloads( | 2573 syncer_thread()->NudgeSyncerWithPayloads( |
2727 kSyncerThreadDelayMsec, | 2574 kSyncerThreadDelayMsec, |
2728 SyncerThread::kNotification, | 2575 SyncerThread::kNotification, |
2729 model_types_with_payloads); | 2576 type_payloads); |
2730 } | 2577 } |
2731 allstatus_.IncrementNotificationsReceived(); | 2578 allstatus_.IncrementNotificationsReceived(); |
2732 } else { | 2579 } else { |
2733 LOG(WARNING) << "Sync received notification without any type information."; | 2580 LOG(WARNING) << "Sync received notification without any type information."; |
2734 } | 2581 } |
2735 | 2582 |
2736 if (parent_router_) { | 2583 if (parent_router_) { |
2737 ListValue args; | 2584 ListValue args; |
2738 ListValue* changed_types = new ListValue(); | 2585 ListValue* changed_types = new ListValue(); |
2739 args.Append(changed_types); | 2586 args.Append(changed_types); |
2740 for (browser_sync::sessions::TypePayloadMap::const_iterator | 2587 for (browser_sync::sessions::TypePayloadMap::const_iterator |
2741 it = model_types_with_payloads.begin(); | 2588 it = type_payloads.begin(); |
2742 it != model_types_with_payloads.end(); ++it) { | 2589 it != type_payloads.end(); ++it) { |
2743 const std::string& model_type_str = | 2590 const std::string& model_type_str = |
2744 syncable::ModelTypeToString(it->first); | 2591 syncable::ModelTypeToString(it->first); |
2745 changed_types->Append(Value::CreateStringValue(model_type_str)); | 2592 changed_types->Append(Value::CreateStringValue(model_type_str)); |
2746 } | 2593 } |
2747 parent_router_->RouteJsEvent("onSyncIncomingNotification", | 2594 parent_router_->RouteJsEvent("onSyncIncomingNotification", |
2748 browser_sync::JsArgList(args), NULL); | 2595 browser_sync::JsArgList(args), NULL); |
2749 } | 2596 } |
2750 } | 2597 } |
2751 | 2598 |
2752 void SyncManager::SyncInternal::OnOutgoingNotification() { | 2599 void SyncManager::SyncInternal::StoreState( |
2753 DCHECK_NE(notifier_options_.notification_method, | 2600 const std::string& state) { |
2754 notifier::NOTIFICATION_SERVER); | |
2755 allstatus_.IncrementNotificationsSent(); | |
2756 } | |
2757 | |
2758 void SyncManager::SyncInternal::WriteState(const std::string& state) { | |
2759 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | 2601 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); |
2760 if (!lookup.good()) { | 2602 if (!lookup.good()) { |
2761 LOG(ERROR) << "Could not write notification state"; | 2603 LOG(ERROR) << "Could not write notification state"; |
2762 // TODO(akalin): Propagate result callback all the way to this | 2604 // TODO(akalin): Propagate result callback all the way to this |
2763 // function and call it with "false" to signal failure. | 2605 // function and call it with "false" to signal failure. |
2764 return; | 2606 return; |
2765 } | 2607 } |
2766 if (VLOG_IS_ON(1)) { | 2608 if (VLOG_IS_ON(1)) { |
2767 std::string encoded_state; | 2609 std::string encoded_state; |
2768 base::Base64Encode(state, &encoded_state); | 2610 base::Base64Encode(state, &encoded_state); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2830 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2672 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
2831 } | 2673 } |
2832 | 2674 |
2833 void SyncManager::TriggerOnNotificationStateChangeForTest( | 2675 void SyncManager::TriggerOnNotificationStateChangeForTest( |
2834 bool notifications_enabled) { | 2676 bool notifications_enabled) { |
2835 data_->OnNotificationStateChange(notifications_enabled); | 2677 data_->OnNotificationStateChange(notifications_enabled); |
2836 } | 2678 } |
2837 | 2679 |
2838 void SyncManager::TriggerOnIncomingNotificationForTest( | 2680 void SyncManager::TriggerOnIncomingNotificationForTest( |
2839 const syncable::ModelTypeBitSet& model_types) { | 2681 const syncable::ModelTypeBitSet& model_types) { |
2840 IncomingNotificationData notification_data; | 2682 browser_sync::sessions::TypePayloadMap model_types_with_payloads; |
2841 notification_data.service_url = model_types.to_string(); | 2683 |
2684 model_types_with_payloads = | |
2685 browser_sync::sessions::MakeTypePayloadMapFromBitSet(model_types, | |
2686 std::string()); | |
2687 | |
2842 // Here we rely on the default notification method being SERVER. | 2688 // Here we rely on the default notification method being SERVER. |
akalin
2011/03/11 04:17:14
Remove this now-obsolete comment
Agrawal
2011/03/11 21:42:20
Done.
| |
2843 data_->OnIncomingNotification(notification_data); | 2689 data_->OnIncomingNotification(model_types_with_payloads); |
2844 } | 2690 } |
2845 | 2691 |
2846 } // namespace sync_api | 2692 } // namespace sync_api |
OLD | NEW |