Chromium Code Reviews| 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_TEST_TEST_ENTRY_FACTORY_H_ | 5 #ifndef SYNC_TEST_TEST_ENTRY_FACTORY_H_ |
| 6 #define SYNC_TEST_TEST_ENTRY_FACTORY_H_ | 6 #define SYNC_TEST_TEST_ENTRY_FACTORY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "sync/internal_api/public/base/model_type.h" | 11 #include "sync/internal_api/public/base/model_type.h" |
| 12 #include "sync/protocol/sync.pb.h" | 12 #include "sync/protocol/sync.pb.h" |
| 13 | 13 |
| 14 namespace syncer { | 14 namespace syncer { |
| 15 | 15 |
| 16 namespace syncable { | 16 namespace syncable { |
| 17 class Directory; | 17 class Directory; |
| 18 class Id; | 18 class Id; |
| 19 } | 19 } |
| 20 | 20 |
| 21 enum SpecificsType { | |
| 22 SERVER_SPECIFICS, | |
|
rlarocque
2012/09/13 22:10:51
This identifier is dangerously close to syncable::
Nicolas Zea
2012/09/13 22:50:14
Moot now that it's two methods.
| |
| 23 LOCAL_SPECIFICS, | |
| 24 }; | |
| 25 | |
| 21 class TestEntryFactory { | 26 class TestEntryFactory { |
| 22 public: | 27 public: |
| 23 explicit TestEntryFactory(syncable::Directory* dir); | 28 explicit TestEntryFactory(syncable::Directory* dir); |
| 24 ~TestEntryFactory(); | 29 ~TestEntryFactory(); |
| 25 | 30 |
| 26 // Create a new unapplied folder node with a parent. | 31 // Create a new unapplied folder node with a parent. |
| 27 void CreateUnappliedNewItemWithParent( | 32 void CreateUnappliedNewItemWithParent( |
| 28 const std::string& item_id, | 33 const std::string& item_id, |
| 29 const sync_pb::EntitySpecifics& specifics, | 34 const sync_pb::EntitySpecifics& specifics, |
| 30 const std::string& parent_id); | 35 const std::string& parent_id); |
| 31 | 36 |
| 32 // Create a new unapplied update without a parent. | 37 // Create a new unapplied update without a parent. |
| 33 void CreateUnappliedNewItem(const std::string& item_id, | 38 int64 CreateUnappliedNewItem(const std::string& item_id, |
| 34 const sync_pb::EntitySpecifics& specifics, | 39 const sync_pb::EntitySpecifics& specifics, |
| 35 bool is_unique); | 40 bool is_unique); |
| 36 | 41 |
| 37 // Create an unsynced item in the database. If item_id is a local ID, it will | 42 // Create an unsynced item in the database. If item_id is a local ID, it will |
| 38 // be treated as a create-new. Otherwise, if it's a server ID, we'll fake the | 43 // be treated as a create-new. Otherwise, if it's a server ID, we'll fake the |
| 39 // server data so that it looks like it exists on the server. Returns the | 44 // server data so that it looks like it exists on the server. Returns the |
| 40 // methandle of the created item in |metahandle_out| if not NULL. | 45 // methandle of the created item in |metahandle_out| if not NULL. |
| 41 void CreateUnsyncedItem(const syncable::Id& item_id, | 46 void CreateUnsyncedItem(const syncable::Id& item_id, |
| 42 const syncable::Id& parent_id, | 47 const syncable::Id& parent_id, |
| 43 const std::string& name, | 48 const std::string& name, |
| 44 bool is_folder, | 49 bool is_folder, |
| 45 ModelType model_type, | 50 ModelType model_type, |
| 46 int64* metahandle_out); | 51 int64* metahandle_out); |
| 47 | 52 |
| 48 // Creates an item that is both unsynced an an unapplied update. Returns the | 53 // Creates an item that is both unsynced an an unapplied update. Returns the |
| 49 // metahandle of the created item. | 54 // metahandle of the created item. |
| 50 int64 CreateUnappliedAndUnsyncedItem(const std::string& name, | 55 int64 CreateUnappliedAndUnsyncedItem(const std::string& name, |
| 51 ModelType model_type); | 56 ModelType model_type); |
| 52 | 57 |
| 53 // Creates an item that has neither IS_UNSYNED or IS_UNAPPLIED_UPDATE. The | 58 // Creates an item that has neither IS_UNSYNED or IS_UNAPPLIED_UPDATE. The |
| 54 // item is known to both the server and client. Returns the metahandle of | 59 // item is known to both the server and client. Returns the metahandle of |
| 55 // the created item. | 60 // the created item. |
| 56 int64 CreateSyncedItem(const std::string& name, | 61 int64 CreateSyncedItem(const std::string& name, |
| 57 ModelType model_type, bool is_folder); | 62 ModelType model_type, bool is_folder); |
| 58 | 63 |
| 64 // Looks up the item referenced by |meta_handle|. If successful, overwrites | |
| 65 // the specifics determined by |specifics_type| with |specifics|, sets | |
| 66 // IS_UNAPPLIED_UPDATES/IS_UNSYNCED appropriately, and returns true. | |
| 67 // Else, return false. | |
| 68 bool SetSpecificsForItem(int64 meta_handle, | |
| 69 SpecificsType specifics_type, | |
| 70 const sync_pb::EntitySpecifics specifics); | |
| 71 | |
| 72 // Looks up the item referenced by |meta_handle|. If successful, stores | |
| 73 // the specifics determined by |specifics_type| into |specifics| and returns | |
| 74 // true. Else, return false. | |
| 75 const sync_pb::EntitySpecifics& GetSpecificsForItem( | |
| 76 int64 meta_handle, | |
| 77 SpecificsType specifics_type) const; | |
| 78 | |
| 79 // Getters for IS_UNSYNCED and IS_UNAPPLIED_UPDATE bit fields. | |
| 80 bool GetIsUnsyncedForItem(int64 meta_handle) const; | |
| 81 bool GetIsUnappliedForItem(int64 meta_handle) const; | |
| 82 | |
| 59 int64 GetNextRevision(); | 83 int64 GetNextRevision(); |
| 60 | 84 |
| 61 private: | 85 private: |
| 62 syncable::Directory* directory_; | 86 syncable::Directory* directory_; |
| 63 int64 next_revision_; | 87 int64 next_revision_; |
| 64 | 88 |
| 65 DISALLOW_COPY_AND_ASSIGN(TestEntryFactory); | 89 DISALLOW_COPY_AND_ASSIGN(TestEntryFactory); |
| 66 }; | 90 }; |
| 67 | 91 |
| 68 } // namespace syncer | 92 } // namespace syncer |
| 69 | 93 |
| 70 #endif // SYNC_TEST_TEST_ENTRY_FACTORY_H_ | 94 #endif // SYNC_TEST_TEST_ENTRY_FACTORY_H_ |
| OLD | NEW |