1 // Copyright 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 #ifndef SYNC_API_SYNC_CHANGE_H_
6 #define SYNC_API_SYNC_CHANGE_H_
12 #include "base/location.h"
13 #include "sync/api/sync_data.h"
14 #include "sync/base/sync_export.h"
18 // A SyncChange object reflects a change to a piece of synced data. The change
19 // can be either a delete, add, or an update. All data relevant to the change
20 // is encapsulated within the SyncChange, which, once created, is immutable.
21 // Note: it is safe and cheap to pass these by value or make copies, as they do
22 // not create deep copies of their internal data.
23 class SYNC_EXPORT SyncChange
{
32 // Default constructor creates an invalid change.
34 // Create a new change with the specified sync data.
36 const tracked_objects::Location
& from_here
,
37 SyncChangeType change_type
,
38 const SyncData
& sync_data
);
41 // Copy constructor and assignment operator welcome.
43 // Whether this change is valid. This must be true before attempting to access
45 // Deletes: Requires valid tag when going to the syncer. Requires valid
46 // specifics when coming from the syncer.
47 // Adds, Updates: Require valid tag and specifics when going to the syncer.
48 // Require only valid specifics when coming from the syncer.
52 SyncChangeType
change_type() const;
53 SyncData
sync_data() const;
54 tracked_objects::Location
location() const;
56 // Returns a string representation of |change_type|.
57 static std::string
ChangeTypeToString(SyncChangeType change_type
);
59 // Returns a string representation of the entire object. Used for gmock
60 // printing method, PrintTo.
61 std::string
ToString() const;
64 tracked_objects::Location location_
;
66 SyncChangeType change_type_
;
68 // An immutable container for the data of this SyncChange. Whenever
69 // SyncChanges are copied, they copy references to this data.
73 // gmock printer helper.
74 SYNC_EXPORT
void PrintTo(const SyncChange
& sync_change
, std::ostream
* os
);
78 #endif // SYNC_API_SYNC_CHANGE_H_