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 #ifndef SYNC_API_SYNC_CHANGE_H_ | 5 #ifndef SYNC_API_SYNC_CHANGE_H_ |
6 #define SYNC_API_SYNC_CHANGE_H_ | 6 #define SYNC_API_SYNC_CHANGE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <iosfwd> | 9 #include <iosfwd> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
| 13 #include "base/location.h" |
13 #include "sync/api/sync_data.h" | 14 #include "sync/api/sync_data.h" |
14 | 15 |
15 namespace syncer { | 16 namespace syncer { |
16 | 17 |
17 // A SyncChange object reflects a change to a piece of synced data. The change | 18 // A SyncChange object reflects a change to a piece of synced data. The change |
18 // can be either a delete, add, or an update. All data relevant to the change | 19 // can be either a delete, add, or an update. All data relevant to the change |
19 // is encapsulated within the SyncChange, which, once created, is immutable. | 20 // is encapsulated within the SyncChange, which, once created, is immutable. |
20 // Note: it is safe and cheap to pass these by value or make copies, as they do | 21 // Note: it is safe and cheap to pass these by value or make copies, as they do |
21 // not create deep copies of their internal data. | 22 // not create deep copies of their internal data. |
22 class SyncChange { | 23 class SyncChange { |
23 public: | 24 public: |
24 enum SyncChangeType { | 25 enum SyncChangeType { |
25 ACTION_INVALID, | 26 ACTION_INVALID, |
26 ACTION_ADD, | 27 ACTION_ADD, |
27 ACTION_UPDATE, | 28 ACTION_UPDATE, |
28 ACTION_DELETE | 29 ACTION_DELETE |
29 }; | 30 }; |
30 | 31 |
31 // Default constructor creates an invalid change. | 32 // Default constructor creates an invalid change. |
32 SyncChange(); | 33 SyncChange(); |
33 // Create a new change with the specified sync data. | 34 // Create a new change with the specified sync data. |
34 SyncChange(SyncChangeType change_type, const SyncData& sync_data); | 35 SyncChange( |
| 36 const tracked_objects::Location& from_here, |
| 37 SyncChangeType change_type, |
| 38 const SyncData& sync_data); |
35 ~SyncChange(); | 39 ~SyncChange(); |
36 | 40 |
37 // Copy constructor and assignment operator welcome. | 41 // Copy constructor and assignment operator welcome. |
38 | 42 |
39 // Whether this change is valid. This must be true before attempting to access | 43 // Whether this change is valid. This must be true before attempting to access |
40 // the data. | 44 // the data. |
41 // Deletes: Requires valid tag when going to the syncer. Requires valid | 45 // Deletes: Requires valid tag when going to the syncer. Requires valid |
42 // specifics when coming from the syncer. | 46 // specifics when coming from the syncer. |
43 // Adds, Updates: Require valid tag and specifics when going to the syncer. | 47 // Adds, Updates: Require valid tag and specifics when going to the syncer. |
44 // Require only valid specifics when coming from the syncer. | 48 // Require only valid specifics when coming from the syncer. |
45 bool IsValid() const; | 49 bool IsValid() const; |
46 | 50 |
47 // Getters. | 51 // Getters. |
48 SyncChangeType change_type() const; | 52 SyncChangeType change_type() const; |
49 SyncData sync_data() const; | 53 SyncData sync_data() const; |
50 | 54 |
51 // Returns a string representation of |change_type|. | 55 // Returns a string representation of |change_type|. |
52 static std::string ChangeTypeToString(SyncChangeType change_type); | 56 static std::string ChangeTypeToString(SyncChangeType change_type); |
53 | 57 |
54 // Returns a string representation of the entire object. Used for gmock | 58 // Returns a string representation of the entire object. Used for gmock |
55 // printing method, PrintTo. | 59 // printing method, PrintTo. |
56 std::string ToString() const; | 60 std::string ToString() const; |
57 | 61 |
58 private: | 62 private: |
| 63 tracked_objects::Location location_; |
| 64 |
59 SyncChangeType change_type_; | 65 SyncChangeType change_type_; |
60 | 66 |
61 // An immutable container for the data of this SyncChange. Whenever | 67 // An immutable container for the data of this SyncChange. Whenever |
62 // SyncChanges are copied, they copy references to this data. | 68 // SyncChanges are copied, they copy references to this data. |
63 SyncData sync_data_; | 69 SyncData sync_data_; |
64 }; | 70 }; |
65 | 71 |
66 // gmock printer helper. | 72 // gmock printer helper. |
67 void PrintTo(const SyncChange& sync_change, std::ostream* os); | 73 void PrintTo(const SyncChange& sync_change, std::ostream* os); |
68 | 74 |
69 } // namespace syncer | 75 } // namespace syncer |
70 | 76 |
71 #endif // SYNC_API_SYNC_CHANGE_H_ | 77 #endif // SYNC_API_SYNC_CHANGE_H_ |
OLD | NEW |