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 <bitset> | 7 #include <bitset> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
(...skipping 2224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2235 DCHECK(!email.empty()); | 2235 DCHECK(!email.empty()); |
2236 DCHECK(!token.empty()); | 2236 DCHECK(!token.empty()); |
2237 InitializeTalkMediator(); | 2237 InitializeTalkMediator(); |
2238 talk_mediator_->SetAuthToken(email, token, SYNC_SERVICE_NAME); | 2238 talk_mediator_->SetAuthToken(email, token, SYNC_SERVICE_NAME); |
2239 talk_mediator_->Login(); | 2239 talk_mediator_->Login(); |
2240 } | 2240 } |
2241 | 2241 |
2242 void SyncManager::SyncInternal::OnIncomingNotification( | 2242 void SyncManager::SyncInternal::OnIncomingNotification( |
2243 const IncomingNotificationData& notification_data) { | 2243 const IncomingNotificationData& notification_data) { |
2244 syncable::ModelTypeBitSet model_types; | 2244 syncable::ModelTypeBitSet model_types; |
| 2245 std::vector<std::string> payloads; |
2245 | 2246 |
2246 // Check if the service url is a sync URL. An empty service URL is | 2247 // Check if the service url is a sync URL. An empty service URL is |
2247 // treated as a legacy sync notification. If we're listening to | 2248 // treated as a legacy sync notification. If we're listening to |
2248 // server-issued notifications, no need to check the service_url. | 2249 // server-issued notifications, no need to check the service_url. |
2249 if (notifier_options_.notification_method == | 2250 if (notifier_options_.notification_method == |
2250 notifier::NOTIFICATION_SERVER) { | 2251 notifier::NOTIFICATION_SERVER) { |
2251 VLOG(1) << "Sync received server notification: " << | 2252 VLOG(1) << "Sync received server notification from " << |
| 2253 notification_data.service_url << ": " << |
2252 notification_data.service_specific_data; | 2254 notification_data.service_specific_data; |
2253 | 2255 |
2254 if (!syncable::ModelTypeBitSetFromString( | 2256 if (!syncable::ModelTypeBitSetFromString( |
2255 notification_data.service_specific_data, | 2257 notification_data.service_url, |
2256 &model_types)) { | 2258 &model_types)) { |
2257 LOG(DFATAL) << "Could not extract model types from server data."; | 2259 LOG(DFATAL) << "Could not extract model types from server data."; |
2258 model_types.set(); | 2260 model_types.set(); |
2259 } | 2261 } |
| 2262 if (!notification_data.service_specific_data.empty()) { |
| 2263 payloads.resize(model_types.size()); |
| 2264 for (size_t i = syncable::FIRST_REAL_MODEL_TYPE; |
| 2265 i < model_types.size(); |
| 2266 ++i) { |
| 2267 if (model_types[i]) |
| 2268 payloads[i] = notification_data.service_specific_data; |
| 2269 } |
| 2270 } |
2260 } else if (notification_data.service_url.empty() || | 2271 } else if (notification_data.service_url.empty() || |
2261 (notification_data.service_url == | 2272 (notification_data.service_url == |
2262 browser_sync::kSyncLegacyServiceUrl) || | 2273 browser_sync::kSyncLegacyServiceUrl) || |
2263 (notification_data.service_url == | 2274 (notification_data.service_url == |
2264 browser_sync::kSyncServiceUrl)) { | 2275 browser_sync::kSyncServiceUrl)) { |
2265 VLOG(1) << "Sync received P2P notification."; | 2276 VLOG(1) << "Sync received P2P notification."; |
2266 | 2277 |
2267 // Catch for sync integration tests (uses p2p). Just set all datatypes. | 2278 // Catch for sync integration tests (uses p2p). Just set all datatypes. |
2268 model_types.set(); | 2279 model_types.set(); |
2269 } else { | 2280 } else { |
2270 LOG(WARNING) << "Notification fron unexpected source: " | 2281 LOG(WARNING) << "Notification fron unexpected source: " |
2271 << notification_data.service_url; | 2282 << notification_data.service_url; |
2272 } | 2283 } |
2273 | 2284 |
2274 if (model_types.any()) { | 2285 if (model_types.any()) { |
| 2286 // Introduce a delay to help coalesce initial notifications. |
| 2287 int milliseconds_from_now = 250; |
2275 if (syncer_thread()) { | 2288 if (syncer_thread()) { |
2276 // Introduce a delay to help coalesce initial notifications. | 2289 // If this notification had a payload, pass it along, else just pass the |
2277 syncer_thread()->NudgeSyncerWithDataTypes( | 2290 // datatypes that triggered the notification. |
2278 250, | 2291 if (notification_data.service_specific_data.empty()) { |
2279 SyncerThread::kNotification, | 2292 syncer_thread()->NudgeSyncerWithDataTypes( |
2280 model_types); | 2293 milliseconds_from_now, |
| 2294 SyncerThread::kNotification, |
| 2295 model_types); |
| 2296 } else { |
| 2297 syncer_thread()->NudgeSyncerWithPayloads( |
| 2298 milliseconds_from_now, |
| 2299 SyncerThread::kNotification, |
| 2300 payloads); |
| 2301 } |
2281 } | 2302 } |
2282 allstatus_.IncrementNotificationsReceived(); | 2303 allstatus_.IncrementNotificationsReceived(); |
2283 } else { | 2304 } else { |
2284 LOG(WARNING) << "Sync received notification without any type information."; | 2305 LOG(WARNING) << "Sync received notification without any type information."; |
2285 } | 2306 } |
2286 } | 2307 } |
2287 | 2308 |
2288 void SyncManager::SyncInternal::OnOutgoingNotification() { | 2309 void SyncManager::SyncInternal::OnOutgoingNotification() { |
2289 DCHECK_NE(notifier_options_.notification_method, | 2310 DCHECK_NE(notifier_options_.notification_method, |
2290 notifier::NOTIFICATION_SERVER); | 2311 notifier::NOTIFICATION_SERVER); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2350 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2371 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
2351 return data_->GetUserShare(); | 2372 return data_->GetUserShare(); |
2352 } | 2373 } |
2353 | 2374 |
2354 bool SyncManager::HasUnsyncedItems() const { | 2375 bool SyncManager::HasUnsyncedItems() const { |
2355 sync_api::ReadTransaction trans(GetUserShare()); | 2376 sync_api::ReadTransaction trans(GetUserShare()); |
2356 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2377 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
2357 } | 2378 } |
2358 | 2379 |
2359 } // namespace sync_api | 2380 } // namespace sync_api |
OLD | NEW |