OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sync/api/sync_change.h" | 5 #include "sync/api/sync_change.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 | 8 |
9 namespace syncer { | 9 namespace syncer { |
10 | 10 |
11 SyncChange::SyncChange() : change_type_(ACTION_INVALID) { | 11 SyncChange::SyncChange() : change_type_(ACTION_INVALID) { |
12 } | 12 } |
13 | 13 |
14 SyncChange::SyncChange( | 14 SyncChange::SyncChange( |
15 const tracked_objects::Location& from_here, | 15 const tracked_objects::Location& from_here, |
16 SyncChangeType change_type, | 16 SyncChangeType change_type, |
17 const SyncData& sync_data) | 17 const SyncData& sync_data) |
18 : location_(from_here), | 18 : location_(from_here), |
19 change_type_(change_type), | 19 change_type_(change_type), |
20 sync_data_(sync_data) { | 20 sync_data_(sync_data) { |
21 DCHECK(IsValid()); | 21 DCHECK(IsValid()); |
22 } | 22 } |
23 | 23 |
24 SyncChange::~SyncChange() {} | 24 SyncChange::~SyncChange() {} |
25 | 25 |
26 bool SyncChange::IsValid() const { | 26 bool SyncChange::IsValid() const { |
27 if (change_type_ == ACTION_INVALID || !sync_data_.IsValid()) | 27 if (change_type_ == ACTION_INVALID || !sync_data_.IsValid()) |
28 return false; | 28 return false; |
29 | 29 |
30 // Context changes must not have valid specifics. | |
31 if (change_type_ == CONTEXT_UPDATE && | |
32 GetModelTypeFromSpecifics(sync_data_.GetSpecifics()) != UNSPECIFIED) { | |
33 return false; | |
34 } | |
35 | |
30 // Data from the syncer must always have valid specifics. | 36 // Data from the syncer must always have valid specifics. |
31 if (!sync_data_.IsLocal()) | 37 if (!sync_data_.IsLocal()) |
32 return IsRealDataType(sync_data_.GetDataType()); | 38 return IsRealDataType(sync_data_.GetDataType()); |
33 | 39 |
34 // Local changes must always have a tag and specify a valid datatype. | 40 // Local changes must always have a tag and specify a valid datatype. |
35 if (sync_data_.GetTag().empty() || | 41 if (sync_data_.GetTag().empty() || |
36 !IsRealDataType(sync_data_.GetDataType())) { | 42 !IsRealDataType(sync_data_.GetDataType())) { |
37 return false; | 43 return false; |
38 } | 44 } |
39 | 45 |
(...skipping 20 matching lines...) Expand all Loading... | |
60 std::string SyncChange::ChangeTypeToString(SyncChangeType change_type) { | 66 std::string SyncChange::ChangeTypeToString(SyncChangeType change_type) { |
61 switch (change_type) { | 67 switch (change_type) { |
62 case ACTION_INVALID: | 68 case ACTION_INVALID: |
63 return "ACTION_INVALID"; | 69 return "ACTION_INVALID"; |
64 case ACTION_ADD: | 70 case ACTION_ADD: |
65 return "ACTION_ADD"; | 71 return "ACTION_ADD"; |
66 case ACTION_UPDATE: | 72 case ACTION_UPDATE: |
67 return "ACTION_UPDATE"; | 73 return "ACTION_UPDATE"; |
68 case ACTION_DELETE: | 74 case ACTION_DELETE: |
69 return "ACTION_DELETE"; | 75 return "ACTION_DELETE"; |
70 default: | 76 default: |
maniscalco
2014/03/31 23:59:16
Needs to be updated?
Nicolas Zea
2014/04/02 18:34:36
Woops, good catch, done.
| |
71 NOTREACHED(); | 77 NOTREACHED(); |
72 } | 78 } |
73 return std::string(); | 79 return std::string(); |
74 } | 80 } |
75 | 81 |
76 std::string SyncChange::ToString() const { | 82 std::string SyncChange::ToString() const { |
77 return "{ " + location_.ToString() + ", changeType: " + | 83 return "{ " + location_.ToString() + ", changeType: " + |
78 ChangeTypeToString(change_type_) + ", syncData: " + | 84 ChangeTypeToString(change_type_) + ", syncData: " + |
79 sync_data_.ToString() + "}"; | 85 sync_data_.ToString() + "}"; |
80 } | 86 } |
81 | 87 |
82 void PrintTo(const SyncChange& sync_change, std::ostream* os) { | 88 void PrintTo(const SyncChange& sync_change, std::ostream* os) { |
83 *os << sync_change.ToString(); | 89 *os << sync_change.ToString(); |
84 } | 90 } |
85 | 91 |
86 } // namespace syncer | 92 } // namespace syncer |
OLD | NEW |