OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // This file defines the "sync API", an interface to the syncer | 5 // This file defines the "sync API", an interface to the syncer |
6 // backend that exposes (1) the core functionality of maintaining a consistent | 6 // backend that exposes (1) the core functionality of maintaining a consistent |
7 // local snapshot of a hierarchical object set; (2) a means to transactionally | 7 // local snapshot of a hierarchical object set; (2) a means to transactionally |
8 // access and modify those objects; (3) a means to control client/server | 8 // access and modify those objects; (3) a means to control client/server |
9 // synchronization tasks, namely: pushing local object modifications to a | 9 // synchronization tasks, namely: pushing local object modifications to a |
10 // server, pulling nonlocal object modifications from a server to this client, | 10 // server, pulling nonlocal object modifications from a server to this client, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 #include <vector> | 42 #include <vector> |
43 | 43 |
44 #include "base/basictypes.h" | 44 #include "base/basictypes.h" |
45 #include "base/file_path.h" | 45 #include "base/file_path.h" |
46 #include "base/scoped_ptr.h" | 46 #include "base/scoped_ptr.h" |
47 #include "build/build_config.h" | 47 #include "build/build_config.h" |
48 #include "chrome/browser/google_service_auth_error.h" | 48 #include "chrome/browser/google_service_auth_error.h" |
49 #include "chrome/browser/sync/notification_method.h" | 49 #include "chrome/browser/sync/notification_method.h" |
50 #include "chrome/browser/sync/syncable/model_type.h" | 50 #include "chrome/browser/sync/syncable/model_type.h" |
51 #include "googleurl/src/gurl.h" | 51 #include "googleurl/src/gurl.h" |
52 | 52 |
ncarter (slow)
2010/02/18 01:05:40
no blank line.
chron
2010/02/18 01:09:32
Done.
| |
53 #include "testing/gtest/include/gtest/gtest_prod.h" // for FRIEND_TEST | |
54 | |
53 namespace browser_sync { | 55 namespace browser_sync { |
54 class ModelSafeWorkerRegistrar; | 56 class ModelSafeWorkerRegistrar; |
55 } | 57 } |
56 | 58 |
57 // Forward declarations of internal class types so that sync API objects | 59 // Forward declarations of internal class types so that sync API objects |
58 // may have opaque pointers to these types. | 60 // may have opaque pointers to these types. |
59 namespace syncable { | 61 namespace syncable { |
60 class BaseTransaction; | 62 class BaseTransaction; |
61 class DirectoryManager; | 63 class DirectoryManager; |
62 class Entry; | 64 class Entry; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 class BaseNode { | 110 class BaseNode { |
109 public: | 111 public: |
110 // All subclasses of BaseNode must provide a way to initialize themselves by | 112 // All subclasses of BaseNode must provide a way to initialize themselves by |
111 // doing an ID lookup. Returns false on failure. An invalid or deleted | 113 // doing an ID lookup. Returns false on failure. An invalid or deleted |
112 // ID will result in failure. | 114 // ID will result in failure. |
113 virtual bool InitByIdLookup(int64 id) = 0; | 115 virtual bool InitByIdLookup(int64 id) = 0; |
114 | 116 |
115 // All subclasses of BaseNode must also provide a way to initialize themselves | 117 // All subclasses of BaseNode must also provide a way to initialize themselves |
116 // by doing a client tag lookup. Returns false on failure. A deleted node | 118 // by doing a client tag lookup. Returns false on failure. A deleted node |
117 // will return FALSE. | 119 // will return FALSE. |
118 virtual bool InitByClientTagLookup(const std::string& tag) = 0; | 120 virtual bool InitByClientTagLookup(syncable::ModelType model_type, |
121 const std::string& tag) = 0; | |
119 | 122 |
120 // Each object is identified by a 64-bit id (internally, the syncable | 123 // Each object is identified by a 64-bit id (internally, the syncable |
121 // metahandle). These ids are strictly local handles. They will persist | 124 // metahandle). These ids are strictly local handles. They will persist |
122 // on this client, but the same object on a different client may have a | 125 // on this client, but the same object on a different client may have a |
123 // different ID value. | 126 // different ID value. |
124 int64 GetId() const; | 127 int64 GetId() const; |
125 | 128 |
126 // Nodes are hierarchically arranged into a single-rooted tree. | 129 // Nodes are hierarchically arranged into a single-rooted tree. |
127 // InitByRootLookup on ReadNode allows access to the root. GetParentId is | 130 // InitByRootLookup on ReadNode allows access to the root. GetParentId is |
128 // how you find a node's parent. | 131 // how you find a node's parent. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 // children, return 0. | 181 // children, return 0. |
179 int64 GetFirstChildId() const; | 182 int64 GetFirstChildId() const; |
180 | 183 |
181 // These virtual accessors provide access to data members of derived classes. | 184 // These virtual accessors provide access to data members of derived classes. |
182 virtual const syncable::Entry* GetEntry() const = 0; | 185 virtual const syncable::Entry* GetEntry() const = 0; |
183 virtual const BaseTransaction* GetTransaction() const = 0; | 186 virtual const BaseTransaction* GetTransaction() const = 0; |
184 | 187 |
185 protected: | 188 protected: |
186 BaseNode(); | 189 BaseNode(); |
187 virtual ~BaseNode(); | 190 virtual ~BaseNode(); |
191 // The server has a size limit on client tags, so we generate a fixed length | |
192 // hash locally. This also ensures that ModelTypes have unique namespaces. | |
193 static std::string GenerateSyncableHash(syncable::ModelType model_type, | |
194 const std::string& client_tag); | |
188 | 195 |
189 private: | 196 private: |
190 // Node is meant for stack use only. | 197 // Node is meant for stack use only. |
191 void* operator new(size_t size); | 198 void* operator new(size_t size); |
192 | 199 |
200 friend class SyncApiTest; | |
201 FRIEND_TEST(SyncApiTest, GenerateSyncableHash); | |
202 | |
193 DISALLOW_COPY_AND_ASSIGN(BaseNode); | 203 DISALLOW_COPY_AND_ASSIGN(BaseNode); |
194 }; | 204 }; |
195 | 205 |
196 // WriteNode extends BaseNode to add mutation, and wraps | 206 // WriteNode extends BaseNode to add mutation, and wraps |
197 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode. | 207 // syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode. |
198 class WriteNode : public BaseNode { | 208 class WriteNode : public BaseNode { |
199 public: | 209 public: |
200 // Create a WriteNode using the given transaction. | 210 // Create a WriteNode using the given transaction. |
201 explicit WriteNode(WriteTransaction* transaction); | 211 explicit WriteNode(WriteTransaction* transaction); |
202 virtual ~WriteNode(); | 212 virtual ~WriteNode(); |
203 | 213 |
204 // A client must use one (and only one) of the following Init variants to | 214 // A client must use one (and only one) of the following Init variants to |
205 // populate the node. | 215 // populate the node. |
206 | 216 |
207 // BaseNode implementation. | 217 // BaseNode implementation. |
208 virtual bool InitByIdLookup(int64 id); | 218 virtual bool InitByIdLookup(int64 id); |
209 virtual bool InitByClientTagLookup(const std::string& tag); | 219 virtual bool InitByClientTagLookup(syncable::ModelType model_type, |
220 const std::string& tag); | |
210 | 221 |
211 // Create a new node with the specified parent and predecessor. |model_type| | 222 // Create a new node with the specified parent and predecessor. |model_type| |
212 // dictates the type of the item, and controls which EntitySpecifics proto | 223 // dictates the type of the item, and controls which EntitySpecifics proto |
213 // extension can be used with this item. Use a NULL |predecessor| | 224 // extension can be used with this item. Use a NULL |predecessor| |
214 // to indicate that this is to be the first child. | 225 // to indicate that this is to be the first child. |
215 // |predecessor| must be a child of |new_parent| or NULL. Returns false on | 226 // |predecessor| must be a child of |new_parent| or NULL. Returns false on |
216 // failure. | 227 // failure. |
217 bool InitByCreation(syncable::ModelType model_type, | 228 bool InitByCreation(syncable::ModelType model_type, |
218 const BaseNode& parent, | 229 const BaseNode& parent, |
219 const BaseNode* predecessor); | 230 const BaseNode* predecessor); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 // Create an unpopulated ReadNode on the given transaction. Call some flavor | 315 // Create an unpopulated ReadNode on the given transaction. Call some flavor |
305 // of Init to populate the ReadNode with a database entry. | 316 // of Init to populate the ReadNode with a database entry. |
306 explicit ReadNode(const BaseTransaction* transaction); | 317 explicit ReadNode(const BaseTransaction* transaction); |
307 virtual ~ReadNode(); | 318 virtual ~ReadNode(); |
308 | 319 |
309 // A client must use one (and only one) of the following Init variants to | 320 // A client must use one (and only one) of the following Init variants to |
310 // populate the node. | 321 // populate the node. |
311 | 322 |
312 // BaseNode implementation. | 323 // BaseNode implementation. |
313 virtual bool InitByIdLookup(int64 id); | 324 virtual bool InitByIdLookup(int64 id); |
314 virtual bool InitByClientTagLookup(const std::string& tag); | 325 virtual bool InitByClientTagLookup(syncable::ModelType model_type, |
326 const std::string& tag); | |
315 | 327 |
316 // There is always a root node, so this can't fail. The root node is | 328 // There is always a root node, so this can't fail. The root node is |
317 // never mutable, so root lookup is only possible on a ReadNode. | 329 // never mutable, so root lookup is only possible on a ReadNode. |
318 void InitByRootLookup(); | 330 void InitByRootLookup(); |
319 | 331 |
320 // Each server-created permanent node is tagged with a unique string. | 332 // Each server-created permanent node is tagged with a unique string. |
321 // Look up the node with the particular tag. If it does not exist, | 333 // Look up the node with the particular tag. If it does not exist, |
322 // return false. Since these nodes are special, lookup is only | 334 // return false. Since these nodes are special, lookup is only |
323 // provided through ReadNode. | 335 // provided through ReadNode. |
324 // TODO(chron): Rename this function. | 336 // TODO(chron): Rename this function. |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
723 // This allows actual HttpPostProvider subclass implementations to be | 735 // This allows actual HttpPostProvider subclass implementations to be |
724 // reference counted, which is useful if a particular implementation uses | 736 // reference counted, which is useful if a particular implementation uses |
725 // multiple threads to serve network requests. | 737 // multiple threads to serve network requests. |
726 virtual void Destroy(HttpPostProviderInterface* http) = 0; | 738 virtual void Destroy(HttpPostProviderInterface* http) = 0; |
727 virtual ~HttpPostProviderFactory() { } | 739 virtual ~HttpPostProviderFactory() { } |
728 }; | 740 }; |
729 | 741 |
730 } // namespace sync_api | 742 } // namespace sync_api |
731 | 743 |
732 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ | 744 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ |
OLD | NEW |