[MemSheriff] Exclude flaky browser_tests test
[chromium-blink-merge.git] / sync / api / sync_change.cc
blob32b4129a1d859ec64b130a76f3f5d331f832bcff
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"
7 #include <ostream>
9 namespace syncer {
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) {
21 DCHECK(IsValid());
24 SyncChange::~SyncChange() {}
26 bool SyncChange::IsValid() const {
27 if (change_type_ == ACTION_INVALID || !sync_data_.IsValid())
28 return false;
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 (SyncDataLocal(sync_data_).GetTag().empty() ||
36 !IsRealDataType(sync_data_.GetDataType())) {
37 return false;
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());
44 return true;
47 SyncChange::SyncChangeType SyncChange::change_type() const {
48 return change_type_;
51 SyncData SyncChange::sync_data() const {
52 return sync_data_;
55 tracked_objects::Location SyncChange::location() const {
56 return location_;
59 // static
60 std::string SyncChange::ChangeTypeToString(SyncChangeType change_type) {
61 switch (change_type) {
62 case ACTION_INVALID:
63 return "ACTION_INVALID";
64 case ACTION_ADD:
65 return "ACTION_ADD";
66 case ACTION_UPDATE:
67 return "ACTION_UPDATE";
68 case ACTION_DELETE:
69 return "ACTION_DELETE";
70 default:
71 NOTREACHED();
73 return std::string();
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();
86 } // namespace syncer