This source file includes following definitions.
- ApplyControlDataUpdates
- ApplyNigoriUpdate
- ApplyControlUpdate
#include "sync/engine/apply_control_data_updates.h"
#include "base/metrics/histogram.h"
#include "sync/engine/conflict_resolver.h"
#include "sync/engine/conflict_util.h"
#include "sync/engine/syncer_util.h"
#include "sync/syncable/directory.h"
#include "sync/syncable/mutable_entry.h"
#include "sync/syncable/nigori_handler.h"
#include "sync/syncable/nigori_util.h"
#include "sync/syncable/syncable_write_transaction.h"
#include "sync/util/cryptographer.h"
namespace syncer {
using syncable::GET_BY_SERVER_TAG;
using syncable::IS_UNAPPLIED_UPDATE;
using syncable::IS_UNSYNCED;
using syncable::SERVER_SPECIFICS;
using syncable::SPECIFICS;
using syncable::SYNCER;
void ApplyControlDataUpdates(syncable::Directory* dir) {
syncable::WriteTransaction trans(FROM_HERE, SYNCER, dir);
std::vector<int64> handles;
dir->GetUnappliedUpdateMetaHandles(
&trans, ToFullModelTypeSet(ControlTypes()), &handles);
ModelTypeSet control_types = ControlTypes();
for (ModelTypeSet::Iterator iter = control_types.First(); iter.Good();
iter.Inc()) {
syncable::MutableEntry entry(&trans,
syncable::GET_BY_SERVER_TAG,
ModelTypeToRootTag(iter.Get()));
if (!entry.good())
continue;
if (!entry.GetIsUnappliedUpdate())
continue;
ModelType type = entry.GetServerModelType();
if (type == NIGORI) {
ApplyNigoriUpdate(&trans,
&entry,
dir->GetCryptographer(&trans));
} else {
ApplyControlUpdate(&trans,
&entry,
dir->GetCryptographer(&trans));
}
}
for (std::vector<int64>::const_iterator iter = handles.begin();
iter != handles.end(); ++iter) {
syncable::MutableEntry entry(&trans, syncable::GET_BY_HANDLE, *iter);
CHECK(entry.good());
ModelType type = entry.GetServerModelType();
CHECK(ControlTypes().Has(type));
if (!entry.GetUniqueServerTag().empty()) {
DCHECK(!entry.GetIsUnappliedUpdate());
continue;
}
ApplyControlUpdate(&trans,
&entry,
dir->GetCryptographer(&trans));
}
}
void ApplyNigoriUpdate(syncable::WriteTransaction* const trans,
syncable::MutableEntry* const entry,
Cryptographer* cryptographer) {
DCHECK(entry->GetIsUnappliedUpdate());
const sync_pb::NigoriSpecifics& nigori =
entry->GetServerSpecifics().nigori();
trans->directory()->GetNigoriHandler()->ApplyNigoriUpdate(nigori, trans);
if (cryptographer->is_ready()) {
DVLOG(1) << "Received new nigori, encrypting unsynced changes.";
syncable::ProcessUnsyncedChangesForEncryption(trans);
}
if (!entry->GetIsUnsynced()) {
UpdateLocalDataFromServerData(trans, entry);
} else {
const sync_pb::EntitySpecifics& server_specifics =
entry->GetServerSpecifics();
const sync_pb::NigoriSpecifics& server_nigori = server_specifics.nigori();
const sync_pb::EntitySpecifics& local_specifics =
entry->GetSpecifics();
const sync_pb::NigoriSpecifics& local_nigori = local_specifics.nigori();
sync_pb::EntitySpecifics new_specifics = entry->GetServerSpecifics();
sync_pb::NigoriSpecifics* new_nigori = new_specifics.mutable_nigori();
if (cryptographer->is_ready()) {
if (local_nigori.has_passphrase_type() &&
server_nigori.has_passphrase_type()) {
if (server_nigori.passphrase_type() ==
sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE &&
local_nigori.passphrase_type() !=
sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE) {
DCHECK(local_nigori.passphrase_type() ==
sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE ||
local_nigori.passphrase_type() ==
sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE);
new_nigori->CopyFrom(local_nigori);
cryptographer->GetKeys(new_nigori->mutable_encryption_keybag());
}
} else if (!local_nigori.has_passphrase_type() &&
!server_nigori.has_passphrase_type()) {
new_nigori->set_keybag_is_frozen(local_nigori.keybag_is_frozen());
cryptographer->GetKeys(new_nigori->mutable_encryption_keybag());
} else if (local_nigori.has_passphrase_type()) {
new_nigori->CopyFrom(local_nigori);
cryptographer->GetKeys(new_nigori->mutable_encryption_keybag());
}
}
trans->directory()->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes(
new_nigori,
trans);
entry->PutSpecifics(new_specifics);
DVLOG(1) << "Resolving simple conflict, merging nigori nodes: "
<< entry;
conflict_util::OverwriteServerChanges(entry);
UMA_HISTOGRAM_ENUMERATION("Sync.ResolveSimpleConflict",
ConflictResolver::NIGORI_MERGE,
ConflictResolver::CONFLICT_RESOLUTION_SIZE);
}
}
void ApplyControlUpdate(syncable::WriteTransaction* const trans,
syncable::MutableEntry* const entry,
Cryptographer* cryptographer) {
DCHECK_NE(entry->GetServerModelType(), NIGORI);
DCHECK(entry->GetIsUnappliedUpdate());
if (entry->GetIsUnsynced()) {
DVLOG(1) << "Ignoring local changes for control update.";
conflict_util::IgnoreLocalChanges(entry);
UMA_HISTOGRAM_ENUMERATION("Sync.ResolveSimpleConflict",
ConflictResolver::OVERWRITE_LOCAL,
ConflictResolver::CONFLICT_RESOLUTION_SIZE);
}
UpdateAttemptResponse response = AttemptToUpdateEntry(
trans, entry, cryptographer);
DCHECK_EQ(SUCCESS, response);
}
}