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_INTERNAL_API_WRITE_NODE_H_ | 5 #ifndef SYNC_INTERNAL_API_WRITE_NODE_H_ |
6 #define SYNC_INTERNAL_API_WRITE_NODE_H_ | 6 #define SYNC_INTERNAL_API_WRITE_NODE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 | 40 |
41 namespace sync_api { | 41 namespace sync_api { |
42 | 42 |
43 class WriteTransaction; | 43 class WriteTransaction; |
44 | 44 |
45 // WriteNode extends BaseNode to add mutation, and wraps | 45 // WriteNode extends BaseNode to add mutation, and wraps |
46 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode. | 46 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode. |
47 class WriteNode : public BaseNode { | 47 class WriteNode : public BaseNode { |
48 public: | 48 public: |
| 49 enum InitUniqueByCreationResult { |
| 50 INIT_SUCCESS, |
| 51 // The tag passed into this method was empty. |
| 52 INIT_FAILED_EMPTY_TAG, |
| 53 // An entry with this tag already exists. |
| 54 INIT_FAILED_ENTRY_ALREADY_EXISTS, |
| 55 // The constructor for a new MutableEntry with the specified data failed. |
| 56 INIT_FAILED_COULD_NOT_CREATE_ENTRY, |
| 57 // Setting the predecessor failed |
| 58 INIT_FAILED_SET_PREDECESSOR, |
| 59 }; |
| 60 |
49 // Create a WriteNode using the given transaction. | 61 // Create a WriteNode using the given transaction. |
50 explicit WriteNode(WriteTransaction* transaction); | 62 explicit WriteNode(WriteTransaction* transaction); |
51 virtual ~WriteNode(); | 63 virtual ~WriteNode(); |
52 | 64 |
53 // A client must use one (and only one) of the following Init variants to | 65 // A client must use one (and only one) of the following Init variants to |
54 // populate the node. | 66 // populate the node. |
55 | 67 |
56 // BaseNode implementation. | 68 // BaseNode implementation. |
57 virtual InitByLookupResult InitByIdLookup(int64 id) OVERRIDE; | 69 virtual InitByLookupResult InitByIdLookup(int64 id) OVERRIDE; |
58 virtual InitByLookupResult InitByClientTagLookup( | 70 virtual InitByLookupResult InitByClientTagLookup( |
59 syncable::ModelType model_type, | 71 syncable::ModelType model_type, |
60 const std::string& tag) OVERRIDE; | 72 const std::string& tag) OVERRIDE; |
61 | 73 |
62 // Create a new node with the specified parent and predecessor. |model_type| | 74 // Create a new node with the specified parent and predecessor. |model_type| |
63 // dictates the type of the item, and controls which EntitySpecifics proto | 75 // dictates the type of the item, and controls which EntitySpecifics proto |
64 // extension can be used with this item. Use a NULL |predecessor| | 76 // extension can be used with this item. Use a NULL |predecessor| |
65 // to indicate that this is to be the first child. | 77 // to indicate that this is to be the first child. |
66 // |predecessor| must be a child of |new_parent| or NULL. Returns false on | 78 // |predecessor| must be a child of |new_parent| or NULL. Returns false on |
67 // failure. | 79 // failure. |
68 bool InitByCreation(syncable::ModelType model_type, | 80 bool InitByCreation(syncable::ModelType model_type, |
69 const BaseNode& parent, | 81 const BaseNode& parent, |
70 const BaseNode* predecessor); | 82 const BaseNode* predecessor); |
71 | 83 |
72 // Create nodes using this function if they're unique items that | 84 // Create nodes using this function if they're unique items that |
73 // you want to fetch using client_tag. Note that the behavior of these | 85 // you want to fetch using client_tag. Note that the behavior of these |
74 // items is slightly different than that of normal items. | 86 // items is slightly different than that of normal items. |
75 // Most importantly, if it exists locally, this function will | 87 // Most importantly, if it exists locally, this function will |
76 // actually undelete it | 88 // actually undelete it |
77 // Client unique tagged nodes must NOT be folders. | 89 // Client unique tagged nodes must NOT be folders. |
78 bool InitUniqueByCreation(syncable::ModelType model_type, | 90 InitUniqueByCreationResult InitUniqueByCreation( |
79 const BaseNode& parent, | 91 syncable::ModelType model_type, |
80 const std::string& client_tag); | 92 const BaseNode& parent, |
| 93 const std::string& client_tag); |
81 | 94 |
82 // Each server-created permanent node is tagged with a unique string. | 95 // Each server-created permanent node is tagged with a unique string. |
83 // Look up the node with the particular tag. If it does not exist, | 96 // Look up the node with the particular tag. If it does not exist, |
84 // return false. | 97 // return false. |
85 InitByLookupResult InitByTagLookup(const std::string& tag); | 98 InitByLookupResult InitByTagLookup(const std::string& tag); |
86 | 99 |
87 // These Set() functions correspond to the Get() functions of BaseNode. | 100 // These Set() functions correspond to the Get() functions of BaseNode. |
88 void SetIsFolder(bool folder); | 101 void SetIsFolder(bool folder); |
89 void SetTitle(const std::wstring& title); | 102 void SetTitle(const std::wstring& title); |
90 | 103 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 194 |
182 // The sync API transaction that is the parent of this node. | 195 // The sync API transaction that is the parent of this node. |
183 WriteTransaction* transaction_; | 196 WriteTransaction* transaction_; |
184 | 197 |
185 DISALLOW_COPY_AND_ASSIGN(WriteNode); | 198 DISALLOW_COPY_AND_ASSIGN(WriteNode); |
186 }; | 199 }; |
187 | 200 |
188 } // namespace sync_api | 201 } // namespace sync_api |
189 | 202 |
190 #endif // SYNC_INTERNAL_API_WRITE_NODE_H_ | 203 #endif // SYNC_INTERNAL_API_WRITE_NODE_H_ |
OLD | NEW |