OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync/engine/syncapi.h" | 5 #include "chrome/browser/sync/engine/syncapi.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <bitset> | 8 #include <bitset> |
9 #include <iomanip> | 9 #include <iomanip> |
10 #include <list> | 10 #include <list> |
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1194 public syncable::DirectoryChangeDelegate { | 1194 public syncable::DirectoryChangeDelegate { |
1195 static const int kDefaultNudgeDelayMilliseconds; | 1195 static const int kDefaultNudgeDelayMilliseconds; |
1196 static const int kPreferencesNudgeDelayMilliseconds; | 1196 static const int kPreferencesNudgeDelayMilliseconds; |
1197 public: | 1197 public: |
1198 explicit SyncInternal(const std::string& name) | 1198 explicit SyncInternal(const std::string& name) |
1199 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 1199 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
1200 parent_router_(NULL), | 1200 parent_router_(NULL), |
1201 registrar_(NULL), | 1201 registrar_(NULL), |
1202 initialized_(false), | 1202 initialized_(false), |
1203 setup_for_test_mode_(false), | 1203 setup_for_test_mode_(false), |
1204 observing_ip_address_changes_(false), | |
1204 js_transaction_observer_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 1205 js_transaction_observer_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
1205 // Pre-fill |notification_info_map_|. | 1206 // Pre-fill |notification_info_map_|. |
1206 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 1207 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
1207 i < syncable::MODEL_TYPE_COUNT; ++i) { | 1208 i < syncable::MODEL_TYPE_COUNT; ++i) { |
1208 notification_info_map_.insert( | 1209 notification_info_map_.insert( |
1209 std::make_pair(syncable::ModelTypeFromInt(i), NotificationInfo())); | 1210 std::make_pair(syncable::ModelTypeFromInt(i), NotificationInfo())); |
1210 } | 1211 } |
1211 | 1212 |
1212 // Bind message handlers. | 1213 // Bind message handlers. |
1213 BindJsMessageHandler( | 1214 BindJsMessageHandler( |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1620 // The instance is shared between the SyncManager and the Syncer. | 1621 // The instance is shared between the SyncManager and the Syncer. |
1621 ModelSafeWorkerRegistrar* registrar_; | 1622 ModelSafeWorkerRegistrar* registrar_; |
1622 | 1623 |
1623 // Set to true once Init has been called. | 1624 // Set to true once Init has been called. |
1624 bool initialized_; | 1625 bool initialized_; |
1625 | 1626 |
1626 // True if the SyncManager should be running in test mode (no sync | 1627 // True if the SyncManager should be running in test mode (no sync |
1627 // scheduler actually communicating with the server). | 1628 // scheduler actually communicating with the server). |
1628 bool setup_for_test_mode_; | 1629 bool setup_for_test_mode_; |
1629 | 1630 |
1631 // Whether we should respond to an IP address change notification. | |
1632 bool observing_ip_address_changes_; | |
akalin
2011/07/29 03:08:57
I think having 'bool has_valid_credentials_;' is c
| |
1633 | |
1630 // Map used to store the notification info to be displayed in | 1634 // Map used to store the notification info to be displayed in |
1631 // about:sync page. | 1635 // about:sync page. |
1632 NotificationInfoMap notification_info_map_; | 1636 NotificationInfoMap notification_info_map_; |
1633 | 1637 |
1634 browser_sync::JsTransactionObserver js_transaction_observer_; | 1638 browser_sync::JsTransactionObserver js_transaction_observer_; |
1635 | 1639 |
1636 JsMessageHandlerMap js_message_handlers_; | 1640 JsMessageHandlerMap js_message_handlers_; |
1637 }; | 1641 }; |
1638 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 1642 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
1639 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 1643 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1763 setup_for_test_mode_ = setup_for_test_mode; | 1767 setup_for_test_mode_ = setup_for_test_mode; |
1764 | 1768 |
1765 sync_notifier_.reset(sync_notifier); | 1769 sync_notifier_.reset(sync_notifier); |
1766 | 1770 |
1767 share_.dir_manager.reset(new DirectoryManager(database_location)); | 1771 share_.dir_manager.reset(new DirectoryManager(database_location)); |
1768 | 1772 |
1769 connection_manager_.reset(new SyncAPIServerConnectionManager( | 1773 connection_manager_.reset(new SyncAPIServerConnectionManager( |
1770 sync_server_and_path, port, use_ssl, user_agent, post_factory)); | 1774 sync_server_and_path, port, use_ssl, user_agent, post_factory)); |
1771 | 1775 |
1772 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 1776 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
1777 observing_ip_address_changes_ = true; | |
akalin
2011/07/29 03:08:57
shouldn't this remain false? We're initing, but w
| |
1773 | 1778 |
1774 connection_manager()->AddListener(this); | 1779 connection_manager()->AddListener(this); |
1775 | 1780 |
1776 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we | 1781 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we |
1777 // try to shut down sync. Fix this. | 1782 // try to shut down sync. Fix this. |
1778 MessageLoop::current()->PostTask( | 1783 MessageLoop::current()->PostTask( |
1779 FROM_HERE, base::Bind(&SyncInternal::CheckServerReachable, | 1784 FROM_HERE, base::Bind(&SyncInternal::CheckServerReachable, |
1780 weak_ptr_factory_.GetWeakPtr())); | 1785 weak_ptr_factory_.GetWeakPtr())); |
1781 | 1786 |
1782 // Test mode does not use a syncer context or syncer thread. | 1787 // Test mode does not use a syncer context or syncer thread. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1934 UpdateEnabledTypes(); | 1939 UpdateEnabledTypes(); |
1935 return true; | 1940 return true; |
1936 } | 1941 } |
1937 | 1942 |
1938 void SyncManager::SyncInternal::UpdateCredentials( | 1943 void SyncManager::SyncInternal::UpdateCredentials( |
1939 const SyncCredentials& credentials) { | 1944 const SyncCredentials& credentials) { |
1940 DCHECK(thread_checker_.CalledOnValidThread()); | 1945 DCHECK(thread_checker_.CalledOnValidThread()); |
1941 DCHECK_EQ(credentials.email, share_.name); | 1946 DCHECK_EQ(credentials.email, share_.name); |
1942 DCHECK(!credentials.email.empty()); | 1947 DCHECK(!credentials.email.empty()); |
1943 DCHECK(!credentials.sync_token.empty()); | 1948 DCHECK(!credentials.sync_token.empty()); |
1949 | |
1950 observing_ip_address_changes_ = true; | |
1944 connection_manager()->set_auth_token(credentials.sync_token); | 1951 connection_manager()->set_auth_token(credentials.sync_token); |
1945 sync_notifier_->UpdateCredentials( | 1952 sync_notifier_->UpdateCredentials( |
1946 credentials.email, credentials.sync_token); | 1953 credentials.email, credentials.sync_token); |
1947 if (!setup_for_test_mode_) { | 1954 if (!setup_for_test_mode_) { |
1948 CheckServerReachable(); | 1955 CheckServerReachable(); |
1949 } | 1956 } |
1950 } | 1957 } |
1951 | 1958 |
1952 void SyncManager::SyncInternal::UpdateEnabledTypes() { | 1959 void SyncManager::SyncInternal::UpdateEnabledTypes() { |
1953 DCHECK(thread_checker_.CalledOnValidThread()); | 1960 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2230 sync_notifier_->RemoveObserver(this); | 2237 sync_notifier_->RemoveObserver(this); |
2231 } | 2238 } |
2232 sync_notifier_.reset(); | 2239 sync_notifier_.reset(); |
2233 | 2240 |
2234 if (connection_manager_.get()) { | 2241 if (connection_manager_.get()) { |
2235 connection_manager_->RemoveListener(this); | 2242 connection_manager_->RemoveListener(this); |
2236 } | 2243 } |
2237 connection_manager_.reset(); | 2244 connection_manager_.reset(); |
2238 | 2245 |
2239 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 2246 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
2247 observing_ip_address_changes_ = false; | |
2240 | 2248 |
2241 if (dir_manager()) { | 2249 if (dir_manager()) { |
2242 dir_manager()->FinalSaveChangesForAll(); | 2250 dir_manager()->FinalSaveChangesForAll(); |
2243 dir_manager()->Close(username_for_share()); | 2251 dir_manager()->Close(username_for_share()); |
2244 } | 2252 } |
2245 | 2253 |
2246 // Reset the DirectoryManager and UserSettings so they relinquish sqlite | 2254 // Reset the DirectoryManager and UserSettings so they relinquish sqlite |
2247 // handles to backing files. | 2255 // handles to backing files. |
2248 share_.dir_manager.reset(); | 2256 share_.dir_manager.reset(); |
2249 | 2257 |
2250 setup_for_test_mode_ = false; | 2258 setup_for_test_mode_ = false; |
2251 parent_router_ = NULL; | 2259 parent_router_ = NULL; |
2252 registrar_ = NULL; | 2260 registrar_ = NULL; |
2253 | 2261 |
2254 initialized_ = false; | 2262 initialized_ = false; |
2255 | 2263 |
2256 // We reset this here, since only now we know it will not be | 2264 // We reset this here, since only now we know it will not be |
2257 // accessed from other threads (since we shut down everything). | 2265 // accessed from other threads (since we shut down everything). |
2258 weak_handle_this_.Reset(); | 2266 weak_handle_this_.Reset(); |
2259 } | 2267 } |
2260 | 2268 |
2261 void SyncManager::SyncInternal::OnIPAddressChanged() { | 2269 void SyncManager::SyncInternal::OnIPAddressChanged() { |
2262 VLOG(1) << "IP address change detected"; | 2270 VLOG(1) << "IP address change detected"; |
2271 if (!observing_ip_address_changes_) { | |
2272 VLOG(1) << "IP address change dropped."; | |
akalin
2011/07/29 03:08:57
VLOG can also say something like "IP address chang
| |
2273 return; | |
2274 } | |
2275 | |
2263 #if defined (OS_CHROMEOS) | 2276 #if defined (OS_CHROMEOS) |
2264 // TODO(tim): This is a hack to intentionally lose a race with flimflam at | 2277 // TODO(tim): This is a hack to intentionally lose a race with flimflam at |
2265 // shutdown, so we don't cause shutdown to wait for our http request. | 2278 // shutdown, so we don't cause shutdown to wait for our http request. |
2266 // http://crosbug.com/8429 | 2279 // http://crosbug.com/8429 |
2267 MessageLoop::current()->PostDelayedTask( | 2280 MessageLoop::current()->PostDelayedTask( |
2268 FROM_HERE, | 2281 FROM_HERE, |
2269 base::Bind(&SyncInternal::OnIPAddressChangedImpl, | 2282 base::Bind(&SyncInternal::OnIPAddressChangedImpl, |
2270 weak_ptr_factory_.GetWeakPtr()), | 2283 weak_ptr_factory_.GetWeakPtr()), |
2271 kChromeOSNetworkChangeReactionDelayHackMsec); | 2284 kChromeOSNetworkChangeReactionDelayHackMsec); |
2272 #else | 2285 #else |
(...skipping 12 matching lines...) Expand all Loading... | |
2285 allstatus_.HandleServerConnectionEvent(event); | 2298 allstatus_.HandleServerConnectionEvent(event); |
2286 if (event.connection_code == | 2299 if (event.connection_code == |
2287 browser_sync::HttpResponse::SERVER_CONNECTION_OK) { | 2300 browser_sync::HttpResponse::SERVER_CONNECTION_OK) { |
2288 ObserverList<SyncManager::Observer> temp_obs_list; | 2301 ObserverList<SyncManager::Observer> temp_obs_list; |
2289 CopyObservers(&temp_obs_list); | 2302 CopyObservers(&temp_obs_list); |
2290 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 2303 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
2291 OnAuthError(AuthError::None())); | 2304 OnAuthError(AuthError::None())); |
2292 } | 2305 } |
2293 | 2306 |
2294 if (event.connection_code == browser_sync::HttpResponse::SYNC_AUTH_ERROR) { | 2307 if (event.connection_code == browser_sync::HttpResponse::SYNC_AUTH_ERROR) { |
2308 observing_ip_address_changes_ = false; | |
2295 ObserverList<SyncManager::Observer> temp_obs_list; | 2309 ObserverList<SyncManager::Observer> temp_obs_list; |
2296 CopyObservers(&temp_obs_list); | 2310 CopyObservers(&temp_obs_list); |
2297 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 2311 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
2298 OnAuthError(AuthError(AuthError::INVALID_GAIA_CREDENTIALS))); | 2312 OnAuthError(AuthError(AuthError::INVALID_GAIA_CREDENTIALS))); |
2299 } | 2313 } |
2300 | 2314 |
2301 if (event.connection_code == | 2315 if (event.connection_code == |
2302 browser_sync::HttpResponse::SYNC_SERVER_ERROR) { | 2316 browser_sync::HttpResponse::SYNC_SERVER_ERROR) { |
2303 ObserverList<SyncManager::Observer> temp_obs_list; | 2317 ObserverList<SyncManager::Observer> temp_obs_list; |
2304 CopyObservers(&temp_obs_list); | 2318 CopyObservers(&temp_obs_list); |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3045 void SyncManager::TriggerOnIncomingNotificationForTest( | 3059 void SyncManager::TriggerOnIncomingNotificationForTest( |
3046 const syncable::ModelTypeBitSet& model_types) { | 3060 const syncable::ModelTypeBitSet& model_types) { |
3047 syncable::ModelTypePayloadMap model_types_with_payloads = | 3061 syncable::ModelTypePayloadMap model_types_with_payloads = |
3048 syncable::ModelTypePayloadMapFromBitSet(model_types, | 3062 syncable::ModelTypePayloadMapFromBitSet(model_types, |
3049 std::string()); | 3063 std::string()); |
3050 | 3064 |
3051 data_->OnIncomingNotification(model_types_with_payloads); | 3065 data_->OnIncomingNotification(model_types_with_payloads); |
3052 } | 3066 } |
3053 | 3067 |
3054 } // namespace sync_api | 3068 } // namespace sync_api |
OLD | NEW |