1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sync/api/sync_change.h"
11 SyncChange::SyncChange() : change_type_(ACTION_INVALID) {
14 SyncChange::SyncChange(
15 const tracked_objects::Location& from_here,
16 SyncChangeType change_type,
17 const SyncData& sync_data)
18 : location_(from_here),
19 change_type_(change_type),
20 sync_data_(sync_data) {
24 SyncChange::~SyncChange() {}
26 bool SyncChange::IsValid() const {
27 if (change_type_ == ACTION_INVALID || !sync_data_.IsValid())
30 // Data from the syncer must always have valid specifics.
31 if (!sync_data_.IsLocal())
32 return IsRealDataType(sync_data_.GetDataType());
34 // Local changes must always have a tag and specify a valid datatype.
35 if (sync_data_.GetTag().empty() ||
36 !IsRealDataType(sync_data_.GetDataType())) {
40 // Adds and updates must have a non-unique-title.
41 if (change_type_ == ACTION_ADD || change_type_ == ACTION_UPDATE)
42 return (!sync_data_.GetTitle().empty());
47 SyncChange::SyncChangeType SyncChange::change_type() const {
51 SyncData SyncChange::sync_data() const {
55 tracked_objects::Location SyncChange::location() const {
60 std::string SyncChange::ChangeTypeToString(SyncChangeType change_type) {
61 switch (change_type) {
63 return "ACTION_INVALID";
67 return "ACTION_UPDATE";
69 return "ACTION_DELETE";
76 std::string SyncChange::ToString() const {
77 return "{ " + location_.ToString() + ", changeType: " +
78 ChangeTypeToString(change_type_) + ", syncData: " +
79 sync_data_.ToString() + "}";
82 void PrintTo(const SyncChange& sync_change, std::ostream* os) {
83 *os << sync_change.ToString();