Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: sync/api/sync_change.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/api/sync_change.h ('k') | sync/api/sync_change_processor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "sync/api/sync_change.h"
6
7 #include <ostream>
8
9 namespace syncer {
10
11 SyncChange::SyncChange() : change_type_(ACTION_INVALID) {
12 }
13
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());
22 }
23
24 SyncChange::~SyncChange() {}
25
26 bool SyncChange::IsValid() const {
27 if (change_type_ == ACTION_INVALID || !sync_data_.IsValid())
28 return false;
29
30 // Data from the syncer must always have valid specifics.
31 if (!sync_data_.IsLocal())
32 return IsRealDataType(sync_data_.GetDataType());
33
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;
38 }
39
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());
43
44 return true;
45 }
46
47 SyncChange::SyncChangeType SyncChange::change_type() const {
48 return change_type_;
49 }
50
51 SyncData SyncChange::sync_data() const {
52 return sync_data_;
53 }
54
55 tracked_objects::Location SyncChange::location() const {
56 return location_;
57 }
58
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();
72 }
73 return std::string();
74 }
75
76 std::string SyncChange::ToString() const {
77 return "{ " + location_.ToString() + ", changeType: " +
78 ChangeTypeToString(change_type_) + ", syncData: " +
79 sync_data_.ToString() + "}";
80 }
81
82 void PrintTo(const SyncChange& sync_change, std::ostream* os) {
83 *os << sync_change.ToString();
84 }
85
86 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/api/sync_change.h ('k') | sync/api/sync_change_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698