| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <iomanip> | 9 #include <iomanip> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/sync/sync_constants.h" | 26 #include "chrome/browser/sync/sync_constants.h" |
| 27 #include "chrome/browser/sync/engine/all_status.h" | 27 #include "chrome/browser/sync/engine/all_status.h" |
| 28 #include "chrome/browser/sync/engine/auth_watcher.h" | 28 #include "chrome/browser/sync/engine/auth_watcher.h" |
| 29 #include "chrome/browser/sync/engine/change_reorder_buffer.h" | 29 #include "chrome/browser/sync/engine/change_reorder_buffer.h" |
| 30 #include "chrome/browser/sync/engine/model_safe_worker.h" | 30 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 31 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 31 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 32 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" | 32 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" |
| 33 #include "chrome/browser/sync/engine/syncer.h" | 33 #include "chrome/browser/sync/engine/syncer.h" |
| 34 #include "chrome/browser/sync/engine/syncer_thread.h" | 34 #include "chrome/browser/sync/engine/syncer_thread.h" |
| 35 #include "chrome/browser/sync/notifier/server_notifier_thread.h" |
| 35 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 36 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
| 36 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 37 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 37 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 38 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
| 38 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 39 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
| 39 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 40 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 40 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 41 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
| 41 #include "chrome/browser/sync/protocol/service_constants.h" | 42 #include "chrome/browser/sync/protocol/service_constants.h" |
| 42 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 43 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
| 43 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 44 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
| 44 #include "chrome/browser/sync/sessions/sync_session_context.h" | 45 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| (...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 allstatus_.WatchConnectionManager(connection_manager()); | 1279 allstatus_.WatchConnectionManager(connection_manager()); |
| 1279 | 1280 |
| 1280 network_change_notifier_.reset( | 1281 network_change_notifier_.reset( |
| 1281 new chrome_common_net::NetworkChangeNotifierProxy( | 1282 new chrome_common_net::NetworkChangeNotifierProxy( |
| 1282 network_change_notifier_thread)); | 1283 network_change_notifier_thread)); |
| 1283 network_change_notifier_->AddObserver(this); | 1284 network_change_notifier_->AddObserver(this); |
| 1284 // TODO(akalin): CheckServerReachable() can block, which may cause | 1285 // TODO(akalin): CheckServerReachable() can block, which may cause |
| 1285 // jank if we try to shut down sync. Fix this. | 1286 // jank if we try to shut down sync. Fix this. |
| 1286 connection_manager()->CheckServerReachable(); | 1287 connection_manager()->CheckServerReachable(); |
| 1287 | 1288 |
| 1289 // NOTIFICATION_SERVER uses a substantially different notification |
| 1290 // method, so it has its own MediatorThread implementation. |
| 1291 // Everything else just uses MediatorThreadImpl. |
| 1292 notifier::MediatorThread* mediator_thread = |
| 1293 (notification_method == browser_sync::NOTIFICATION_SERVER) ? |
| 1294 static_cast<notifier::MediatorThread*>( |
| 1295 new sync_notifier::ServerNotifierThread( |
| 1296 network_change_notifier_thread)) : |
| 1297 static_cast<notifier::MediatorThread*>( |
| 1298 new notifier::MediatorThreadImpl(network_change_notifier_thread)); |
| 1288 const bool kInitializeSsl = true; | 1299 const bool kInitializeSsl = true; |
| 1289 const bool kConnectImmediately = false; | 1300 const bool kConnectImmediately = false; |
| 1290 talk_mediator_.reset(new TalkMediatorImpl( | 1301 talk_mediator_.reset(new TalkMediatorImpl( |
| 1291 new notifier::MediatorThreadImpl(network_change_notifier_thread), | 1302 mediator_thread, |
| 1292 kInitializeSsl, kConnectImmediately, invalidate_xmpp_auth_token)); | 1303 kInitializeSsl, kConnectImmediately, invalidate_xmpp_auth_token)); |
| 1293 if (notification_method != browser_sync::NOTIFICATION_LEGACY) { | 1304 if (notification_method != browser_sync::NOTIFICATION_LEGACY && |
| 1305 notification_method != browser_sync::NOTIFICATION_SERVER) { |
| 1294 if (notification_method == browser_sync::NOTIFICATION_TRANSITIONAL) { | 1306 if (notification_method == browser_sync::NOTIFICATION_TRANSITIONAL) { |
| 1295 talk_mediator_->AddSubscribedServiceUrl( | 1307 talk_mediator_->AddSubscribedServiceUrl( |
| 1296 browser_sync::kSyncLegacyServiceUrl); | 1308 browser_sync::kSyncLegacyServiceUrl); |
| 1297 } | 1309 } |
| 1298 talk_mediator_->AddSubscribedServiceUrl(browser_sync::kSyncServiceUrl); | 1310 talk_mediator_->AddSubscribedServiceUrl(browser_sync::kSyncServiceUrl); |
| 1299 } | 1311 } |
| 1300 | 1312 |
| 1301 // Listen to TalkMediator events ourselves | 1313 // Listen to TalkMediator events ourselves |
| 1302 talk_mediator_->SetDelegate(this); | 1314 talk_mediator_->SetDelegate(this); |
| 1303 | 1315 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 } | 1384 } |
| 1373 | 1385 |
| 1374 // Notify that initialization is complete. | 1386 // Notify that initialization is complete. |
| 1375 if (observer_) | 1387 if (observer_) |
| 1376 observer_->OnInitializationComplete(); | 1388 observer_->OnInitializationComplete(); |
| 1377 } | 1389 } |
| 1378 | 1390 |
| 1379 void SyncManager::SyncInternal::SendPendingXMPPNotification( | 1391 void SyncManager::SyncInternal::SendPendingXMPPNotification( |
| 1380 bool new_pending_notification) { | 1392 bool new_pending_notification) { |
| 1381 DCHECK_EQ(MessageLoop::current(), core_message_loop_); | 1393 DCHECK_EQ(MessageLoop::current(), core_message_loop_); |
| 1394 DCHECK_NE(notification_method_, browser_sync::NOTIFICATION_SERVER); |
| 1382 notification_pending_ = notification_pending_ || new_pending_notification; | 1395 notification_pending_ = notification_pending_ || new_pending_notification; |
| 1383 if (!notification_pending_) { | 1396 if (!notification_pending_) { |
| 1384 LOG(INFO) << "Not sending notification: no pending notification"; | 1397 LOG(INFO) << "Not sending notification: no pending notification"; |
| 1385 return; | 1398 return; |
| 1386 } | 1399 } |
| 1387 if (!talk_mediator_.get()) { | 1400 if (!talk_mediator_.get()) { |
| 1388 LOG(INFO) << "Not sending notification: shutting down " | 1401 LOG(INFO) << "Not sending notification: shutting down " |
| 1389 << "(talk_mediator_ is NULL)"; | 1402 << "(talk_mediator_ is NULL)"; |
| 1390 return; | 1403 return; |
| 1391 } | 1404 } |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1765 // locally we are "all happy" and up-to-date. There may be new changes on | 1778 // locally we are "all happy" and up-to-date. There may be new changes on |
| 1766 // the server, but we'll get them on a subsequent sync. | 1779 // the server, but we'll get them on a subsequent sync. |
| 1767 // | 1780 // |
| 1768 // Notifications are sent at the end of every sync cycle, regardless of | 1781 // Notifications are sent at the end of every sync cycle, regardless of |
| 1769 // whether we should sync again. | 1782 // whether we should sync again. |
| 1770 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED) { | 1783 if (event.what_happened == SyncerEvent::SYNC_CYCLE_ENDED) { |
| 1771 if (!event.snapshot->has_more_to_sync) { | 1784 if (!event.snapshot->has_more_to_sync) { |
| 1772 observer_->OnSyncCycleCompleted(event.snapshot); | 1785 observer_->OnSyncCycleCompleted(event.snapshot); |
| 1773 } | 1786 } |
| 1774 | 1787 |
| 1775 // TODO(chron): Consider changing this back to track has_more_to_sync | 1788 if (notification_method_ != browser_sync::NOTIFICATION_SERVER) { |
| 1776 // only notify peers if a successful commit has occurred. | 1789 // TODO(chron): Consider changing this back to track has_more_to_sync |
| 1777 bool new_pending_notification = | 1790 // only notify peers if a successful commit has occurred. |
| 1778 (event.snapshot->syncer_status.num_successful_commits > 0); | 1791 bool new_pending_notification = |
| 1779 core_message_loop_->PostTask( | 1792 (event.snapshot->syncer_status.num_successful_commits > 0); |
| 1780 FROM_HERE, | 1793 core_message_loop_->PostTask( |
| 1781 NewRunnableMethod( | 1794 FROM_HERE, |
| 1782 this, | 1795 NewRunnableMethod( |
| 1783 &SyncManager::SyncInternal::SendPendingXMPPNotification, | 1796 this, |
| 1784 new_pending_notification)); | 1797 &SyncManager::SyncInternal::SendPendingXMPPNotification, |
| 1798 new_pending_notification)); |
| 1799 } |
| 1785 } | 1800 } |
| 1786 | 1801 |
| 1787 if (event.what_happened == SyncerEvent::PAUSED) { | 1802 if (event.what_happened == SyncerEvent::PAUSED) { |
| 1788 observer_->OnPaused(); | 1803 observer_->OnPaused(); |
| 1789 return; | 1804 return; |
| 1790 } | 1805 } |
| 1791 | 1806 |
| 1792 if (event.what_happened == SyncerEvent::RESUMED) { | 1807 if (event.what_happened == SyncerEvent::RESUMED) { |
| 1793 observer_->OnResumed(); | 1808 observer_->OnResumed(); |
| 1794 return; | 1809 return; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1897 } | 1912 } |
| 1898 | 1913 |
| 1899 void SyncManager::SyncInternal::OnNotificationStateChange( | 1914 void SyncManager::SyncInternal::OnNotificationStateChange( |
| 1900 bool notifications_enabled) { | 1915 bool notifications_enabled) { |
| 1901 LOG(INFO) << "P2P: Notifications enabled = " | 1916 LOG(INFO) << "P2P: Notifications enabled = " |
| 1902 << (notifications_enabled ? "true" : "false"); | 1917 << (notifications_enabled ? "true" : "false"); |
| 1903 allstatus_.SetNotificationsEnabled(notifications_enabled); | 1918 allstatus_.SetNotificationsEnabled(notifications_enabled); |
| 1904 if (syncer_thread()) { | 1919 if (syncer_thread()) { |
| 1905 syncer_thread()->SetNotificationsEnabled(notifications_enabled); | 1920 syncer_thread()->SetNotificationsEnabled(notifications_enabled); |
| 1906 } | 1921 } |
| 1907 if (notifications_enabled) { | 1922 if ((notification_method_ != browser_sync::NOTIFICATION_SERVER) && |
| 1923 notifications_enabled) { |
| 1908 // Send a notification as soon as subscriptions are on | 1924 // Send a notification as soon as subscriptions are on |
| 1909 // (see http://code.google.com/p/chromium/issues/detail?id=38563 ). | 1925 // (see http://code.google.com/p/chromium/issues/detail?id=38563 ). |
| 1910 core_message_loop_->PostTask( | 1926 core_message_loop_->PostTask( |
| 1911 FROM_HERE, | 1927 FROM_HERE, |
| 1912 NewRunnableMethod( | 1928 NewRunnableMethod( |
| 1913 this, | 1929 this, |
| 1914 &SyncManager::SyncInternal::SendPendingXMPPNotification, | 1930 &SyncManager::SyncInternal::SendPendingXMPPNotification, |
| 1915 true)); | 1931 true)); |
| 1916 } | 1932 } |
| 1917 } | 1933 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2021 UserShare* SyncManager::GetUserShare() const { | 2037 UserShare* SyncManager::GetUserShare() const { |
| 2022 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2038 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
| 2023 return data_->GetUserShare(); | 2039 return data_->GetUserShare(); |
| 2024 } | 2040 } |
| 2025 | 2041 |
| 2026 SyncManager::ExtraAutofillChangeRecordData::~ExtraAutofillChangeRecordData() { | 2042 SyncManager::ExtraAutofillChangeRecordData::~ExtraAutofillChangeRecordData() { |
| 2027 delete pre_deletion_data; | 2043 delete pre_deletion_data; |
| 2028 } | 2044 } |
| 2029 | 2045 |
| 2030 } // namespace sync_api | 2046 } // namespace sync_api |
| OLD | NEW |