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

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

Issue 6874018: make new syncer thread the default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Upload before submit. Created 9 years, 8 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>
11 #include <queue> 11 #include <queue>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/base64.h" 15 #include "base/base64.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/message_loop.h" 19 #include "base/message_loop.h"
20 #include "base/observer_list.h" 20 #include "base/observer_list.h"
21 #include "base/sha1.h" 21 #include "base/sha1.h"
22 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
23 #include "base/string_util.h" 23 #include "base/string_util.h"
24 #include "base/synchronization/lock.h" 24 #include "base/synchronization/lock.h"
25 #include "base/task.h" 25 #include "base/task.h"
26 #include "base/time.h"
26 #include "base/utf_string_conversions.h" 27 #include "base/utf_string_conversions.h"
27 #include "base/values.h" 28 #include "base/values.h"
28 #include "chrome/browser/sync/engine/all_status.h" 29 #include "chrome/browser/sync/engine/all_status.h"
29 #include "chrome/browser/sync/engine/change_reorder_buffer.h" 30 #include "chrome/browser/sync/engine/change_reorder_buffer.h"
30 #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/nudge_source.h"
31 #include "chrome/browser/sync/engine/net/server_connection_manager.h" 33 #include "chrome/browser/sync/engine/net/server_connection_manager.h"
32 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" 34 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h"
33 #include "chrome/browser/sync/engine/syncer.h" 35 #include "chrome/browser/sync/engine/syncer.h"
34 #include "chrome/browser/sync/engine/syncer_thread.h" 36 #include "chrome/browser/sync/engine/syncer_thread.h"
35 #include "chrome/browser/sync/engine/syncer_thread2.h"
36 #include "chrome/browser/sync/engine/syncer_thread_adapter.h"
37 #include "chrome/browser/sync/engine/http_post_provider_factory.h" 37 #include "chrome/browser/sync/engine/http_post_provider_factory.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/sync_notifier.h" 41 #include "chrome/browser/sync/notifier/sync_notifier.h"
42 #include "chrome/browser/sync/notifier/sync_notifier_observer.h" 42 #include "chrome/browser/sync/notifier/sync_notifier_observer.h"
43 #include "chrome/browser/sync/protocol/app_specifics.pb.h" 43 #include "chrome/browser/sync/protocol/app_specifics.pb.h"
44 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" 44 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
45 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" 45 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
46 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" 46 #include "chrome/browser/sync/protocol/extension_specifics.pb.h"
47 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" 47 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h"
48 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" 48 #include "chrome/browser/sync/protocol/preference_specifics.pb.h"
49 #include "chrome/browser/sync/protocol/proto_value_conversions.h" 49 #include "chrome/browser/sync/protocol/proto_value_conversions.h"
50 #include "chrome/browser/sync/protocol/service_constants.h" 50 #include "chrome/browser/sync/protocol/service_constants.h"
51 #include "chrome/browser/sync/protocol/session_specifics.pb.h" 51 #include "chrome/browser/sync/protocol/session_specifics.pb.h"
52 #include "chrome/browser/sync/protocol/sync.pb.h" 52 #include "chrome/browser/sync/protocol/sync.pb.h"
53 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" 53 #include "chrome/browser/sync/protocol/theme_specifics.pb.h"
54 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" 54 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h"
55 #include "chrome/browser/sync/sessions/sync_session.h" 55 #include "chrome/browser/sync/sessions/sync_session.h"
56 #include "chrome/browser/sync/sessions/sync_session_context.h" 56 #include "chrome/browser/sync/sessions/sync_session_context.h"
57 #include "chrome/browser/sync/syncable/autofill_migration.h" 57 #include "chrome/browser/sync/syncable/autofill_migration.h"
58 #include "chrome/browser/sync/syncable/directory_manager.h" 58 #include "chrome/browser/sync/syncable/directory_manager.h"
59 #include "chrome/browser/sync/syncable/model_type_payload_map.h" 59 #include "chrome/browser/sync/syncable/model_type_payload_map.h"
60 #include "chrome/browser/sync/syncable/model_type.h"
60 #include "chrome/browser/sync/syncable/nigori_util.h" 61 #include "chrome/browser/sync/syncable/nigori_util.h"
61 #include "chrome/browser/sync/syncable/syncable.h" 62 #include "chrome/browser/sync/syncable/syncable.h"
62 #include "chrome/browser/sync/util/crypto_helpers.h" 63 #include "chrome/browser/sync/util/crypto_helpers.h"
63 #include "chrome/common/chrome_switches.h" 64 #include "chrome/common/chrome_switches.h"
64 #include "chrome/common/deprecated/event_sys.h" 65 #include "chrome/common/deprecated/event_sys.h"
65 #include "chrome/common/net/gaia/gaia_authenticator.h" 66 #include "chrome/common/net/gaia/gaia_authenticator.h"
66 #include "content/browser/browser_thread.h" 67 #include "content/browser/browser_thread.h"
67 #include "net/base/network_change_notifier.h" 68 #include "net/base/network_change_notifier.h"
68 69
70 using base::TimeDelta;
69 using browser_sync::AllStatus; 71 using browser_sync::AllStatus;
70 using browser_sync::Cryptographer; 72 using browser_sync::Cryptographer;
71 using browser_sync::KeyParams; 73 using browser_sync::KeyParams;
72 using browser_sync::ModelSafeRoutingInfo; 74 using browser_sync::ModelSafeRoutingInfo;
73 using browser_sync::ModelSafeWorker; 75 using browser_sync::ModelSafeWorker;
74 using browser_sync::ModelSafeWorkerRegistrar; 76 using browser_sync::ModelSafeWorkerRegistrar;
75 using browser_sync::ServerConnectionEvent; 77 using browser_sync::ServerConnectionEvent;
76 using browser_sync::ServerConnectionEvent2; 78 using browser_sync::ServerConnectionEvent2;
77 using browser_sync::ServerConnectionEventListener; 79 using browser_sync::ServerConnectionEventListener;
78 using browser_sync::SyncEngineEvent; 80 using browser_sync::SyncEngineEvent;
79 using browser_sync::SyncEngineEventListener; 81 using browser_sync::SyncEngineEventListener;
80 using browser_sync::Syncer; 82 using browser_sync::Syncer;
81 using browser_sync::SyncerThread; 83 using browser_sync::SyncerThread;
82 using browser_sync::SyncerThreadAdapter;
83 using browser_sync::kNigoriTag; 84 using browser_sync::kNigoriTag;
84 using browser_sync::sessions::SyncSessionContext; 85 using browser_sync::sessions::SyncSessionContext;
85 using std::list; 86 using std::list;
86 using std::hex; 87 using std::hex;
87 using std::string; 88 using std::string;
88 using std::vector; 89 using std::vector;
89 using syncable::Directory; 90 using syncable::Directory;
90 using syncable::DirectoryManager; 91 using syncable::DirectoryManager;
91 using syncable::Entry; 92 using syncable::Entry;
93 using syncable::ModelTypeBitSet;
92 using syncable::SPECIFICS; 94 using syncable::SPECIFICS;
93 using sync_pb::AutofillProfileSpecifics; 95 using sync_pb::AutofillProfileSpecifics;
94 96
95 typedef GoogleServiceAuthError AuthError; 97 typedef GoogleServiceAuthError AuthError;
96 98
97 static const int kThreadExitTimeoutMsec = 60000; 99 static const int kThreadExitTimeoutMsec = 60000;
98 static const int kSSLPort = 443; 100 static const int kSSLPort = 443;
99 static const int kSyncerThreadDelayMsec = 250; 101 static const int kSyncerThreadDelayMsec = 250;
100 102
101 #if defined(OS_CHROMEOS) 103 #if defined(OS_CHROMEOS)
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 1264
1263 void AddObserver(SyncManager::Observer* observer); 1265 void AddObserver(SyncManager::Observer* observer);
1264 1266
1265 void RemoveObserver(SyncManager::Observer* observer); 1267 void RemoveObserver(SyncManager::Observer* observer);
1266 1268
1267 // Accessors for the private members. 1269 // Accessors for the private members.
1268 DirectoryManager* dir_manager() { return share_.dir_manager.get(); } 1270 DirectoryManager* dir_manager() { return share_.dir_manager.get(); }
1269 SyncAPIServerConnectionManager* connection_manager() { 1271 SyncAPIServerConnectionManager* connection_manager() {
1270 return connection_manager_.get(); 1272 return connection_manager_.get();
1271 } 1273 }
1272 SyncerThreadAdapter* syncer_thread() { return syncer_thread_.get(); } 1274 SyncerThread* syncer_thread() { return syncer_thread_.get(); }
1273 UserShare* GetUserShare() { return &share_; } 1275 UserShare* GetUserShare() { return &share_; }
1274 1276
1275 // Return the currently active (validated) username for use with syncable 1277 // Return the currently active (validated) username for use with syncable
1276 // types. 1278 // types.
1277 const std::string& username_for_share() const { 1279 const std::string& username_for_share() const {
1278 return share_.name; 1280 return share_.name;
1279 } 1281 }
1280 1282
1281 Status GetStatus(); 1283 Status GetStatus();
1282 1284
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 1511
1510 ObserverList<SyncManager::Observer> observers_; 1512 ObserverList<SyncManager::Observer> observers_;
1511 1513
1512 browser_sync::JsEventRouter* parent_router_; 1514 browser_sync::JsEventRouter* parent_router_;
1513 1515
1514 // The ServerConnectionManager used to abstract communication between the 1516 // The ServerConnectionManager used to abstract communication between the
1515 // client (the Syncer) and the sync server. 1517 // client (the Syncer) and the sync server.
1516 scoped_ptr<SyncAPIServerConnectionManager> connection_manager_; 1518 scoped_ptr<SyncAPIServerConnectionManager> connection_manager_;
1517 1519
1518 // The thread that runs the Syncer. Needs to be explicitly Start()ed. 1520 // The thread that runs the Syncer. Needs to be explicitly Start()ed.
1519 scoped_ptr<SyncerThreadAdapter> syncer_thread_; 1521 scoped_ptr<SyncerThread> syncer_thread_;
1520 1522
1521 // The SyncNotifier which notifies us when updates need to be downloaded. 1523 // The SyncNotifier which notifies us when updates need to be downloaded.
1522 sync_notifier::SyncNotifier* sync_notifier_; 1524 sync_notifier::SyncNotifier* sync_notifier_;
1523 1525
1524 // A multi-purpose status watch object that aggregates stats from various 1526 // A multi-purpose status watch object that aggregates stats from various
1525 // sync components. 1527 // sync components.
1526 AllStatus allstatus_; 1528 AllStatus allstatus_;
1527 1529
1528 // Each element of this array is a store of change records produced by 1530 // Each element of this array is a store of change records produced by
1529 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are 1531 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 1659
1658 void SyncManager::EncryptDataTypes( 1660 void SyncManager::EncryptDataTypes(
1659 const syncable::ModelTypeSet& encrypted_types) { 1661 const syncable::ModelTypeSet& encrypted_types) {
1660 data_->EncryptDataTypes(encrypted_types); 1662 data_->EncryptDataTypes(encrypted_types);
1661 } 1663 }
1662 1664
1663 bool SyncManager::IsUsingExplicitPassphrase() { 1665 bool SyncManager::IsUsingExplicitPassphrase() {
1664 return data_ && data_->IsUsingExplicitPassphrase(); 1666 return data_ && data_->IsUsingExplicitPassphrase();
1665 } 1667 }
1666 1668
1667 bool SyncManager::RequestPause() {
1668 if (data_->syncer_thread())
1669 return data_->syncer_thread()->RequestPause();
1670 return false;
1671 }
1672
1673 bool SyncManager::RequestResume() {
1674 if (data_->syncer_thread())
1675 return data_->syncer_thread()->RequestResume();
1676 return false;
1677 }
1678
1679 void SyncManager::RequestNudge(const tracked_objects::Location& location) { 1669 void SyncManager::RequestNudge(const tracked_objects::Location& location) {
1680 if (data_->syncer_thread()) 1670 if (data_->syncer_thread())
1681 data_->syncer_thread()->NudgeSyncer(0, SyncerThread::kLocal, location); 1671 data_->syncer_thread()->ScheduleNudge(
1672 TimeDelta::FromMilliseconds(0), browser_sync::NUDGE_SOURCE_LOCAL,
1673 ModelTypeBitSet(), location);
1682 } 1674 }
1683 1675
1684 void SyncManager::RequestClearServerData() { 1676 void SyncManager::RequestClearServerData() {
1685 if (data_->syncer_thread()) 1677 if (data_->syncer_thread())
1686 data_->syncer_thread()->NudgeSyncer(0, SyncerThread::kClearPrivateData, 1678 data_->syncer_thread()->ScheduleClearUserData();
1687 FROM_HERE);
1688 } 1679 }
1689 1680
1690 void SyncManager::RequestConfig(const syncable::ModelTypeBitSet& types) { 1681 void SyncManager::RequestConfig(const syncable::ModelTypeBitSet& types) {
1691 if (!data_->syncer_thread()) 1682 if (!data_->syncer_thread())
1692 return; 1683 return;
1693 // It is an error for this to be called if new_impl is null.
1694 StartConfigurationMode(NULL); 1684 StartConfigurationMode(NULL);
1695 data_->syncer_thread()->new_impl()->ScheduleConfig(types); 1685 data_->syncer_thread()->ScheduleConfig(types);
1696 } 1686 }
1697 1687
1698 void SyncManager::StartConfigurationMode(ModeChangeCallback* callback) { 1688 void SyncManager::StartConfigurationMode(ModeChangeCallback* callback) {
1699 if (!data_->syncer_thread()) 1689 if (!data_->syncer_thread())
1700 return; 1690 return;
1701 if (!data_->syncer_thread()->new_impl()) 1691 data_->syncer_thread()->Start(
1702 return; 1692 browser_sync::SyncerThread::CONFIGURATION_MODE, callback);
1703 data_->syncer_thread()->new_impl()->Start(
1704 browser_sync::s3::SyncerThread::CONFIGURATION_MODE, callback);
1705 } 1693 }
1706 1694
1707 const std::string& SyncManager::GetAuthenticatedUsername() { 1695 const std::string& SyncManager::GetAuthenticatedUsername() {
1708 DCHECK(data_); 1696 DCHECK(data_);
1709 return data_->username_for_share(); 1697 return data_->username_for_share();
1710 } 1698 }
1711 1699
1712 bool SyncManager::SyncInternal::Init( 1700 bool SyncManager::SyncInternal::Init(
1713 const FilePath& database_location, 1701 const FilePath& database_location,
1714 const std::string& sync_server_and_path, 1702 const std::string& sync_server_and_path,
(...skipping 17 matching lines...) Expand all
1732 sync_notifier_ = sync_notifier; 1720 sync_notifier_ = sync_notifier;
1733 sync_notifier_->AddObserver(this); 1721 sync_notifier_->AddObserver(this);
1734 1722
1735 share_.dir_manager.reset(new DirectoryManager(database_location)); 1723 share_.dir_manager.reset(new DirectoryManager(database_location));
1736 1724
1737 connection_manager_.reset(new SyncAPIServerConnectionManager( 1725 connection_manager_.reset(new SyncAPIServerConnectionManager(
1738 sync_server_and_path, port, use_ssl, user_agent, post_factory)); 1726 sync_server_and_path, port, use_ssl, user_agent, post_factory));
1739 1727
1740 net::NetworkChangeNotifier::AddIPAddressObserver(this); 1728 net::NetworkChangeNotifier::AddIPAddressObserver(this);
1741 1729
1742 bool new_syncer_thread = CommandLine::ForCurrentProcess()->HasSwitch( 1730 connection_manager()->AddListener(this);
1743 switches::kNewSyncerThread);
1744
1745 if (new_syncer_thread) {
1746 connection_manager()->AddListener(this);
1747 } else {
1748 connection_manager_hookup_.reset(
1749 NewEventListenerHookup(connection_manager()->channel(), this,
1750 &SyncManager::SyncInternal::HandleServerConnectionEvent));
1751 }
1752 1731
1753 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we 1732 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we
1754 // try to shut down sync. Fix this. 1733 // try to shut down sync. Fix this.
1755 core_message_loop_->PostTask(FROM_HERE, 1734 core_message_loop_->PostTask(FROM_HERE,
1756 method_factory_.NewRunnableMethod(&SyncInternal::CheckServerReachable)); 1735 method_factory_.NewRunnableMethod(&SyncInternal::CheckServerReachable));
1757 1736
1758 // Test mode does not use a syncer context or syncer thread. 1737 // Test mode does not use a syncer context or syncer thread.
1759 if (!setup_for_test_mode_) { 1738 if (!setup_for_test_mode_) {
1760 // Build a SyncSessionContext and store the worker in it. 1739 // Build a SyncSessionContext and store the worker in it.
1761 VLOG(1) << "Sync is bringing up SyncSessionContext."; 1740 VLOG(1) << "Sync is bringing up SyncSessionContext.";
1762 std::vector<SyncEngineEventListener*> listeners; 1741 std::vector<SyncEngineEventListener*> listeners;
1763 listeners.push_back(&allstatus_); 1742 listeners.push_back(&allstatus_);
1764 listeners.push_back(this); 1743 listeners.push_back(this);
1765 SyncSessionContext* context = new SyncSessionContext( 1744 SyncSessionContext* context = new SyncSessionContext(
1766 connection_manager_.get(), 1745 connection_manager_.get(),
1767 dir_manager(), 1746 dir_manager(),
1768 model_safe_worker_registrar, 1747 model_safe_worker_registrar,
1769 listeners); 1748 listeners);
1770 context->set_account_name(credentials.email); 1749 context->set_account_name(credentials.email);
1771 // The SyncerThread takes ownership of |context|. 1750 // The SyncerThread takes ownership of |context|.
1772 syncer_thread_.reset(new SyncerThreadAdapter(context, 1751 syncer_thread_.reset(new SyncerThread(context, new Syncer()));
1773 new_syncer_thread));
1774 } 1752 }
1775 1753
1776 bool signed_in = SignIn(credentials); 1754 bool signed_in = SignIn(credentials);
1777 1755
1778 // Do this once the directory is opened. 1756 // Do this once the directory is opened.
1779 BootstrapEncryption(restored_key_for_bootstrapping); 1757 BootstrapEncryption(restored_key_for_bootstrapping);
1780 return signed_in; 1758 return signed_in;
1781 } 1759 }
1782 1760
1783 void SyncManager::SyncInternal::BootstrapEncryption( 1761 void SyncManager::SyncInternal::BootstrapEncryption(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 1796
1819 // Refresh list of encrypted datatypes. 1797 // Refresh list of encrypted datatypes.
1820 syncable::ModelTypeSet encrypted_types = 1798 syncable::ModelTypeSet encrypted_types =
1821 syncable::GetEncryptedDataTypesFromNigori(nigori); 1799 syncable::GetEncryptedDataTypesFromNigori(nigori);
1822 1800
1823 // Ensure any datatypes that need encryption are encrypted. 1801 // Ensure any datatypes that need encryption are encrypted.
1824 EncryptDataTypes(encrypted_types); 1802 EncryptDataTypes(encrypted_types);
1825 } 1803 }
1826 1804
1827 void SyncManager::SyncInternal::StartSyncing() { 1805 void SyncManager::SyncInternal::StartSyncing() {
1806 // Start the syncer thread. This won't actually
1807 // result in any syncing until at least the
1808 // DirectoryManager broadcasts the OPENED event,
1809 // and a valid server connection is detected.
1828 if (syncer_thread()) // NULL during certain unittests. 1810 if (syncer_thread()) // NULL during certain unittests.
1829 syncer_thread()->Start(); // Start the syncer thread. This won't actually 1811 syncer_thread()->Start(SyncerThread::NORMAL_MODE, NULL);
1830 // result in any syncing until at least the
1831 // DirectoryManager broadcasts the OPENED event,
1832 // and a valid server connection is detected.
1833 } 1812 }
1834 1813
1835 void SyncManager::SyncInternal::MarkAndNotifyInitializationComplete() { 1814 void SyncManager::SyncInternal::MarkAndNotifyInitializationComplete() {
1836 // There is only one real time we need this mutex. If we get an auth 1815 // There is only one real time we need this mutex. If we get an auth
1837 // success, and before the initial sync ends we get an auth failure. In this 1816 // success, and before the initial sync ends we get an auth failure. In this
1838 // case we'll be listening to both the AuthWatcher and Syncer, and it's a race 1817 // case we'll be listening to both the AuthWatcher and Syncer, and it's a race
1839 // between their respective threads to call MarkAndNotify. We need to make 1818 // between their respective threads to call MarkAndNotify. We need to make
1840 // sure the observer is notified once and only once. 1819 // sure the observer is notified once and only once.
1841 { 1820 {
1842 base::AutoLock lock(initialized_mutex_); 1821 base::AutoLock lock(initialized_mutex_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 1854
1876 // Database has to be initialized for the guid to be available. 1855 // Database has to be initialized for the guid to be available.
1877 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); 1856 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share());
1878 if (!lookup.good()) { 1857 if (!lookup.good()) {
1879 NOTREACHED(); 1858 NOTREACHED();
1880 return false; 1859 return false;
1881 } 1860 }
1882 1861
1883 connection_manager()->set_client_id(lookup->cache_guid()); 1862 connection_manager()->set_client_id(lookup->cache_guid());
1884 1863
1885 if (syncer_thread())
1886 syncer_thread()->CreateSyncer(username_for_share());
1887
1888 MarkAndNotifyInitializationComplete(); 1864 MarkAndNotifyInitializationComplete();
1889 dir_change_hookup_.reset(lookup->AddChangeObserver(this)); 1865 dir_change_hookup_.reset(lookup->AddChangeObserver(this));
1890 return true; 1866 return true;
1891 } 1867 }
1892 1868
1893 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) { 1869 bool SyncManager::SyncInternal::SignIn(const SyncCredentials& credentials) {
1894 DCHECK_EQ(MessageLoop::current(), core_message_loop_); 1870 DCHECK_EQ(MessageLoop::current(), core_message_loop_);
1895 DCHECK(share_.name.empty()); 1871 DCHECK(share_.name.empty());
1896 share_.name = credentials.email; 1872 share_.name = credentials.email;
1897 1873
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 } 2179 }
2204 2180
2205 void SyncManager::Shutdown() { 2181 void SyncManager::Shutdown() {
2206 data_->Shutdown(); 2182 data_->Shutdown();
2207 } 2183 }
2208 2184
2209 void SyncManager::SyncInternal::Shutdown() { 2185 void SyncManager::SyncInternal::Shutdown() {
2210 method_factory_.RevokeAll(); 2186 method_factory_.RevokeAll();
2211 2187
2212 if (syncer_thread()) { 2188 if (syncer_thread()) {
2213 if (!syncer_thread()->Stop(kThreadExitTimeoutMsec)) { 2189 syncer_thread()->Stop();
2214 LOG(FATAL) << "Unable to stop the syncer, it won't be happy...";
2215 }
2216 syncer_thread_.reset(); 2190 syncer_thread_.reset();
2217 } 2191 }
2218 2192
2219 // We NULL out sync_notifer_ so that any pending tasks do not 2193 // We NULL out sync_notifer_ so that any pending tasks do not
2220 // trigger further notifications. 2194 // trigger further notifications.
2221 // TODO(akalin): NULL the other member variables defensively, too. 2195 // TODO(akalin): NULL the other member variables defensively, too.
2222 if (sync_notifier_) { 2196 if (sync_notifier_) {
2223 sync_notifier_->RemoveObserver(this); 2197 sync_notifier_->RemoveObserver(this);
2224 } 2198 }
2225 2199
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 exists_unsynced_items = true; 2384 exists_unsynced_items = true;
2411 2385
2412 model_types[model_type] = true; 2386 model_types[model_type] = true;
2413 if (model_type != syncable::PREFERENCES) 2387 if (model_type != syncable::PREFERENCES)
2414 only_preference_changes = false; 2388 only_preference_changes = false;
2415 } 2389 }
2416 } 2390 }
2417 if (exists_unsynced_items && syncer_thread()) { 2391 if (exists_unsynced_items && syncer_thread()) {
2418 int nudge_delay = only_preference_changes ? 2392 int nudge_delay = only_preference_changes ?
2419 kPreferencesNudgeDelayMilliseconds : kDefaultNudgeDelayMilliseconds; 2393 kPreferencesNudgeDelayMilliseconds : kDefaultNudgeDelayMilliseconds;
2420 syncer_thread()->NudgeSyncerWithDataTypes( 2394 syncer_thread()->ScheduleNudge(
2421 nudge_delay, 2395 TimeDelta::FromMilliseconds(nudge_delay),
2422 SyncerThread::kLocal, 2396 browser_sync::NUDGE_SOURCE_LOCAL,
2423 model_types, 2397 model_types,
2424 FROM_HERE); 2398 FROM_HERE);
2425 } 2399 }
2426 } 2400 }
2427 2401
2428 void SyncManager::SyncInternal::SetExtraChangeRecordData(int64 id, 2402 void SyncManager::SyncInternal::SetExtraChangeRecordData(int64 id,
2429 syncable::ModelType type, ChangeReorderBuffer* buffer, 2403 syncable::ModelType type, ChangeReorderBuffer* buffer,
2430 Cryptographer* cryptographer, const syncable::EntryKernel& original, 2404 Cryptographer* cryptographer, const syncable::EntryKernel& original,
2431 bool existed_before, bool exists_now) { 2405 bool existed_before, bool exists_now) {
2432 // If this is a deletion and the datatype was encrypted, we need to decrypt it 2406 // If this is a deletion and the datatype was encrypted, we need to decrypt it
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2568 (event.snapshot->syncer_status.num_successful_commits > 0); 2542 (event.snapshot->syncer_status.num_successful_commits > 0);
2569 if (new_notification) { 2543 if (new_notification) {
2570 core_message_loop_->PostTask( 2544 core_message_loop_->PostTask(
2571 FROM_HERE, 2545 FROM_HERE,
2572 NewRunnableMethod( 2546 NewRunnableMethod(
2573 this, 2547 this,
2574 &SyncManager::SyncInternal::SendNotification)); 2548 &SyncManager::SyncInternal::SendNotification));
2575 } 2549 }
2576 } 2550 }
2577 2551
2578 if (event.what_happened == SyncEngineEvent::SYNCER_THREAD_PAUSED) {
2579 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
2580 OnPaused());
2581 return;
2582 }
2583
2584 if (event.what_happened == SyncEngineEvent::SYNCER_THREAD_RESUMED) {
2585 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
2586 OnResumed());
2587 return;
2588 }
2589
2590 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { 2552 if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) {
2591 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 2553 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
2592 OnStopSyncingPermanently()); 2554 OnStopSyncingPermanently());
2593 return; 2555 return;
2594 } 2556 }
2595 2557
2596 if (event.what_happened == SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED) { 2558 if (event.what_happened == SyncEngineEvent::CLEAR_SERVER_DATA_SUCCEEDED) {
2597 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 2559 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
2598 OnClearServerDataSucceeded()); 2560 OnClearServerDataSucceeded());
2599 return; 2561 return;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2736 return_args.Append(result); 2698 return_args.Append(result);
2737 return browser_sync::JsArgList(return_args); 2699 return browser_sync::JsArgList(return_args);
2738 } 2700 }
2739 2701
2740 void SyncManager::SyncInternal::OnNotificationStateChange( 2702 void SyncManager::SyncInternal::OnNotificationStateChange(
2741 bool notifications_enabled) { 2703 bool notifications_enabled) {
2742 VLOG(1) << "P2P: Notifications enabled = " 2704 VLOG(1) << "P2P: Notifications enabled = "
2743 << (notifications_enabled ? "true" : "false"); 2705 << (notifications_enabled ? "true" : "false");
2744 allstatus_.SetNotificationsEnabled(notifications_enabled); 2706 allstatus_.SetNotificationsEnabled(notifications_enabled);
2745 if (syncer_thread()) { 2707 if (syncer_thread()) {
2746 syncer_thread()->SetNotificationsEnabled(notifications_enabled); 2708 syncer_thread()->set_notifications_enabled(notifications_enabled);
2747 } 2709 }
2748 if (parent_router_) { 2710 if (parent_router_) {
2749 ListValue args; 2711 ListValue args;
2750 args.Append(Value::CreateBooleanValue(notifications_enabled)); 2712 args.Append(Value::CreateBooleanValue(notifications_enabled));
2751 // TODO(akalin): Tidy up grammar in event names. 2713 // TODO(akalin): Tidy up grammar in event names.
2752 parent_router_->RouteJsEvent("onSyncNotificationStateChange", 2714 parent_router_->RouteJsEvent("onSyncNotificationStateChange",
2753 browser_sync::JsArgList(args), NULL); 2715 browser_sync::JsArgList(args), NULL);
2754 } 2716 }
2755 } 2717 }
2756 2718
2757 void SyncManager::SyncInternal::UpdateNotificationInfo( 2719 void SyncManager::SyncInternal::UpdateNotificationInfo(
2758 const syncable::ModelTypePayloadMap& type_payloads) { 2720 const syncable::ModelTypePayloadMap& type_payloads) {
2759 for (syncable::ModelTypePayloadMap::const_iterator it = type_payloads.begin(); 2721 for (syncable::ModelTypePayloadMap::const_iterator it = type_payloads.begin();
2760 it != type_payloads.end(); ++it) { 2722 it != type_payloads.end(); ++it) {
2761 NotificationInfo* info = &notification_info_map_[it->first]; 2723 NotificationInfo* info = &notification_info_map_[it->first];
2762 info->total_count++; 2724 info->total_count++;
2763 info->payload = it->second; 2725 info->payload = it->second;
2764 } 2726 }
2765 } 2727 }
2766 2728
2767 void SyncManager::SyncInternal::OnIncomingNotification( 2729 void SyncManager::SyncInternal::OnIncomingNotification(
2768 const syncable::ModelTypePayloadMap& type_payloads) { 2730 const syncable::ModelTypePayloadMap& type_payloads) {
2769 if (!type_payloads.empty()) { 2731 if (!type_payloads.empty()) {
2770 if (syncer_thread()) { 2732 if (syncer_thread()) {
2771 syncer_thread()->NudgeSyncerWithPayloads( 2733 syncer_thread()->ScheduleNudgeWithPayloads(
2772 kSyncerThreadDelayMsec, 2734 TimeDelta::FromMilliseconds(kSyncerThreadDelayMsec),
2773 SyncerThread::kNotification, 2735 browser_sync::NUDGE_SOURCE_NOTIFICATION,
2774 type_payloads, FROM_HERE); 2736 type_payloads, FROM_HERE);
2775 } 2737 }
2776 allstatus_.IncrementNotificationsReceived(); 2738 allstatus_.IncrementNotificationsReceived();
2777 UpdateNotificationInfo(type_payloads); 2739 UpdateNotificationInfo(type_payloads);
2778 } else { 2740 } else {
2779 LOG(WARNING) << "Sync received notification without any type information."; 2741 LOG(WARNING) << "Sync received notification without any type information.";
2780 } 2742 }
2781 2743
2782 if (parent_router_) { 2744 if (parent_router_) {
2783 ListValue args; 2745 ListValue args;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2879 void SyncManager::TriggerOnIncomingNotificationForTest( 2841 void SyncManager::TriggerOnIncomingNotificationForTest(
2880 const syncable::ModelTypeBitSet& model_types) { 2842 const syncable::ModelTypeBitSet& model_types) {
2881 syncable::ModelTypePayloadMap model_types_with_payloads = 2843 syncable::ModelTypePayloadMap model_types_with_payloads =
2882 syncable::ModelTypePayloadMapFromBitSet(model_types, 2844 syncable::ModelTypePayloadMapFromBitSet(model_types,
2883 std::string()); 2845 std::string());
2884 2846
2885 data_->OnIncomingNotification(model_types_with_payloads); 2847 data_->OnIncomingNotification(model_types_with_payloads);
2886 } 2848 }
2887 2849
2888 } // namespace sync_api 2850 } // 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