Chromium Code Reviews| 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 << ": " << | |
| 2208 notification_data.service_specific_data; | |
| 2209 const std::string& model_type_list = notification_data.service_url; | |
| 2210 const std::string& notification_payload = | |
| 2204 notification_data.service_specific_data; | 2211 notification_data.service_specific_data; |
| 2205 | 2212 |
| 2206 if (!syncable::ModelTypeBitSetFromString( | 2213 if (!syncable::ModelTypeBitSetFromString(model_type_list, &model_types)) { |
| 2207 notification_data.service_specific_data, | |
| 2208 &model_types)) { | |
| 2209 LOG(DFATAL) << "Could not extract model types from server data."; | 2214 LOG(DFATAL) << "Could not extract model types from server data."; |
| 2210 model_types.set(); | 2215 model_types.set(); |
| 2211 } | 2216 } |
| 2217 | |
| 2218 for (size_t i = syncable::FIRST_REAL_MODEL_TYPE; | |
|
akalin
2011/01/21 19:50:09
I think there's room for a utility function that c
Nicolas Zea
2011/01/21 21:57:44
Done.
| |
| 2219 i < model_types.size(); | |
| 2220 ++i) { | |
| 2221 if (model_types[i]) { | |
| 2222 payloads[syncable::ModelTypeFromInt(i)] = notification_payload; | |
| 2223 } | |
| 2224 } | |
| 2212 } else if (notification_data.service_url.empty() || | 2225 } else if (notification_data.service_url.empty() || |
| 2213 (notification_data.service_url == | 2226 (notification_data.service_url == |
|
akalin
2011/01/21 19:50:09
revert indentation?
Nicolas Zea
2011/01/21 21:57:44
Done.
| |
| 2214 browser_sync::kSyncLegacyServiceUrl) || | 2227 browser_sync::kSyncLegacyServiceUrl) || |
| 2215 (notification_data.service_url == | 2228 (notification_data.service_url == |
| 2216 browser_sync::kSyncServiceUrl)) { | 2229 browser_sync::kSyncServiceUrl)) { |
| 2217 VLOG(1) << "Sync received P2P notification."; | 2230 VLOG(1) << "Sync received P2P notification."; |
| 2218 | 2231 |
| 2219 // Catch for sync integration tests (uses p2p). Just set all datatypes. | 2232 // Catch for sync integration tests (uses p2p). Just set all datatypes. |
| 2220 model_types.set(); | 2233 model_types.set(); |
| 2221 } else { | 2234 } else { |
| 2222 LOG(WARNING) << "Notification fron unexpected source: " | 2235 LOG(WARNING) << "Notification fron unexpected source: " |
| 2223 << notification_data.service_url; | 2236 << notification_data.service_url; |
| 2224 } | 2237 } |
| 2225 | 2238 |
| 2226 if (model_types.any()) { | 2239 if (model_types.any()) { |
| 2227 if (syncer_thread()) { | 2240 if (syncer_thread()) { |
| 2228 // Introduce a delay to help coalesce initial notifications. | 2241 syncer_thread()->NudgeSyncerWithPayloads( |
| 2229 syncer_thread()->NudgeSyncerWithDataTypes( | 2242 kSyncerThreadDelayMsec, |
| 2230 250, | 2243 SyncerThread::kNotification, |
| 2231 SyncerThread::kNotification, | 2244 payloads); |
| 2232 model_types); | |
| 2233 } | 2245 } |
| 2234 allstatus_.IncrementNotificationsReceived(); | 2246 allstatus_.IncrementNotificationsReceived(); |
| 2235 } else { | 2247 } else { |
| 2236 LOG(WARNING) << "Sync received notification without any type information."; | 2248 LOG(WARNING) << "Sync received notification without any type information."; |
| 2237 } | 2249 } |
| 2238 } | 2250 } |
| 2239 | 2251 |
| 2240 void SyncManager::SyncInternal::OnOutgoingNotification() { | 2252 void SyncManager::SyncInternal::OnOutgoingNotification() { |
| 2241 DCHECK_NE(notifier_options_.notification_method, | 2253 DCHECK_NE(notifier_options_.notification_method, |
| 2242 notifier::NOTIFICATION_SERVER); | 2254 notifier::NOTIFICATION_SERVER); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2302 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2314 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
| 2303 return data_->GetUserShare(); | 2315 return data_->GetUserShare(); |
| 2304 } | 2316 } |
| 2305 | 2317 |
| 2306 bool SyncManager::HasUnsyncedItems() const { | 2318 bool SyncManager::HasUnsyncedItems() const { |
| 2307 sync_api::ReadTransaction trans(GetUserShare()); | 2319 sync_api::ReadTransaction trans(GetUserShare()); |
| 2308 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2320 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
| 2309 } | 2321 } |
| 2310 | 2322 |
| 2311 } // namespace sync_api | 2323 } // namespace sync_api |
| OLD | NEW |