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 // TODO(tim): Trying to debug 401-request-loop, temporarily adding this | |
lipalani1
2011/07/29 02:30:38
Not sure if this stmt is needed. This looks like a
| |
1632 // line to see if it makes a difference. | |
1633 bool observing_ip_address_changes_; | |
1634 | |
1630 // Map used to store the notification info to be displayed in | 1635 // Map used to store the notification info to be displayed in |
1631 // about:sync page. | 1636 // about:sync page. |
1632 NotificationInfoMap notification_info_map_; | 1637 NotificationInfoMap notification_info_map_; |
1633 | 1638 |
1634 browser_sync::JsTransactionObserver js_transaction_observer_; | 1639 browser_sync::JsTransactionObserver js_transaction_observer_; |
1635 | 1640 |
1636 JsMessageHandlerMap js_message_handlers_; | 1641 JsMessageHandlerMap js_message_handlers_; |
1637 }; | 1642 }; |
1638 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; | 1643 const int SyncManager::SyncInternal::kDefaultNudgeDelayMilliseconds = 200; |
1639 const int SyncManager::SyncInternal::kPreferencesNudgeDelayMilliseconds = 2000; | 1644 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; | 1768 setup_for_test_mode_ = setup_for_test_mode; |
1764 | 1769 |
1765 sync_notifier_.reset(sync_notifier); | 1770 sync_notifier_.reset(sync_notifier); |
1766 | 1771 |
1767 share_.dir_manager.reset(new DirectoryManager(database_location)); | 1772 share_.dir_manager.reset(new DirectoryManager(database_location)); |
1768 | 1773 |
1769 connection_manager_.reset(new SyncAPIServerConnectionManager( | 1774 connection_manager_.reset(new SyncAPIServerConnectionManager( |
1770 sync_server_and_path, port, use_ssl, user_agent, post_factory)); | 1775 sync_server_and_path, port, use_ssl, user_agent, post_factory)); |
1771 | 1776 |
1772 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 1777 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
1778 observing_ip_address_changes_ = true; | |
1773 | 1779 |
1774 connection_manager()->AddListener(this); | 1780 connection_manager()->AddListener(this); |
1775 | 1781 |
1776 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we | 1782 // TODO(akalin): CheckServerReachable() can block, which may cause jank if we |
1777 // try to shut down sync. Fix this. | 1783 // try to shut down sync. Fix this. |
1778 MessageLoop::current()->PostTask( | 1784 MessageLoop::current()->PostTask( |
1779 FROM_HERE, base::Bind(&SyncInternal::CheckServerReachable, | 1785 FROM_HERE, base::Bind(&SyncInternal::CheckServerReachable, |
1780 weak_ptr_factory_.GetWeakPtr())); | 1786 weak_ptr_factory_.GetWeakPtr())); |
1781 | 1787 |
1782 // Test mode does not use a syncer context or syncer thread. | 1788 // 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(); | 1940 UpdateEnabledTypes(); |
1935 return true; | 1941 return true; |
1936 } | 1942 } |
1937 | 1943 |
1938 void SyncManager::SyncInternal::UpdateCredentials( | 1944 void SyncManager::SyncInternal::UpdateCredentials( |
1939 const SyncCredentials& credentials) { | 1945 const SyncCredentials& credentials) { |
1940 DCHECK(thread_checker_.CalledOnValidThread()); | 1946 DCHECK(thread_checker_.CalledOnValidThread()); |
1941 DCHECK_EQ(credentials.email, share_.name); | 1947 DCHECK_EQ(credentials.email, share_.name); |
1942 DCHECK(!credentials.email.empty()); | 1948 DCHECK(!credentials.email.empty()); |
1943 DCHECK(!credentials.sync_token.empty()); | 1949 DCHECK(!credentials.sync_token.empty()); |
1950 | |
1951 observing_ip_address_changes_ = true; | |
1944 connection_manager()->set_auth_token(credentials.sync_token); | 1952 connection_manager()->set_auth_token(credentials.sync_token); |
1945 sync_notifier_->UpdateCredentials( | 1953 sync_notifier_->UpdateCredentials( |
1946 credentials.email, credentials.sync_token); | 1954 credentials.email, credentials.sync_token); |
1947 if (!setup_for_test_mode_) { | 1955 if (!setup_for_test_mode_) { |
1948 CheckServerReachable(); | 1956 CheckServerReachable(); |
1949 } | 1957 } |
1950 } | 1958 } |
1951 | 1959 |
1952 void SyncManager::SyncInternal::UpdateEnabledTypes() { | 1960 void SyncManager::SyncInternal::UpdateEnabledTypes() { |
1953 DCHECK(thread_checker_.CalledOnValidThread()); | 1961 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2230 sync_notifier_->RemoveObserver(this); | 2238 sync_notifier_->RemoveObserver(this); |
2231 } | 2239 } |
2232 sync_notifier_.reset(); | 2240 sync_notifier_.reset(); |
2233 | 2241 |
2234 if (connection_manager_.get()) { | 2242 if (connection_manager_.get()) { |
2235 connection_manager_->RemoveListener(this); | 2243 connection_manager_->RemoveListener(this); |
2236 } | 2244 } |
2237 connection_manager_.reset(); | 2245 connection_manager_.reset(); |
2238 | 2246 |
2239 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 2247 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
2248 observing_ip_address_changes_ = false; | |
2240 | 2249 |
2241 if (dir_manager()) { | 2250 if (dir_manager()) { |
2242 dir_manager()->FinalSaveChangesForAll(); | 2251 dir_manager()->FinalSaveChangesForAll(); |
2243 dir_manager()->Close(username_for_share()); | 2252 dir_manager()->Close(username_for_share()); |
2244 } | 2253 } |
2245 | 2254 |
2246 // Reset the DirectoryManager and UserSettings so they relinquish sqlite | 2255 // Reset the DirectoryManager and UserSettings so they relinquish sqlite |
2247 // handles to backing files. | 2256 // handles to backing files. |
2248 share_.dir_manager.reset(); | 2257 share_.dir_manager.reset(); |
2249 | 2258 |
2250 setup_for_test_mode_ = false; | 2259 setup_for_test_mode_ = false; |
2251 parent_router_ = NULL; | 2260 parent_router_ = NULL; |
2252 registrar_ = NULL; | 2261 registrar_ = NULL; |
2253 | 2262 |
2254 initialized_ = false; | 2263 initialized_ = false; |
2255 | 2264 |
2256 // We reset this here, since only now we know it will not be | 2265 // We reset this here, since only now we know it will not be |
2257 // accessed from other threads (since we shut down everything). | 2266 // accessed from other threads (since we shut down everything). |
2258 weak_handle_this_.Reset(); | 2267 weak_handle_this_.Reset(); |
2259 } | 2268 } |
2260 | 2269 |
2261 void SyncManager::SyncInternal::OnIPAddressChanged() { | 2270 void SyncManager::SyncInternal::OnIPAddressChanged() { |
2262 VLOG(1) << "IP address change detected"; | 2271 VLOG(1) << "IP address change detected"; |
2272 if (!observing_ip_address_changes_) | |
lipalani1
2011/07/29 02:30:38
Can you add a log stmt here to say that it was dro
| |
2273 return; | |
2274 | |
2263 #if defined (OS_CHROMEOS) | 2275 #if defined (OS_CHROMEOS) |
2264 // TODO(tim): This is a hack to intentionally lose a race with flimflam at | 2276 // 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. | 2277 // shutdown, so we don't cause shutdown to wait for our http request. |
2266 // http://crosbug.com/8429 | 2278 // http://crosbug.com/8429 |
2267 MessageLoop::current()->PostDelayedTask( | 2279 MessageLoop::current()->PostDelayedTask( |
2268 FROM_HERE, | 2280 FROM_HERE, |
2269 base::Bind(&SyncInternal::OnIPAddressChangedImpl, | 2281 base::Bind(&SyncInternal::OnIPAddressChangedImpl, |
2270 weak_ptr_factory_.GetWeakPtr()), | 2282 weak_ptr_factory_.GetWeakPtr()), |
2271 kChromeOSNetworkChangeReactionDelayHackMsec); | 2283 kChromeOSNetworkChangeReactionDelayHackMsec); |
2272 #else | 2284 #else |
(...skipping 12 matching lines...) Expand all Loading... | |
2285 allstatus_.HandleServerConnectionEvent(event); | 2297 allstatus_.HandleServerConnectionEvent(event); |
2286 if (event.connection_code == | 2298 if (event.connection_code == |
2287 browser_sync::HttpResponse::SERVER_CONNECTION_OK) { | 2299 browser_sync::HttpResponse::SERVER_CONNECTION_OK) { |
2288 ObserverList<SyncManager::Observer> temp_obs_list; | 2300 ObserverList<SyncManager::Observer> temp_obs_list; |
2289 CopyObservers(&temp_obs_list); | 2301 CopyObservers(&temp_obs_list); |
2290 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 2302 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
2291 OnAuthError(AuthError::None())); | 2303 OnAuthError(AuthError::None())); |
2292 } | 2304 } |
2293 | 2305 |
2294 if (event.connection_code == browser_sync::HttpResponse::SYNC_AUTH_ERROR) { | 2306 if (event.connection_code == browser_sync::HttpResponse::SYNC_AUTH_ERROR) { |
2307 observing_ip_address_changes_ = false; | |
2295 ObserverList<SyncManager::Observer> temp_obs_list; | 2308 ObserverList<SyncManager::Observer> temp_obs_list; |
2296 CopyObservers(&temp_obs_list); | 2309 CopyObservers(&temp_obs_list); |
2297 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, | 2310 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, |
2298 OnAuthError(AuthError(AuthError::INVALID_GAIA_CREDENTIALS))); | 2311 OnAuthError(AuthError(AuthError::INVALID_GAIA_CREDENTIALS))); |
2299 } | 2312 } |
2300 | 2313 |
2301 if (event.connection_code == | 2314 if (event.connection_code == |
2302 browser_sync::HttpResponse::SYNC_SERVER_ERROR) { | 2315 browser_sync::HttpResponse::SYNC_SERVER_ERROR) { |
2303 ObserverList<SyncManager::Observer> temp_obs_list; | 2316 ObserverList<SyncManager::Observer> temp_obs_list; |
2304 CopyObservers(&temp_obs_list); | 2317 CopyObservers(&temp_obs_list); |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3045 void SyncManager::TriggerOnIncomingNotificationForTest( | 3058 void SyncManager::TriggerOnIncomingNotificationForTest( |
3046 const syncable::ModelTypeBitSet& model_types) { | 3059 const syncable::ModelTypeBitSet& model_types) { |
3047 syncable::ModelTypePayloadMap model_types_with_payloads = | 3060 syncable::ModelTypePayloadMap model_types_with_payloads = |
3048 syncable::ModelTypePayloadMapFromBitSet(model_types, | 3061 syncable::ModelTypePayloadMapFromBitSet(model_types, |
3049 std::string()); | 3062 std::string()); |
3050 | 3063 |
3051 data_->OnIncomingNotification(model_types_with_payloads); | 3064 data_->OnIncomingNotification(model_types_with_payloads); |
3052 } | 3065 } |
3053 | 3066 |
3054 } // namespace sync_api | 3067 } // namespace sync_api |
OLD | NEW |