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