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 "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <bitset> | 9 #include <bitset> |
10 #include <iomanip> | 10 #include <iomanip> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 using syncable::Directory; | 82 using syncable::Directory; |
83 using syncable::DirectoryManager; | 83 using syncable::DirectoryManager; |
84 using syncable::Entry; | 84 using syncable::Entry; |
85 using syncable::SPECIFICS; | 85 using syncable::SPECIFICS; |
86 | 86 |
87 typedef GoogleServiceAuthError AuthError; | 87 typedef GoogleServiceAuthError AuthError; |
88 | 88 |
89 static const int kThreadExitTimeoutMsec = 60000; | 89 static const int kThreadExitTimeoutMsec = 60000; |
90 static const int kSSLPort = 443; | 90 static const int kSSLPort = 443; |
91 | 91 |
| 92 #if defined(OS_CHROMEOS) |
| 93 static const int kChromeOSNetworkChangeReactionDelayHackMsec = 5000; |
| 94 #endif // OS_CHROMEOS |
| 95 |
92 // We manage the lifetime of sync_api::SyncManager::SyncInternal ourselves. | 96 // We manage the lifetime of sync_api::SyncManager::SyncInternal ourselves. |
93 DISABLE_RUNNABLE_METHOD_REFCOUNT(sync_api::SyncManager::SyncInternal); | 97 DISABLE_RUNNABLE_METHOD_REFCOUNT(sync_api::SyncManager::SyncInternal); |
94 | 98 |
95 namespace sync_api { | 99 namespace sync_api { |
96 | 100 |
97 static const FilePath::CharType kBookmarkSyncUserSettingsDatabase[] = | 101 static const FilePath::CharType kBookmarkSyncUserSettingsDatabase[] = |
98 FILE_PATH_LITERAL("BookmarkSyncSettings.sqlite3"); | 102 FILE_PATH_LITERAL("BookmarkSyncSettings.sqlite3"); |
99 static const char kDefaultNameForNewNodes[] = " "; | 103 static const char kDefaultNameForNewNodes[] = " "; |
100 | 104 |
101 // The list of names which are reserved for use by the server. | 105 // The list of names which are reserved for use by the server. |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 | 1166 |
1163 // Initializes (bootstraps) the Cryptographer if NIGORI has finished | 1167 // Initializes (bootstraps) the Cryptographer if NIGORI has finished |
1164 // initial sync so that it can immediately start encrypting / decrypting. | 1168 // initial sync so that it can immediately start encrypting / decrypting. |
1165 // If the restored key is incompatible with the current version of the NIGORI | 1169 // If the restored key is incompatible with the current version of the NIGORI |
1166 // node (which could happen if a restart occurred just after an update to | 1170 // node (which could happen if a restart occurred just after an update to |
1167 // NIGORI was downloaded and the user must enter a new passphrase to decrypt) | 1171 // NIGORI was downloaded and the user must enter a new passphrase to decrypt) |
1168 // then we will raise OnPassphraseRequired and set pending keys for | 1172 // then we will raise OnPassphraseRequired and set pending keys for |
1169 // decryption. Otherwise, the cryptographer is made ready (is_ready()). | 1173 // decryption. Otherwise, the cryptographer is made ready (is_ready()). |
1170 void BootstrapEncryption(const std::string& restored_key_for_bootstrapping); | 1174 void BootstrapEncryption(const std::string& restored_key_for_bootstrapping); |
1171 | 1175 |
| 1176 // Checks for server reachabilty and requests a nudge. |
| 1177 void OnIPAddressChangedImpl(); |
| 1178 |
1172 // We couple the DirectoryManager and username together in a UserShare member | 1179 // We couple the DirectoryManager and username together in a UserShare member |
1173 // so we can return a handle to share_ to clients of the API for use when | 1180 // so we can return a handle to share_ to clients of the API for use when |
1174 // constructing any transaction type. | 1181 // constructing any transaction type. |
1175 UserShare share_; | 1182 UserShare share_; |
1176 | 1183 |
1177 MessageLoop* core_message_loop_; | 1184 MessageLoop* core_message_loop_; |
1178 | 1185 |
1179 // Observer registered via SetObserver/RemoveObserver. | 1186 // Observer registered via SetObserver/RemoveObserver. |
1180 // WARNING: This can be NULL! | 1187 // WARNING: This can be NULL! |
1181 SyncManager::Observer* observer_; | 1188 SyncManager::Observer* observer_; |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1711 share_.dir_manager.reset(); | 1718 share_.dir_manager.reset(); |
1712 | 1719 |
1713 // We don't want to process any more events. | 1720 // We don't want to process any more events. |
1714 dir_change_hookup_.reset(); | 1721 dir_change_hookup_.reset(); |
1715 | 1722 |
1716 core_message_loop_ = NULL; | 1723 core_message_loop_ = NULL; |
1717 } | 1724 } |
1718 | 1725 |
1719 void SyncManager::SyncInternal::OnIPAddressChanged() { | 1726 void SyncManager::SyncInternal::OnIPAddressChanged() { |
1720 VLOG(1) << "IP address change detected"; | 1727 VLOG(1) << "IP address change detected"; |
| 1728 #if defined (OS_CHROMEOS) |
| 1729 // TODO(tim): This is a hack to intentionally lose a race with flimflam at |
| 1730 // shutdown, so we don't cause shutdown to wait for our http request. |
| 1731 // http://crosbug.com/8429 |
| 1732 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 1733 method_factory_.NewRunnableMethod(&SyncInternal::OnIPAddressChangedImpl), |
| 1734 kChromeOSNetworkChangeReactionDelayHackMsec); |
| 1735 #else |
| 1736 OnIPAddressChangedImpl(); |
| 1737 #endif // defined(OS_CHROMEOS) |
| 1738 } |
| 1739 |
| 1740 void SyncManager::SyncInternal::OnIPAddressChangedImpl() { |
1721 // TODO(akalin): CheckServerReachable() can block, which may cause | 1741 // TODO(akalin): CheckServerReachable() can block, which may cause |
1722 // jank if we try to shut down sync. Fix this. | 1742 // jank if we try to shut down sync. Fix this. |
1723 connection_manager()->CheckServerReachable(); | 1743 connection_manager()->CheckServerReachable(); |
1724 sync_manager_->RequestNudge(); | 1744 sync_manager_->RequestNudge(); |
1725 } | 1745 } |
1726 | 1746 |
1727 // Listen to model changes, filter out ones initiated by the sync API, and | 1747 // Listen to model changes, filter out ones initiated by the sync API, and |
1728 // saves the rest (hopefully just backend Syncer changes resulting from | 1748 // saves the rest (hopefully just backend Syncer changes resulting from |
1729 // ApplyUpdates) to data_->changelist. | 1749 // ApplyUpdates) to data_->changelist. |
1730 void SyncManager::SyncInternal::HandleChannelEvent( | 1750 void SyncManager::SyncInternal::HandleChannelEvent( |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2175 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2195 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
2176 return data_->GetUserShare(); | 2196 return data_->GetUserShare(); |
2177 } | 2197 } |
2178 | 2198 |
2179 bool SyncManager::HasUnsyncedItems() const { | 2199 bool SyncManager::HasUnsyncedItems() const { |
2180 sync_api::ReadTransaction trans(GetUserShare()); | 2200 sync_api::ReadTransaction trans(GetUserShare()); |
2181 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2201 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
2182 } | 2202 } |
2183 | 2203 |
2184 } // namespace sync_api | 2204 } // namespace sync_api |
OLD | NEW |