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