OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "components/sync/api/sync_change.h" | |
6 | |
7 #include <ostream> | |
8 | |
9 namespace syncer { | |
10 | |
11 SyncChange::SyncChange() : change_type_(ACTION_INVALID) {} | |
12 | |
13 SyncChange::SyncChange(const tracked_objects::Location& from_here, | |
14 SyncChangeType change_type, | |
15 const SyncData& sync_data) | |
16 : location_(from_here), change_type_(change_type), sync_data_(sync_data) { | |
17 DCHECK(IsValid()); | |
18 } | |
19 | |
20 SyncChange::~SyncChange() {} | |
21 | |
22 bool SyncChange::IsValid() const { | |
23 if (change_type_ == ACTION_INVALID || !sync_data_.IsValid()) | |
24 return false; | |
25 | |
26 // Data from the syncer must always have valid specifics. | |
27 if (!sync_data_.IsLocal()) | |
28 return IsRealDataType(sync_data_.GetDataType()); | |
29 | |
30 // Local changes must always have a tag and specify a valid datatype. | |
31 if (SyncDataLocal(sync_data_).GetTag().empty() || | |
32 !IsRealDataType(sync_data_.GetDataType())) { | |
33 return false; | |
34 } | |
35 | |
36 // Adds and updates must have a non-unique-title. | |
37 if (change_type_ == ACTION_ADD || change_type_ == ACTION_UPDATE) | |
38 return (!sync_data_.GetTitle().empty()); | |
39 | |
40 return true; | |
41 } | |
42 | |
43 SyncChange::SyncChangeType SyncChange::change_type() const { | |
44 return change_type_; | |
45 } | |
46 | |
47 SyncData SyncChange::sync_data() const { | |
48 return sync_data_; | |
49 } | |
50 | |
51 tracked_objects::Location SyncChange::location() const { | |
52 return location_; | |
53 } | |
54 | |
55 // static | |
56 std::string SyncChange::ChangeTypeToString(SyncChangeType change_type) { | |
57 switch (change_type) { | |
58 case ACTION_INVALID: | |
59 return "ACTION_INVALID"; | |
60 case ACTION_ADD: | |
61 return "ACTION_ADD"; | |
62 case ACTION_UPDATE: | |
63 return "ACTION_UPDATE"; | |
64 case ACTION_DELETE: | |
65 return "ACTION_DELETE"; | |
66 default: | |
67 NOTREACHED(); | |
68 } | |
69 return std::string(); | |
70 } | |
71 | |
72 std::string SyncChange::ToString() const { | |
73 return "{ " + location_.ToString() + ", changeType: " + | |
74 ChangeTypeToString(change_type_) + ", syncData: " + | |
75 sync_data_.ToString() + "}"; | |
76 } | |
77 | |
78 void PrintTo(const SyncChange& sync_change, std::ostream* os) { | |
79 *os << sync_change.ToString(); | |
80 } | |
81 | |
82 } // namespace syncer | |
OLD | NEW |