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 23 matching lines...) Expand all Loading... | |
34 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 34 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
35 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 35 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
36 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 36 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
37 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 37 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
38 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 38 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
39 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | 39 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
40 #include "chrome/browser/sync/protocol/service_constants.h" | 40 #include "chrome/browser/sync/protocol/service_constants.h" |
41 #include "chrome/browser/sync/protocol/sync.pb.h" | 41 #include "chrome/browser/sync/protocol/sync.pb.h" |
42 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 42 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
43 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 43 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
44 #include "chrome/browser/sync/sessions/sync_session.h" | |
44 #include "chrome/browser/sync/sessions/sync_session_context.h" | 45 #include "chrome/browser/sync/sessions/sync_session_context.h" |
45 #include "chrome/browser/sync/syncable/autofill_migration.h" | 46 #include "chrome/browser/sync/syncable/autofill_migration.h" |
46 #include "chrome/browser/sync/syncable/directory_manager.h" | 47 #include "chrome/browser/sync/syncable/directory_manager.h" |
47 #include "chrome/browser/sync/syncable/syncable.h" | 48 #include "chrome/browser/sync/syncable/syncable.h" |
48 #include "chrome/browser/sync/util/crypto_helpers.h" | 49 #include "chrome/browser/sync/util/crypto_helpers.h" |
49 #include "chrome/common/deprecated/event_sys.h" | 50 #include "chrome/common/deprecated/event_sys.h" |
50 #include "chrome/common/net/gaia/gaia_authenticator.h" | 51 #include "chrome/common/net/gaia/gaia_authenticator.h" |
51 #include "jingle/notifier/listener/mediator_thread_impl.h" | 52 #include "jingle/notifier/listener/mediator_thread_impl.h" |
52 #include "jingle/notifier/listener/notification_constants.h" | 53 #include "jingle/notifier/listener/notification_constants.h" |
53 #include "jingle/notifier/listener/talk_mediator.h" | 54 #include "jingle/notifier/listener/talk_mediator.h" |
(...skipping 22 matching lines...) Expand all 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 static 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 browser_sync::sessions::TypePayloadMap model_types_with_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 model_types_with_payloads = | |
2219 browser_sync::sessions::ModelTypeBitSetToTypePayloadMap( | |
2220 model_types, notification_payload); | |
2212 } else if (notification_data.service_url.empty() || | 2221 } else if (notification_data.service_url.empty() || |
2213 (notification_data.service_url == | 2222 (notification_data.service_url == |
2214 browser_sync::kSyncLegacyServiceUrl) || | 2223 browser_sync::kSyncLegacyServiceUrl) || |
2215 (notification_data.service_url == | 2224 (notification_data.service_url == |
2216 browser_sync::kSyncServiceUrl)) { | 2225 browser_sync::kSyncServiceUrl)) { |
2217 VLOG(1) << "Sync received P2P notification."; | 2226 VLOG(1) << "Sync received P2P notification."; |
2218 | 2227 |
2219 // Catch for sync integration tests (uses p2p). Just set all datatypes. | 2228 // Catch for sync integration tests (uses p2p). Just set all datatypes. |
2220 model_types.set(); | 2229 model_types.set(); |
akalin
2011/01/26 01:15:17
This should probably set only enabled types, i.e.
Nicolas Zea
2011/01/26 01:41:28
Done.
| |
2230 model_types_with_payloads = | |
2231 browser_sync::sessions::ModelTypeBitSetToTypePayloadMap( | |
2232 model_types, std::string()); | |
2221 } else { | 2233 } else { |
2222 LOG(WARNING) << "Notification fron unexpected source: " | 2234 LOG(WARNING) << "Notification fron unexpected source: " |
2223 << notification_data.service_url; | 2235 << notification_data.service_url; |
2224 } | 2236 } |
2225 | 2237 |
2226 if (model_types.any()) { | 2238 if (model_types.any()) { |
2227 if (syncer_thread()) { | 2239 if (syncer_thread()) { |
2228 // Introduce a delay to help coalesce initial notifications. | 2240 syncer_thread()->NudgeSyncerWithPayloads( |
2229 syncer_thread()->NudgeSyncerWithDataTypes( | 2241 kSyncerThreadDelayMsec, |
2230 250, | 2242 SyncerThread::kNotification, |
2231 SyncerThread::kNotification, | 2243 model_types_with_payloads); |
2232 model_types); | |
2233 } | 2244 } |
2234 allstatus_.IncrementNotificationsReceived(); | 2245 allstatus_.IncrementNotificationsReceived(); |
2235 } else { | 2246 } else { |
2236 LOG(WARNING) << "Sync received notification without any type information."; | 2247 LOG(WARNING) << "Sync received notification without any type information."; |
2237 } | 2248 } |
2238 } | 2249 } |
2239 | 2250 |
2240 void SyncManager::SyncInternal::OnOutgoingNotification() { | 2251 void SyncManager::SyncInternal::OnOutgoingNotification() { |
2241 DCHECK_NE(notifier_options_.notification_method, | 2252 DCHECK_NE(notifier_options_.notification_method, |
2242 notifier::NOTIFICATION_SERVER); | 2253 notifier::NOTIFICATION_SERVER); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2302 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2313 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
2303 return data_->GetUserShare(); | 2314 return data_->GetUserShare(); |
2304 } | 2315 } |
2305 | 2316 |
2306 bool SyncManager::HasUnsyncedItems() const { | 2317 bool SyncManager::HasUnsyncedItems() const { |
2307 sync_api::ReadTransaction trans(GetUserShare()); | 2318 sync_api::ReadTransaction trans(GetUserShare()); |
2308 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2319 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
2309 } | 2320 } |
2310 | 2321 |
2311 } // namespace sync_api | 2322 } // namespace sync_api |
OLD | NEW |