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 "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <bitset> | 9 #include <bitset> |
10 #include <iomanip> | 10 #include <iomanip> |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
27 #include "chrome/browser/browser_thread.h" | 27 #include "chrome/browser/browser_thread.h" |
28 #include "chrome/browser/sync/sync_constants.h" | 28 #include "chrome/browser/sync/sync_constants.h" |
29 #include "chrome/browser/sync/engine/all_status.h" | 29 #include "chrome/browser/sync/engine/all_status.h" |
30 #include "chrome/browser/sync/engine/change_reorder_buffer.h" | 30 #include "chrome/browser/sync/engine/change_reorder_buffer.h" |
31 #include "chrome/browser/sync/engine/model_safe_worker.h" | 31 #include "chrome/browser/sync/engine/model_safe_worker.h" |
32 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 32 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
33 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" | 33 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" |
34 #include "chrome/browser/sync/engine/syncer.h" | 34 #include "chrome/browser/sync/engine/syncer.h" |
35 #include "chrome/browser/sync/engine/syncer_thread.h" | 35 #include "chrome/browser/sync/engine/syncer_thread.h" |
36 #include "chrome/browser/sync/glue/autofill_model_associator.h" | |
37 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" | |
tim (not reviewing)
2010/12/10 22:16:02
this is also strictly not allowed. glue is code ch
lipalani
2010/12/11 00:12:36
Done.
| |
36 #include "chrome/browser/sync/notifier/server_notifier_thread.h" | 38 #include "chrome/browser/sync/notifier/server_notifier_thread.h" |
37 #include "chrome/browser/sync/notifier/state_writer.h" | 39 #include "chrome/browser/sync/notifier/state_writer.h" |
38 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 40 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
39 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 41 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
40 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 42 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
41 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 43 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
42 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 44 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
43 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 45 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
44 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 46 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
45 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | 47 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 PutAutofillSpecificsAndMarkForSyncing(new_value); | 375 PutAutofillSpecificsAndMarkForSyncing(new_value); |
374 } | 376 } |
375 | 377 |
376 void WriteNode::PutAutofillSpecificsAndMarkForSyncing( | 378 void WriteNode::PutAutofillSpecificsAndMarkForSyncing( |
377 const sync_pb::AutofillSpecifics& new_value) { | 379 const sync_pb::AutofillSpecifics& new_value) { |
378 sync_pb::EntitySpecifics entity_specifics; | 380 sync_pb::EntitySpecifics entity_specifics; |
379 entity_specifics.MutableExtension(sync_pb::autofill)->CopyFrom(new_value); | 381 entity_specifics.MutableExtension(sync_pb::autofill)->CopyFrom(new_value); |
380 PutSpecificsAndMarkForSyncing(entity_specifics); | 382 PutSpecificsAndMarkForSyncing(entity_specifics); |
381 } | 383 } |
382 | 384 |
385 void WriteNode::SetAutofillProfileSpecifics( | |
386 const sync_pb::AutofillProfileSpecifics& new_value) { | |
387 DCHECK_EQ(GetModelType(), syncable::AUTOFILL_PROFILE); | |
388 PutAutofillProfileSpecificsAndMarkForSyncing(new_value); | |
389 } | |
390 | |
391 void WriteNode::PutAutofillProfileSpecificsAndMarkForSyncing( | |
392 const sync_pb::AutofillProfileSpecifics& new_value) { | |
393 sync_pb::EntitySpecifics entity_specifics; | |
394 entity_specifics.MutableExtension(sync_pb::autofill_profile)->CopyFrom( | |
395 new_value); | |
396 PutSpecificsAndMarkForSyncing(entity_specifics); | |
397 } | |
398 | |
383 void WriteNode::SetBookmarkSpecifics( | 399 void WriteNode::SetBookmarkSpecifics( |
384 const sync_pb::BookmarkSpecifics& new_value) { | 400 const sync_pb::BookmarkSpecifics& new_value) { |
385 DCHECK(GetModelType() == syncable::BOOKMARKS); | 401 DCHECK(GetModelType() == syncable::BOOKMARKS); |
386 PutBookmarkSpecificsAndMarkForSyncing(new_value); | 402 PutBookmarkSpecificsAndMarkForSyncing(new_value); |
387 } | 403 } |
388 | 404 |
389 void WriteNode::PutBookmarkSpecificsAndMarkForSyncing( | 405 void WriteNode::PutBookmarkSpecificsAndMarkForSyncing( |
390 const sync_pb::BookmarkSpecifics& new_value) { | 406 const sync_pb::BookmarkSpecifics& new_value) { |
391 sync_pb::EntitySpecifics entity_specifics; | 407 sync_pb::EntitySpecifics entity_specifics; |
392 entity_specifics.MutableExtension(sync_pb::bookmark)->CopyFrom(new_value); | 408 entity_specifics.MutableExtension(sync_pb::bookmark)->CopyFrom(new_value); |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1092 ModelSafeRoutingInfo enabled_types; | 1108 ModelSafeRoutingInfo enabled_types; |
1093 registrar_->GetModelSafeRoutingInfo(&enabled_types); | 1109 registrar_->GetModelSafeRoutingInfo(&enabled_types); |
1094 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); | 1110 for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin(); |
1095 i != enabled_types.end(); ++i) { | 1111 i != enabled_types.end(); ++i) { |
1096 if (!lookup->initial_sync_ended_for_type(i->first)) | 1112 if (!lookup->initial_sync_ended_for_type(i->first)) |
1097 return false; | 1113 return false; |
1098 } | 1114 } |
1099 return true; | 1115 return true; |
1100 } | 1116 } |
1101 | 1117 |
1118 syncable::Directory::PersistedKernelInfo::AutofillMigrationState | |
1119 GetAutofillMigrationState() { | |
1120 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | |
1121 if (!lookup.good()) { | |
1122 DCHECK(false) << "ScopedDirLookup failed when checking initial sync"; | |
1123 return | |
1124 syncable::Directory::PersistedKernelInfo::NOT_MIGRATED; | |
1125 } | |
1126 | |
1127 return lookup->get_autofill_migration_state(); | |
1128 } | |
1129 | |
1130 void SetAutofillMigrationState( | |
1131 syncable::Directory::PersistedKernelInfo::AutofillMigrationState state) { | |
1132 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | |
1133 if (!lookup.good()) { | |
1134 DCHECK(false) << "ScopedDirLookup failed when checking initial sync"; | |
1135 return; | |
1136 } | |
1137 | |
1138 return lookup->set_autofill_migration_state(state); | |
1139 } | |
1140 | |
1141 void SetAutofillMigrationDebugInfo( | |
1142 syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set, | |
1143 const syncable::AutofillMigrationDebugInfo& info) { | |
1144 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | |
1145 if (!lookup.good()) { | |
1146 DCHECK(false) << "ScopedDirLookup failed when checking initial sync"; | |
1147 return; | |
1148 } | |
1149 | |
1150 return lookup->set_autofill_migration_state_debug_info(property_to_set, info ); | |
lipalani
2010/12/09 19:45:25
change it to less than 80 characters.
lipalani
2010/12/11 00:12:36
Done.
| |
1151 } | |
1152 | |
1153 syncable::AutofillMigrationDebugInfo | |
1154 GetAutofillMigrationDebugInfo() { | |
1155 syncable::ScopedDirLookup lookup(dir_manager(), username_for_share()); | |
1156 if (!lookup.good()) { | |
1157 DCHECK(false) << "ScopedDirLookup failed when checking initial sync"; | |
1158 syncable::AutofillMigrationDebugInfo null_value = {0}; | |
1159 return null_value; | |
1160 } | |
1161 return lookup->get_autofill_migration_debug_info(); | |
1162 } | |
1163 | |
1102 // SyncEngineEventListener implementation. | 1164 // SyncEngineEventListener implementation. |
1103 virtual void OnSyncEngineEvent(const SyncEngineEvent& event); | 1165 virtual void OnSyncEngineEvent(const SyncEngineEvent& event); |
1104 private: | 1166 private: |
1105 // Helper to handle the details of initializing the TalkMediator. | 1167 // Helper to handle the details of initializing the TalkMediator. |
1106 // Must be called only after OpenDirectory() is called. | 1168 // Must be called only after OpenDirectory() is called. |
1107 void InitializeTalkMediator(); | 1169 void InitializeTalkMediator(); |
1108 | 1170 |
1109 // Helper to call OnAuthError when no authentication credentials are | 1171 // Helper to call OnAuthError when no authentication credentials are |
1110 // available. | 1172 // available. |
1111 void RaiseAuthNeededEvent(); | 1173 void RaiseAuthNeededEvent(); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1309 | 1371 |
1310 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) { | 1372 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) { |
1311 data_->UpdateCredentials(credentials); | 1373 data_->UpdateCredentials(credentials); |
1312 } | 1374 } |
1313 | 1375 |
1314 | 1376 |
1315 bool SyncManager::InitialSyncEndedForAllEnabledTypes() { | 1377 bool SyncManager::InitialSyncEndedForAllEnabledTypes() { |
1316 return data_->InitialSyncEndedForAllEnabledTypes(); | 1378 return data_->InitialSyncEndedForAllEnabledTypes(); |
1317 } | 1379 } |
1318 | 1380 |
1381 void SyncManager::ConfigureAutofillMigration() { | |
1382 if (GetAutofillMigrationState() | |
1383 == syncable::Directory::PersistedKernelInfo::NOT_DETERMINED) { | |
1384 ReadTransaction trans(GetUserShare()); | |
1385 ReadNode autofil_root_node(&trans); | |
1386 | |
1387 // Check for the presence of autofill node. | |
1388 if (!autofil_root_node.InitByTagLookup(browser_sync::kAutofillTag)) { | |
1389 SetAutofillMigrationState( | |
1390 syncable::Directory::PersistedKernelInfo::INSUFFICIENT_INFO_TO_DETERMI NE); | |
1391 return; | |
1392 } | |
1393 | |
1394 // Check for children under autofill node. | |
1395 if (autofil_root_node.GetFirstChildId() == static_cast<int64>(0)) { | |
1396 SetAutofillMigrationState( | |
lipalani
2010/12/09 19:45:25
fix 80 characters
lipalani
2010/12/11 00:12:36
Done.
| |
1397 syncable::Directory::PersistedKernelInfo::INSUFFICIENT_INFO_TO_DETERMI NE); | |
1398 return; | |
1399 } | |
1400 | |
1401 ReadNode autofill_profile_root_node(&trans); | |
1402 | |
1403 // Check for the presence of autofill profile root node. | |
1404 if (!autofill_profile_root_node.InitByTagLookup( | |
1405 browser_sync::kAutofillProfileTag)) { | |
1406 SetAutofillMigrationState( | |
1407 syncable::Directory::PersistedKernelInfo::NOT_MIGRATED); | |
1408 return; | |
1409 } | |
1410 | |
1411 // If our state is not determined then we should not have the autofill | |
1412 // profile node. | |
1413 DCHECK(false); | |
1414 | |
1415 // just set it as not migrated. | |
1416 SetAutofillMigrationState( | |
1417 syncable::Directory::PersistedKernelInfo::NOT_MIGRATED); | |
1418 return; | |
1419 } | |
1420 } | |
1421 | |
1319 void SyncManager::StartSyncing() { | 1422 void SyncManager::StartSyncing() { |
1320 data_->StartSyncing(); | 1423 data_->StartSyncing(); |
1321 } | 1424 } |
1322 | 1425 |
1426 syncable::Directory::PersistedKernelInfo::AutofillMigrationState | |
1427 SyncManager::GetAutofillMigrationState() { | |
1428 return data_->GetAutofillMigrationState(); | |
1429 } | |
1430 | |
1431 void SyncManager::SetAutofillMigrationState( | |
1432 syncable::Directory::PersistedKernelInfo::AutofillMigrationState state) { | |
1433 return data_->SetAutofillMigrationState(state); | |
1434 } | |
1435 | |
1436 syncable::AutofillMigrationDebugInfo | |
1437 SyncManager::GetAutofillMigrationDebugInfo() { | |
1438 return data_->GetAutofillMigrationDebugInfo(); | |
1439 } | |
1440 | |
1441 void SyncManager::SetAutofillMigrationDebugInfo( | |
1442 syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set, | |
1443 const syncable::AutofillMigrationDebugInfo& info) { | |
1444 return data_->SetAutofillMigrationDebugInfo(property_to_set, info); | |
1445 } | |
1446 | |
1323 void SyncManager::SetPassphrase(const std::string& passphrase, | 1447 void SyncManager::SetPassphrase(const std::string& passphrase, |
1324 bool is_explicit) { | 1448 bool is_explicit) { |
1325 data_->SetPassphrase(passphrase, is_explicit); | 1449 data_->SetPassphrase(passphrase, is_explicit); |
1326 } | 1450 } |
1327 | 1451 |
1328 bool SyncManager::IsUsingExplicitPassphrase() { | 1452 bool SyncManager::IsUsingExplicitPassphrase() { |
1329 return data_ && data_->IsUsingExplicitPassphrase(); | 1453 return data_ && data_->IsUsingExplicitPassphrase(); |
1330 } | 1454 } |
1331 | 1455 |
1332 bool SyncManager::RequestPause() { | 1456 bool SyncManager::RequestPause() { |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2170 // treated as a legacy sync notification. If we're listening to | 2294 // treated as a legacy sync notification. If we're listening to |
2171 // server-issued notifications, no need to check the service_url. | 2295 // server-issued notifications, no need to check the service_url. |
2172 if (notifier_options_.notification_method == | 2296 if (notifier_options_.notification_method == |
2173 notifier::NOTIFICATION_SERVER) { | 2297 notifier::NOTIFICATION_SERVER) { |
2174 VLOG(1) << "Sync received server notification: " << | 2298 VLOG(1) << "Sync received server notification: " << |
2175 notification_data.service_specific_data; | 2299 notification_data.service_specific_data; |
2176 | 2300 |
2177 if (!syncable::ModelTypeBitSetFromString( | 2301 if (!syncable::ModelTypeBitSetFromString( |
2178 notification_data.service_specific_data, | 2302 notification_data.service_specific_data, |
2179 &model_types)) { | 2303 &model_types)) { |
2180 LOG(DFATAL) << "Could not extract model types from server data."; | 2304 // LOG(DFATAL) << "Could not extract model types from server data."; |
2181 model_types.set(); | 2305 model_types.set(); |
2182 } | 2306 } |
2183 } else if (notification_data.service_url.empty() || | 2307 } else if (notification_data.service_url.empty() || |
2184 (notification_data.service_url == | 2308 (notification_data.service_url == |
2185 browser_sync::kSyncLegacyServiceUrl) || | 2309 browser_sync::kSyncLegacyServiceUrl) || |
2186 (notification_data.service_url == | 2310 (notification_data.service_url == |
2187 browser_sync::kSyncServiceUrl)) { | 2311 browser_sync::kSyncServiceUrl)) { |
2188 VLOG(1) << "Sync received P2P notification."; | 2312 VLOG(1) << "Sync received P2P notification."; |
2189 | 2313 |
2190 // Catch for sync integration tests (uses p2p). Just set all datatypes. | 2314 // Catch for sync integration tests (uses p2p). Just set all datatypes. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2273 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 2397 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
2274 return data_->GetUserShare(); | 2398 return data_->GetUserShare(); |
2275 } | 2399 } |
2276 | 2400 |
2277 bool SyncManager::HasUnsyncedItems() const { | 2401 bool SyncManager::HasUnsyncedItems() const { |
2278 sync_api::ReadTransaction trans(GetUserShare()); | 2402 sync_api::ReadTransaction trans(GetUserShare()); |
2279 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 2403 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
2280 } | 2404 } |
2281 | 2405 |
2282 } // namespace sync_api | 2406 } // namespace sync_api |
OLD | NEW |