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 <map> | |
10 #include <string> | 11 #include <string> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/base64.h" | 14 #include "base/base64.h" |
14 #include "base/lock.h" | 15 #include "base/lock.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
17 #include "base/scoped_ptr.h" | 18 #include "base/scoped_ptr.h" |
18 #include "base/sha1.h" | 19 #include "base/sha1.h" |
19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 using syncable::Directory; | 77 using syncable::Directory; |
77 using syncable::DirectoryManager; | 78 using syncable::DirectoryManager; |
78 using syncable::Entry; | 79 using syncable::Entry; |
79 using syncable::SPECIFICS; | 80 using syncable::SPECIFICS; |
80 using sync_pb::AutofillProfileSpecifics; | 81 using sync_pb::AutofillProfileSpecifics; |
81 | 82 |
82 typedef GoogleServiceAuthError AuthError; | 83 typedef GoogleServiceAuthError AuthError; |
83 | 84 |
84 static const int kThreadExitTimeoutMsec = 60000; | 85 static const int kThreadExitTimeoutMsec = 60000; |
85 static const int kSSLPort = 443; | 86 static const int kSSLPort = 443; |
87 const int kSyncerThreadDelayMsec = 250; | |
86 | 88 |
87 #if defined(OS_CHROMEOS) | 89 #if defined(OS_CHROMEOS) |
88 static const int kChromeOSNetworkChangeReactionDelayHackMsec = 5000; | 90 static const int kChromeOSNetworkChangeReactionDelayHackMsec = 5000; |
89 #endif // OS_CHROMEOS | 91 #endif // OS_CHROMEOS |
90 | 92 |
91 // We manage the lifetime of sync_api::SyncManager::SyncInternal ourselves. | 93 // We manage the lifetime of sync_api::SyncManager::SyncInternal ourselves. |
92 DISABLE_RUNNABLE_METHOD_REFCOUNT(sync_api::SyncManager::SyncInternal); | 94 DISABLE_RUNNABLE_METHOD_REFCOUNT(sync_api::SyncManager::SyncInternal); |
93 | 95 |
94 namespace sync_api { | 96 namespace sync_api { |
95 | 97 |
(...skipping 2091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2187 DCHECK(!email.empty()); | 2189 DCHECK(!email.empty()); |
2188 DCHECK(!token.empty()); | 2190 DCHECK(!token.empty()); |
2189 InitializeTalkMediator(); | 2191 InitializeTalkMediator(); |
2190 talk_mediator_->SetAuthToken(email, token, SYNC_SERVICE_NAME); | 2192 talk_mediator_->SetAuthToken(email, token, SYNC_SERVICE_NAME); |
2191 talk_mediator_->Login(); | 2193 talk_mediator_->Login(); |
2192 } | 2194 } |
2193 | 2195 |
2194 void SyncManager::SyncInternal::OnIncomingNotification( | 2196 void SyncManager::SyncInternal::OnIncomingNotification( |
2195 const IncomingNotificationData& notification_data) { | 2197 const IncomingNotificationData& notification_data) { |
2196 syncable::ModelTypeBitSet model_types; | 2198 syncable::ModelTypeBitSet model_types; |
2199 std::map<syncable::ModelType, std::string> payloads; | |
2197 | 2200 |
2198 // Check if the service url is a sync URL. An empty service URL is | 2201 // Check if the service url is a sync URL. An empty service URL is |
2199 // treated as a legacy sync notification. If we're listening to | 2202 // treated as a legacy sync notification. If we're listening to |
2200 // server-issued notifications, no need to check the service_url. | 2203 // server-issued notifications, no need to check the service_url. |
2201 if (notifier_options_.notification_method == | 2204 if (notifier_options_.notification_method == |
2202 notifier::NOTIFICATION_SERVER) { | 2205 notifier::NOTIFICATION_SERVER) { |
2203 VLOG(1) << "Sync received server notification: " << | 2206 VLOG(1) << "Sync received server notification from " << |
2207 notification_data.service_url << ": " << | |
2204 notification_data.service_specific_data; | 2208 notification_data.service_specific_data; |
2205 | 2209 |
2206 if (!syncable::ModelTypeBitSetFromString( | 2210 if (!syncable::ModelTypeBitSetFromString( |
2207 notification_data.service_specific_data, | 2211 notification_data.service_url, |
2208 &model_types)) { | 2212 &model_types)) { |
2209 LOG(DFATAL) << "Could not extract model types from server data."; | 2213 LOG(DFATAL) << "Could not extract model types from server data."; |
2210 model_types.set(); | 2214 model_types.set(); |
2211 } | 2215 } |
2216 if (!notification_data.service_specific_data.empty()) { | |
akalin
2011/01/19 22:14:52
no need for the empty check -- we can just always
Nicolas Zea
2011/01/19 22:54:56
Done.
| |
2217 for (size_t i = syncable::FIRST_REAL_MODEL_TYPE; | |
2218 i < model_types.size(); | |
2219 ++i) { | |
2220 if (model_types[i]) { | |
2221 payloads[syncable::ModelTypeFromInt(i)] = | |
2222 notification_data.service_specific_data; | |
2223 } | |
2224 } | |
2225 } | |
2212 } else if (notification_data.service_url.empty() || | 2226 } else if (notification_data.service_url.empty() || |
2213 (notification_data.service_url == | 2227 (notification_data.service_url == |
2214 browser_sync::kSyncLegacyServiceUrl) || | 2228 browser_sync::kSyncLegacyServiceUrl) || |
2215 (notification_data.service_url == | 2229 (notification_data.service_url == |
2216 browser_sync::kSyncServiceUrl)) { | 2230 browser_sync::kSyncServiceUrl)) { |
2217 VLOG(1) << "Sync received P2P notification."; | 2231 VLOG(1) << "Sync received P2P notification."; |
2218 | 2232 |
2219 // Catch for sync integration tests (uses p2p). Just set all datatypes. | 2233 // Catch for sync integration tests (uses p2p). Just set all datatypes. |
2220 model_types.set(); | 2234 model_types.set(); |
2221 } else { | 2235 } else { |
2222 LOG(WARNING) << "Notification fron unexpected source: " | 2236 LOG(WARNING) << "Notification fron unexpected source: " |
2223 << notification_data.service_url; | 2237 << notification_data.service_url; |
2224 } | 2238 } |
2225 | 2239 |
2226 if (model_types.any()) { | 2240 if (model_types.any()) { |
2227 if (syncer_thread()) { | 2241 if (syncer_thread()) { |
2228 // Introduce a delay to help coalesce initial notifications. | 2242 // If this notification had a payload, pass it along, else just pass the |
akalin
2011/01/19 22:14:52
Per the above, no need for this check either -- ju
Nicolas Zea
2011/01/19 22:54:56
Done.
| |
2229 syncer_thread()->NudgeSyncerWithDataTypes( | 2243 // datatypes that triggered the notification. |
2230 250, | 2244 if (notification_data.service_specific_data.empty()) { |
2231 SyncerThread::kNotification, | 2245 syncer_thread()->NudgeSyncerWithDataTypes( |
2232 model_types); | 2246 kSyncerThreadDelayMsec, |
2247 SyncerThread::kNotification, | |
2248 model_types); | |
2249 } else { | |
2250 syncer_thread()->NudgeSyncerWithPayloads( | |
2251 kSyncerThreadDelayMsec, | |
2252 SyncerThread::kNotification, | |
2253 payloads); | |
2254 } | |
2233 } | 2255 } |
2234 allstatus_.IncrementNotificationsReceived(); | 2256 allstatus_.IncrementNotificationsReceived(); |
2235 } else { | 2257 } else { |
2236 LOG(WARNING) << "Sync received notification without any type information."; | 2258 LOG(WARNING) << "Sync received notification without any type information."; |
2237 } | 2259 } |
2238 } | 2260 } |
2239 | 2261 |
2240 void SyncManager::SyncInternal::OnOutgoingNotification() { | 2262 void SyncManager::SyncInternal::OnOutgoingNotification() { |
2241 DCHECK_NE(notifier_options_.notification_method, | 2263 DCHECK_NE(notifier_options_.notification_method, |
2242 notifier::NOTIFICATION_SERVER); | 2264 notifier::NOTIFICATION_SERVER); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2302 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2324 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
2303 return data_->GetUserShare(); | 2325 return data_->GetUserShare(); |
2304 } | 2326 } |
2305 | 2327 |
2306 bool SyncManager::HasUnsyncedItems() const { | 2328 bool SyncManager::HasUnsyncedItems() const { |
2307 sync_api::ReadTransaction trans(GetUserShare()); | 2329 sync_api::ReadTransaction trans(GetUserShare()); |
2308 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2330 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
2309 } | 2331 } |
2310 | 2332 |
2311 } // namespace sync_api | 2333 } // namespace sync_api |
OLD | NEW |