Chromium Code Reviews| Index: sync/internal_api/sync_manager_impl.cc |
| diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc |
| index 28d6b3c2f4714fb753505b0fc1439e6b85b49640..c0fc303764abf199768d6a74e12430aeb6ac6220 100644 |
| --- a/sync/internal_api/sync_manager_impl.cc |
| +++ b/sync/internal_api/sync_manager_impl.cc |
| @@ -499,17 +499,26 @@ void SyncManagerImpl::Init( |
| true, InitialSyncEndedTypes())); |
| } |
| -void SyncManagerImpl::RefreshNigori(const std::string& chrome_version, |
| - const base::Closure& done_callback) { |
| +void SyncManagerImpl::InitialProcessMetadata( |
| + const std::string& chrome_version, |
| + const base::Closure& done_callback) { |
| DCHECK(initialized_); |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - GetSessionName( |
| - blocking_task_runner_, |
| - base::Bind( |
| - &SyncManagerImpl::UpdateCryptographerAndNigoriCallback, |
| - weak_ptr_factory_.GetWeakPtr(), |
| - chrome_version, |
| - done_callback)); |
| + GetSessionName(blocking_task_runner_, |
| + base::Bind( |
| + &SyncManagerImpl::InitialProcessMetadataContinuation, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + chrome_version, |
| + done_callback)); |
| +} |
| + |
| +void SyncManagerImpl::InitialProcessMetadataContinuation( |
|
rlarocque
2012/08/11 01:31:52
This would be a great place to put the code that c
|
| + const std::string& chrome_version, |
| + const base::Closure& done_callback, |
| + const std::string& session_name) { |
| + UpdateCryptographerAndNigori(); |
| + UpdateDeviceInformation(chrome_version, session_name); |
| + done_callback.Run(); |
| } |
| void SyncManagerImpl::UpdateNigoriEncryptionState( |
| @@ -546,14 +555,8 @@ void SyncManagerImpl::UpdateNigoriEncryptionState( |
| nigori_node->SetNigoriSpecifics(nigori); |
| } |
| -void SyncManagerImpl::UpdateCryptographerAndNigoriCallback( |
| - const std::string& chrome_version, |
| - const base::Closure& done_callback, |
| - const std::string& session_name) { |
| - if (!directory()->initial_sync_ended_for_type(NIGORI)) { |
| - done_callback.Run(); // Should only happen during first time sync. |
| - return; |
| - } |
| +void SyncManagerImpl::UpdateCryptographerAndNigori() { |
| + DCHECK(directory()->initial_sync_ended_for_type(NIGORI)); |
| bool success = false; |
| { |
| @@ -573,41 +576,6 @@ void SyncManagerImpl::UpdateCryptographerAndNigoriCallback( |
| pending_keys)); |
| } |
| - // Add or update device information. |
| - bool contains_this_device = false; |
| - for (int i = 0; i < nigori.device_information_size(); ++i) { |
| - const sync_pb::DeviceInformation& device_information = |
| - nigori.device_information(i); |
| - if (device_information.cache_guid() == directory()->cache_guid()) { |
| - // Update the version number in case it changed due to an update. |
| - if (device_information.chrome_version() != chrome_version) { |
| - sync_pb::DeviceInformation* mutable_device_information = |
| - nigori.mutable_device_information(i); |
| - mutable_device_information->set_chrome_version( |
| - chrome_version); |
| - } |
| - contains_this_device = true; |
| - } |
| - } |
| - |
| - if (!contains_this_device) { |
| - sync_pb::DeviceInformation* device_information = |
| - nigori.add_device_information(); |
| - device_information->set_cache_guid(directory()->cache_guid()); |
| -#if defined(OS_CHROMEOS) |
| - device_information->set_platform("ChromeOS"); |
| -#elif defined(OS_LINUX) |
| - device_information->set_platform("Linux"); |
| -#elif defined(OS_MACOSX) |
| - device_information->set_platform("Mac"); |
| -#elif defined(OS_WIN) |
| - device_information->set_platform("Windows"); |
| -#endif |
| - device_information->set_name(session_name); |
| - device_information->set_chrome_version(chrome_version); |
| - } |
| - // Disabled to avoid nigori races. TODO(zea): re-enable. crbug.com/122837 |
| - // node.SetNigoriSpecifics(nigori); |
| // Make sure the nigori node has the up to date encryption info. |
| UpdateNigoriEncryptionState(cryptographer, &node); |
| @@ -623,7 +591,58 @@ void SyncManagerImpl::UpdateCryptographerAndNigoriCallback( |
| if (success) |
| RefreshEncryption(); |
| - done_callback.Run(); |
| +} |
| + |
| +void SyncManagerImpl::UpdateDeviceInformation(const std::string& chrome_version, |
| + const std::string& session_name) { |
| + DCHECK(!directory()->cache_guid().empty()); |
| + |
| + WriteTransaction trans(FROM_HERE, GetUserShare()); |
| + |
| + WriteNode node(&trans); |
| + BaseNode::InitByLookupResult lookup_result = |
| + node.InitByClientTagLookup(PER_DEVICE_METADATA, |
| + directory()->cache_guid()); |
| + if (lookup_result == BaseNode::INIT_OK) { |
| + // Found an existing node. Update its version, if necessary. |
| + sync_pb::PerDeviceSpecifics specifics = node.GetPerDeviceSpecifics(); |
| + if (specifics.device_information().chrome_version() != chrome_version) { |
| + specifics.mutable_device_information()->set_chrome_version( |
| + chrome_version); |
| + node.SetPerDeviceSpecifics(specifics); |
| + } |
| + } else { |
| + ReadNode type_root(&trans); |
| + BaseNode::InitByLookupResult type_root_lookup_result = |
| + type_root.InitByTagLookup(ModelTypeToRootTag(PER_DEVICE_METADATA)); |
| + DCHECK(type_root_lookup_result == BaseNode::INIT_OK); |
| + |
| + WriteNode new_node(&trans); |
| + WriteNode::InitUniqueByCreationResult create_result = |
| + new_node.InitUniqueByCreation(PER_DEVICE_METADATA, |
| + type_root, |
| + directory()->cache_guid()); |
| + DCHECK(create_result == WriteNode::INIT_SUCCESS); |
| + sync_pb::PerDeviceSpecifics per_device_specifics = |
| + new_node.GetPerDeviceSpecifics(); |
| + sync_pb::DeviceInformation* device_information = |
| + per_device_specifics.mutable_device_information(); |
| + |
| + device_information->set_cache_guid(directory()->cache_guid()); |
| + device_information->set_name(session_name); |
| + device_information->set_chrome_version(chrome_version); |
| + |
| +#if defined(OS_CHROMEOS) |
| + device_information->set_platform("ChromeOS"); |
| +#elif defined(OS_LINUX) |
| + device_information->set_platform("Linux"); |
| +#elif defined(OS_MACOSX) |
| + device_information->set_platform("Mac"); |
| +#elif defined(OS_WIN) |
| + device_information->set_platform("Windows"); |
| +#endif |
| + new_node.SetPerDeviceSpecifics(per_device_specifics); |
| + } |
| } |
| void SyncManagerImpl::NotifyCryptographerState(Cryptographer * cryptographer) { |
| @@ -1143,7 +1162,7 @@ void SyncManagerImpl::ReEncryptEverything( |
| ModelTypeSet encrypted_types = GetEncryptedTypes(trans); |
| for (ModelTypeSet::Iterator iter = encrypted_types.First(); |
| iter.Good(); iter.Inc()) { |
| - if (iter.Get() == PASSWORDS || iter.Get() == NIGORI) |
| + if (iter.Get() == PASSWORDS || IsControlType(iter.Get())) |
| continue; // These types handle encryption differently. |
| ReadNode type_root(trans); |