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_TEST_TEST_ENTRY_FACTORY_H_ 6 #define SYNC_TEST_TEST_ENTRY_FACTORY_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "sync/internal_api/public/base/model_type.h" 12 #include "sync/protocol/sync.pb.h" 13 14 namespace syncer { 15 16 namespace syncable { 17 class Directory; 18 class Id; 19 } 20 21 class TestEntryFactory { 22 public: 23 explicit TestEntryFactory(syncable::Directory* dir); 24 ~TestEntryFactory(); 25 26 // Create a new unapplied folder node with a parent. 27 int64 CreateUnappliedNewItemWithParent( 28 const std::string& item_id, 29 const sync_pb::EntitySpecifics& specifics, 30 const std::string& parent_id); 31 32 int64 CreateUnappliedNewBookmarkItemWithParent( 33 const std::string& item_id, 34 const sync_pb::EntitySpecifics& specifics, 35 const std::string& parent_id); 36 37 // Create a new unapplied update without a parent. 38 int64 CreateUnappliedNewItem(const std::string& item_id, 39 const sync_pb::EntitySpecifics& specifics, 40 bool is_unique); 41 42 // Create an unsynced unique_client_tag item in the database. If item_id is a 43 // local ID, it will be treated as a create-new. Otherwise, if it's a server 44 // ID, we'll fake the server data so that it looks like it exists on the 45 // server. Returns the methandle of the created item in |metahandle_out| if 46 // not NULL. 47 void CreateUnsyncedItem(const syncable::Id& item_id, 48 const syncable::Id& parent_id, 49 const std::string& name, 50 bool is_folder, 51 ModelType model_type, 52 int64* metahandle_out); 53 54 // Creates a bookmark that is both unsynced an an unapplied update. Returns 55 // the metahandle of the created item. 56 int64 CreateUnappliedAndUnsyncedBookmarkItem(const std::string& name); 57 58 // Creates a unique_client_tag item that has neither IS_UNSYNED or 59 // IS_UNAPPLIED_UPDATE. The item is known to both the server and client. 60 // Returns the metahandle of the created item. 61 int64 CreateSyncedItem(const std::string& name, 62 ModelType model_type, bool is_folder); 63 64 // Creates a root node that IS_UNAPPLIED. Smiilar to what one would find in 65 // the database between the ProcessUpdates of an initial datatype configure 66 // cycle and the ApplyUpdates step of the same sync cycle. 67 int64 CreateUnappliedRootNode(ModelType model_type); 68 69 // Looks up the item referenced by |meta_handle|. If successful, overwrites 70 // the server specifics with |specifics|, sets 71 // IS_UNAPPLIED_UPDATES/IS_UNSYNCED appropriately, and returns true. 72 // Else, return false. 73 bool SetServerSpecificsForItem(int64 meta_handle, 74 const sync_pb::EntitySpecifics specifics); 75 76 // Looks up the item referenced by |meta_handle|. If successful, overwrites 77 // the local specifics with |specifics|, sets 78 // IS_UNAPPLIED_UPDATES/IS_UNSYNCED appropriately, and returns true. 79 // Else, return false. 80 bool SetLocalSpecificsForItem(int64 meta_handle, 81 const sync_pb::EntitySpecifics specifics); 82 83 // Looks up the item referenced by |meta_handle|. If successful, stores 84 // the server specifics into |specifics| and returns true. Else, return false. 85 const sync_pb::EntitySpecifics& GetServerSpecificsForItem( 86 int64 meta_handle) const; 87 88 // Looks up the item referenced by |meta_handle|. If successful, stores 89 // the local specifics into |specifics| and returns true. Else, return false. 90 const sync_pb::EntitySpecifics& GetLocalSpecificsForItem( 91 int64 meta_handle) const; 92 93 // Getters for IS_UNSYNCED and IS_UNAPPLIED_UPDATE bit fields. 94 bool GetIsUnsyncedForItem(int64 meta_handle) const; 95 bool GetIsUnappliedForItem(int64 meta_handle) const; 96 97 int64 GetNextRevision(); 98 99 private: 100 syncable::Directory* directory_; 101 int64 next_revision_; 102 103 DISALLOW_COPY_AND_ASSIGN(TestEntryFactory); 104 }; 105 106 } // namespace syncer 107 108 #endif // SYNC_TEST_TEST_ENTRY_FACTORY_H_ 109