1ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file.
4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This file defines the "sync API", an interface to the syncer
6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// backend that exposes (1) the core functionality of maintaining a consistent
7c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// local snapshot of a hierarchical object set; (2) a means to transactionally
8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// access and modify those objects; (3) a means to control client/server
9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// synchronization tasks, namely: pushing local object modifications to a
10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// server, pulling nonlocal object modifications from a server to this client,
11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// and resolving conflicts that may arise between the two; and (4) an
12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// abstraction of some external functionality that is to be provided by the
13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// host environment.
14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch//
15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This interface is used as the entry point into the syncer backend
16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// when the backend is compiled as a library and embedded in another
17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// application.  A goal for this interface layer is to depend on very few
18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// external types, so that an application can use the sync backend
19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// without introducing a dependency on specific types.  A non-goal is to
20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// have binary compatibility across versions or compilers; this allows the
21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// interface to use C++ classes.  An application wishing to use the sync API
22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// should ideally compile the syncer backend and this API as part of the
23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// application's own build, to avoid e.g. mismatches in calling convention,
24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// structure padding, or name mangling that could arise if there were a
25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// compiler mismatch.
26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch//
27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// The schema of the objects in the sync domain is based on the model, which
28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// is essentially a hierarchy of items and folders similar to a filesystem,
29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// but with a few important differences.  The sync API contains fields
30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// such as URL to easily allow the embedding application to store web
31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// browser bookmarks.  Also, the sync API allows duplicate titles in a parent.
32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Consequently, it does not support looking up an object by title
33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// and parent, since such a lookup is not uniquely determined.  Lastly,
34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// unlike a filesystem model, objects in the Sync API model have a strict
35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// ordering within a parent; the position is manipulable by callers, and
36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// children of a node can be enumerated in the order of their position.
37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_
39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_
403345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once
41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <string>
43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <vector>
44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/basictypes.h"
46ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/callback.h"
47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/gtest_prod_util.h"
48ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/memory/scoped_ptr.h"
49ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/tracked.h"
50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "build/build_config.h"
513345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#include "chrome/browser/sync/protocol/password_specifics.pb.h"
5221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#include "chrome/browser/sync/syncable/autofill_migration.h"
53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/sync/syncable/model_type.h"
54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/sync/util/cryptographer.h"
553345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#include "chrome/common/net/gaia/google_service_auth_error.h"
56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "googleurl/src/gurl.h"
57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
5872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenclass DictionaryValue;
593345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickclass FilePath;
603345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace browser_sync {
6272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenclass JsBackend;
63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ModelSafeWorkerRegistrar;
64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace sessions {
66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochstruct SyncSessionSnapshot;
67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}
68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}
69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
70ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsennamespace sync_notifier {
71ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsenclass SyncNotifier;
72ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen}  // namespace sync_notifier
733345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
74c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Forward declarations of internal class types so that sync API objects
75c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// may have opaque pointers to these types.
76c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace syncable {
77c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass BaseTransaction;
78c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass DirectoryManager;
79c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass Entry;
80c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass MutableEntry;
81c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ReadTransaction;
82c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ScopedDirLookup;
83c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass WriteTransaction;
84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}
85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
86c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace sync_pb {
873345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickclass AppSpecifics;
88c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass AutofillSpecifics;
89201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdochclass AutofillProfileSpecifics;
90c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass BookmarkSpecifics;
91c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass EntitySpecifics;
92c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ExtensionSpecifics;
933345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickclass SessionSpecifics;
94c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass NigoriSpecifics;
95c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass PasswordSpecifics;
96c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass PreferenceSpecifics;
97c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass PasswordSpecifics;
98c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass PasswordSpecificsData;
99c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ThemeSpecifics;
100c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass TypedUrlSpecifics;
101c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}
102c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
103c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace sync_api {
104c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
105c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass BaseTransaction;
106c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass HttpPostProviderFactory;
107c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass SyncManager;
108c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass WriteTransaction;
109c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
110c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// A UserShare encapsulates the syncable pieces that represent an authenticated
111c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// user and their data (share).
112c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This encompasses all pieces required to build transaction objects on the
113c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// syncable share.
114c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochstruct UserShare {
115731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  UserShare();
116731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  ~UserShare();
117731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
118c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The DirectoryManager itself, which is the parent of Transactions and can
119c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // be shared across multiple threads (unlike Directory).
120c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_ptr<syncable::DirectoryManager> dir_manager;
121c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
1223345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // The username of the sync user.
1233345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  std::string name;
1243345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick};
1253345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
1263345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick// Contains everything needed to talk to and identify a user account.
1273345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrickstruct SyncCredentials {
1283345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  std::string email;
1293345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  std::string sync_token;
130c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
131c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
132c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// A valid BaseNode will never have an ID of zero.
133c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochstatic const int64 kInvalidId = 0;
134c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
135c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// BaseNode wraps syncable::Entry, and corresponds to a single object's state.
136c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This, like syncable::Entry, is intended for use on the stack.  A valid
137c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// transaction is necessary to create a BaseNode or any of its children.
138c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Unlike syncable::Entry, a sync API BaseNode is identified primarily by its
139c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// int64 metahandle, which we call an ID here.
140c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass BaseNode {
141c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
142c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // All subclasses of BaseNode must provide a way to initialize themselves by
143c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // doing an ID lookup.  Returns false on failure.  An invalid or deleted
144c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // ID will result in failure.
145c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool InitByIdLookup(int64 id) = 0;
146c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
147c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // All subclasses of BaseNode must also provide a way to initialize themselves
148c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // by doing a client tag lookup. Returns false on failure. A deleted node
149c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // will return FALSE.
150c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool InitByClientTagLookup(syncable::ModelType model_type,
151c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const std::string& tag) = 0;
152c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
153c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Each object is identified by a 64-bit id (internally, the syncable
154c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // metahandle).  These ids are strictly local handles.  They will persist
155c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // on this client, but the same object on a different client may have a
156c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // different ID value.
157201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  virtual int64 GetId() const;
158c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
1593f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen  // Returns the modification time of the object (in TimeTicks internal format).
1603f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen  int64 GetModificationTime() const;
1613f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen
162c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Nodes are hierarchically arranged into a single-rooted tree.
163c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // InitByRootLookup on ReadNode allows access to the root. GetParentId is
164c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // how you find a node's parent.
165c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  int64 GetParentId() const;
166c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
167c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Nodes are either folders or not.  This corresponds to the IS_DIR property
168c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // of syncable::Entry.
169c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool GetIsFolder() const;
170c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
171c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns the title of the object.
172c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Uniqueness of the title is not enforced on siblings -- it is not an error
173c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // for two children to share a title.
174c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  std::wstring GetTitle() const;
175c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
176c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns the model type of this object.  The model type is set at node
177c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // creation time and is expected never to change.
178c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  syncable::ModelType GetModelType() const;
179c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
180c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Getter specific to the BOOKMARK datatype.  Returns protobuf
181c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // data.  Can only be called if GetModelType() == BOOKMARK.
182c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const sync_pb::BookmarkSpecifics& GetBookmarkSpecifics() const;
183c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
184c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Legacy, bookmark-specific getter that wraps GetBookmarkSpecifics() above.
185c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns the URL of a bookmark object.
186c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // TODO(ncarter): Remove this datatype-specific accessor.
187c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  GURL GetURL() const;
188c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
189c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Legacy, bookmark-specific getter that wraps GetBookmarkSpecifics() above.
190c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Fill in a vector with the byte data of this node's favicon.  Assumes
191c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // that the node is a bookmark.
192c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Favicons are expected to be PNG images, and though no verification is
193c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // done on the syncapi client of this, the server may reject favicon updates
194c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // that are invalid for whatever reason.
195c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // TODO(ncarter): Remove this datatype-specific accessor.
196c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void GetFaviconBytes(std::vector<unsigned char>* output) const;
197c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
1983345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Getter specific to the APPS datatype.  Returns protobuf
1993345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // data.  Can only be called if GetModelType() == APPS.
2003345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  const sync_pb::AppSpecifics& GetAppSpecifics() const;
2013345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
202c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Getter specific to the AUTOFILL datatype.  Returns protobuf
203c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // data.  Can only be called if GetModelType() == AUTOFILL.
204c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const sync_pb::AutofillSpecifics& GetAutofillSpecifics() const;
205c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
206201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  virtual const sync_pb::AutofillProfileSpecifics&
207201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch      GetAutofillProfileSpecifics() const;
208201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch
209c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Getter specific to the NIGORI datatype.  Returns protobuf
210c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // data.  Can only be called if GetModelType() == NIGORI.
211c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const sync_pb::NigoriSpecifics& GetNigoriSpecifics() const;
212c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
213c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Getter specific to the PASSWORD datatype.  Returns protobuf
214c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // data.  Can only be called if GetModelType() == PASSWORD.
215c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const sync_pb::PasswordSpecificsData& GetPasswordSpecifics() const;
216c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
217c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Getter specific to the PREFERENCE datatype.  Returns protobuf
218c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // data.  Can only be called if GetModelType() == PREFERENCE.
219c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const sync_pb::PreferenceSpecifics& GetPreferenceSpecifics() const;
220c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
221c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Getter specific to the THEME datatype.  Returns protobuf
222c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // data.  Can only be called if GetModelType() == THEME.
223c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const sync_pb::ThemeSpecifics& GetThemeSpecifics() const;
224c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
225c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Getter specific to the TYPED_URLS datatype.  Returns protobuf
226c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // data.  Can only be called if GetModelType() == TYPED_URLS.
227c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const sync_pb::TypedUrlSpecifics& GetTypedUrlSpecifics() const;
228c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
229c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Getter specific to the EXTENSIONS datatype.  Returns protobuf
230c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // data.  Can only be called if GetModelType() == EXTENSIONS.
231c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const sync_pb::ExtensionSpecifics& GetExtensionSpecifics() const;
232c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
2333345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Getter specific to the SESSIONS datatype.  Returns protobuf
2343345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // data.  Can only be called if GetModelType() == SESSIONS.
2353345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  const sync_pb::SessionSpecifics& GetSessionSpecifics() const;
2363345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
237c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns the local external ID associated with the node.
238c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  int64 GetExternalId() const;
239c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
240c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Return the ID of the node immediately before this in the sibling order.
241c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // For the first node in the ordering, return 0.
242c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  int64 GetPredecessorId() const;
243c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
244c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Return the ID of the node immediately after this in the sibling order.
245c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // For the last node in the ordering, return 0.
246201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  virtual int64 GetSuccessorId() const;
247c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
248c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Return the ID of the first child of this node.  If this node has no
249c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // children, return 0.
250201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  virtual int64 GetFirstChildId() const;
251c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
252c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // These virtual accessors provide access to data members of derived classes.
253c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual const syncable::Entry* GetEntry() const = 0;
254c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual const BaseTransaction* GetTransaction() const = 0;
255c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
25672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Dumps all node info into a DictionaryValue and returns it.
25772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Transfers ownership of the DictionaryValue to the caller.
25872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  DictionaryValue* ToValue() const;
25972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
260ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Does a case in-sensitive search for a given string, which must be
261ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // lower case.
262ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  bool ContainsString(const std::string& lowercase_query) const;
263ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
264c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch protected:
265c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  BaseNode();
266c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ~BaseNode();
267c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The server has a size limit on client tags, so we generate a fixed length
268c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // hash locally. This also ensures that ModelTypes have unique namespaces.
269c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  static std::string GenerateSyncableHash(syncable::ModelType model_type,
270c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const std::string& client_tag);
271c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
272c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Determines whether part of the entry is encrypted, and if so attempts to
273c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // decrypt it. Unless decryption is necessary and fails, this will always
274dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // return |true|. If the contents are encrypted, the decrypted data will be
275dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // stored in |unencrypted_data_|.
276dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // This method is invoked once when the BaseNode is initialized.
277c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool DecryptIfNecessary(syncable::Entry* entry);
278c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
279dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // Returns the unencrypted specifics associated with |entry|. If |entry| was
280dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // not encrypted, it directly returns |entry|'s EntitySpecifics. Otherwise,
281dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // returns |unencrypted_data_|.
282dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // This method is invoked by the datatype specific Get<datatype>Specifics
283dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // methods.
284dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  const sync_pb::EntitySpecifics& GetUnencryptedSpecifics(
285dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen      const syncable::Entry* entry) const;
286dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
287c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
288201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  void* operator new(size_t size);  // Node is meant for stack use only.
289c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
290dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // A holder for the unencrypted data stored in an encrypted node.
291dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  sync_pb::EntitySpecifics unencrypted_data_;
292dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
293dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // Same as |unencrypted_data_|, but for legacy password encryption.
294c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_ptr<sync_pb::PasswordSpecificsData> password_data_;
295c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
296c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  friend class SyncApiTest;
297c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  FRIEND_TEST_ALL_PREFIXES(SyncApiTest, GenerateSyncableHash);
298c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
299c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(BaseNode);
300c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
301c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
302c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// WriteNode extends BaseNode to add mutation, and wraps
303c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode.
304c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass WriteNode : public BaseNode {
305c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
306c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Create a WriteNode using the given transaction.
307c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  explicit WriteNode(WriteTransaction* transaction);
308c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ~WriteNode();
309c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
310c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // A client must use one (and only one) of the following Init variants to
311c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // populate the node.
312c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
313c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // BaseNode implementation.
314c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool InitByIdLookup(int64 id);
315c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool InitByClientTagLookup(syncable::ModelType model_type,
316c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const std::string& tag);
317c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
318c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Create a new node with the specified parent and predecessor.  |model_type|
319c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // dictates the type of the item, and controls which EntitySpecifics proto
320c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // extension can be used with this item.  Use a NULL |predecessor|
321c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to indicate that this is to be the first child.
322c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // |predecessor| must be a child of |new_parent| or NULL. Returns false on
323c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // failure.
324c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool InitByCreation(syncable::ModelType model_type,
325c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                      const BaseNode& parent,
326c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                      const BaseNode* predecessor);
327c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
328c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Create nodes using this function if they're unique items that
329c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // you want to fetch using client_tag. Note that the behavior of these
330c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // items is slightly different than that of normal items.
331c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Most importantly, if it exists locally, this function will
332c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // actually undelete it
333c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Client unique tagged nodes must NOT be folders.
334c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool InitUniqueByCreation(syncable::ModelType model_type,
335c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                            const BaseNode& parent,
336c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                            const std::string& client_tag);
337c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
338c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Each server-created permanent node is tagged with a unique string.
339c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Look up the node with the particular tag.  If it does not exist,
340c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // return false.
341c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool InitByTagLookup(const std::string& tag);
342c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
343c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // These Set() functions correspond to the Get() functions of BaseNode.
344c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetIsFolder(bool folder);
345c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetTitle(const std::wstring& title);
346c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
347c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // External ID is a client-only field, so setting it doesn't cause the item to
348c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // be synced again.
349c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetExternalId(int64 external_id);
350c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
351c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Remove this node and its children.
352c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void Remove();
353c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
354c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Set a new parent and position.  Position is specified by |predecessor|; if
355c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // it is NULL, the node is moved to the first position.  |predecessor| must
356c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // be a child of |new_parent| or NULL.  Returns false on failure..
357c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool SetPosition(const BaseNode& new_parent, const BaseNode* predecessor);
358c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
359c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Set the bookmark specifics (url and favicon).
360c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Should only be called if GetModelType() == BOOKMARK.
361c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetBookmarkSpecifics(const sync_pb::BookmarkSpecifics& specifics);
362c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
363c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Legacy, bookmark-specific setters that wrap SetBookmarkSpecifics() above.
364c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Should only be called if GetModelType() == BOOKMARK.
365c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // TODO(ncarter): Remove these two datatype-specific accessors.
366c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetURL(const GURL& url);
367c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetFaviconBytes(const std::vector<unsigned char>& bytes);
368c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
3693345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Set the app specifics (id, update url, enabled state, etc).
3703345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Should only be called if GetModelType() == APPS.
3713345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void SetAppSpecifics(const sync_pb::AppSpecifics& specifics);
3723345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
373c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Set the autofill specifics (name and value).
374c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Should only be called if GetModelType() == AUTOFILL.
375c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetAutofillSpecifics(const sync_pb::AutofillSpecifics& specifics);
376c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
37721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  void SetAutofillProfileSpecifics(
37821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen      const sync_pb::AutofillProfileSpecifics& specifics);
37921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
380c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Set the nigori specifics.
381c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Should only be called if GetModelType() == NIGORI.
382c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetNigoriSpecifics(const sync_pb::NigoriSpecifics& specifics);
383c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
384c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Set the password specifics.
385c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Should only be called if GetModelType() == PASSWORD.
386c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetPasswordSpecifics(const sync_pb::PasswordSpecificsData& specifics);
387c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
388c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Set the preference specifics (name and value).
389c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Should only be called if GetModelType() == PREFERENCE.
390c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetPreferenceSpecifics(const sync_pb::PreferenceSpecifics& specifics);
391c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
392c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Set the theme specifics (name and value).
393c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Should only be called if GetModelType() == THEME.
394c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetThemeSpecifics(const sync_pb::ThemeSpecifics& specifics);
395c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
396c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Set the typed_url specifics (url, title, typed_count, etc).
397c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Should only be called if GetModelType() == TYPED_URLS.
398c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetTypedUrlSpecifics(const sync_pb::TypedUrlSpecifics& specifics);
399c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
400c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Set the extension specifics (id, update url, enabled state, etc).
401c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Should only be called if GetModelType() == EXTENSIONS.
402c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetExtensionSpecifics(const sync_pb::ExtensionSpecifics& specifics);
403c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
4043345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Set the session specifics (windows, tabs, navigations etc.).
4053345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Should only be called if GetModelType() == SESSIONS.
4063345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void SetSessionSpecifics(const sync_pb::SessionSpecifics& specifics);
4073345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
408dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // Resets the EntitySpecifics for this node based on the unencrypted data.
409dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // Will encrypt if necessary.
410dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  void ResetFromSpecifics();
411dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
412c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Implementation of BaseNode's abstract virtual accessors.
413c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual const syncable::Entry* GetEntry() const;
414c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
415c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual const BaseTransaction* GetTransaction() const;
416c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
417c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
418c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void* operator new(size_t size);  // Node is meant for stack use only.
419c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
420c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Helper to set model type. This will clear any specifics data.
421c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void PutModelType(syncable::ModelType model_type);
422c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
423c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Helper to set the previous node.
424c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void PutPredecessor(const BaseNode* predecessor);
425c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
426c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Private helpers to set type-specific protobuf data.  These don't
427c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // do any checking on the previous modeltype, so they can be used
428c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // for internal initialization (you can use them to set the modeltype).
429c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Additionally, they will mark for syncing if the underlying value
430c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // changes.
4313345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void PutAppSpecificsAndMarkForSyncing(
4323345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      const sync_pb::AppSpecifics& new_value);
433c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void PutAutofillSpecificsAndMarkForSyncing(
434c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const sync_pb::AutofillSpecifics& new_value);
43521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  void PutAutofillProfileSpecificsAndMarkForSyncing(
43621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen      const sync_pb::AutofillProfileSpecifics& new_value);
437c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void PutBookmarkSpecificsAndMarkForSyncing(
438c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const sync_pb::BookmarkSpecifics& new_value);
439c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void PutNigoriSpecificsAndMarkForSyncing(
440c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const sync_pb::NigoriSpecifics& new_value);
441c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void PutPasswordSpecificsAndMarkForSyncing(
442c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const sync_pb::PasswordSpecifics& new_value);
443c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void PutPreferenceSpecificsAndMarkForSyncing(
444c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const sync_pb::PreferenceSpecifics& new_value);
445c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void PutThemeSpecificsAndMarkForSyncing(
446c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const sync_pb::ThemeSpecifics& new_value);
447c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void PutTypedUrlSpecificsAndMarkForSyncing(
448c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const sync_pb::TypedUrlSpecifics& new_value);
449c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void PutExtensionSpecificsAndMarkForSyncing(
450c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const sync_pb::ExtensionSpecifics& new_value);
4513345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void PutSessionSpecificsAndMarkForSyncing(
4523345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick      const sync_pb::SessionSpecifics& new_value);
453c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void PutSpecificsAndMarkForSyncing(
454c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const sync_pb::EntitySpecifics& specifics);
455c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
456c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Sets IS_UNSYNCED and SYNCING to ensure this entry is considered in an
457c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // upcoming commit pass.
458c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void MarkForSyncing();
459c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
460dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // Encrypt the specifics if the datatype requries it.
461dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  void EncryptIfNecessary(sync_pb::EntitySpecifics* new_value);
462dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
463c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The underlying syncable object which this class wraps.
464c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  syncable::MutableEntry* entry_;
465c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
466c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The sync API transaction that is the parent of this node.
467c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  WriteTransaction* transaction_;
468c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
469c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(WriteNode);
470c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
471c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
472c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// ReadNode wraps a syncable::Entry to provide the functionality of a
473c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// read-only BaseNode.
474c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ReadNode : public BaseNode {
475c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
476c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Create an unpopulated ReadNode on the given transaction.  Call some flavor
477c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // of Init to populate the ReadNode with a database entry.
478c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  explicit ReadNode(const BaseTransaction* transaction);
479c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ~ReadNode();
480c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
481c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // A client must use one (and only one) of the following Init variants to
482c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // populate the node.
483c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
484c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // BaseNode implementation.
485c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool InitByIdLookup(int64 id);
486c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual bool InitByClientTagLookup(syncable::ModelType model_type,
487c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      const std::string& tag);
488c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
489c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // There is always a root node, so this can't fail.  The root node is
490c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // never mutable, so root lookup is only possible on a ReadNode.
491c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void InitByRootLookup();
492c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
493c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Each server-created permanent node is tagged with a unique string.
494c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Look up the node with the particular tag.  If it does not exist,
495c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // return false.
496c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool InitByTagLookup(const std::string& tag);
497c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
498c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Implementation of BaseNode's abstract virtual accessors.
499c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual const syncable::Entry* GetEntry() const;
500c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual const BaseTransaction* GetTransaction() const;
501c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
502201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch protected:
503201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  ReadNode();
504201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch
505c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
506c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void* operator new(size_t size);  // Node is meant for stack use only.
507c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
508c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The underlying syncable object which this class wraps.
509c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  syncable::Entry* entry_;
510c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
511c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The sync API transaction that is the parent of this node.
512c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const BaseTransaction* transaction_;
513c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
514c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(ReadNode);
515c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
516c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
517c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Sync API's BaseTransaction, ReadTransaction, and WriteTransaction allow for
518c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// batching of several read and/or write operations.  The read and write
519c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// operations are performed by creating ReadNode and WriteNode instances using
520c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// the transaction. These transaction classes wrap identically named classes in
521c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// syncable, and are used in a similar way. Unlike syncable::BaseTransaction,
522c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// whose construction requires an explicit syncable::ScopedDirLookup, a sync
523c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// API BaseTransaction creates its own ScopedDirLookup implicitly.
524c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass BaseTransaction {
525c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
526c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Provide access to the underlying syncable.h objects from BaseNode.
527c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual syncable::BaseTransaction* GetWrappedTrans() const = 0;
528c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const syncable::ScopedDirLookup& GetLookup() const { return *lookup_; }
529c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  browser_sync::Cryptographer* GetCryptographer() const {
530c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    return cryptographer_;
531c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  }
532c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
533c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch protected:
534c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The ScopedDirLookup is created in the constructor and destroyed
535c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // in the destructor.  Creation of the ScopedDirLookup is not expected
536c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to fail.
537c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  explicit BaseTransaction(UserShare* share);
538c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ~BaseTransaction();
539c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
540201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  BaseTransaction() { lookup_= NULL; }
541201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch
542c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
543c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // A syncable ScopedDirLookup, which is the parent of syncable transactions.
544c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  syncable::ScopedDirLookup* lookup_;
545c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
546c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  browser_sync::Cryptographer* cryptographer_;
547c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
548c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(BaseTransaction);
549c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
550c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
551c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Sync API's ReadTransaction is a read-only BaseTransaction.  It wraps
552c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// a syncable::ReadTransaction.
553c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass ReadTransaction : public BaseTransaction {
554c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
555c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Start a new read-only transaction on the specified repository.
556c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  explicit ReadTransaction(UserShare* share);
557c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
558c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Resume the middle of a transaction. Will not close transaction.
559c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  ReadTransaction(UserShare* share, syncable::BaseTransaction* trans);
560c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
561c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ~ReadTransaction();
562c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
563c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // BaseTransaction override.
564c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual syncable::BaseTransaction* GetWrappedTrans() const;
565c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
566c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void* operator new(size_t size);  // Transaction is meant for stack use only.
567c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
568c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The underlying syncable object which this class wraps.
569c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  syncable::BaseTransaction* transaction_;
570c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool close_transaction_;
571c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
572c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(ReadTransaction);
573c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
574c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
575c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Sync API's WriteTransaction is a read/write BaseTransaction.  It wraps
576c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// a syncable::WriteTransaction.
577c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass WriteTransaction : public BaseTransaction {
578c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
579c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Start a new read/write transaction.
580c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  explicit WriteTransaction(UserShare* share);
581c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ~WriteTransaction();
582c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
583c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Provide access to the syncable.h transaction from the API WriteNode.
584c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual syncable::BaseTransaction* GetWrappedTrans() const;
585c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  syncable::WriteTransaction* GetWrappedWriteTrans() { return transaction_; }
586c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
587201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch protected:
588201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  WriteTransaction() {}
589201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch
590201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch  void SetTransaction(syncable::WriteTransaction* trans) {
591201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch      transaction_ = trans;}
592201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch
593c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
594c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void* operator new(size_t size);  // Transaction is meant for stack use only.
595c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
596c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The underlying syncable object which this class wraps.
597c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  syncable::WriteTransaction* transaction_;
598c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
599c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(WriteTransaction);
600c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
601c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
602c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// SyncManager encapsulates syncable::DirectoryManager and serves as the parent
603c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// of all other objects in the sync API.  SyncManager is thread-safe.  If
604c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// multiple threads interact with the same local sync repository (i.e. the
605c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// same sqlite database), they should share a single SyncManager instance.  The
606c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// caller should typically create one SyncManager for the lifetime of a user
607c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// session.
608c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass SyncManager {
609c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
610c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // SyncInternal contains the implementation of SyncManager, while abstracting
611c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // internal types from clients of the interface.
612c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  class SyncInternal;
613c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
614dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // TODO(zea): One day get passwords playing nicely with the rest of encryption
615dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // and get rid of this.
616dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  class ExtraPasswordChangeRecordData {
6173345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick   public:
618dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    ExtraPasswordChangeRecordData();
619dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    explicit ExtraPasswordChangeRecordData(
620dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen        const sync_pb::PasswordSpecificsData& data);
621dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    virtual ~ExtraPasswordChangeRecordData();
62272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
62372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    // Transfers ownership of the DictionaryValue to the caller.
624dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    virtual DictionaryValue* ToValue() const;
625dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
626dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    const sync_pb::PasswordSpecificsData& unencrypted() const;
627dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen   private:
628dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    sync_pb::PasswordSpecificsData unencrypted_;
6293345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  };
6303345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
631c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // ChangeRecord indicates a single item that changed as a result of a sync
632c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // operation.  This gives the sync id of the node that changed, and the type
633c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // of change.  To get the actual property values after an ADD or UPDATE, the
634c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // client should get the node with InitByIdLookup(), using the provided id.
635c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  struct ChangeRecord {
636c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    enum Action {
637c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      ACTION_ADD,
638c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      ACTION_DELETE,
639c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      ACTION_UPDATE,
640c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    };
641731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick    ChangeRecord();
642731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick    ~ChangeRecord();
643731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
64472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    // Transfers ownership of the DictionaryValue to the caller.
64572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    DictionaryValue* ToValue(const BaseTransaction* trans) const;
64672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
647c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int64 id;
648c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    Action action;
649c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    sync_pb::EntitySpecifics specifics;
650dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    linked_ptr<ExtraPasswordChangeRecordData> extra;
651c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  };
652c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
653c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Status encapsulates detailed state about the internals of the SyncManager.
654c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  struct Status {
655c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Summary is a distilled set of important information that the end-user may
656c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // wish to be informed about (through UI, for example). Note that if a
657c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // summary state requires user interaction (such as auth failures), more
658c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // detailed information may be contained in additional status fields.
659c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    enum Summary {
660c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      // The internal instance is in an unrecognizable state. This should not
661c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      // happen.
662c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      INVALID = 0,
663c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      // Can't connect to server, but there are no pending changes in
664c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      // our local cache.
665c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      OFFLINE,
666c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      // Can't connect to server, and there are pending changes in our
667c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      // local cache.
668c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      OFFLINE_UNSYNCED,
669c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      // Connected and syncing.
670c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      SYNCING,
671c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      // Connected, no pending changes.
672c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      READY,
673c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      // Internal sync error.
674c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      CONFLICT,
675c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      // Can't connect to server, and we haven't completed the initial
676c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      // sync yet.  So there's nothing we can do but wait for the server.
677c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      OFFLINE_UNUSABLE,
67872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
67972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      SUMMARY_STATUS_COUNT,
680c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    };
681c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
68272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    Summary summary;
683c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    bool authenticated;      // Successfully authenticated via GAIA.
684c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    bool server_up;          // True if we have received at least one good
685c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                             // reply from the server.
686c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    bool server_reachable;   // True if we received any reply from the server.
687c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    bool server_broken;      // True of the syncer is stopped because of server
688c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                             // issues.
689c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    bool notifications_enabled;  // True only if subscribed for notifications.
69072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
69172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    // Notifications counters updated by the actions in synapi.
692c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int notifications_received;
693c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int notifications_sent;
694c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
69572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    // The max number of consecutive errors from any component.
69672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    int max_consecutive_errors;
69772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
698c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int unsynced_count;
69972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
700c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int conflicting_count;
701c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    bool syncing;
70272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    // True after a client has done a first sync.
703c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    bool initial_sync_ended;
70472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    // True if any syncer is stuck.
705c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    bool syncer_stuck;
70672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
70772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    // Total updates available.  If zero, nothing left to download.
708c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    int64 updates_available;
70972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    // Total updates received by the syncer since browser start.
71072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    int updates_received;
71172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
71272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    // Of updates_received, how many were tombstones.
71372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    int tombstone_updates_received;
714c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    bool disk_full;
715c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  };
716c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
717c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // An interface the embedding application implements to receive notifications
718c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // from the SyncManager.  Register an observer via SyncManager::AddObserver.
719c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // This observer is an event driven model as the events may be raised from
720c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // different internal threads, and simply providing an "OnStatusChanged" type
721c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // notification complicates things such as trying to determine "what changed",
722c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // if different members of the Status object are modified from different
723c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // threads.  This way, the event is explicit, and it is safe for the Observer
724c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to dispatch to a native thread or synchronize accordingly.
725c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  class Observer {
726c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch   public:
727c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Notify the observer that changes have been applied to the sync model.
728c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    //
729c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // This will be invoked on the same thread as on which ApplyChanges was
730c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // called. |changes| is an array of size |change_count|, and contains the
731c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // ID of each individual item that was changed. |changes| exists only for
732c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // the duration of the call. If items of multiple data types change at
733c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // the same time, this method is invoked once per data type and |changes|
734c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // is restricted to items of the ModelType indicated by |model_type|.
735c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Because the observer is passed a |trans|, the observer can assume a
736c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // read lock on the sync model that will be released after the function
737c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // returns.
738c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    //
739c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // The SyncManager constructs |changes| in the following guaranteed order:
740c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    //
741c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // 1. Deletions, from leaves up to parents.
742c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // 2. Updates to existing items with synced parents & predecessors.
743c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // 3. New items with synced parents & predecessors.
744c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // 4. Items with parents & predecessors in |changes|.
745c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // 5. Repeat #4 until all items are in |changes|.
746c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    //
747c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Thus, an implementation of OnChangesApplied should be able to
748c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // process the change records in the order without having to worry about
749c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // forward dependencies.  But since deletions come before reparent
750c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // operations, a delete may temporarily orphan a node that is
751c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // updated later in the list.
752c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnChangesApplied(syncable::ModelType model_type,
753c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                  const BaseTransaction* trans,
754c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                  const ChangeRecord* changes,
755c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                  int change_count) = 0;
756c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
7573345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // OnChangesComplete gets called when the TransactionComplete event is
7583345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // posted (after OnChangesApplied finishes), after the transaction lock
7593345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // and the change channel mutex are released.
7603345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    //
7613345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // The purpose of this function is to support processors that require
7623345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // split-transactions changes. For example, if a model processor wants to
7633345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // perform blocking I/O due to a change, it should calculate the changes
7643345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // while holding the transaction lock (from within OnChangesApplied), buffer
7653345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // those changes, let the transaction fall out of scope, and then commit
7663345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // those changes from within OnChangesComplete (postponing the blocking
7673345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // I/O to when it no longer holds any lock).
7683345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    virtual void OnChangesComplete(syncable::ModelType model_type) = 0;
7693345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
770c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // A round-trip sync-cycle took place and the syncer has resolved any
771c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // conflicts that may have arisen.
772c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnSyncCycleCompleted(
773c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch        const browser_sync::sessions::SyncSessionSnapshot* snapshot) = 0;
774c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
775c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when user interaction may be required due to an auth problem.
776c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnAuthError(const GoogleServiceAuthError& auth_error) = 0;
777c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
7783345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // Called when a new auth token is provided by the sync server.
7793345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    virtual void OnUpdatedToken(const std::string& token) = 0;
7803345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
781c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when user interaction is required to obtain a valid passphrase.
782201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch    // If the passphrase is required to decrypt something that has
783201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch    // already been encrypted (and thus has to match the existing key),
784201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch    // |for_decryption| will be true.  If the passphrase is needed for
785201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch    // encryption, |for_decryption| will be false.
786201ade2fbba22bfb27ae029f4d23fca6ded109a0Ben Murdoch    virtual void OnPassphraseRequired(bool for_decryption) = 0;
787c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
788dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    // Called only by SyncInternal::SetPassphrase to indiciate that an attempted
789dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    // passphrase failed to decrypt pending keys. This is different from
790dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    // OnPassphraseRequired in that it denotes we finished an attempt to set
791dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    // a passphrase. OnPassphraseRequired means we have data we could not
792dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    // decrypt yet, and can come from numerous places.
793dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    virtual void OnPassphraseFailed() = 0;
794dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
795c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when the passphrase provided by the user has been accepted and is
7963345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // now used to encrypt sync data.  |bootstrap_token| is an opaque base64
7973345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // encoded representation of the key generated by the accepted passphrase,
7983345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // and is provided to the observer for persistence purposes and use in a
7993345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // future initialization of sync (e.g. after restart).
8003345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    virtual void OnPassphraseAccepted(const std::string& bootstrap_token) = 0;
801c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
802c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Called when initialization is complete to the point that SyncManager can
803c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // process changes. This does not necessarily mean authentication succeeded
804c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // or that the SyncManager is online.
805c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // IMPORTANT: Creating any type of transaction before receiving this
806c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // notification is illegal!
807c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // WARNING: Calling methods on the SyncManager before receiving this
808c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // message, unless otherwise specified, produces undefined behavior.
809c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnInitializationComplete() = 0;
810c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
811c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // We are no longer permitted to communicate with the server. Sync should
812c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // be disabled and state cleaned up at once.  This can happen for a number
813c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // of reasons, e.g. swapping from a test instance to production, or a
814c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // global stop syncing operation has wiped the store.
815c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnStopSyncingPermanently() = 0;
816c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
8173345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    // After a request to clear server data, these callbacks are invoked to
818dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    // indicate success or failure.
8193345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    virtual void OnClearServerDataSucceeded() = 0;
8203345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick    virtual void OnClearServerDataFailed() = 0;
8213345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
822dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    // Called after we finish encrypting all appropriate datatypes.
823dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen    virtual void OnEncryptionComplete(
824dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen        const syncable::ModelTypeSet& encrypted_types) = 0;
825dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
82672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen   protected:
82772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen    virtual ~Observer();
828c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  };
829c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
830ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  typedef Callback0::Type ModeChangeCallback;
831ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
832c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Create an uninitialized SyncManager.  Callers must Init() before using.
833c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  SyncManager();
834c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual ~SyncManager();
835c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
836c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Initialize the sync manager.  |database_location| specifies the path of
837c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // the directory in which to locate a sqlite repository storing the syncer
838c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // backend state. Initialization will open the database, or create it if it
839c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // does not already exist. Returns false on failure.
840c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // |sync_server_and_path| and |sync_server_port| represent the Chrome sync
841c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // server to use, and |use_ssl| specifies whether to communicate securely;
842c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // the default is false.
843c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // |post_factory| will be owned internally and used to create
844c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // instances of an HttpPostProvider.
845c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // |model_safe_worker| ownership is given to the SyncManager.
846c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent
847c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // HTTP header. Used internally when collecting stats to classify clients.
848ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // |sync_notifier| used to listen for notifications, not owned.
849c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool Init(const FilePath& database_location,
850c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch            const char* sync_server_and_path,
851c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch            int sync_server_port,
852c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch            bool use_ssl,
853c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch            HttpPostProviderFactory* post_factory,
854c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch            browser_sync::ModelSafeWorkerRegistrar* registrar,
855c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch            const char* user_agent,
8563345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick            const SyncCredentials& credentials,
857ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen            sync_notifier::SyncNotifier* sync_notifier,
8583345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick            const std::string& restored_key_for_bootstrapping,
8593345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick            bool setup_for_test_mode);
860c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
861c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns the username last used for a successful authentication.
862c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns empty if there is no such username.
863c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  const std::string& GetAuthenticatedUsername();
864c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
8653345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Check if the database has been populated with a full "initial" download of
8663345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // sync items for each data type currently present in the routing info.
8673345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Prerequisite for calling this is that OnInitializationComplete has been
8683345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // called.
8693345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  bool InitialSyncEndedForAllEnabledTypes();
8703345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
87121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  syncable::AutofillMigrationState GetAutofillMigrationState();
87221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
87321d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  void SetAutofillMigrationState(
87421d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen    syncable::AutofillMigrationState state);
87521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
87621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  syncable::AutofillMigrationDebugInfo GetAutofillMigrationDebugInfo();
87721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
87821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  void SetAutofillMigrationDebugInfo(
87921d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen      syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set,
88021d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen      const syncable::AutofillMigrationDebugInfo& info);
88121d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen
8823345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Migrate tokens from user settings DB to the token service.
8833345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void MigrateTokens();
8843345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
8853345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Update tokens that we're using in Sync. Email must stay the same.
8863345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void UpdateCredentials(const SyncCredentials& credentials);
887c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
888ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Called when the user disables or enables a sync type.
889ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void UpdateEnabledTypes();
890dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
891c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Start the SyncerThread.
892dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // TODO(tim): With the new impl, this would mean starting "NORMAL" operation.
893dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // Rename this when switched over or at least update comment.
894c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void StartSyncing();
895c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
896c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Attempt to set the passphrase. If the passphrase is valid,
897c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // OnPassphraseAccepted will be fired to notify the ProfileSyncService and the
898c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // syncer will be nudged so that any update that was waiting for this
899c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // passphrase gets applied as soon as possible.
900c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // If the passphrase in invalid, OnPassphraseRequired will be fired.
901c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Calling this metdod again is the appropriate course of action to "retry"
902c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // with a new passphrase.
9034a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch  // |is_explicit| is true if the call is in response to the user explicitly
9044a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch  // setting a passphrase as opposed to implicitly (from the users' perspective)
9054a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch  // using their Google Account password.  An implicit SetPassphrase will *not*
9064a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch  // *not* override an explicit passphrase set previously.
9074a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch  void SetPassphrase(const std::string& passphrase, bool is_explicit);
908c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
909dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // Set the datatypes we want to encrypt and encrypt any nodes as necessary.
910dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // Note: |encrypted_types| will be unioned with the current set of encrypted
911dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // types, as we do not currently support decrypting datatypes.
912dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  void EncryptDataTypes(const syncable::ModelTypeSet& encrypted_types);
913dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
914ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Puts the SyncerThread into a mode where no normal nudge or poll traffic
915ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // will occur, but calls to RequestConfig will be supported.  If |callback|
916ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // is provided, it will be invoked (from the internal SyncerThread) when
917ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // the thread has changed to configuration mode.
918ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void StartConfigurationMode(ModeChangeCallback* callback);
919c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
920dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // For the new SyncerThread impl, this switches the mode of operation to
921dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // CONFIGURATION_MODE and schedules a config task to fetch updates for
922dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // |types|. It is an error to call this with legacy SyncerThread in use.
923dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  void RequestConfig(const syncable::ModelTypeBitSet& types);
924dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
925c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Request a nudge of the syncer, which will cause the syncer thread
926c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to run at the next available opportunity.
927ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void RequestNudge(const tracked_objects::Location& nudge_location);
928c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
9293345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Request a clearing of all data on the server
9303345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void RequestClearServerData();
9313345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
932c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Adds a listener to be notified of sync events.
933c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // NOTE: It is OK (in fact, it's probably a good idea) to call this before
934c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // having received OnInitializationCompleted.
93572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  void AddObserver(Observer* observer);
93672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
93772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Remove the given observer.  Make sure to call this if the
93872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Observer is being destroyed so the SyncManager doesn't
93972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // potentially dereference garbage.
94072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  void RemoveObserver(Observer* observer);
94172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
94272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Returns a pointer to the JsBackend (which is owned by the sync
94372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // manager).  Never returns NULL.  The following events are sent by
94472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // the returned backend:
94572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
94672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // onSyncNotificationStateChange(boolean notificationsEnabled):
94772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   Sent when notifications are enabled or disabled.
94872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
94972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // onSyncIncomingNotification(array changedTypes):
95072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   Sent when an incoming notification arrives.  |changedTypes|
95172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   contains a list of sync types (strings) which have changed.
95272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
95372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // The following messages are processed by the returned backend:
95472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
95572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // getNotificationState():
95672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   If there is a parent router, sends the
95772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   onGetNotificationStateFinished(boolean notificationsEnabled)
95872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   event to |sender| via the parent router with whether or not
95972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   notifications are enabled.
96072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
96172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // getRootNode():
96272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   If there is a parent router, sends the
96372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   onGetRootNodeFinished(dictionary nodeInfo) event to |sender|
96472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   via the parent router with information on the root node.
96572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
96672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // getNodeById(string id):
96772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   If there is a parent router, sends the
96872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   onGetNodeByIdFinished(dictionary nodeInfo) event to |sender|
96972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   via the parent router with information on the node with the
97072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   given id (metahandle), if the id is valid and a node with that
97172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //   id exists.  Otherwise, calls onGetNodeByIdFinished(null).
97272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  //
97372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // All other messages are dropped.
97472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  browser_sync::JsBackend* GetJsBackend();
975c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
976c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Status-related getters. Typically GetStatusSummary will suffice, but
977c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // GetDetailedSyncStatus can be useful for gathering debug-level details of
978c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // the internals of the sync engine.
979c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  Status::Summary GetStatusSummary() const;
980c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  Status GetDetailedStatus() const;
981c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
9824a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch  // Whether or not the Nigori node is encrypted using an explicit passphrase.
9834a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch  bool IsUsingExplicitPassphrase();
9844a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch
985c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Get the internal implementation for use by BaseTransaction, etc.
986c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  SyncInternal* GetImpl() const;
987c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
988c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Call periodically from a database-safe thread to persist recent changes
989c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to the syncapi model.
990c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SaveChanges();
991c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
992c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Issue a final SaveChanges, close sqlite handles, and stop running threads.
993c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Must be called from the same thread that called Init().
994c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void Shutdown();
995c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
996c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  UserShare* GetUserShare() const;
997c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
9983345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Uses a read-only transaction to determine if the directory being synced has
9993345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // any remaining unsynced items.
10003345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  bool HasUnsyncedItems() const;
10013345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
100272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Functions used for testing.
100372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
100472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  void TriggerOnNotificationStateChangeForTest(
100572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      bool notifications_enabled);
100672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
100772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  void TriggerOnIncomingNotificationForTest(
100872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen      const syncable::ModelTypeBitSet& model_types);
100972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
1010c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private:
1011c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // An opaque pointer to the nested private class.
1012c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  SyncInternal* data_;
1013c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
1014c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(SyncManager);
1015c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
1016c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
1017c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}  // namespace sync_api
1018c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
1019c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif  // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_
1020