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" | |
45 #include "chrome/browser/sync/sessions/sync_session_context.h" | 44 #include "chrome/browser/sync/sessions/sync_session_context.h" |
46 #include "chrome/browser/sync/syncable/autofill_migration.h" | 45 #include "chrome/browser/sync/syncable/autofill_migration.h" |
47 #include "chrome/browser/sync/syncable/directory_manager.h" | 46 #include "chrome/browser/sync/syncable/directory_manager.h" |
48 #include "chrome/browser/sync/syncable/syncable.h" | 47 #include "chrome/browser/sync/syncable/syncable.h" |
49 #include "chrome/browser/sync/util/crypto_helpers.h" | 48 #include "chrome/browser/sync/util/crypto_helpers.h" |
50 #include "chrome/common/deprecated/event_sys.h" | 49 #include "chrome/common/deprecated/event_sys.h" |
51 #include "chrome/common/net/gaia/gaia_authenticator.h" | 50 #include "chrome/common/net/gaia/gaia_authenticator.h" |
52 #include "jingle/notifier/listener/mediator_thread_impl.h" | 51 #include "jingle/notifier/listener/mediator_thread_impl.h" |
53 #include "jingle/notifier/listener/notification_constants.h" | 52 #include "jingle/notifier/listener/notification_constants.h" |
54 #include "jingle/notifier/listener/talk_mediator.h" | 53 #include "jingle/notifier/listener/talk_mediator.h" |
(...skipping 22 matching lines...) Expand all Loading... |
77 using syncable::Directory; | 76 using syncable::Directory; |
78 using syncable::DirectoryManager; | 77 using syncable::DirectoryManager; |
79 using syncable::Entry; | 78 using syncable::Entry; |
80 using syncable::SPECIFICS; | 79 using syncable::SPECIFICS; |
81 using sync_pb::AutofillProfileSpecifics; | 80 using sync_pb::AutofillProfileSpecifics; |
82 | 81 |
83 typedef GoogleServiceAuthError AuthError; | 82 typedef GoogleServiceAuthError AuthError; |
84 | 83 |
85 static const int kThreadExitTimeoutMsec = 60000; | 84 static const int kThreadExitTimeoutMsec = 60000; |
86 static const int kSSLPort = 443; | 85 static const int kSSLPort = 443; |
87 static const int kSyncerThreadDelayMsec = 250; | |
88 | 86 |
89 #if defined(OS_CHROMEOS) | 87 #if defined(OS_CHROMEOS) |
90 static const int kChromeOSNetworkChangeReactionDelayHackMsec = 5000; | 88 static const int kChromeOSNetworkChangeReactionDelayHackMsec = 5000; |
91 #endif // OS_CHROMEOS | 89 #endif // OS_CHROMEOS |
92 | 90 |
93 // We manage the lifetime of sync_api::SyncManager::SyncInternal ourselves. | 91 // We manage the lifetime of sync_api::SyncManager::SyncInternal ourselves. |
94 DISABLE_RUNNABLE_METHOD_REFCOUNT(sync_api::SyncManager::SyncInternal); | 92 DISABLE_RUNNABLE_METHOD_REFCOUNT(sync_api::SyncManager::SyncInternal); |
95 | 93 |
96 namespace sync_api { | 94 namespace sync_api { |
97 | 95 |
(...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2188 DCHECK_EQ(MessageLoop::current(), core_message_loop_); | 2186 DCHECK_EQ(MessageLoop::current(), core_message_loop_); |
2189 DCHECK(!email.empty()); | 2187 DCHECK(!email.empty()); |
2190 DCHECK(!token.empty()); | 2188 DCHECK(!token.empty()); |
2191 InitializeTalkMediator(); | 2189 InitializeTalkMediator(); |
2192 talk_mediator_->SetAuthToken(email, token, SYNC_SERVICE_NAME); | 2190 talk_mediator_->SetAuthToken(email, token, SYNC_SERVICE_NAME); |
2193 talk_mediator_->Login(); | 2191 talk_mediator_->Login(); |
2194 } | 2192 } |
2195 | 2193 |
2196 void SyncManager::SyncInternal::OnIncomingNotification( | 2194 void SyncManager::SyncInternal::OnIncomingNotification( |
2197 const IncomingNotificationData& notification_data) { | 2195 const IncomingNotificationData& notification_data) { |
2198 browser_sync::sessions::TypePayloadMap model_types_with_payloads; | 2196 syncable::ModelTypeBitSet model_types; |
2199 | 2197 |
2200 // Check if the service url is a sync URL. An empty service URL is | 2198 // Check if the service url is a sync URL. An empty service URL is |
2201 // treated as a legacy sync notification. If we're listening to | 2199 // treated as a legacy sync notification. If we're listening to |
2202 // server-issued notifications, no need to check the service_url. | 2200 // server-issued notifications, no need to check the service_url. |
2203 if (notifier_options_.notification_method == | 2201 if (notifier_options_.notification_method == |
2204 notifier::NOTIFICATION_SERVER) { | 2202 notifier::NOTIFICATION_SERVER) { |
2205 VLOG(1) << "Sync received server notification from " << | 2203 VLOG(1) << "Sync received server notification: " << |
2206 notification_data.service_url << ": " << | |
2207 notification_data.service_specific_data; | |
2208 syncable::ModelTypeBitSet model_types; | |
2209 const std::string& model_type_list = notification_data.service_url; | |
2210 const std::string& notification_payload = | |
2211 notification_data.service_specific_data; | 2204 notification_data.service_specific_data; |
2212 | 2205 |
2213 if (!syncable::ModelTypeBitSetFromString(model_type_list, &model_types)) { | 2206 if (!syncable::ModelTypeBitSetFromString( |
| 2207 notification_data.service_specific_data, |
| 2208 &model_types)) { |
2214 LOG(DFATAL) << "Could not extract model types from server data."; | 2209 LOG(DFATAL) << "Could not extract model types from server data."; |
2215 model_types.set(); | 2210 model_types.set(); |
2216 } | 2211 } |
2217 | |
2218 model_types_with_payloads = | |
2219 browser_sync::sessions::ModelTypeBitSetToTypePayloadMap( | |
2220 model_types, notification_payload); | |
2221 } else if (notification_data.service_url.empty() || | 2212 } else if (notification_data.service_url.empty() || |
2222 (notification_data.service_url == | 2213 (notification_data.service_url == |
2223 browser_sync::kSyncLegacyServiceUrl) || | 2214 browser_sync::kSyncLegacyServiceUrl) || |
2224 (notification_data.service_url == | 2215 (notification_data.service_url == |
2225 browser_sync::kSyncServiceUrl)) { | 2216 browser_sync::kSyncServiceUrl)) { |
2226 VLOG(1) << "Sync received P2P notification."; | 2217 VLOG(1) << "Sync received P2P notification."; |
2227 | 2218 |
2228 // Catch for sync integration tests (uses p2p). Just set all enabled | 2219 // Catch for sync integration tests (uses p2p). Just set all datatypes. |
2229 // datatypes. | 2220 model_types.set(); |
2230 ModelSafeRoutingInfo routes; | |
2231 registrar_->GetModelSafeRoutingInfo(&routes); | |
2232 model_types_with_payloads = | |
2233 browser_sync::sessions::RoutingInfoToTypePayloadMap(routes, | |
2234 std::string()); | |
2235 } else { | 2221 } else { |
2236 LOG(WARNING) << "Notification fron unexpected source: " | 2222 LOG(WARNING) << "Notification fron unexpected source: " |
2237 << notification_data.service_url; | 2223 << notification_data.service_url; |
2238 } | 2224 } |
2239 | 2225 |
2240 if (!model_types_with_payloads.empty()) { | 2226 if (model_types.any()) { |
2241 if (syncer_thread()) { | 2227 if (syncer_thread()) { |
2242 syncer_thread()->NudgeSyncerWithPayloads( | 2228 // Introduce a delay to help coalesce initial notifications. |
2243 kSyncerThreadDelayMsec, | 2229 syncer_thread()->NudgeSyncerWithDataTypes( |
2244 SyncerThread::kNotification, | 2230 250, |
2245 model_types_with_payloads); | 2231 SyncerThread::kNotification, |
| 2232 model_types); |
2246 } | 2233 } |
2247 allstatus_.IncrementNotificationsReceived(); | 2234 allstatus_.IncrementNotificationsReceived(); |
2248 } else { | 2235 } else { |
2249 LOG(WARNING) << "Sync received notification without any type information."; | 2236 LOG(WARNING) << "Sync received notification without any type information."; |
2250 } | 2237 } |
2251 } | 2238 } |
2252 | 2239 |
2253 void SyncManager::SyncInternal::OnOutgoingNotification() { | 2240 void SyncManager::SyncInternal::OnOutgoingNotification() { |
2254 DCHECK_NE(notifier_options_.notification_method, | 2241 DCHECK_NE(notifier_options_.notification_method, |
2255 notifier::NOTIFICATION_SERVER); | 2242 notifier::NOTIFICATION_SERVER); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2315 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2302 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
2316 return data_->GetUserShare(); | 2303 return data_->GetUserShare(); |
2317 } | 2304 } |
2318 | 2305 |
2319 bool SyncManager::HasUnsyncedItems() const { | 2306 bool SyncManager::HasUnsyncedItems() const { |
2320 sync_api::ReadTransaction trans(GetUserShare()); | 2307 sync_api::ReadTransaction trans(GetUserShare()); |
2321 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2308 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
2322 } | 2309 } |
2323 | 2310 |
2324 } // namespace sync_api | 2311 } // namespace sync_api |
OLD | NEW |