canmove, Confirmed users
725
edits
Line 8: | Line 8: | ||
This page describes how to the client-side Sync API for sync engines (and their helper objects). The focus is on using this API to create a new sync engine to synchronize a new data type. The data type can be anything that extension JS code has access to through any Mozilla API; this means this page must of necessity be pretty vague about reading and writing the underlying data. You'll have to fill in those blanks yourself. Try browsing the [link] xpcom documentation to find out how to get at the many types of useful data that Mozilla stores. | This page describes how to the client-side Sync API for sync engines (and their helper objects). The focus is on using this API to create a new sync engine to synchronize a new data type. The data type can be anything that extension JS code has access to through any Mozilla API; this means this page must of necessity be pretty vague about reading and writing the underlying data. You'll have to fill in those blanks yourself. Try browsing the [link] xpcom documentation to find out how to get at the many types of useful data that Mozilla stores. | ||
To sync a new data type, you'll need to write an engine object that extends the base <tt>SyncEngine</tt> object; you'll also need to extend three helper objects. Here are the | To sync a new data type, you'll need to write an engine object that extends the base <tt>SyncEngine</tt> object; you'll also need to extend three helper objects. Here are the base implementations you need to extend, and the files in which they're defined: | ||
# <tt>CryptoWrapper</tt>, in <tt>services/sync/modules/record.js</tt> | |||
# <tt>SyncEngine</tt>, <tt>Store</tt>, <tt>Tracker</tt> in <tt>services/sync/modules/engines.js</tt> | # <tt>SyncEngine</tt>, <tt>Store</tt>, <tt>Tracker</tt> in <tt>services/sync/modules/engines.js</tt> | ||
So to start out, import these files at the top of your JS module. We're also going to import <tt>util.js</tt> as it contains many useful helpers. | |||
<pre> | |||
const Cu = Components.utils; | |||
Cu.import("resource://services-sync/engines.js"); | |||
Cu.import("resource://services-sync/record.js"); | |||
Cu.import("resource://services-sync/util.js"); | |||
</pre> | |||
It will be very helpful to look at the existing sync engines -- such as the one for bookmarks and the one for history -- and their helper classes, for guidance. You can find these files at: | It will be very helpful to look at the existing sync engines -- such as the one for bookmarks and the one for history -- and their helper classes, for guidance. You can find these files at: | ||
Line 17: | Line 26: | ||
* <tt>services/sync/modules/engines/bookmarks.js</tt> -- the Record implementations for the various subtypes of bookmarks and the <tt>BookmarkEngine</tt>, <tt>BookmarkStore</tt>, and <tt>BookmarkTracker</tt>. | * <tt>services/sync/modules/engines/bookmarks.js</tt> -- the Record implementations for the various subtypes of bookmarks and the <tt>BookmarkEngine</tt>, <tt>BookmarkStore</tt>, and <tt>BookmarkTracker</tt>. | ||
* <tt>services/sync/modules/engines/history.js</tt> -- the <tt>HistoryRec</tt>,<tt>HistoryEngine</tt>, <tt>HistoryStore</tt>, and <tt>HistoryTracker</tt>. | * <tt>services/sync/modules/engines/history.js</tt> -- the <tt>HistoryRec</tt>,<tt>HistoryEngine</tt>, <tt>HistoryStore</tt>, and <tt>HistoryTracker</tt>. | ||
== Writing a Record object == | == Writing a Record object == |