blob: a816e76e90c86ce5fbabca48a583e32221b21431 [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include <memory>
#include <string>
#include "components/sync/engine/non_blocking_sync_common.h"
#include "components/sync/model/metadata_change_list.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync/protocol/model_type_state.pb.h"
namespace syncer {
// A MetadataChangeList base class that stores changes in member fields.
// There are no accessors; TransferChangesTo() can be used to forward all
// changes to another instance.
class InMemoryMetadataChangeList : public MetadataChangeList {
~InMemoryMetadataChangeList() override;
// Moves all currently accumulated changes into |*other|, resetting the state
// of |*this| to the default, empty state.
void TransferChangesTo(MetadataChangeList* other);
// MetadataChangeList implementation.
void UpdateModelTypeState(
const sync_pb::ModelTypeState& model_type_state) override;
void ClearModelTypeState() override;
void UpdateMetadata(const std::string& storage_key,
const sync_pb::EntityMetadata& metadata) override;
void ClearMetadata(const std::string& storage_key) override;
enum ChangeType { UPDATE, CLEAR };
struct MetadataChange {
ChangeType type;
sync_pb::EntityMetadata metadata;
struct ModelTypeStateChange {
ChangeType type;
sync_pb::ModelTypeState state;
std::map<std::string, MetadataChange> metadata_changes_;
std::unique_ptr<ModelTypeStateChange> state_change_;
} // namespace syncer