summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/sync/abstract_profile_sync_service_test.cc2
-rw-r--r--chrome/browser/sync/engine/DEPS8
-rw-r--r--chrome/browser/sync/engine/all_status.h2
-rw-r--r--chrome/browser/sync/engine/change_reorder_buffer.cc1
-rw-r--r--chrome/browser/sync/engine/change_reorder_buffer.h3
-rw-r--r--chrome/browser/sync/engine/net/server_connection_manager.cc1
-rw-r--r--chrome/browser/sync/engine/net/syncapi_server_connection_manager.cc1
-rw-r--r--chrome/browser/sync/engine/nigori_util.cc2
-rw-r--r--chrome/browser/sync/engine/sync_scheduler.h7
-rw-r--r--chrome/browser/sync/engine/syncapi.h1095
-rw-r--r--chrome/browser/sync/engine/syncapi_internal.cc78
-rw-r--r--chrome/browser/sync/engine/syncapi_internal.h34
-rw-r--r--chrome/browser/sync/glue/app_change_processor.cc1
-rw-r--r--chrome/browser/sync/glue/app_change_processor.h2
-rw-r--r--chrome/browser/sync/glue/app_model_associator.cc5
-rw-r--r--chrome/browser/sync/glue/autofill_change_processor.cc5
-rw-r--r--chrome/browser/sync/glue/autofill_change_processor.h8
-rw-r--r--chrome/browser/sync/glue/autofill_model_associator.cc5
-rw-r--r--chrome/browser/sync/glue/autofill_model_associator.h2
-rw-r--r--chrome/browser/sync/glue/autofill_profile_change_processor.cc5
-rw-r--r--chrome/browser/sync/glue/autofill_profile_change_processor.h8
-rw-r--r--chrome/browser/sync/glue/autofill_profile_model_associator.cc4
-rw-r--r--chrome/browser/sync/glue/autofill_profile_model_associator.h4
-rw-r--r--chrome/browser/sync/glue/autofill_profile_model_associator_unittest.cc4
-rw-r--r--chrome/browser/sync/glue/bookmark_change_processor.cc3
-rw-r--r--chrome/browser/sync/glue/bookmark_change_processor.h7
-rw-r--r--chrome/browser/sync/glue/bookmark_model_associator.cc5
-rw-r--r--chrome/browser/sync/glue/change_processor.h2
-rw-r--r--chrome/browser/sync/glue/change_processor_mock.h3
-rw-r--r--chrome/browser/sync/glue/extension_change_processor.cc1
-rw-r--r--chrome/browser/sync/glue/extension_change_processor.h2
-rw-r--r--chrome/browser/sync/glue/extension_model_associator.cc3
-rw-r--r--chrome/browser/sync/glue/extension_sync.cc5
-rw-r--r--chrome/browser/sync/glue/extension_sync_traits.cc2
-rw-r--r--chrome/browser/sync/glue/generic_change_processor.cc6
-rw-r--r--chrome/browser/sync/glue/http_bridge.h3
-rw-r--r--chrome/browser/sync/glue/password_change_processor.cc5
-rw-r--r--chrome/browser/sync/glue/password_model_associator.cc5
-rw-r--r--chrome/browser/sync/glue/session_change_processor.cc3
-rw-r--r--chrome/browser/sync/glue/session_change_processor.h2
-rw-r--r--chrome/browser/sync/glue/session_model_associator.cc4
-rw-r--r--chrome/browser/sync/glue/session_model_associator.h4
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.cc4
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.h2
-rw-r--r--chrome/browser/sync/glue/sync_backend_host_unittest.cc3
-rw-r--r--chrome/browser/sync/glue/theme_change_processor.cc7
-rw-r--r--chrome/browser/sync/glue/theme_change_processor.h2
-rw-r--r--chrome/browser/sync/glue/theme_model_associator.cc5
-rw-r--r--chrome/browser/sync/glue/typed_url_change_processor.cc3
-rw-r--r--chrome/browser/sync/glue/typed_url_model_associator.cc5
-rw-r--r--chrome/browser/sync/glue/ui_model_worker.h5
-rw-r--r--chrome/browser/sync/glue/ui_model_worker_unittest.cc6
-rw-r--r--chrome/browser/sync/internal_api/DEPS14
-rw-r--r--chrome/browser/sync/internal_api/README32
-rw-r--r--chrome/browser/sync/internal_api/base_node.cc298
-rw-r--r--chrome/browser/sync/internal_api/base_node.h224
-rw-r--r--chrome/browser/sync/internal_api/base_transaction.cc35
-rw-r--r--chrome/browser/sync/internal_api/base_transaction.h59
-rw-r--r--chrome/browser/sync/internal_api/read_node.cc92
-rw-r--r--chrome/browser/sync/internal_api/read_node.h79
-rw-r--r--chrome/browser/sync/internal_api/read_node_mock.cc (renamed from chrome/browser/sync/engine/read_node_mock.cc)2
-rw-r--r--chrome/browser/sync/internal_api/read_node_mock.h (renamed from chrome/browser/sync/engine/read_node_mock.h)9
-rw-r--r--chrome/browser/sync/internal_api/read_transaction.cc37
-rw-r--r--chrome/browser/sync/internal_api/read_transaction.h45
-rw-r--r--chrome/browser/sync/internal_api/sync_manager.cc (renamed from chrome/browser/sync/engine/syncapi.cc)1154
-rw-r--r--chrome/browser/sync/internal_api/sync_manager.h546
-rw-r--r--chrome/browser/sync/internal_api/syncapi_mock.h (renamed from chrome/browser/sync/engine/syncapi_mock.h)8
-rw-r--r--chrome/browser/sync/internal_api/syncapi_unittest.cc (renamed from chrome/browser/sync/engine/syncapi_unittest.cc)8
-rw-r--r--chrome/browser/sync/internal_api/user_share.cc15
-rw-r--r--chrome/browser/sync/internal_api/user_share.h37
-rw-r--r--chrome/browser/sync/internal_api/write_node.cc538
-rw-r--r--chrome/browser/sync/internal_api/write_node.h193
-rw-r--r--chrome/browser/sync/internal_api/write_transaction.cc29
-rw-r--r--chrome/browser/sync/internal_api/write_transaction.h56
-rw-r--r--chrome/browser/sync/js/DEPS4
-rw-r--r--chrome/browser/sync/js/js_sync_manager_observer.h2
-rw-r--r--chrome/browser/sync/js/js_sync_manager_observer_unittest.cc5
-rw-r--r--chrome/browser/sync/notifier/DEPS2
-rw-r--r--chrome/browser/sync/profile_sync_factory_impl_unittest.cc5
-rw-r--r--chrome/browser/sync/profile_sync_service.cc2
-rw-r--r--chrome/browser/sync/profile_sync_service.h3
-rw-r--r--chrome/browser/sync/profile_sync_service_autofill_unittest.cc5
-rw-r--r--chrome/browser/sync/profile_sync_service_bookmark_unittest.cc6
-rw-r--r--chrome/browser/sync/profile_sync_service_password_unittest.cc5
-rw-r--r--chrome/browser/sync/profile_sync_service_preference_unittest.cc8
-rw-r--r--chrome/browser/sync/profile_sync_service_session_unittest.cc7
-rw-r--r--chrome/browser/sync/profile_sync_service_typed_url_unittest.cc5
-rw-r--r--chrome/browser/sync/protocol/DEPS2
-rw-r--r--chrome/browser/sync/sessions/DEPS2
-rw-r--r--chrome/browser/sync/sync_setup_wizard_unittest.cc1
-rw-r--r--chrome/browser/sync/syncable/DEPS2
-rw-r--r--chrome/browser/sync/syncable/model_type_payload_map.cc2
-rw-r--r--chrome/browser/sync/syncable/syncable.cc6
-rw-r--r--chrome/browser/sync/test_profile_sync_service.cc2
-rw-r--r--chrome/browser/ui/webui/ntp/foreign_session_handler.cc3
-rw-r--r--chrome/browser/ui/webui/sessions_ui.cc2
-rw-r--r--chrome/chrome.gyp22
-rw-r--r--chrome/chrome_tests.gypi8
-rw-r--r--chrome/test/sync/engine/test_user_share.h2
99 files changed, 2721 insertions, 2296 deletions
diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.cc b/chrome/browser/sync/abstract_profile_sync_service_test.cc
index 2dcace3..640b273 100644
--- a/chrome/browser/sync/abstract_profile_sync_service_test.cc
+++ b/chrome/browser/sync/abstract_profile_sync_service_test.cc
@@ -5,7 +5,7 @@
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
#include "base/tracked.h"
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
diff --git a/chrome/browser/sync/engine/DEPS b/chrome/browser/sync/engine/DEPS
index ce9fd8a..0142088 100644
--- a/chrome/browser/sync/engine/DEPS
+++ b/chrome/browser/sync/engine/DEPS
@@ -11,13 +11,13 @@ include_rules = [
"+chrome/browser/sync/syncable",
"+chrome/browser/sync/util",
+ # TODO(rlarocque) 19878: Move remaining syncapi-related headers to
+ # internal_api/, then remove this DEPS rule.
+ "+chrome/browser/sync/internal_api",
+
# this should live in base
"+chrome/browser/sync/weak_handle.h",
- # unittests need this for mac osx keychain overriding
- "+chrome/browser/password_manager/encryptor.h",
-
- "+chrome/common/net/gaia/google_service_auth_error.h",
"+chrome/common/net/http_return.h",
# various command line flags
diff --git a/chrome/browser/sync/engine/all_status.h b/chrome/browser/sync/engine/all_status.h
index dd1461b..bef60c9 100644
--- a/chrome/browser/sync/engine/all_status.h
+++ b/chrome/browser/sync/engine/all_status.h
@@ -13,8 +13,8 @@
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/engine/syncer_types.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "chrome/browser/sync/syncable/model_type.h"
namespace browser_sync {
diff --git a/chrome/browser/sync/engine/change_reorder_buffer.cc b/chrome/browser/sync/engine/change_reorder_buffer.cc
index 76f6e03..189c072 100644
--- a/chrome/browser/sync/engine/change_reorder_buffer.cc
+++ b/chrome/browser/sync/engine/change_reorder_buffer.cc
@@ -10,6 +10,7 @@
#include <utility> // for pair<>
#include <vector>
+#include "chrome/browser/sync/internal_api/read_node.h"
#include "chrome/browser/sync/syncable/model_type.h"
#include "chrome/browser/sync/syncable/syncable.h"
diff --git a/chrome/browser/sync/engine/change_reorder_buffer.h b/chrome/browser/sync/engine/change_reorder_buffer.h
index f4062ef..25bb086 100644
--- a/chrome/browser/sync/engine/change_reorder_buffer.h
+++ b/chrome/browser/sync/engine/change_reorder_buffer.h
@@ -14,7 +14,8 @@
#include <vector>
#include "base/memory/linked_ptr.h"
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/internal_api/base_transaction.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "chrome/browser/sync/protocol/sync.pb.h"
namespace sync_api {
diff --git a/chrome/browser/sync/engine/net/server_connection_manager.cc b/chrome/browser/sync/engine/net/server_connection_manager.cc
index 2765508..3604026 100644
--- a/chrome/browser/sync/engine/net/server_connection_manager.cc
+++ b/chrome/browser/sync/engine/net/server_connection_manager.cc
@@ -13,7 +13,6 @@
#include "base/command_line.h"
#include "build/build_config.h"
#include "chrome/browser/sync/engine/net/url_translator.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/engine/syncer.h"
#include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/protocol/sync.pb.h"
diff --git a/chrome/browser/sync/engine/net/syncapi_server_connection_manager.cc b/chrome/browser/sync/engine/net/syncapi_server_connection_manager.cc
index b05c525..826f930 100644
--- a/chrome/browser/sync/engine/net/syncapi_server_connection_manager.cc
+++ b/chrome/browser/sync/engine/net/syncapi_server_connection_manager.cc
@@ -6,7 +6,6 @@
#include "chrome/browser/sync/engine/http_post_provider_factory.h"
#include "chrome/browser/sync/engine/http_post_provider_interface.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/util/oauth.h"
#include "chrome/common/net/http_return.h"
diff --git a/chrome/browser/sync/engine/nigori_util.cc b/chrome/browser/sync/engine/nigori_util.cc
index b305c49..ce721c2 100644
--- a/chrome/browser/sync/engine/nigori_util.cc
+++ b/chrome/browser/sync/engine/nigori_util.cc
@@ -8,8 +8,8 @@
#include <string>
#include <vector>
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/engine/syncer_util.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/util/cryptographer.h"
diff --git a/chrome/browser/sync/engine/sync_scheduler.h b/chrome/browser/sync/engine/sync_scheduler.h
index eda53b1..7a025fb 100644
--- a/chrome/browser/sync/engine/sync_scheduler.h
+++ b/chrome/browser/sync/engine/sync_scheduler.h
@@ -19,14 +19,13 @@
#include "base/time.h"
#include "base/timer.h"
#include "chrome/browser/sync/engine/configure_reason.h"
+#include "chrome/browser/sync/engine/net/server_connection_manager.h"
#include "chrome/browser/sync/engine/nudge_source.h"
#include "chrome/browser/sync/engine/polling_constants.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/engine/syncer.h"
-#include "chrome/browser/sync/syncable/model_type_payload_map.h"
-#include "chrome/browser/sync/engine/net/server_connection_manager.h"
-#include "chrome/browser/sync/sessions/sync_session.h"
#include "chrome/browser/sync/sessions/sync_session_context.h"
+#include "chrome/browser/sync/sessions/sync_session.h"
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
class MessageLoop;
diff --git a/chrome/browser/sync/engine/syncapi.h b/chrome/browser/sync/engine/syncapi.h
deleted file mode 100644
index eaf9a56..0000000
--- a/chrome/browser/sync/engine/syncapi.h
+++ /dev/null
@@ -1,1095 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// This file defines the "sync API", an interface to the syncer
-// backend that exposes (1) the core functionality of maintaining a consistent
-// local snapshot of a hierarchical object set; (2) a means to transactionally
-// access and modify those objects; (3) a means to control client/server
-// synchronization tasks, namely: pushing local object modifications to a
-// server, pulling nonlocal object modifications from a server to this client,
-// and resolving conflicts that may arise between the two; and (4) an
-// abstraction of some external functionality that is to be provided by the
-// host environment.
-//
-// This interface is used as the entry point into the syncer backend
-// when the backend is compiled as a library and embedded in another
-// application. A goal for this interface layer is to depend on very few
-// external types, so that an application can use the sync backend
-// without introducing a dependency on specific types. A non-goal is to
-// have binary compatibility across versions or compilers; this allows the
-// interface to use C++ classes. An application wishing to use the sync API
-// should ideally compile the syncer backend and this API as part of the
-// application's own build, to avoid e.g. mismatches in calling convention,
-// structure padding, or name mangling that could arise if there were a
-// compiler mismatch.
-//
-// The schema of the objects in the sync domain is based on the model, which
-// is essentially a hierarchy of items and folders similar to a filesystem,
-// but with a few important differences. The sync API contains fields
-// such as URL to easily allow the embedding application to store web
-// browser bookmarks. Also, the sync API allows duplicate titles in a parent.
-// Consequently, it does not support looking up an object by title
-// and parent, since such a lookup is not uniquely determined. Lastly,
-// unlike a filesystem model, objects in the Sync API model have a strict
-// ordering within a parent; the position is manipulable by callers, and
-// children of a node can be enumerated in the order of their position.
-
-#ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_
-#define CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_
-#pragma once
-
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/callback_old.h"
-#include "base/gtest_prod_util.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/tracked.h"
-#include "build/build_config.h"
-#include "chrome/browser/sync/engine/configure_reason.h"
-#include "chrome/browser/sync/protocol/password_specifics.pb.h"
-#include "chrome/browser/sync/syncable/model_type.h"
-#include "chrome/browser/sync/util/cryptographer.h"
-#include "chrome/browser/sync/weak_handle.h"
-#include "chrome/common/net/gaia/google_service_auth_error.h"
-#include "googleurl/src/gurl.h"
-
-class FilePath;
-
-namespace base {
-class DictionaryValue;
-}
-
-namespace browser_sync {
-class JsBackend;
-class JsEventHandler;
-class ModelSafeWorkerRegistrar;
-
-namespace sessions {
-struct SyncSessionSnapshot;
-}
-}
-
-namespace sync_notifier {
-class SyncNotifier;
-} // namespace sync_notifier
-
-// Forward declarations of internal class types so that sync API objects
-// may have opaque pointers to these types.
-namespace syncable {
-class BaseTransaction;
-class DirectoryManager;
-class Entry;
-class MutableEntry;
-class ReadTransaction;
-class ScopedDirLookup;
-class WriteTransaction;
-}
-
-namespace sync_pb {
-class AppSpecifics;
-class AutofillSpecifics;
-class AutofillProfileSpecifics;
-class BookmarkSpecifics;
-class EntitySpecifics;
-class ExtensionSpecifics;
-class SessionSpecifics;
-class NigoriSpecifics;
-class PasswordSpecifics;
-class PreferenceSpecifics;
-class PasswordSpecifics;
-class PasswordSpecificsData;
-class ThemeSpecifics;
-class TypedUrlSpecifics;
-}
-
-namespace tracked_objects {
-class Location;
-} // namespace tracked_objects
-
-namespace sync_api {
-
-class BaseTransaction;
-class HttpPostProviderFactory;
-class SyncManager;
-class WriteTransaction;
-
-syncable::ModelTypeSet GetEncryptedTypes(
- const sync_api::BaseTransaction* trans);
-
-
-// Reasons due to which browser_sync::Cryptographer might require a passphrase.
-enum PassphraseRequiredReason {
- REASON_PASSPHRASE_NOT_REQUIRED = 0, // Initial value.
- REASON_ENCRYPTION = 1, // The cryptographer requires a
- // passphrase for its first attempt at
- // encryption. Happens only during
- // migration or upgrade.
- REASON_DECRYPTION = 2, // The cryptographer requires a
- // passphrase for its first attempt at
- // decryption.
- REASON_SET_PASSPHRASE_FAILED = 3, // The cryptographer requires a new
- // passphrase because its attempt at
- // decryption with the cached passphrase
- // was unsuccessful.
-};
-
-// Returns the string representation of a PassphraseRequiredReason value.
-std::string PassphraseRequiredReasonToString(PassphraseRequiredReason reason);
-
-// A UserShare encapsulates the syncable pieces that represent an authenticated
-// user and their data (share).
-// This encompasses all pieces required to build transaction objects on the
-// syncable share.
-struct UserShare {
- UserShare();
- ~UserShare();
-
- // The DirectoryManager itself, which is the parent of Transactions and can
- // be shared across multiple threads (unlike Directory).
- scoped_ptr<syncable::DirectoryManager> dir_manager;
-
- // The username of the sync user.
- std::string name;
-};
-
-bool InitialSyncEndedForTypes(syncable::ModelTypeSet types, UserShare* share);
-
-// Contains everything needed to talk to and identify a user account.
-struct SyncCredentials {
- std::string email;
- std::string sync_token;
-};
-
-// A valid BaseNode will never have an ID of zero.
-static const int64 kInvalidId = 0;
-
-// BaseNode wraps syncable::Entry, and corresponds to a single object's state.
-// This, like syncable::Entry, is intended for use on the stack. A valid
-// transaction is necessary to create a BaseNode or any of its children.
-// Unlike syncable::Entry, a sync API BaseNode is identified primarily by its
-// int64 metahandle, which we call an ID here.
-class BaseNode {
- public:
- // All subclasses of BaseNode must provide a way to initialize themselves by
- // doing an ID lookup. Returns false on failure. An invalid or deleted
- // ID will result in failure.
- virtual bool InitByIdLookup(int64 id) = 0;
-
- // All subclasses of BaseNode must also provide a way to initialize themselves
- // by doing a client tag lookup. Returns false on failure. A deleted node
- // will return FALSE.
- virtual bool InitByClientTagLookup(syncable::ModelType model_type,
- const std::string& tag) = 0;
-
- // Each object is identified by a 64-bit id (internally, the syncable
- // metahandle). These ids are strictly local handles. They will persist
- // on this client, but the same object on a different client may have a
- // different ID value.
- virtual int64 GetId() const;
-
- // Returns the modification time of the object (in TimeTicks internal format).
- int64 GetModificationTime() const;
-
- // Nodes are hierarchically arranged into a single-rooted tree.
- // InitByRootLookup on ReadNode allows access to the root. GetParentId is
- // how you find a node's parent.
- int64 GetParentId() const;
-
- // Nodes are either folders or not. This corresponds to the IS_DIR property
- // of syncable::Entry.
- bool GetIsFolder() const;
-
- // Returns the title of the object.
- // Uniqueness of the title is not enforced on siblings -- it is not an error
- // for two children to share a title.
- std::string GetTitle() const;
-
- // Returns the model type of this object. The model type is set at node
- // creation time and is expected never to change.
- syncable::ModelType GetModelType() const;
-
- // Getter specific to the BOOKMARK datatype. Returns protobuf
- // data. Can only be called if GetModelType() == BOOKMARK.
- const sync_pb::BookmarkSpecifics& GetBookmarkSpecifics() const;
-
- // Legacy, bookmark-specific getter that wraps GetBookmarkSpecifics() above.
- // Returns the URL of a bookmark object.
- // TODO(ncarter): Remove this datatype-specific accessor.
- GURL GetURL() const;
-
- // Legacy, bookmark-specific getter that wraps GetBookmarkSpecifics() above.
- // Fill in a vector with the byte data of this node's favicon. Assumes
- // that the node is a bookmark.
- // Favicons are expected to be PNG images, and though no verification is
- // done on the syncapi client of this, the server may reject favicon updates
- // that are invalid for whatever reason.
- // TODO(ncarter): Remove this datatype-specific accessor.
- void GetFaviconBytes(std::vector<unsigned char>* output) const;
-
- // Getter specific to the APPS datatype. Returns protobuf
- // data. Can only be called if GetModelType() == APPS.
- const sync_pb::AppSpecifics& GetAppSpecifics() const;
-
- // Getter specific to the AUTOFILL datatype. Returns protobuf
- // data. Can only be called if GetModelType() == AUTOFILL.
- const sync_pb::AutofillSpecifics& GetAutofillSpecifics() const;
-
- virtual const sync_pb::AutofillProfileSpecifics&
- GetAutofillProfileSpecifics() const;
-
- // Getter specific to the NIGORI datatype. Returns protobuf
- // data. Can only be called if GetModelType() == NIGORI.
- const sync_pb::NigoriSpecifics& GetNigoriSpecifics() const;
-
- // Getter specific to the PASSWORD datatype. Returns protobuf
- // data. Can only be called if GetModelType() == PASSWORD.
- const sync_pb::PasswordSpecificsData& GetPasswordSpecifics() const;
-
- // Getter specific to the PREFERENCE datatype. Returns protobuf
- // data. Can only be called if GetModelType() == PREFERENCE.
- const sync_pb::PreferenceSpecifics& GetPreferenceSpecifics() const;
-
- // Getter specific to the THEME datatype. Returns protobuf
- // data. Can only be called if GetModelType() == THEME.
- const sync_pb::ThemeSpecifics& GetThemeSpecifics() const;
-
- // Getter specific to the TYPED_URLS datatype. Returns protobuf
- // data. Can only be called if GetModelType() == TYPED_URLS.
- const sync_pb::TypedUrlSpecifics& GetTypedUrlSpecifics() const;
-
- // Getter specific to the EXTENSIONS datatype. Returns protobuf
- // data. Can only be called if GetModelType() == EXTENSIONS.
- const sync_pb::ExtensionSpecifics& GetExtensionSpecifics() const;
-
- // Getter specific to the SESSIONS datatype. Returns protobuf
- // data. Can only be called if GetModelType() == SESSIONS.
- const sync_pb::SessionSpecifics& GetSessionSpecifics() const;
-
- const sync_pb::EntitySpecifics& GetEntitySpecifics() const;
-
- // Returns the local external ID associated with the node.
- int64 GetExternalId() const;
-
- // Return the ID of the node immediately before this in the sibling order.
- // For the first node in the ordering, return 0.
- int64 GetPredecessorId() const;
-
- // Return the ID of the node immediately after this in the sibling order.
- // For the last node in the ordering, return 0.
- virtual int64 GetSuccessorId() const;
-
- // Return the ID of the first child of this node. If this node has no
- // children, return 0.
- virtual int64 GetFirstChildId() const;
-
- // These virtual accessors provide access to data members of derived classes.
- virtual const syncable::Entry* GetEntry() const = 0;
- virtual const BaseTransaction* GetTransaction() const = 0;
-
- // Dumps a summary of node info into a DictionaryValue and returns it.
- // Transfers ownership of the DictionaryValue to the caller.
- base::DictionaryValue* GetSummaryAsValue() const;
-
- // Dumps all node details into a DictionaryValue and returns it.
- // Transfers ownership of the DictionaryValue to the caller.
- base::DictionaryValue* GetDetailsAsValue() const;
-
- protected:
- BaseNode();
- virtual ~BaseNode();
- // The server has a size limit on client tags, so we generate a fixed length
- // hash locally. This also ensures that ModelTypes have unique namespaces.
- static std::string GenerateSyncableHash(syncable::ModelType model_type,
- const std::string& client_tag);
-
- // Determines whether part of the entry is encrypted, and if so attempts to
- // decrypt it. Unless decryption is necessary and fails, this will always
- // return |true|. If the contents are encrypted, the decrypted data will be
- // stored in |unencrypted_data_|.
- // This method is invoked once when the BaseNode is initialized.
- bool DecryptIfNecessary();
-
- // Returns the unencrypted specifics associated with |entry|. If |entry| was
- // not encrypted, it directly returns |entry|'s EntitySpecifics. Otherwise,
- // returns |unencrypted_data_|.
- const sync_pb::EntitySpecifics& GetUnencryptedSpecifics(
- const syncable::Entry* entry) const;
-
- // Copy |specifics| into |unencrypted_data_|.
- void SetUnencryptedSpecifics(const sync_pb::EntitySpecifics& specifics);
-
- private:
- void* operator new(size_t size); // Node is meant for stack use only.
-
- // A holder for the unencrypted data stored in an encrypted node.
- sync_pb::EntitySpecifics unencrypted_data_;
-
- // Same as |unencrypted_data_|, but for legacy password encryption.
- scoped_ptr<sync_pb::PasswordSpecificsData> password_data_;
-
- friend class SyncApiTest;
- FRIEND_TEST_ALL_PREFIXES(SyncApiTest, GenerateSyncableHash);
-
- DISALLOW_COPY_AND_ASSIGN(BaseNode);
-};
-
-// WriteNode extends BaseNode to add mutation, and wraps
-// syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode.
-class WriteNode : public BaseNode {
- public:
- // Create a WriteNode using the given transaction.
- explicit WriteNode(WriteTransaction* transaction);
- virtual ~WriteNode();
-
- // A client must use one (and only one) of the following Init variants to
- // populate the node.
-
- // BaseNode implementation.
- virtual bool InitByIdLookup(int64 id);
- virtual bool InitByClientTagLookup(syncable::ModelType model_type,
- const std::string& tag);
-
- // Create a new node with the specified parent and predecessor. |model_type|
- // dictates the type of the item, and controls which EntitySpecifics proto
- // extension can be used with this item. Use a NULL |predecessor|
- // to indicate that this is to be the first child.
- // |predecessor| must be a child of |new_parent| or NULL. Returns false on
- // failure.
- bool InitByCreation(syncable::ModelType model_type,
- const BaseNode& parent,
- const BaseNode* predecessor);
-
- // Create nodes using this function if they're unique items that
- // you want to fetch using client_tag. Note that the behavior of these
- // items is slightly different than that of normal items.
- // Most importantly, if it exists locally, this function will
- // actually undelete it
- // Client unique tagged nodes must NOT be folders.
- bool InitUniqueByCreation(syncable::ModelType model_type,
- const BaseNode& parent,
- const std::string& client_tag);
-
- // Each server-created permanent node is tagged with a unique string.
- // Look up the node with the particular tag. If it does not exist,
- // return false.
- bool InitByTagLookup(const std::string& tag);
-
- // These Set() functions correspond to the Get() functions of BaseNode.
- void SetIsFolder(bool folder);
- void SetTitle(const std::wstring& title);
-
- // External ID is a client-only field, so setting it doesn't cause the item to
- // be synced again.
- void SetExternalId(int64 external_id);
-
- // Remove this node and its children.
- void Remove();
-
- // Set a new parent and position. Position is specified by |predecessor|; if
- // it is NULL, the node is moved to the first position. |predecessor| must
- // be a child of |new_parent| or NULL. Returns false on failure..
- bool SetPosition(const BaseNode& new_parent, const BaseNode* predecessor);
-
- // Set the bookmark specifics (url and favicon).
- // Should only be called if GetModelType() == BOOKMARK.
- void SetBookmarkSpecifics(const sync_pb::BookmarkSpecifics& specifics);
-
- // Legacy, bookmark-specific setters that wrap SetBookmarkSpecifics() above.
- // Should only be called if GetModelType() == BOOKMARK.
- // TODO(ncarter): Remove these two datatype-specific accessors.
- void SetURL(const GURL& url);
- void SetFaviconBytes(const std::vector<unsigned char>& bytes);
-
- // Generic set specifics method. Will extract the model type from |specifics|.
- void SetEntitySpecifics(const sync_pb::EntitySpecifics& specifics);
-
- // Resets the EntitySpecifics for this node based on the unencrypted data.
- // Will encrypt if necessary.
- void ResetFromSpecifics();
-
- // TODO(sync): Remove the setters below when the corresponding data
- // types are ported to the new sync service API.
-
- // Set the app specifics (id, update url, enabled state, etc).
- // Should only be called if GetModelType() == APPS.
- void SetAppSpecifics(const sync_pb::AppSpecifics& specifics);
-
- // Set the autofill specifics (name and value).
- // Should only be called if GetModelType() == AUTOFILL.
- void SetAutofillSpecifics(const sync_pb::AutofillSpecifics& specifics);
-
- void SetAutofillProfileSpecifics(
- const sync_pb::AutofillProfileSpecifics& specifics);
-
- // Set the nigori specifics.
- // Should only be called if GetModelType() == NIGORI.
- void SetNigoriSpecifics(const sync_pb::NigoriSpecifics& specifics);
-
- // Set the password specifics.
- // Should only be called if GetModelType() == PASSWORD.
- void SetPasswordSpecifics(const sync_pb::PasswordSpecificsData& specifics);
-
- // Set the theme specifics (name and value).
- // Should only be called if GetModelType() == THEME.
- void SetThemeSpecifics(const sync_pb::ThemeSpecifics& specifics);
-
- // Set the typed_url specifics (url, title, typed_count, etc).
- // Should only be called if GetModelType() == TYPED_URLS.
- void SetTypedUrlSpecifics(const sync_pb::TypedUrlSpecifics& specifics);
-
- // Set the extension specifics (id, update url, enabled state, etc).
- // Should only be called if GetModelType() == EXTENSIONS.
- void SetExtensionSpecifics(const sync_pb::ExtensionSpecifics& specifics);
-
- // Set the session specifics (windows, tabs, navigations etc.).
- // Should only be called if GetModelType() == SESSIONS.
- void SetSessionSpecifics(const sync_pb::SessionSpecifics& specifics);
-
- // Stores |new_specifics| into |entry|, encrypting if necessary.
- // Returns false if an error encrypting occurred (does not modify |entry|).
- // Note: gracefully handles new_specifics aliasing with entry->Get(SPECIFICS).
- static bool UpdateEntryWithEncryption(
- browser_sync::Cryptographer* cryptographer,
- const sync_pb::EntitySpecifics& new_specifics,
- syncable::MutableEntry* entry);
-
- // Implementation of BaseNode's abstract virtual accessors.
- virtual const syncable::Entry* GetEntry() const;
-
- virtual const BaseTransaction* GetTransaction() const;
-
- private:
- void* operator new(size_t size); // Node is meant for stack use only.
-
- // Helper to set model type. This will clear any specifics data.
- void PutModelType(syncable::ModelType model_type);
-
- // Helper to set the previous node.
- void PutPredecessor(const BaseNode* predecessor);
-
- // Sets IS_UNSYNCED and SYNCING to ensure this entry is considered in an
- // upcoming commit pass.
- void MarkForSyncing();
-
- // The underlying syncable object which this class wraps.
- syncable::MutableEntry* entry_;
-
- // The sync API transaction that is the parent of this node.
- WriteTransaction* transaction_;
-
- DISALLOW_COPY_AND_ASSIGN(WriteNode);
-};
-
-// ReadNode wraps a syncable::Entry to provide the functionality of a
-// read-only BaseNode.
-class ReadNode : public BaseNode {
- public:
- // Create an unpopulated ReadNode on the given transaction. Call some flavor
- // of Init to populate the ReadNode with a database entry.
- explicit ReadNode(const BaseTransaction* transaction);
- virtual ~ReadNode();
-
- // A client must use one (and only one) of the following Init variants to
- // populate the node.
-
- // BaseNode implementation.
- virtual bool InitByIdLookup(int64 id);
- virtual bool InitByClientTagLookup(syncable::ModelType model_type,
- const std::string& tag);
-
- // There is always a root node, so this can't fail. The root node is
- // never mutable, so root lookup is only possible on a ReadNode.
- void InitByRootLookup();
-
- // Each server-created permanent node is tagged with a unique string.
- // Look up the node with the particular tag. If it does not exist,
- // return false.
- bool InitByTagLookup(const std::string& tag);
-
- // Implementation of BaseNode's abstract virtual accessors.
- virtual const syncable::Entry* GetEntry() const;
- virtual const BaseTransaction* GetTransaction() const;
-
- protected:
- ReadNode();
-
- private:
- void* operator new(size_t size); // Node is meant for stack use only.
-
- // The underlying syncable object which this class wraps.
- syncable::Entry* entry_;
-
- // The sync API transaction that is the parent of this node.
- const BaseTransaction* transaction_;
-
- DISALLOW_COPY_AND_ASSIGN(ReadNode);
-};
-
-// Sync API's BaseTransaction, ReadTransaction, and WriteTransaction allow for
-// batching of several read and/or write operations. The read and write
-// operations are performed by creating ReadNode and WriteNode instances using
-// the transaction. These transaction classes wrap identically named classes in
-// syncable, and are used in a similar way. Unlike syncable::BaseTransaction,
-// whose construction requires an explicit syncable::ScopedDirLookup, a sync
-// API BaseTransaction creates its own ScopedDirLookup implicitly.
-class BaseTransaction {
- public:
- // Provide access to the underlying syncable.h objects from BaseNode.
- virtual syncable::BaseTransaction* GetWrappedTrans() const = 0;
- const syncable::ScopedDirLookup& GetLookup() const { return *lookup_; }
- browser_sync::Cryptographer* GetCryptographer() const {
- return cryptographer_;
- }
-
- protected:
- // The ScopedDirLookup is created in the constructor and destroyed
- // in the destructor. Creation of the ScopedDirLookup is not expected
- // to fail.
- explicit BaseTransaction(UserShare* share);
- virtual ~BaseTransaction();
-
- BaseTransaction() { lookup_= NULL; }
-
- private:
- // A syncable ScopedDirLookup, which is the parent of syncable transactions.
- syncable::ScopedDirLookup* lookup_;
-
- browser_sync::Cryptographer* cryptographer_;
-
- DISALLOW_COPY_AND_ASSIGN(BaseTransaction);
-};
-
-// TODO(akalin): Make ReadTransaction/WriteTransaction take a Location
-// parameter.
-
-// Sync API's ReadTransaction is a read-only BaseTransaction. It wraps
-// a syncable::ReadTransaction.
-class ReadTransaction : public BaseTransaction {
- public:
- // Start a new read-only transaction on the specified repository.
- ReadTransaction(const tracked_objects::Location& from_here,
- UserShare* share);
-
- // Resume the middle of a transaction. Will not close transaction.
- ReadTransaction(UserShare* share, syncable::BaseTransaction* trans);
-
- virtual ~ReadTransaction();
-
- // BaseTransaction override.
- virtual syncable::BaseTransaction* GetWrappedTrans() const;
- private:
- void* operator new(size_t size); // Transaction is meant for stack use only.
-
- // The underlying syncable object which this class wraps.
- syncable::BaseTransaction* transaction_;
- bool close_transaction_;
-
- DISALLOW_COPY_AND_ASSIGN(ReadTransaction);
-};
-
-// Sync API's WriteTransaction is a read/write BaseTransaction. It wraps
-// a syncable::WriteTransaction.
-//
-// NOTE: Only a single model type can be mutated for a given
-// WriteTransaction.
-class WriteTransaction : public BaseTransaction {
- public:
- // Start a new read/write transaction.
- WriteTransaction(const tracked_objects::Location& from_here,
- UserShare* share);
- virtual ~WriteTransaction();
-
- // Provide access to the syncable.h transaction from the API WriteNode.
- virtual syncable::BaseTransaction* GetWrappedTrans() const;
- syncable::WriteTransaction* GetWrappedWriteTrans() { return transaction_; }
-
- protected:
- WriteTransaction() {}
-
- void SetTransaction(syncable::WriteTransaction* trans) {
- transaction_ = trans;
- }
-
- private:
- void* operator new(size_t size); // Transaction is meant for stack use only.
-
- // The underlying syncable object which this class wraps.
- syncable::WriteTransaction* transaction_;
-
- DISALLOW_COPY_AND_ASSIGN(WriteTransaction);
-};
-
-// SyncManager encapsulates syncable::DirectoryManager and serves as the parent
-// of all other objects in the sync API. SyncManager is thread-safe. If
-// multiple threads interact with the same local sync repository (i.e. the
-// same sqlite database), they should share a single SyncManager instance. The
-// caller should typically create one SyncManager for the lifetime of a user
-// session.
-class SyncManager {
- public:
- // SyncInternal contains the implementation of SyncManager, while abstracting
- // internal types from clients of the interface.
- class SyncInternal;
-
- // TODO(zea): One day get passwords playing nicely with the rest of encryption
- // and get rid of this.
- class ExtraPasswordChangeRecordData {
- public:
- ExtraPasswordChangeRecordData();
- explicit ExtraPasswordChangeRecordData(
- const sync_pb::PasswordSpecificsData& data);
- virtual ~ExtraPasswordChangeRecordData();
-
- // Transfers ownership of the DictionaryValue to the caller.
- virtual base::DictionaryValue* ToValue() const;
-
- const sync_pb::PasswordSpecificsData& unencrypted() const;
- private:
- sync_pb::PasswordSpecificsData unencrypted_;
- };
-
- // ChangeRecord indicates a single item that changed as a result of a sync
- // operation. This gives the sync id of the node that changed, and the type
- // of change. To get the actual property values after an ADD or UPDATE, the
- // client should get the node with InitByIdLookup(), using the provided id.
- struct ChangeRecord {
- enum Action {
- ACTION_ADD,
- ACTION_DELETE,
- ACTION_UPDATE,
- };
- ChangeRecord();
- ~ChangeRecord();
-
- // Transfers ownership of the DictionaryValue to the caller.
- base::DictionaryValue* ToValue(const BaseTransaction* trans) const;
-
- int64 id;
- Action action;
- sync_pb::EntitySpecifics specifics;
- linked_ptr<ExtraPasswordChangeRecordData> extra;
- };
-
- // Status encapsulates detailed state about the internals of the SyncManager.
- struct Status {
- // Summary is a distilled set of important information that the end-user may
- // wish to be informed about (through UI, for example). Note that if a
- // summary state requires user interaction (such as auth failures), more
- // detailed information may be contained in additional status fields.
- enum Summary {
- // The internal instance is in an unrecognizable state. This should not
- // happen.
- INVALID = 0,
- // Can't connect to server, but there are no pending changes in
- // our local cache.
- OFFLINE,
- // Can't connect to server, and there are pending changes in our
- // local cache.
- OFFLINE_UNSYNCED,
- // Connected and syncing.
- SYNCING,
- // Connected, no pending changes.
- READY,
- // Internal sync error.
- CONFLICT,
- // Can't connect to server, and we haven't completed the initial
- // sync yet. So there's nothing we can do but wait for the server.
- OFFLINE_UNUSABLE,
-
- SUMMARY_STATUS_COUNT,
- };
-
- Status();
- ~Status();
-
- Summary summary;
- bool authenticated; // Successfully authenticated via GAIA.
- bool server_up; // True if we have received at least one good
- // reply from the server.
- bool server_reachable; // True if we received any reply from the server.
- bool server_broken; // True of the syncer is stopped because of server
- // issues.
- bool notifications_enabled; // True only if subscribed for notifications.
-
- // Notifications counters updated by the actions in synapi.
- int notifications_received;
- int notifiable_commits;
-
- // The max number of consecutive errors from any component.
- int max_consecutive_errors;
-
- int unsynced_count;
-
- int conflicting_count;
- bool syncing;
- // True after a client has done a first sync.
- bool initial_sync_ended;
- // True if any syncer is stuck.
- bool syncer_stuck;
-
- // Total updates available. If zero, nothing left to download.
- int64 updates_available;
- // Total updates received by the syncer since browser start.
- int updates_received;
-
- // Of updates_received, how many were tombstones.
- int tombstone_updates_received;
- bool disk_full;
-
- // Total number of overwrites due to conflict resolver since browser start.
- int num_local_overwrites_total;
- int num_server_overwrites_total;
-
- // Count of empty and non empty getupdates;
- int nonempty_get_updates;
- int empty_get_updates;
-
- // Count of useless and useful syncs we perform.
- int useless_sync_cycles;
- int useful_sync_cycles;
-
- // Encryption related.
- syncable::ModelTypeSet encrypted_types;
- bool cryptographer_ready;
- bool crypto_has_pending_keys;
- };
-
- // An interface the embedding application implements to receive notifications
- // from the SyncManager. Register an observer via SyncManager::AddObserver.
- // This observer is an event driven model as the events may be raised from
- // different internal threads, and simply providing an "OnStatusChanged" type
- // notification complicates things such as trying to determine "what changed",
- // if different members of the Status object are modified from different
- // threads. This way, the event is explicit, and it is safe for the Observer
- // to dispatch to a native thread or synchronize accordingly.
- class Observer {
- public:
- // Notify the observer that changes have been applied to the sync model.
- //
- // This will be invoked on the same thread as on which ApplyChanges was
- // called. |changes| is an array of size |change_count|, and contains the
- // ID of each individual item that was changed. |changes| exists only for
- // the duration of the call. If items of multiple data types change at
- // the same time, this method is invoked once per data type and |changes|
- // is restricted to items of the ModelType indicated by |model_type|.
- // Because the observer is passed a |trans|, the observer can assume a
- // read lock on the sync model that will be released after the function
- // returns.
- //
- // The SyncManager constructs |changes| in the following guaranteed order:
- //
- // 1. Deletions, from leaves up to parents.
- // 2. Updates to existing items with synced parents & predecessors.
- // 3. New items with synced parents & predecessors.
- // 4. Items with parents & predecessors in |changes|.
- // 5. Repeat #4 until all items are in |changes|.
- //
- // Thus, an implementation of OnChangesApplied should be able to
- // process the change records in the order without having to worry about
- // forward dependencies. But since deletions come before reparent
- // operations, a delete may temporarily orphan a node that is
- // updated later in the list.
- virtual void OnChangesApplied(syncable::ModelType model_type,
- const BaseTransaction* trans,
- const ChangeRecord* changes,
- int change_count) = 0;
-
- // OnChangesComplete gets called when the TransactionComplete event is
- // posted (after OnChangesApplied finishes), after the transaction lock
- // and the change channel mutex are released.
- //
- // The purpose of this function is to support processors that require
- // split-transactions changes. For example, if a model processor wants to
- // perform blocking I/O due to a change, it should calculate the changes
- // while holding the transaction lock (from within OnChangesApplied), buffer
- // those changes, let the transaction fall out of scope, and then commit
- // those changes from within OnChangesComplete (postponing the blocking
- // I/O to when it no longer holds any lock).
- virtual void OnChangesComplete(syncable::ModelType model_type) = 0;
-
- // A round-trip sync-cycle took place and the syncer has resolved any
- // conflicts that may have arisen.
- virtual void OnSyncCycleCompleted(
- const browser_sync::sessions::SyncSessionSnapshot* snapshot) = 0;
-
- // Called when user interaction may be required due to an auth problem.
- virtual void OnAuthError(const GoogleServiceAuthError& auth_error) = 0;
-
- // Called when a new auth token is provided by the sync server.
- virtual void OnUpdatedToken(const std::string& token) = 0;
-
- // Called when user interaction is required to obtain a valid passphrase.
- // - If the passphrase is required for encryption, |reason| will be
- // REASON_ENCRYPTION.
- // - If the passphrase is required for the decryption of data that has
- // already been encrypted, |reason| will be REASON_DECRYPTION.
- // - If the passphrase is required because decryption failed, and a new
- // passphrase is required, |reason| will be REASON_SET_PASSPHRASE_FAILED.
- virtual void OnPassphraseRequired(PassphraseRequiredReason reason) = 0;
-
- // Called when the passphrase provided by the user has been accepted and is
- // now used to encrypt sync data. |bootstrap_token| is an opaque base64
- // encoded representation of the key generated by the accepted passphrase,
- // and is provided to the observer for persistence purposes and use in a
- // future initialization of sync (e.g. after restart).
- virtual void OnPassphraseAccepted(const std::string& bootstrap_token) = 0;
-
- // Called when initialization is complete to the point that SyncManager can
- // process changes. This does not necessarily mean authentication succeeded
- // or that the SyncManager is online.
- // IMPORTANT: Creating any type of transaction before receiving this
- // notification is illegal!
- // WARNING: Calling methods on the SyncManager before receiving this
- // message, unless otherwise specified, produces undefined behavior.
- //
- // |js_backend| is what about:sync interacts with. It can emit
- // the following events:
-
- /**
- * @param {{ enabled: boolean }} details A dictionary containing:
- * - enabled: whether or not notifications are enabled.
- */
- // function onNotificationStateChange(details);
-
- /**
- * @param {{ changedTypes: Array.<string> }} details A dictionary
- * containing:
- * - changedTypes: a list of types (as strings) for which there
- are new updates.
- */
- // function onIncomingNotification(details);
-
- // Also, it responds to the following messages (all other messages
- // are ignored):
-
- /**
- * Gets the current notification state.
- *
- * @param {function(boolean)} callback Called with whether or not
- * notifications are enabled.
- */
- // function getNotificationState(callback);
-
- /**
- * Gets details about the root node.
- *
- * @param {function(!Object)} callback Called with details about the
- * root node.
- */
- // TODO(akalin): Change this to getRootNodeId or eliminate it
- // entirely.
- // function getRootNodeDetails(callback);
-
- /**
- * Gets summary information for a list of ids.
- *
- * @param {Array.<string>} idList List of 64-bit ids in decimal
- * string form.
- * @param {Array.<{id: string, title: string, isFolder: boolean}>}
- * callback Called with summaries for the nodes in idList that
- * exist.
- */
- // function getNodeSummariesById(idList, callback);
-
- /**
- * Gets detailed information for a list of ids.
- *
- * @param {Array.<string>} idList List of 64-bit ids in decimal
- * string form.
- * @param {Array.<!Object>} callback Called with detailed
- * information for the nodes in idList that exist.
- */
- // function getNodeDetailsById(idList, callback);
-
- /**
- * Gets child ids for a given id.
- *
- * @param {string} id 64-bit id in decimal string form of the parent
- * node.
- * @param {Array.<string>} callback Called with the (possibly empty)
- * list of child ids.
- */
- // function getChildNodeIds(id);
-
- virtual void OnInitializationComplete(
- const browser_sync::WeakHandle<browser_sync::JsBackend>&
- js_backend) = 0;
-
- // We are no longer permitted to communicate with the server. Sync should
- // be disabled and state cleaned up at once. This can happen for a number
- // of reasons, e.g. swapping from a test instance to production, or a
- // global stop syncing operation has wiped the store.
- virtual void OnStopSyncingPermanently() = 0;
-
- // After a request to clear server data, these callbacks are invoked to
- // indicate success or failure.
- virtual void OnClearServerDataSucceeded() = 0;
- virtual void OnClearServerDataFailed() = 0;
-
- // Called after we finish encrypting all appropriate datatypes.
- virtual void OnEncryptionComplete(
- const syncable::ModelTypeSet& encrypted_types) = 0;
-
- protected:
- virtual ~Observer();
- };
-
- typedef Callback0::Type ModeChangeCallback;
-
- // Create an uninitialized SyncManager. Callers must Init() before using.
- explicit SyncManager(const std::string& name);
- virtual ~SyncManager();
-
- // Initialize the sync manager. |database_location| specifies the path of
- // the directory in which to locate a sqlite repository storing the syncer
- // backend state. Initialization will open the database, or create it if it
- // does not already exist. Returns false on failure.
- // |event_handler| is the JsEventHandler used to propagate events to
- // chrome://sync-internals. |event_handler| may be uninitialized.
- // |sync_server_and_path| and |sync_server_port| represent the Chrome sync
- // server to use, and |use_ssl| specifies whether to communicate securely;
- // the default is false.
- // |post_factory| will be owned internally and used to create
- // instances of an HttpPostProvider.
- // |model_safe_worker| ownership is given to the SyncManager.
- // |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent
- // HTTP header. Used internally when collecting stats to classify clients.
- // |sync_notifier| is owned and used to listen for notifications.
- bool Init(const FilePath& database_location,
- const browser_sync::WeakHandle<browser_sync::JsEventHandler>&
- event_handler,
- const std::string& sync_server_and_path,
- int sync_server_port,
- bool use_ssl,
- HttpPostProviderFactory* post_factory,
- browser_sync::ModelSafeWorkerRegistrar* registrar,
- const std::string& user_agent,
- const SyncCredentials& credentials,
- sync_notifier::SyncNotifier* sync_notifier,
- const std::string& restored_key_for_bootstrapping,
- bool setup_for_test_mode);
-
- // Returns the username last used for a successful authentication.
- // Returns empty if there is no such username.
- const std::string& GetAuthenticatedUsername();
-
- // Check if the database has been populated with a full "initial" download of
- // sync items for each data type currently present in the routing info.
- // Prerequisite for calling this is that OnInitializationComplete has been
- // called.
- bool InitialSyncEndedForAllEnabledTypes();
-
- // Update tokens that we're using in Sync. Email must stay the same.
- void UpdateCredentials(const SyncCredentials& credentials);
-
- // Called when the user disables or enables a sync type.
- void UpdateEnabledTypes();
-
- // Put the syncer in normal mode ready to perform nudges and polls.
- void StartSyncingNormally();
-
- // Attempt to set the passphrase. If the passphrase is valid,
- // OnPassphraseAccepted will be fired to notify the ProfileSyncService and the
- // syncer will be nudged so that any update that was waiting for this
- // passphrase gets applied as soon as possible.
- // If the passphrase in invalid, OnPassphraseRequired will be fired.
- // Calling this metdod again is the appropriate course of action to "retry"
- // with a new passphrase.
- // |is_explicit| is true if the call is in response to the user explicitly
- // setting a passphrase as opposed to implicitly (from the users' perspective)
- // using their Google Account password. An implicit SetPassphrase will *not*
- // *not* override an explicit passphrase set previously.
- void SetPassphrase(const std::string& passphrase, bool is_explicit);
-
- // Set the datatypes we want to encrypt and encrypt any nodes as necessary.
- // Note: |encrypted_types| will be unioned with the current set of encrypted
- // types, as we do not currently support decrypting datatypes.
- void EncryptDataTypes(const syncable::ModelTypeSet& encrypted_types);
-
- // Puts the SyncScheduler into a mode where no normal nudge or poll traffic
- // will occur, but calls to RequestConfig will be supported. If |callback|
- // is provided, it will be invoked (from the internal SyncScheduler) when
- // the thread has changed to configuration mode.
- void StartConfigurationMode(ModeChangeCallback* callback);
-
- // Switches the mode of operation to CONFIGURATION_MODE and
- // schedules a config task to fetch updates for |types|.
- void RequestConfig(const syncable::ModelTypeBitSet& types,
- sync_api::ConfigureReason reason);
-
- void RequestCleanupDisabledTypes();
-
- // Request a clearing of all data on the server
- void RequestClearServerData();
-
- // Adds a listener to be notified of sync events.
- // NOTE: It is OK (in fact, it's probably a good idea) to call this before
- // having received OnInitializationCompleted.
- void AddObserver(Observer* observer);
-
- // Remove the given observer. Make sure to call this if the
- // Observer is being destroyed so the SyncManager doesn't
- // potentially dereference garbage.
- void RemoveObserver(Observer* observer);
-
- // Status-related getters. Typically GetStatusSummary will suffice, but
- // GetDetailedSyncStatus can be useful for gathering debug-level details of
- // the internals of the sync engine.
- Status::Summary GetStatusSummary() const;
- Status GetDetailedStatus() const;
-
- // Whether or not the Nigori node is encrypted using an explicit passphrase.
- bool IsUsingExplicitPassphrase();
-
- // Get the internal implementation for use by BaseTransaction, etc.
- SyncInternal* GetImpl() const;
-
- // Call periodically from a database-safe thread to persist recent changes
- // to the syncapi model.
- void SaveChanges();
-
- void RequestEarlyExit();
-
- // Issue a final SaveChanges, close sqlite handles, and stop running threads.
- // Must be called from the same thread that called Init().
- void Shutdown();
-
- UserShare* GetUserShare() const;
-
- // Inform the cryptographer of the most recent passphrase and set of encrypted
- // types (from nigori node), then ensure all data that needs encryption is
- // encrypted with the appropriate passphrase.
- // Note: opens a transaction and can trigger ON_PASSPHRASE_REQUIRED, so must
- // only be called after syncapi has been initialized.
- void RefreshEncryption();
-
- syncable::ModelTypeSet GetEncryptedDataTypes() const;
-
- // Uses a read-only transaction to determine if the directory being synced has
- // any remaining unsynced items.
- bool HasUnsyncedItems() const;
-
- // Logs the list of unsynced meta handles.
- void LogUnsyncedItems(int level) const;
-
- // Functions used for testing.
-
- void TriggerOnNotificationStateChangeForTest(
- bool notifications_enabled);
-
- void TriggerOnIncomingNotificationForTest(
- const syncable::ModelTypeBitSet& model_types);
-
- private:
- // An opaque pointer to the nested private class.
- SyncInternal* data_;
-
- DISALLOW_COPY_AND_ASSIGN(SyncManager);
-};
-
-} // namespace sync_api
-
-#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_
diff --git a/chrome/browser/sync/engine/syncapi_internal.cc b/chrome/browser/sync/engine/syncapi_internal.cc
new file mode 100644
index 0000000..aeb97fc
--- /dev/null
+++ b/chrome/browser/sync/engine/syncapi_internal.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/engine/syncapi_internal.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/sync/util/cryptographer.h"
+#include "chrome/browser/sync/protocol/password_specifics.pb.h"
+
+using browser_sync::Cryptographer;
+
+namespace sync_api {
+
+sync_pb::PasswordSpecificsData* DecryptPasswordSpecifics(
+ const sync_pb::EntitySpecifics& specifics, Cryptographer* crypto) {
+ if (!specifics.HasExtension(sync_pb::password))
+ return NULL;
+ const sync_pb::PasswordSpecifics& password_specifics =
+ specifics.GetExtension(sync_pb::password);
+ if (!password_specifics.has_encrypted())
+ return NULL;
+ const sync_pb::EncryptedData& encrypted = password_specifics.encrypted();
+ scoped_ptr<sync_pb::PasswordSpecificsData> data(
+ new sync_pb::PasswordSpecificsData);
+ if (!crypto->Decrypt(encrypted, data.get()))
+ return NULL;
+ return data.release();
+}
+
+// The list of names which are reserved for use by the server.
+static const char* kForbiddenServerNames[] = { "", ".", ".." };
+
+// Checks whether |name| is a server-illegal name followed by zero or more space
+// characters. The three server-illegal names are the empty string, dot, and
+// dot-dot. Very long names (>255 bytes in UTF-8 Normalization Form C) are
+// also illegal, but are not considered here.
+bool IsNameServerIllegalAfterTrimming(const std::string& name) {
+ size_t untrimmed_count = name.find_last_not_of(' ') + 1;
+ for (size_t i = 0; i < arraysize(kForbiddenServerNames); ++i) {
+ if (name.compare(0, untrimmed_count, kForbiddenServerNames[i]) == 0)
+ return true;
+ }
+ return false;
+}
+
+// Compare the values of two EntitySpecifics, accounting for encryption.
+bool AreSpecificsEqual(const browser_sync::Cryptographer* cryptographer,
+ const sync_pb::EntitySpecifics& left,
+ const sync_pb::EntitySpecifics& right) {
+ // Note that we can't compare encrypted strings directly as they are seeded
+ // with a random value.
+ std::string left_plaintext, right_plaintext;
+ if (left.has_encrypted()) {
+ if (!cryptographer->CanDecrypt(left.encrypted())) {
+ NOTREACHED() << "Attempting to compare undecryptable data.";
+ return false;
+ }
+ left_plaintext = cryptographer->DecryptToString(left.encrypted());
+ } else {
+ left_plaintext = left.SerializeAsString();
+ }
+ if (right.has_encrypted()) {
+ if (!cryptographer->CanDecrypt(right.encrypted())) {
+ NOTREACHED() << "Attempting to compare undecryptable data.";
+ return false;
+ }
+ right_plaintext = cryptographer->DecryptToString(right.encrypted());
+ } else {
+ right_plaintext = right.SerializeAsString();
+ }
+ if (left_plaintext == right_plaintext) {
+ return true;
+ }
+ return false;
+}
+
+} // namespace sync_api
diff --git a/chrome/browser/sync/engine/syncapi_internal.h b/chrome/browser/sync/engine/syncapi_internal.h
new file mode 100644
index 0000000..aa4cf0b0
--- /dev/null
+++ b/chrome/browser/sync/engine/syncapi_internal.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_INTERNAL_H_
+#define CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_INTERNAL_H_
+
+// The functions defined are shared among some of the classes that implement
+// the internal sync_api. They are not to be used by clients of the API.
+
+#include <string>
+
+namespace browser_sync {
+class Cryptographer;
+}
+
+namespace sync_pb {
+class EntitySpecifics;
+class PasswordSpecificsData;
+}
+
+namespace sync_api {
+sync_pb::PasswordSpecificsData* DecryptPasswordSpecifics(
+ const sync_pb::EntitySpecifics& specifics,
+ browser_sync::Cryptographer* crypto);
+
+bool IsNameServerIllegalAfterTrimming(const std::string& name);
+
+bool AreSpecificsEqual(const browser_sync::Cryptographer* cryptographer,
+ const sync_pb::EntitySpecifics& left,
+ const sync_pb::EntitySpecifics& right);
+}
+
+#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_INTERNAL_H_
diff --git a/chrome/browser/sync/glue/app_change_processor.cc b/chrome/browser/sync/glue/app_change_processor.cc
index e8f4009..609bc8b 100644
--- a/chrome/browser/sync/glue/app_change_processor.cc
+++ b/chrome/browser/sync/glue/app_change_processor.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/glue/extension_sync.h"
#include "chrome/browser/sync/glue/extension_util.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
#include "chrome/browser/sync/unrecoverable_error_handler.h"
#include "chrome/common/chrome_notification_types.h"
diff --git a/chrome/browser/sync/glue/app_change_processor.h b/chrome/browser/sync/glue/app_change_processor.h
index 7c2ce3e..0a692a8 100644
--- a/chrome/browser/sync/glue/app_change_processor.h
+++ b/chrome/browser/sync/glue/app_change_processor.h
@@ -7,9 +7,9 @@
#pragma once
#include "base/basictypes.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/change_processor.h"
#include "chrome/browser/sync/glue/extension_sync_traits.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "content/common/content_notification_types.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
diff --git a/chrome/browser/sync/glue/app_model_associator.cc b/chrome/browser/sync/glue/app_model_associator.cc
index 633c680..1130e6a 100644
--- a/chrome/browser/sync/glue/app_model_associator.cc
+++ b/chrome/browser/sync/glue/app_model_associator.cc
@@ -8,9 +8,10 @@
#include "base/tracked.h"
#include "chrome/browser/extensions/extension_sync_data.h"
#include "chrome/browser/sync/api/sync_error.h"
-#include "chrome/browser/sync/engine/syncapi.h"
-#include "chrome/browser/sync/glue/extension_sync_traits.h"
#include "chrome/browser/sync/glue/extension_sync.h"
+#include "chrome/browser/sync/glue/extension_sync_traits.h"
+#include "chrome/browser/sync/glue/extension_sync_traits.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
#include "content/browser/browser_thread.h"
diff --git a/chrome/browser/sync/glue/autofill_change_processor.cc b/chrome/browser/sync/glue/autofill_change_processor.cc
index a3dc858..6c4812a 100644
--- a/chrome/browser/sync/glue/autofill_change_processor.cc
+++ b/chrome/browser/sync/glue/autofill_change_processor.cc
@@ -15,11 +15,14 @@
#include "chrome/browser/sync/glue/autofill_model_associator.h"
#include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
#include "chrome/browser/sync/glue/do_optimistic_refresh_task.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/webdata/autofill_change.h"
#include "chrome/browser/webdata/autofill_table.h"
-#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/browser/webdata/web_database.h"
+#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/guid.h"
#include "content/common/notification_service.h"
diff --git a/chrome/browser/sync/glue/autofill_change_processor.h b/chrome/browser/sync/glue/autofill_change_processor.h
index 1ea0e1a..70325a4 100644
--- a/chrome/browser/sync/glue/autofill_change_processor.h
+++ b/chrome/browser/sync/glue/autofill_change_processor.h
@@ -11,9 +11,9 @@
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/credit_card.h"
#include "chrome/browser/autofill/personal_data_manager.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/change_processor.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "content/common/notification_observer.h"
@@ -25,6 +25,12 @@ class AutofillProfileChange;
class PersonalDataManager;
class WebDatabase;
+namespace sync_api {
+class ReadNode;
+class WriteNode;
+class WriteTransaction;
+} // namespace sync_api
+
namespace browser_sync {
class AutofillModelAssociator;
diff --git a/chrome/browser/sync/glue/autofill_model_associator.cc b/chrome/browser/sync/glue/autofill_model_associator.cc
index 3b8ef96..0ec8b06 100644
--- a/chrome/browser/sync/glue/autofill_model_associator.cc
+++ b/chrome/browser/sync/glue/autofill_model_associator.cc
@@ -15,10 +15,13 @@
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/api/sync_error.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/autofill_change_processor.h"
#include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
#include "chrome/browser/sync/glue/do_optimistic_refresh_task.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
#include "chrome/browser/webdata/autofill_table.h"
diff --git a/chrome/browser/sync/glue/autofill_model_associator.h b/chrome/browser/sync/glue/autofill_model_associator.h
index baffaa8..1de7848 100644
--- a/chrome/browser/sync/glue/autofill_model_associator.h
+++ b/chrome/browser/sync/glue/autofill_model_associator.h
@@ -15,7 +15,6 @@
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "chrome/browser/autofill/personal_data_manager.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/model_associator.h"
#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
#include "chrome/browser/webdata/autofill_entry.h"
@@ -26,6 +25,7 @@ class ProfileSyncService;
class WebDatabase;
namespace sync_api {
+class ReadNode;
class WriteTransaction;
}
diff --git a/chrome/browser/sync/glue/autofill_profile_change_processor.cc b/chrome/browser/sync/glue/autofill_profile_change_processor.cc
index 1bd00a3..1dfe3ca 100644
--- a/chrome/browser/sync/glue/autofill_profile_change_processor.cc
+++ b/chrome/browser/sync/glue/autofill_profile_change_processor.cc
@@ -12,10 +12,13 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/personal_data_manager.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
#include "chrome/browser/sync/glue/change_processor.h"
#include "chrome/browser/sync/glue/do_optimistic_refresh_task.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/unrecoverable_error_handler.h"
#include "chrome/browser/webdata/autofill_change.h"
#include "chrome/browser/webdata/autofill_table.h"
diff --git a/chrome/browser/sync/glue/autofill_profile_change_processor.h b/chrome/browser/sync/glue/autofill_profile_change_processor.h
index c9fd9fe..1f4a6fb 100644
--- a/chrome/browser/sync/glue/autofill_profile_change_processor.h
+++ b/chrome/browser/sync/glue/autofill_profile_change_processor.h
@@ -10,9 +10,9 @@
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/personal_data_manager.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
#include "chrome/browser/sync/glue/change_processor.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "chrome/browser/sync/unrecoverable_error_handler.h"
#include "chrome/browser/webdata/autofill_change.h"
#include "chrome/browser/webdata/web_database.h"
@@ -21,6 +21,12 @@
#include "content/common/notification_registrar.h"
#include "content/common/notification_service.h"
+namespace sync_api {
+class ReadNode;
+class WriteNode;
+class WriteTransaction;
+} // namespace sync_api
+
namespace browser_sync {
class AutofillProfileChangeProcessor : public ChangeProcessor,
diff --git a/chrome/browser/sync/glue/autofill_profile_model_associator.cc b/chrome/browser/sync/glue/autofill_profile_model_associator.cc
index 0197f93..6f08cc4 100644
--- a/chrome/browser/sync/glue/autofill_profile_model_associator.cc
+++ b/chrome/browser/sync/glue/autofill_profile_model_associator.cc
@@ -9,6 +9,10 @@
#include "chrome/browser/sync/api/sync_error.h"
#include "chrome/browser/sync/glue/autofill_profile_change_processor.h"
#include "chrome/browser/sync/glue/do_optimistic_refresh_task.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/webdata/autofill_table.h"
#include "chrome/browser/webdata/web_database.h"
diff --git a/chrome/browser/sync/glue/autofill_profile_model_associator.h b/chrome/browser/sync/glue/autofill_profile_model_associator.h
index 4b0b1a2..af1e9c2 100644
--- a/chrome/browser/sync/glue/autofill_profile_model_associator.h
+++ b/chrome/browser/sync/glue/autofill_profile_model_associator.h
@@ -15,7 +15,6 @@
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "chrome/browser/autofill/personal_data_manager.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/model_associator.h"
#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
#include "chrome/browser/webdata/autofill_entry.h"
@@ -26,8 +25,9 @@ class ProfileSyncService;
class WebDatabase;
namespace sync_api {
+class ReadNode;
class WriteTransaction;
-}
+} // namespace sync_api
namespace browser_sync {
diff --git a/chrome/browser/sync/glue/autofill_profile_model_associator_unittest.cc b/chrome/browser/sync/glue/autofill_profile_model_associator_unittest.cc
index 909b895..312fccd 100644
--- a/chrome/browser/sync/glue/autofill_profile_model_associator_unittest.cc
+++ b/chrome/browser/sync/glue/autofill_profile_model_associator_unittest.cc
@@ -4,8 +4,8 @@
#include "base/tracked.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/sync/engine/read_node_mock.h"
-#include "chrome/browser/sync/engine/syncapi_mock.h"
+#include "chrome/browser/sync/internal_api/read_node_mock.h"
+#include "chrome/browser/sync/internal_api/syncapi_mock.h"
#include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/syncable/syncable_mock.h"
diff --git a/chrome/browser/sync/glue/bookmark_change_processor.cc b/chrome/browser/sync/glue/bookmark_change_processor.cc
index 0e74619..a530f81 100644
--- a/chrome/browser/sync/glue/bookmark_change_processor.cc
+++ b/chrome/browser/sync/glue/bookmark_change_processor.cc
@@ -15,6 +15,9 @@
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "content/browser/browser_thread.h"
#include "third_party/skia/include/core/SkBitmap.h"
diff --git a/chrome/browser/sync/glue/bookmark_change_processor.h b/chrome/browser/sync/glue/bookmark_change_processor.h
index 8802716..5f242fd 100644
--- a/chrome/browser/sync/glue/bookmark_change_processor.h
+++ b/chrome/browser/sync/glue/bookmark_change_processor.h
@@ -9,10 +9,15 @@
#include <vector>
#include "chrome/browser/bookmarks/bookmark_model_observer.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/bookmark_model_associator.h"
#include "chrome/browser/sync/glue/change_processor.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
+
+namespace sync_api {
+class WriteNode;
+class WriteTransaction;
+} // namespace sync_api
namespace browser_sync {
diff --git a/chrome/browser/sync/glue/bookmark_model_associator.cc b/chrome/browser/sync/glue/bookmark_model_associator.cc
index 137bb66..faa377b 100644
--- a/chrome/browser/sync/glue/bookmark_model_associator.cc
+++ b/chrome/browser/sync/glue/bookmark_model_associator.cc
@@ -15,8 +15,11 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/api/sync_error.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/bookmark_change_processor.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/util/cryptographer.h"
#include "chrome/common/chrome_switches.h"
#include "content/browser/browser_thread.h"
diff --git a/chrome/browser/sync/glue/change_processor.h b/chrome/browser/sync/glue/change_processor.h
index fba8301..d525281 100644
--- a/chrome/browser/sync/glue/change_processor.h
+++ b/chrome/browser/sync/glue/change_processor.h
@@ -6,8 +6,8 @@
#define CHROME_BROWSER_SYNC_GLUE_CHANGE_PROCESSOR_H_
#pragma once
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
class Profile;
diff --git a/chrome/browser/sync/glue/change_processor_mock.h b/chrome/browser/sync/glue/change_processor_mock.h
index 65696aa..10d62cd 100644
--- a/chrome/browser/sync/glue/change_processor_mock.h
+++ b/chrome/browser/sync/glue/change_processor_mock.h
@@ -6,8 +6,9 @@
#define CHROME_BROWSER_SYNC_GLUE_CHANGE_PROCESSOR_MOCK_H__
#pragma once
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/change_processor.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
+#include "chrome/browser/sync/syncable/syncable.h"
#include "testing/gmock/include/gmock/gmock.h"
class Profile;
diff --git a/chrome/browser/sync/glue/extension_change_processor.cc b/chrome/browser/sync/glue/extension_change_processor.cc
index 71043a0..9fddd3e 100644
--- a/chrome/browser/sync/glue/extension_change_processor.cc
+++ b/chrome/browser/sync/glue/extension_change_processor.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/glue/extension_sync.h"
#include "chrome/browser/sync/glue/extension_util.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
#include "chrome/browser/sync/unrecoverable_error_handler.h"
#include "chrome/common/chrome_notification_types.h"
diff --git a/chrome/browser/sync/glue/extension_change_processor.h b/chrome/browser/sync/glue/extension_change_processor.h
index f2493be..e223b92 100644
--- a/chrome/browser/sync/glue/extension_change_processor.h
+++ b/chrome/browser/sync/glue/extension_change_processor.h
@@ -7,9 +7,9 @@
#pragma once
#include "base/basictypes.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/change_processor.h"
#include "chrome/browser/sync/glue/extension_sync_traits.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "content/common/content_notification_types.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
diff --git a/chrome/browser/sync/glue/extension_model_associator.cc b/chrome/browser/sync/glue/extension_model_associator.cc
index 46421b7..0856e46 100644
--- a/chrome/browser/sync/glue/extension_model_associator.cc
+++ b/chrome/browser/sync/glue/extension_model_associator.cc
@@ -7,9 +7,10 @@
#include "base/logging.h"
#include "base/tracked.h"
#include "chrome/browser/extensions/extension_sync_data.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/extension_sync_traits.h"
#include "chrome/browser/sync/glue/extension_sync.h"
+#include "chrome/browser/sync/glue/extension_sync_traits.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
#include "content/browser/browser_thread.h"
diff --git a/chrome/browser/sync/glue/extension_sync.cc b/chrome/browser/sync/glue/extension_sync.cc
index c6c19ec..d057d6a 100644
--- a/chrome/browser/sync/glue/extension_sync.cc
+++ b/chrome/browser/sync/glue/extension_sync.cc
@@ -10,9 +10,12 @@
#include "base/tracked.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_sync_data.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/extension_sync_traits.h"
#include "chrome/browser/sync/glue/extension_util.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
namespace browser_sync {
diff --git a/chrome/browser/sync/glue/extension_sync_traits.cc b/chrome/browser/sync/glue/extension_sync_traits.cc
index eae2425..3ef4eda 100644
--- a/chrome/browser/sync/glue/extension_sync_traits.cc
+++ b/chrome/browser/sync/glue/extension_sync_traits.cc
@@ -6,8 +6,8 @@
#include "base/string_piece.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/extension_util.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
#include "chrome/browser/sync/protocol/app_specifics.pb.h"
#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
#include "chrome/common/extensions/extension.h"
diff --git a/chrome/browser/sync/glue/generic_change_processor.cc b/chrome/browser/sync/glue/generic_change_processor.cc
index 075d700..dd1aea0 100644
--- a/chrome/browser/sync/glue/generic_change_processor.cc
+++ b/chrome/browser/sync/glue/generic_change_processor.cc
@@ -9,7 +9,11 @@
#include "chrome/browser/sync/api/syncable_service.h"
#include "chrome/browser/sync/api/sync_change.h"
#include "chrome/browser/sync/api/sync_error.h"
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/unrecoverable_error_handler.h"
namespace browser_sync {
diff --git a/chrome/browser/sync/glue/http_bridge.h b/chrome/browser/sync/glue/http_bridge.h
index d28699f..ed95c72 100644
--- a/chrome/browser/sync/glue/http_bridge.h
+++ b/chrome/browser/sync/glue/http_bridge.h
@@ -15,11 +15,10 @@
#include "base/synchronization/waitable_event.h"
#include "chrome/browser/sync/engine/http_post_provider_factory.h"
#include "chrome/browser/sync/engine/http_post_provider_interface.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "content/common/url_fetcher.h"
#include "googleurl/src/gurl.h"
-#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
+#include "net/url_request/url_request_context.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
class MessageLoop;
diff --git a/chrome/browser/sync/glue/password_change_processor.cc b/chrome/browser/sync/glue/password_change_processor.cc
index d2f4d13..838cf39 100644
--- a/chrome/browser/sync/glue/password_change_processor.cc
+++ b/chrome/browser/sync/glue/password_change_processor.cc
@@ -9,10 +9,13 @@
#include "base/string_util.h"
#include "base/tracked.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/password_manager/password_store.h"
#include "chrome/browser/password_manager/password_store_change.h"
+#include "chrome/browser/password_manager/password_store.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/glue/password_model_associator.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/protocol/password_specifics.pb.h"
#include "chrome/common/chrome_notification_types.h"
diff --git a/chrome/browser/sync/glue/password_model_associator.cc b/chrome/browser/sync/glue/password_model_associator.cc
index 6d96186..b853b3f 100644
--- a/chrome/browser/sync/glue/password_model_associator.cc
+++ b/chrome/browser/sync/glue/password_model_associator.cc
@@ -11,7 +11,10 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/password_manager/password_store.h"
#include "chrome/browser/sync/api/sync_error.h"
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/protocol/password_specifics.pb.h"
#include "net/base/escape.h"
diff --git a/chrome/browser/sync/glue/session_change_processor.cc b/chrome/browser/sync/glue/session_change_processor.cc
index b889853..39b2e8e 100644
--- a/chrome/browser/sync/glue/session_change_processor.cc
+++ b/chrome/browser/sync/glue/session_change_processor.cc
@@ -12,8 +12,9 @@
#include "base/memory/scoped_vector.h"
#include "chrome/browser/extensions/extension_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/session_model_associator.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/chrome_notification_types.h"
diff --git a/chrome/browser/sync/glue/session_change_processor.h b/chrome/browser/sync/glue/session_change_processor.h
index 62fa5c8..35010ef 100644
--- a/chrome/browser/sync/glue/session_change_processor.h
+++ b/chrome/browser/sync/glue/session_change_processor.h
@@ -9,8 +9,8 @@
#include "base/basictypes.h"
#include "chrome/browser/sessions/session_backend.h"
#include "chrome/browser/sessions/session_service.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/change_processor.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "content/common/content_notification_types.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
diff --git a/chrome/browser/sync/glue/session_model_associator.cc b/chrome/browser/sync/glue/session_model_associator.cc
index 227b5ee..4b7496d 100644
--- a/chrome/browser/sync/glue/session_model_associator.cc
+++ b/chrome/browser/sync/glue/session_model_associator.cc
@@ -15,6 +15,10 @@
#include "chrome/browser/sync/api/sync_error.h"
#include "chrome/browser/sync/glue/synced_tab_delegate.h"
#include "chrome/browser/sync/glue/synced_window_delegate.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/common/chrome_notification_types.h"
diff --git a/chrome/browser/sync/glue/session_model_associator.h b/chrome/browser/sync/glue/session_model_associator.h
index 83ea9ef..9579140 100644
--- a/chrome/browser/sync/glue/session_model_associator.h
+++ b/chrome/browser/sync/glue/session_model_associator.h
@@ -21,11 +21,10 @@
#include "chrome/browser/sessions/session_id.h"
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_types.h"
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/glue/model_associator.h"
#include "chrome/browser/sync/glue/synced_session_tracker.h"
#include "chrome/browser/sync/glue/synced_tab_delegate.h"
#include "chrome/browser/sync/glue/synced_window_delegate.h"
-#include "chrome/browser/sync/glue/model_associator.h"
#include "chrome/browser/sync/protocol/session_specifics.pb.h"
#include "chrome/browser/sync/syncable/model_type.h"
@@ -33,6 +32,7 @@ class Profile;
class ProfileSyncService;
namespace sync_api {
+class BaseTransaction;
class ReadNode;
class WriteNode;
class WriteTransaction;
diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc
index a4c11cc..116164f 100644
--- a/chrome/browser/sync/glue/sync_backend_host.cc
+++ b/chrome/browser/sync/glue/sync_backend_host.cc
@@ -5,6 +5,7 @@
#include "build/build_config.h"
#include <algorithm>
+#include <map>
#include "base/bind.h"
#include "base/command_line.h"
@@ -17,7 +18,6 @@
#include "chrome/browser/net/gaia/token_service.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/autofill_model_associator.h"
#include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
#include "chrome/browser/sync/glue/change_processor.h"
@@ -26,6 +26,8 @@
#include "chrome/browser/sync/glue/http_bridge.h"
#include "chrome/browser/sync/glue/password_model_worker.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
+#include "chrome/browser/sync/internal_api/base_transaction.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "chrome/browser/sync/js/js_arg_list.h"
#include "chrome/browser/sync/js/js_event_details.h"
#include "chrome/browser/sync/js/js_event_handler.h"
diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h
index 9270f75..21fe22a 100644
--- a/chrome/browser/sync/glue/sync_backend_host.h
+++ b/chrome/browser/sync/glue/sync_backend_host.h
@@ -15,6 +15,7 @@
#include "base/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread.h"
@@ -22,6 +23,7 @@
#include "chrome/browser/sync/engine/configure_reason.h"
#include "chrome/browser/sync/engine/model_safe_worker.h"
#include "chrome/browser/sync/glue/ui_model_worker.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "chrome/browser/sync/js/js_backend.h"
#include "chrome/browser/sync/notifier/sync_notifier_factory.h"
#include "chrome/browser/sync/syncable/model_type.h"
diff --git a/chrome/browser/sync/glue/sync_backend_host_unittest.cc b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
index 83aa28c..2bf47d1 100644
--- a/chrome/browser/sync/glue/sync_backend_host_unittest.cc
+++ b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
@@ -9,11 +9,10 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "chrome/browser/sync/engine/model_safe_worker.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/syncable/model_type.h"
-#include "chrome/test/base/test_url_request_context_getter.h"
#include "chrome/test/base/testing_browser_process_test.h"
#include "chrome/test/base/testing_profile.h"
+#include "chrome/test/base/test_url_request_context_getter.h"
#include "content/browser/browser_thread.h"
#include "content/common/url_fetcher.h"
#include "content/test/test_url_fetcher_factory.h"
diff --git a/chrome/browser/sync/glue/theme_change_processor.cc b/chrome/browser/sync/glue/theme_change_processor.cc
index 0783225..6876731 100644
--- a/chrome/browser/sync/glue/theme_change_processor.cc
+++ b/chrome/browser/sync/glue/theme_change_processor.cc
@@ -7,12 +7,15 @@
#include "base/logging.h"
#include "base/tracked.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/theme_util.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/protocol/theme_specifics.pb.h"
#include "chrome/browser/sync/unrecoverable_error_handler.h"
-#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
+#include "chrome/browser/themes/theme_service.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/extension.h"
#include "content/common/notification_details.h"
diff --git a/chrome/browser/sync/glue/theme_change_processor.h b/chrome/browser/sync/glue/theme_change_processor.h
index 72c7473..b7c3c9e 100644
--- a/chrome/browser/sync/glue/theme_change_processor.h
+++ b/chrome/browser/sync/glue/theme_change_processor.h
@@ -7,8 +7,8 @@
#pragma once
#include "base/basictypes.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/change_processor.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "content/common/content_notification_types.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
diff --git a/chrome/browser/sync/glue/theme_model_associator.cc b/chrome/browser/sync/glue/theme_model_associator.cc
index 5638bad..6b9ee5a 100644
--- a/chrome/browser/sync/glue/theme_model_associator.cc
+++ b/chrome/browser/sync/glue/theme_model_associator.cc
@@ -9,9 +9,12 @@
#include "base/tracked.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/sync/api/sync_error.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/glue/theme_util.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/protocol/theme_specifics.pb.h"
diff --git a/chrome/browser/sync/glue/typed_url_change_processor.cc b/chrome/browser/sync/glue/typed_url_change_processor.cc
index f309697..be6767a 100644
--- a/chrome/browser/sync/glue/typed_url_change_processor.cc
+++ b/chrome/browser/sync/glue/typed_url_change_processor.cc
@@ -11,6 +11,9 @@
#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/glue/typed_url_model_associator.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/protocol/typed_url_specifics.pb.h"
#include "chrome/common/chrome_notification_types.h"
diff --git a/chrome/browser/sync/glue/typed_url_model_associator.cc b/chrome/browser/sync/glue/typed_url_model_associator.cc
index 08e47d4..0d480ef 100644
--- a/chrome/browser/sync/glue/typed_url_model_associator.cc
+++ b/chrome/browser/sync/glue/typed_url_model_associator.cc
@@ -12,7 +12,10 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/history/history_backend.h"
#include "chrome/browser/sync/api/sync_error.h"
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/protocol/typed_url_specifics.pb.h"
diff --git a/chrome/browser/sync/glue/ui_model_worker.h b/chrome/browser/sync/glue/ui_model_worker.h
index 6a338db..5d0a97daf 100644
--- a/chrome/browser/sync/glue/ui_model_worker.h
+++ b/chrome/browser/sync/glue/ui_model_worker.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,10 +7,9 @@
#pragma once
#include "base/callback.h"
-#include "base/synchronization/lock.h"
#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
#include "base/task.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/engine/model_safe_worker.h"
namespace base {
diff --git a/chrome/browser/sync/glue/ui_model_worker_unittest.cc b/chrome/browser/sync/glue/ui_model_worker_unittest.cc
index 05422c9..c0230f1 100644
--- a/chrome/browser/sync/glue/ui_model_worker_unittest.cc
+++ b/chrome/browser/sync/glue/ui_model_worker_unittest.cc
@@ -4,12 +4,12 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
-#include "base/threading/thread.h"
#include "base/synchronization/waitable_event.h"
-#include "content/browser/browser_thread.h"
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "base/threading/thread.h"
#include "chrome/browser/sync/glue/ui_model_worker.h"
+#include "content/browser/browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
using browser_sync::UIModelWorker;
diff --git a/chrome/browser/sync/internal_api/DEPS b/chrome/browser/sync/internal_api/DEPS
new file mode 100644
index 0000000..ff4b760
--- /dev/null
+++ b/chrome/browser/sync/internal_api/DEPS
@@ -0,0 +1,14 @@
+include_rules = [
+ "-chrome",
+ "+chrome/test/base",
+ "+chrome/test/sync",
+
+ "+chrome/browser/sync",
+ "-chrome/browser/sync/api",
+ "-chrome/browser/sync/glue",
+
+ # unittests need this for mac osx keychain overriding
+ "+chrome/browser/password_manager/encryptor.h",
+
+ "+chrome/common/net/gaia/google_service_auth_error.h",
+]
diff --git a/chrome/browser/sync/internal_api/README b/chrome/browser/sync/internal_api/README
new file mode 100644
index 0000000..32987bb
--- /dev/null
+++ b/chrome/browser/sync/internal_api/README
@@ -0,0 +1,32 @@
+This file defines the "sync API", an interface to the syncer
+backend that exposes (1) the core functionality of maintaining a consistent
+local snapshot of a hierarchical object set; (2) a means to transactionally
+access and modify those objects; (3) a means to control client/server
+synchronization tasks, namely: pushing local object modifications to a
+server, pulling nonlocal object modifications from a server to this client,
+and resolving conflicts that may arise between the two; and (4) an
+abstraction of some external functionality that is to be provided by the
+host environment.
+
+This interface is used as the entry point into the syncer backend
+when the backend is compiled as a library and embedded in another
+application. A goal for this interface layer is to depend on very few
+external types, so that an application can use the sync backend
+without introducing a dependency on specific types. A non-goal is to
+have binary compatibility across versions or compilers; this allows the
+interface to use C++ classes. An application wishing to use the sync API
+should ideally compile the syncer backend and this API as part of the
+application's own build, to avoid e.g. mismatches in calling convention,
+structure padding, or name mangling that could arise if there were a
+compiler mismatch.
+
+The schema of the objects in the sync domain is based on the model, which
+is essentially a hierarchy of items and folders similar to a filesystem,
+but with a few important differences. The sync API contains fields
+such as URL to easily allow the embedding application to store web
+browser bookmarks. Also, the sync API allows duplicate titles in a parent.
+Consequently, it does not support looking up an object by title
+and parent, since such a lookup is not uniquely determined. Lastly,
+unlike a filesystem model, objects in the Sync API model have a strict
+ordering within a parent; the position is manipulable by callers, and
+children of a node can be enumerated in the order of their position.
diff --git a/chrome/browser/sync/internal_api/base_node.cc b/chrome/browser/sync/internal_api/base_node.cc
new file mode 100644
index 0000000..002006c
--- /dev/null
+++ b/chrome/browser/sync/internal_api/base_node.cc
@@ -0,0 +1,298 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/internal_api/base_node.h"
+
+#include "base/base64.h"
+#include "base/sha1.h"
+#include "base/string_number_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/sync/engine/syncapi_internal.h"
+#include "chrome/browser/sync/internal_api/base_transaction.h"
+#include "chrome/browser/sync/protocol/app_specifics.pb.h"
+#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
+#include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
+#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
+#include "chrome/browser/sync/protocol/nigori_specifics.pb.h"
+#include "chrome/browser/sync/protocol/password_specifics.pb.h"
+#include "chrome/browser/sync/protocol/session_specifics.pb.h"
+#include "chrome/browser/sync/protocol/theme_specifics.pb.h"
+#include "chrome/browser/sync/protocol/typed_url_specifics.pb.h"
+#include "chrome/browser/sync/syncable/directory_manager.h"
+#include "chrome/browser/sync/syncable/syncable.h"
+#include "chrome/browser/sync/syncable/syncable_id.h"
+
+using syncable::SPECIFICS;
+using sync_pb::AutofillProfileSpecifics;
+
+namespace sync_api {
+
+// Helper function to look up the int64 metahandle of an object given the ID
+// string.
+static int64 IdToMetahandle(syncable::BaseTransaction* trans,
+ const syncable::Id& id) {
+ syncable::Entry entry(trans, syncable::GET_BY_ID, id);
+ if (!entry.good())
+ return kInvalidId;
+ return entry.Get(syncable::META_HANDLE);
+}
+
+static bool EndsWithSpace(const std::string& string) {
+ return !string.empty() && *string.rbegin() == ' ';
+}
+
+// In the reverse direction, if a server name matches the pattern of a
+// server-illegal name followed by one or more spaces, remove the trailing
+// space.
+static void ServerNameToSyncAPIName(const std::string& server_name,
+ std::string* out) {
+ CHECK(out);
+ int length_to_copy = server_name.length();
+ if (IsNameServerIllegalAfterTrimming(server_name) &&
+ EndsWithSpace(server_name)) {
+ --length_to_copy;
+ }
+ *out = std::string(server_name.c_str(), length_to_copy);
+}
+
+BaseNode::BaseNode() : password_data_(new sync_pb::PasswordSpecificsData) {}
+
+BaseNode::~BaseNode() {}
+
+std::string BaseNode::GenerateSyncableHash(
+ syncable::ModelType model_type, const std::string& client_tag) {
+ // blank PB with just the extension in it has termination symbol,
+ // handy for delimiter
+ sync_pb::EntitySpecifics serialized_type;
+ syncable::AddDefaultExtensionValue(model_type, &serialized_type);
+ std::string hash_input;
+ serialized_type.AppendToString(&hash_input);
+ hash_input.append(client_tag);
+
+ std::string encode_output;
+ CHECK(base::Base64Encode(base::SHA1HashString(hash_input), &encode_output));
+ return encode_output;
+}
+
+bool BaseNode::DecryptIfNecessary() {
+ if (!GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty())
+ return true; // Ignore unique folders.
+ const sync_pb::EntitySpecifics& specifics =
+ GetEntry()->Get(syncable::SPECIFICS);
+ if (specifics.HasExtension(sync_pb::password)) {
+ // Passwords have their own legacy encryption structure.
+ scoped_ptr<sync_pb::PasswordSpecificsData> data(DecryptPasswordSpecifics(
+ specifics, GetTransaction()->GetCryptographer()));
+ if (!data.get()) {
+ LOG(ERROR) << "Failed to decrypt password specifics.";
+ return false;
+ }
+ password_data_.swap(data);
+ return true;
+ }
+
+ // We assume any node with the encrypted field set has encrypted data.
+ if (!specifics.has_encrypted())
+ return true;
+
+ const sync_pb::EncryptedData& encrypted =
+ specifics.encrypted();
+ std::string plaintext_data = GetTransaction()->GetCryptographer()->
+ DecryptToString(encrypted);
+ if (plaintext_data.length() == 0 ||
+ !unencrypted_data_.ParseFromString(plaintext_data)) {
+ LOG(ERROR) << "Failed to decrypt encrypted node of type " <<
+ syncable::ModelTypeToString(GetModelType()) << ".";
+ return false;
+ }
+ VLOG(2) << "Decrypted specifics of type "
+ << syncable::ModelTypeToString(GetModelType())
+ << " with content: " << plaintext_data;
+ return true;
+}
+
+const sync_pb::EntitySpecifics& BaseNode::GetUnencryptedSpecifics(
+ const syncable::Entry* entry) const {
+ const sync_pb::EntitySpecifics& specifics = entry->Get(SPECIFICS);
+ if (specifics.has_encrypted()) {
+ DCHECK(syncable::GetModelTypeFromSpecifics(unencrypted_data_) !=
+ syncable::UNSPECIFIED);
+ return unencrypted_data_;
+ } else {
+ DCHECK(syncable::GetModelTypeFromSpecifics(unencrypted_data_) ==
+ syncable::UNSPECIFIED);
+ return specifics;
+ }
+}
+
+int64 BaseNode::GetParentId() const {
+ return IdToMetahandle(GetTransaction()->GetWrappedTrans(),
+ GetEntry()->Get(syncable::PARENT_ID));
+}
+
+int64 BaseNode::GetId() const {
+ return GetEntry()->Get(syncable::META_HANDLE);
+}
+
+int64 BaseNode::GetModificationTime() const {
+ return GetEntry()->Get(syncable::MTIME);
+}
+
+bool BaseNode::GetIsFolder() const {
+ return GetEntry()->Get(syncable::IS_DIR);
+}
+
+std::string BaseNode::GetTitle() const {
+ std::string result;
+ // TODO(zea): refactor bookmarks to not need this functionality.
+ if (syncable::BOOKMARKS == GetModelType() &&
+ GetEntry()->Get(syncable::SPECIFICS).has_encrypted()) {
+ // Special case for legacy bookmarks dealing with encryption.
+ ServerNameToSyncAPIName(GetBookmarkSpecifics().title(), &result);
+ } else {
+ ServerNameToSyncAPIName(GetEntry()->Get(syncable::NON_UNIQUE_NAME),
+ &result);
+ }
+ return result;
+}
+
+GURL BaseNode::GetURL() const {
+ return GURL(GetBookmarkSpecifics().url());
+}
+
+int64 BaseNode::GetPredecessorId() const {
+ syncable::Id id_string = GetEntry()->Get(syncable::PREV_ID);
+ if (id_string.IsRoot())
+ return kInvalidId;
+ return IdToMetahandle(GetTransaction()->GetWrappedTrans(), id_string);
+}
+
+int64 BaseNode::GetSuccessorId() const {
+ syncable::Id id_string = GetEntry()->Get(syncable::NEXT_ID);
+ if (id_string.IsRoot())
+ return kInvalidId;
+ return IdToMetahandle(GetTransaction()->GetWrappedTrans(), id_string);
+}
+
+int64 BaseNode::GetFirstChildId() const {
+ syncable::Directory* dir = GetTransaction()->GetLookup();
+ syncable::BaseTransaction* trans = GetTransaction()->GetWrappedTrans();
+ syncable::Id id_string =
+ dir->GetFirstChildId(trans, GetEntry()->Get(syncable::ID));
+ if (id_string.IsRoot())
+ return kInvalidId;
+ return IdToMetahandle(GetTransaction()->GetWrappedTrans(), id_string);
+}
+
+DictionaryValue* BaseNode::GetSummaryAsValue() const {
+ DictionaryValue* node_info = new DictionaryValue();
+ node_info->SetString("id", base::Int64ToString(GetId()));
+ node_info->SetBoolean("isFolder", GetIsFolder());
+ node_info->SetString("title", GetTitle());
+ node_info->Set("type", ModelTypeToValue(GetModelType()));
+ return node_info;
+}
+
+DictionaryValue* BaseNode::GetDetailsAsValue() const {
+ DictionaryValue* node_info = GetSummaryAsValue();
+ // TODO(akalin): Return time in a better format.
+ node_info->SetString("modificationTime",
+ base::Int64ToString(GetModificationTime()));
+ node_info->SetString("parentId", base::Int64ToString(GetParentId()));
+ // Specifics are already in the Entry value, so no need to duplicate
+ // it here.
+ node_info->SetString("externalId",
+ base::Int64ToString(GetExternalId()));
+ node_info->SetString("predecessorId",
+ base::Int64ToString(GetPredecessorId()));
+ node_info->SetString("successorId",
+ base::Int64ToString(GetSuccessorId()));
+ node_info->SetString("firstChildId",
+ base::Int64ToString(GetFirstChildId()));
+ node_info->Set("entry", GetEntry()->ToValue());
+ return node_info;
+}
+
+void BaseNode::GetFaviconBytes(std::vector<unsigned char>* output) const {
+ if (!output)
+ return;
+ const std::string& favicon = GetBookmarkSpecifics().favicon();
+ output->assign(reinterpret_cast<const unsigned char*>(favicon.data()),
+ reinterpret_cast<const unsigned char*>(favicon.data() +
+ favicon.length()));
+}
+
+int64 BaseNode::GetExternalId() const {
+ return GetEntry()->Get(syncable::LOCAL_EXTERNAL_ID);
+}
+
+const sync_pb::AppSpecifics& BaseNode::GetAppSpecifics() const {
+ DCHECK_EQ(syncable::APPS, GetModelType());
+ return GetEntitySpecifics().GetExtension(sync_pb::app);
+}
+
+const sync_pb::AutofillSpecifics& BaseNode::GetAutofillSpecifics() const {
+ DCHECK_EQ(syncable::AUTOFILL, GetModelType());
+ return GetEntitySpecifics().GetExtension(sync_pb::autofill);
+}
+
+const AutofillProfileSpecifics& BaseNode::GetAutofillProfileSpecifics() const {
+ DCHECK_EQ(GetModelType(), syncable::AUTOFILL_PROFILE);
+ return GetEntitySpecifics().GetExtension(sync_pb::autofill_profile);
+}
+
+const sync_pb::BookmarkSpecifics& BaseNode::GetBookmarkSpecifics() const {
+ DCHECK_EQ(syncable::BOOKMARKS, GetModelType());
+ return GetEntitySpecifics().GetExtension(sync_pb::bookmark);
+}
+
+const sync_pb::NigoriSpecifics& BaseNode::GetNigoriSpecifics() const {
+ DCHECK_EQ(syncable::NIGORI, GetModelType());
+ return GetEntitySpecifics().GetExtension(sync_pb::nigori);
+}
+
+const sync_pb::PasswordSpecificsData& BaseNode::GetPasswordSpecifics() const {
+ DCHECK_EQ(syncable::PASSWORDS, GetModelType());
+ return *password_data_;
+}
+
+const sync_pb::ThemeSpecifics& BaseNode::GetThemeSpecifics() const {
+ DCHECK_EQ(syncable::THEMES, GetModelType());
+ return GetEntitySpecifics().GetExtension(sync_pb::theme);
+}
+
+const sync_pb::TypedUrlSpecifics& BaseNode::GetTypedUrlSpecifics() const {
+ DCHECK_EQ(syncable::TYPED_URLS, GetModelType());
+ return GetEntitySpecifics().GetExtension(sync_pb::typed_url);
+}
+
+const sync_pb::ExtensionSpecifics& BaseNode::GetExtensionSpecifics() const {
+ DCHECK_EQ(syncable::EXTENSIONS, GetModelType());
+ return GetEntitySpecifics().GetExtension(sync_pb::extension);
+}
+
+const sync_pb::SessionSpecifics& BaseNode::GetSessionSpecifics() const {
+ DCHECK_EQ(syncable::SESSIONS, GetModelType());
+ return GetEntitySpecifics().GetExtension(sync_pb::session);
+}
+
+const sync_pb::EntitySpecifics& BaseNode::GetEntitySpecifics() const {
+ return GetUnencryptedSpecifics(GetEntry());
+}
+
+syncable::ModelType BaseNode::GetModelType() const {
+ return GetEntry()->GetModelType();
+}
+
+void BaseNode::SetUnencryptedSpecifics(
+ const sync_pb::EntitySpecifics& specifics) {
+ syncable::ModelType type = syncable::GetModelTypeFromSpecifics(specifics);
+ DCHECK_NE(syncable::UNSPECIFIED, type);
+ if (GetModelType() != syncable::UNSPECIFIED) {
+ DCHECK_EQ(GetModelType(), type);
+ }
+ unencrypted_data_.CopyFrom(specifics);
+}
+
+} // namespace sync_api
diff --git a/chrome/browser/sync/internal_api/base_node.h b/chrome/browser/sync/internal_api/base_node.h
new file mode 100644
index 0000000..8759966
--- /dev/null
+++ b/chrome/browser/sync/internal_api/base_node.h
@@ -0,0 +1,224 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_INTERNAL_API_BASE_NODE_H_
+#define CHROME_BROWSER_SYNC_INTERNAL_API_BASE_NODE_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/sync/protocol/sync.pb.h"
+#include "chrome/browser/sync/syncable/model_type.h"
+#include "googleurl/src/gurl.h"
+
+// Forward declarations of internal class types so that sync API objects
+// may have opaque pointers to these types.
+namespace base {
+class DictionaryValue;
+}
+
+namespace syncable {
+class BaseTransaction;
+class Entry;
+}
+
+namespace sync_pb {
+class AppSpecifics;
+class AutofillSpecifics;
+class AutofillProfileSpecifics;
+class BookmarkSpecifics;
+class EntitySpecifics;
+class ExtensionSpecifics;
+class SessionSpecifics;
+class NigoriSpecifics;
+class PreferenceSpecifics;
+class PasswordSpecificsData;
+class ThemeSpecifics;
+class TypedUrlSpecifics;
+}
+
+namespace sync_api {
+
+class BaseTransaction;
+
+// A valid BaseNode will never have an ID of zero.
+static const int64 kInvalidId = 0;
+
+// BaseNode wraps syncable::Entry, and corresponds to a single object's state.
+// This, like syncable::Entry, is intended for use on the stack. A valid
+// transaction is necessary to create a BaseNode or any of its children.
+// Unlike syncable::Entry, a sync API BaseNode is identified primarily by its
+// int64 metahandle, which we call an ID here.
+class BaseNode {
+ public:
+ // All subclasses of BaseNode must provide a way to initialize themselves by
+ // doing an ID lookup. Returns false on failure. An invalid or deleted
+ // ID will result in failure.
+ virtual bool InitByIdLookup(int64 id) = 0;
+
+ // All subclasses of BaseNode must also provide a way to initialize themselves
+ // by doing a client tag lookup. Returns false on failure. A deleted node
+ // will return FALSE.
+ virtual bool InitByClientTagLookup(syncable::ModelType model_type,
+ const std::string& tag) = 0;
+
+ // Each object is identified by a 64-bit id (internally, the syncable
+ // metahandle). These ids are strictly local handles. They will persist
+ // on this client, but the same object on a different client may have a
+ // different ID value.
+ virtual int64 GetId() const;
+
+ // Returns the modification time of the object (in TimeTicks internal format).
+ int64 GetModificationTime() const;
+
+ // Nodes are hierarchically arranged into a single-rooted tree.
+ // InitByRootLookup on ReadNode allows access to the root. GetParentId is
+ // how you find a node's parent.
+ int64 GetParentId() const;
+
+ // Nodes are either folders or not. This corresponds to the IS_DIR property
+ // of syncable::Entry.
+ bool GetIsFolder() const;
+
+ // Returns the title of the object.
+ // Uniqueness of the title is not enforced on siblings -- it is not an error
+ // for two children to share a title.
+ std::string GetTitle() const;
+
+ // Returns the model type of this object. The model type is set at node
+ // creation time and is expected never to change.
+ syncable::ModelType GetModelType() const;
+
+ // Getter specific to the BOOKMARK datatype. Returns protobuf
+ // data. Can only be called if GetModelType() == BOOKMARK.
+ const sync_pb::BookmarkSpecifics& GetBookmarkSpecifics() const;
+
+ // Legacy, bookmark-specific getter that wraps GetBookmarkSpecifics() above.
+ // Returns the URL of a bookmark object.
+ // TODO(ncarter): Remove this datatype-specific accessor.
+ GURL GetURL() const;
+
+ // Legacy, bookmark-specific getter that wraps GetBookmarkSpecifics() above.
+ // Fill in a vector with the byte data of this node's favicon. Assumes
+ // that the node is a bookmark.
+ // Favicons are expected to be PNG images, and though no verification is
+ // done on the syncapi client of this, the server may reject favicon updates
+ // that are invalid for whatever reason.
+ // TODO(ncarter): Remove this datatype-specific accessor.
+ void GetFaviconBytes(std::vector<unsigned char>* output) const;
+
+ // Getter specific to the APPS datatype. Returns protobuf
+ // data. Can only be called if GetModelType() == APPS.
+ const sync_pb::AppSpecifics& GetAppSpecifics() const;
+
+ // Getter specific to the AUTOFILL datatype. Returns protobuf
+ // data. Can only be called if GetModelType() == AUTOFILL.
+ const sync_pb::AutofillSpecifics& GetAutofillSpecifics() const;
+
+ virtual const sync_pb::AutofillProfileSpecifics&
+ GetAutofillProfileSpecifics() const;
+
+ // Getter specific to the NIGORI datatype. Returns protobuf
+ // data. Can only be called if GetModelType() == NIGORI.
+ const sync_pb::NigoriSpecifics& GetNigoriSpecifics() const;
+
+ // Getter specific to the PASSWORD datatype. Returns protobuf
+ // data. Can only be called if GetModelType() == PASSWORD.
+ const sync_pb::PasswordSpecificsData& GetPasswordSpecifics() const;
+
+ // Getter specific to the PREFERENCE datatype. Returns protobuf
+ // data. Can only be called if GetModelType() == PREFERENCE.
+ const sync_pb::PreferenceSpecifics& GetPreferenceSpecifics() const;
+
+ // Getter specific to the THEME datatype. Returns protobuf
+ // data. Can only be called if GetModelType() == THEME.
+ const sync_pb::ThemeSpecifics& GetThemeSpecifics() const;
+
+ // Getter specific to the TYPED_URLS datatype. Returns protobuf
+ // data. Can only be called if GetModelType() == TYPED_URLS.
+ const sync_pb::TypedUrlSpecifics& GetTypedUrlSpecifics() const;
+
+ // Getter specific to the EXTENSIONS datatype. Returns protobuf
+ // data. Can only be called if GetModelType() == EXTENSIONS.
+ const sync_pb::ExtensionSpecifics& GetExtensionSpecifics() const;
+
+ // Getter specific to the SESSIONS datatype. Returns protobuf
+ // data. Can only be called if GetModelType() == SESSIONS.
+ const sync_pb::SessionSpecifics& GetSessionSpecifics() const;
+
+ const sync_pb::EntitySpecifics& GetEntitySpecifics() const;
+
+ // Returns the local external ID associated with the node.
+ int64 GetExternalId() const;
+
+ // Return the ID of the node immediately before this in the sibling order.
+ // For the first node in the ordering, return 0.
+ int64 GetPredecessorId() const;
+
+ // Return the ID of the node immediately after this in the sibling order.
+ // For the last node in the ordering, return 0.
+ virtual int64 GetSuccessorId() const;
+
+ // Return the ID of the first child of this node. If this node has no
+ // children, return 0.
+ virtual int64 GetFirstChildId() const;
+
+ // These virtual accessors provide access to data members of derived classes.
+ virtual const syncable::Entry* GetEntry() const = 0;
+ virtual const BaseTransaction* GetTransaction() const = 0;
+
+ // Dumps a summary of node info into a DictionaryValue and returns it.
+ // Transfers ownership of the DictionaryValue to the caller.
+ base::DictionaryValue* GetSummaryAsValue() const;
+
+ // Dumps all node details into a DictionaryValue and returns it.
+ // Transfers ownership of the DictionaryValue to the caller.
+ base::DictionaryValue* GetDetailsAsValue() const;
+
+ protected:
+ BaseNode();
+ virtual ~BaseNode();
+ // The server has a size limit on client tags, so we generate a fixed length
+ // hash locally. This also ensures that ModelTypes have unique namespaces.
+ static std::string GenerateSyncableHash(syncable::ModelType model_type,
+ const std::string& client_tag);
+
+ // Determines whether part of the entry is encrypted, and if so attempts to
+ // decrypt it. Unless decryption is necessary and fails, this will always
+ // return |true|. If the contents are encrypted, the decrypted data will be
+ // stored in |unencrypted_data_|.
+ // This method is invoked once when the BaseNode is initialized.
+ bool DecryptIfNecessary();
+
+ // Returns the unencrypted specifics associated with |entry|. If |entry| was
+ // not encrypted, it directly returns |entry|'s EntitySpecifics. Otherwise,
+ // returns |unencrypted_data_|.
+ const sync_pb::EntitySpecifics& GetUnencryptedSpecifics(
+ const syncable::Entry* entry) const;
+
+ // Copy |specifics| into |unencrypted_data_|.
+ void SetUnencryptedSpecifics(const sync_pb::EntitySpecifics& specifics);
+
+ private:
+ void* operator new(size_t size); // Node is meant for stack use only.
+
+ // A holder for the unencrypted data stored in an encrypted node.
+ sync_pb::EntitySpecifics unencrypted_data_;
+
+ // Same as |unencrypted_data_|, but for legacy password encryption.
+ scoped_ptr<sync_pb::PasswordSpecificsData> password_data_;
+
+ friend class SyncApiTest;
+ FRIEND_TEST_ALL_PREFIXES(SyncApiTest, GenerateSyncableHash);
+
+ DISALLOW_COPY_AND_ASSIGN(BaseNode);
+};
+
+} // namespace sync_api
+
+#endif // CHROME_BROWSER_SYNC_INTERNAL_API_BASE_NODE_H_
diff --git a/chrome/browser/sync/internal_api/base_transaction.cc b/chrome/browser/sync/internal_api/base_transaction.cc
new file mode 100644
index 0000000..8d26702
--- /dev/null
+++ b/chrome/browser/sync/internal_api/base_transaction.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base_transaction.h"
+
+#include "chrome/browser/sync/syncable/directory_manager.h"
+#include "chrome/browser/sync/util/cryptographer.h"
+
+using browser_sync::Cryptographer;
+
+namespace sync_api {
+
+//////////////////////////////////////////////////////////////////////////
+// BaseTransaction member definitions
+BaseTransaction::BaseTransaction(UserShare* share)
+ : lookup_(NULL) {
+ DCHECK(share && share->dir_manager.get());
+ lookup_ = new syncable::ScopedDirLookup(share->dir_manager.get(),
+ share->name);
+ cryptographer_ = share->dir_manager->GetCryptographer(this);
+ if (!(lookup_->good()))
+ DCHECK(false) << "ScopedDirLookup failed on valid DirManager.";
+}
+BaseTransaction::~BaseTransaction() {
+ delete lookup_;
+}
+
+syncable::ModelTypeSet GetEncryptedTypes(
+ const sync_api::BaseTransaction* trans) {
+ Cryptographer* cryptographer = trans->GetCryptographer();
+ return cryptographer->GetEncryptedTypes();
+}
+
+} // namespace sync_api
diff --git a/chrome/browser/sync/internal_api/base_transaction.h b/chrome/browser/sync/internal_api/base_transaction.h
new file mode 100644
index 0000000..9bf2fb3
--- /dev/null
+++ b/chrome/browser/sync/internal_api/base_transaction.h
@@ -0,0 +1,59 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_INTERNAL_API_BASE_TRANSACTION_H_
+#define CHROME_BROWSER_SYNC_INTERNAL_API_BASE_TRANSACTION_H_
+#pragma once
+
+#include "chrome/browser/sync/internal_api/user_share.h"
+
+#include "chrome/browser/sync/util/cryptographer.h"
+
+namespace syncable {
+class BaseTransaction;
+class ScopedDirLookup;
+}
+
+namespace sync_api {
+
+// Sync API's BaseTransaction, ReadTransaction, and WriteTransaction allow for
+// batching of several read and/or write operations. The read and write
+// operations are performed by creating ReadNode and WriteNode instances using
+// the transaction. These transaction classes wrap identically named classes in
+// syncable, and are used in a similar way. Unlike syncable::BaseTransaction,
+// whose construction requires an explicit syncable::ScopedDirLookup, a sync
+// API BaseTransaction creates its own ScopedDirLookup implicitly.
+class BaseTransaction {
+ public:
+ // Provide access to the underlying syncable.h objects from BaseNode.
+ virtual syncable::BaseTransaction* GetWrappedTrans() const = 0;
+ const syncable::ScopedDirLookup& GetLookup() const { return *lookup_; }
+ browser_sync::Cryptographer* GetCryptographer() const {
+ return cryptographer_;
+ }
+
+ protected:
+ // The ScopedDirLookup is created in the constructor and destroyed
+ // in the destructor. Creation of the ScopedDirLookup is not expected
+ // to fail.
+ explicit BaseTransaction(UserShare* share);
+ virtual ~BaseTransaction();
+
+ BaseTransaction() { lookup_= NULL; }
+
+ private:
+ // A syncable ScopedDirLookup, which is the parent of syncable transactions.
+ syncable::ScopedDirLookup* lookup_;
+
+ browser_sync::Cryptographer* cryptographer_;
+
+ DISALLOW_COPY_AND_ASSIGN(BaseTransaction);
+};
+
+syncable::ModelTypeSet GetEncryptedTypes(
+ const sync_api::BaseTransaction* trans);
+
+} // namespace sync_api
+
+#endif // CHROME_BROWSER_SYNC_INTERNAL_API_BASE_TRANSACTION_H_
diff --git a/chrome/browser/sync/internal_api/read_node.cc b/chrome/browser/sync/internal_api/read_node.cc
new file mode 100644
index 0000000..73e0b29
--- /dev/null
+++ b/chrome/browser/sync/internal_api/read_node.cc
@@ -0,0 +1,92 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/internal_api/read_node.h"
+
+#include "base/logging.h"
+#include "chrome/browser/sync/internal_api/base_transaction.h"
+#include "chrome/browser/sync/syncable/syncable.h"
+
+namespace sync_api {
+
+//////////////////////////////////////////////////////////////////////////
+// ReadNode member definitions
+ReadNode::ReadNode(const BaseTransaction* transaction)
+ : entry_(NULL), transaction_(transaction) {
+ DCHECK(transaction);
+}
+
+ReadNode::ReadNode() {
+ entry_ = NULL;
+ transaction_ = NULL;
+}
+
+ReadNode::~ReadNode() {
+ delete entry_;
+}
+
+void ReadNode::InitByRootLookup() {
+ DCHECK(!entry_) << "Init called twice";
+ syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
+ entry_ = new syncable::Entry(trans, syncable::GET_BY_ID, trans->root_id());
+ if (!entry_->good())
+ DCHECK(false) << "Could not lookup root node for reading.";
+}
+
+bool ReadNode::InitByIdLookup(int64 id) {
+ DCHECK(!entry_) << "Init called twice";
+ DCHECK_NE(id, kInvalidId);
+ syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
+ entry_ = new syncable::Entry(trans, syncable::GET_BY_HANDLE, id);
+ if (!entry_->good())
+ return false;
+ if (entry_->Get(syncable::IS_DEL))
+ return false;
+ syncable::ModelType model_type = GetModelType();
+ LOG_IF(WARNING, model_type == syncable::UNSPECIFIED ||
+ model_type == syncable::TOP_LEVEL_FOLDER)
+ << "SyncAPI InitByIdLookup referencing unusual object.";
+ return DecryptIfNecessary();
+}
+
+bool ReadNode::InitByClientTagLookup(syncable::ModelType model_type,
+ const std::string& tag) {
+ DCHECK(!entry_) << "Init called twice";
+ if (tag.empty())
+ return false;
+
+ const std::string hash = GenerateSyncableHash(model_type, tag);
+
+ entry_ = new syncable::Entry(transaction_->GetWrappedTrans(),
+ syncable::GET_BY_CLIENT_TAG, hash);
+ return (entry_->good() && !entry_->Get(syncable::IS_DEL) &&
+ DecryptIfNecessary());
+}
+
+const syncable::Entry* ReadNode::GetEntry() const {
+ return entry_;
+}
+
+const BaseTransaction* ReadNode::GetTransaction() const {
+ return transaction_;
+}
+
+bool ReadNode::InitByTagLookup(const std::string& tag) {
+ DCHECK(!entry_) << "Init called twice";
+ if (tag.empty())
+ return false;
+ syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
+ entry_ = new syncable::Entry(trans, syncable::GET_BY_SERVER_TAG, tag);
+ if (!entry_->good())
+ return false;
+ if (entry_->Get(syncable::IS_DEL))
+ return false;
+ syncable::ModelType model_type = GetModelType();
+ LOG_IF(WARNING, model_type == syncable::UNSPECIFIED ||
+ model_type == syncable::TOP_LEVEL_FOLDER)
+ << "SyncAPI InitByTagLookup referencing unusually typed object.";
+ return DecryptIfNecessary();
+}
+
+} // namespace sync_api
diff --git a/chrome/browser/sync/internal_api/read_node.h b/chrome/browser/sync/internal_api/read_node.h
new file mode 100644
index 0000000..9ad9715
--- /dev/null
+++ b/chrome/browser/sync/internal_api/read_node.h
@@ -0,0 +1,79 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_INTERNAL_API_READ_NODE_H_
+#define CHROME_BROWSER_SYNC_INTERNAL_API_READ_NODE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "chrome/browser/sync/internal_api/base_node.h"
+#include "chrome/browser/sync/syncable/model_type.h"
+
+namespace sync_pb {
+class AppSpecifics;
+class AutofillSpecifics;
+class AutofillProfileSpecifics;
+class BookmarkSpecifics;
+class EntitySpecifics;
+class ExtensionSpecifics;
+class SessionSpecifics;
+class NigoriSpecifics;
+class PreferenceSpecifics;
+class PasswordSpecificsData;
+class ThemeSpecifics;
+class TypedUrlSpecifics;
+}
+
+namespace sync_api {
+
+// ReadNode wraps a syncable::Entry to provide the functionality of a
+// read-only BaseNode.
+class ReadNode : public BaseNode {
+ public:
+ // Create an unpopulated ReadNode on the given transaction. Call some flavor
+ // of Init to populate the ReadNode with a database entry.
+ explicit ReadNode(const BaseTransaction* transaction);
+ virtual ~ReadNode();
+
+ // A client must use one (and only one) of the following Init variants to
+ // populate the node.
+
+ // BaseNode implementation.
+ virtual bool InitByIdLookup(int64 id);
+ virtual bool InitByClientTagLookup(syncable::ModelType model_type,
+ const std::string& tag);
+
+ // There is always a root node, so this can't fail. The root node is
+ // never mutable, so root lookup is only possible on a ReadNode.
+ void InitByRootLookup();
+
+ // Each server-created permanent node is tagged with a unique string.
+ // Look up the node with the particular tag. If it does not exist,
+ // return false.
+ bool InitByTagLookup(const std::string& tag);
+
+ // Implementation of BaseNode's abstract virtual accessors.
+ virtual const syncable::Entry* GetEntry() const;
+ virtual const BaseTransaction* GetTransaction() const;
+
+ protected:
+ ReadNode();
+
+ private:
+ void* operator new(size_t size); // Node is meant for stack use only.
+
+ // The underlying syncable object which this class wraps.
+ syncable::Entry* entry_;
+
+ // The sync API transaction that is the parent of this node.
+ const BaseTransaction* transaction_;
+
+ DISALLOW_COPY_AND_ASSIGN(ReadNode);
+};
+
+} // namespace sync_api
+
+#endif // CHROME_BROWSER_SYNC_INTERNAL_API_READ_NODE_H_
diff --git a/chrome/browser/sync/engine/read_node_mock.cc b/chrome/browser/sync/internal_api/read_node_mock.cc
index 6916688..64007b5 100644
--- a/chrome/browser/sync/engine/read_node_mock.cc
+++ b/chrome/browser/sync/internal_api/read_node_mock.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/sync/engine/read_node_mock.h"
+#include "chrome/browser/sync/internal_api/read_node_mock.h"
#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
diff --git a/chrome/browser/sync/engine/read_node_mock.h b/chrome/browser/sync/internal_api/read_node_mock.h
index 9d31f6f..598d4e2 100644
--- a/chrome/browser/sync/engine/read_node_mock.h
+++ b/chrome/browser/sync/internal_api/read_node_mock.h
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_SYNC_ENGINE_READ_NODE_MOCK_H_
-#define CHROME_BROWSER_SYNC_ENGINE_READ_NODE_MOCK_H_
+#ifndef CHROME_BROWSER_SYNC_INTERNAL_API_READ_NODE_MOCK_H_
+#define CHROME_BROWSER_SYNC_INTERNAL_API_READ_NODE_MOCK_H_
#pragma once
#include <string>
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
#include "testing/gmock/include/gmock/gmock.h"
class ReadNodeMock : public sync_api::ReadNode {
@@ -27,5 +27,4 @@ class ReadNodeMock : public sync_api::ReadNode {
MOCK_METHOD1(InitByIdLookup, bool(int64 id));
};
-#endif // CHROME_BROWSER_SYNC_ENGINE_READ_NODE_MOCK_H_
-
+#endif // CHROME_BROWSER_SYNC_INTERNAL_API_READ_NODE_MOCK_H_
diff --git a/chrome/browser/sync/internal_api/read_transaction.cc b/chrome/browser/sync/internal_api/read_transaction.cc
new file mode 100644
index 0000000..40691dd
--- /dev/null
+++ b/chrome/browser/sync/internal_api/read_transaction.cc
@@ -0,0 +1,37 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+
+#include "chrome/browser/sync/syncable/syncable.h"
+
+namespace sync_api {
+
+//////////////////////////////////////////////////////////////////////////
+// ReadTransaction member definitions
+ReadTransaction::ReadTransaction(const tracked_objects::Location& from_here,
+ UserShare* share)
+ : BaseTransaction(share),
+ transaction_(NULL),
+ close_transaction_(true) {
+ transaction_ = new syncable::ReadTransaction(from_here, GetLookup());
+}
+
+ReadTransaction::ReadTransaction(UserShare* share,
+ syncable::BaseTransaction* trans)
+ : BaseTransaction(share),
+ transaction_(trans),
+ close_transaction_(false) {}
+
+ReadTransaction::~ReadTransaction() {
+ if (close_transaction_) {
+ delete transaction_;
+ }
+}
+
+syncable::BaseTransaction* ReadTransaction::GetWrappedTrans() const {
+ return transaction_;
+}
+
+} // namespace sync_api
diff --git a/chrome/browser/sync/internal_api/read_transaction.h b/chrome/browser/sync/internal_api/read_transaction.h
new file mode 100644
index 0000000..c1b97d9
--- /dev/null
+++ b/chrome/browser/sync/internal_api/read_transaction.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_INTERNAL_API_READ_TRANSACTION_H_
+#define CHROME_BROWSER_SYNC_INTERNAL_API_READ_TRANSACTION_H_
+
+#include "chrome/browser/sync/internal_api/base_transaction.h"
+
+namespace tracked_objects {
+class Location;
+} // namespace tracked_objects
+
+namespace sync_api {
+
+struct UserShare;
+
+// Sync API's ReadTransaction is a read-only BaseTransaction. It wraps
+// a syncable::ReadTransaction.
+class ReadTransaction : public BaseTransaction {
+ public:
+ // Start a new read-only transaction on the specified repository.
+ ReadTransaction(const tracked_objects::Location& from_here,
+ UserShare* share);
+
+ // Resume the middle of a transaction. Will not close transaction.
+ ReadTransaction(UserShare* share, syncable::BaseTransaction* trans);
+
+ virtual ~ReadTransaction();
+
+ // BaseTransaction override.
+ virtual syncable::BaseTransaction* GetWrappedTrans() const;
+ private:
+ void* operator new(size_t size); // Transaction is meant for stack use only.
+
+ // The underlying syncable object which this class wraps.
+ syncable::BaseTransaction* transaction_;
+ bool close_transaction_;
+
+ DISALLOW_COPY_AND_ASSIGN(ReadTransaction);
+};
+
+} // namespace sync_api
+
+#endif // CHROME_BROWSER_SYNC_INTERNAL_API_READ_TRANSACTION_H_
diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/internal_api/sync_manager.cc
index 408f71c..40ebdd5 100644
--- a/chrome/browser/sync/engine/syncapi.cc
+++ b/chrome/browser/sync/internal_api/sync_manager.cc
@@ -2,47 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/sync/engine/syncapi.h"
-
-#include <algorithm>
-#include <bitset>
-#include <iomanip>
-#include <list>
-#include <map>
-#include <queue>
+#include "chrome/browser/sync/internal_api/sync_manager.h"
+
#include <string>
#include <vector>
#include "base/base64.h"
-#include "base/bind.h"
-#include "base/callback.h"
-#include "base/command_line.h"
-#include "base/compiler_specific.h"
#include "base/json/json_writer.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
-#include "base/message_loop.h"
-#include "base/observer_list.h"
-#include "base/sha1.h"
#include "base/string_number_conversions.h"
-#include "base/string_util.h"
-#include "base/threading/thread_checker.h"
-#include "base/time.h"
-#include "base/tracked.h"
-#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/sync/engine/all_status.h"
#include "chrome/browser/sync/engine/change_reorder_buffer.h"
-#include "chrome/browser/sync/engine/http_post_provider_factory.h"
-#include "chrome/browser/sync/engine/model_safe_worker.h"
-#include "chrome/browser/sync/engine/nigori_util.h"
-#include "chrome/browser/sync/engine/nudge_source.h"
#include "chrome/browser/sync/engine/net/server_connection_manager.h"
#include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h"
-#include "chrome/browser/sync/engine/nudge_source.h"
+#include "chrome/browser/sync/engine/nigori_util.h"
+#include "chrome/browser/sync/engine/syncapi_internal.h"
+#include "chrome/browser/sync/engine/syncer_types.h"
#include "chrome/browser/sync/engine/sync_scheduler.h"
-#include "chrome/browser/sync/engine/syncer.h"
+#include "chrome/browser/sync/internal_api/base_node.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/user_share.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/js/js_arg_list.h"
#include "chrome/browser/sync/js/js_backend.h"
#include "chrome/browser/sync/js/js_event_details.h"
@@ -52,29 +34,18 @@
#include "chrome/browser/sync/js/js_transaction_observer.h"
#include "chrome/browser/sync/notifier/sync_notifier.h"
#include "chrome/browser/sync/notifier/sync_notifier_observer.h"
-#include "chrome/browser/sync/protocol/app_specifics.pb.h"
-#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
-#include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
-#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
-#include "chrome/browser/sync/protocol/nigori_specifics.pb.h"
-#include "chrome/browser/sync/protocol/preference_specifics.pb.h"
#include "chrome/browser/sync/protocol/proto_value_conversions.h"
-#include "chrome/browser/sync/protocol/service_constants.h"
-#include "chrome/browser/sync/protocol/session_specifics.pb.h"
-#include "chrome/browser/sync/protocol/sync.pb.h"
-#include "chrome/browser/sync/protocol/theme_specifics.pb.h"
-#include "chrome/browser/sync/protocol/typed_url_specifics.pb.h"
-#include "chrome/browser/sync/sessions/sync_session.h"
-#include "chrome/browser/sync/sessions/sync_session_context.h"
#include "chrome/browser/sync/syncable/directory_change_delegate.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/model_type.h"
-#include "chrome/browser/sync/syncable/model_type_payload_map.h"
#include "chrome/browser/sync/syncable/syncable.h"
+#include "chrome/browser/sync/util/cryptographer.h"
#include "chrome/browser/sync/weak_handle.h"
-#include "chrome/common/chrome_switches.h"
#include "net/base/network_change_notifier.h"
+using std::string;
+using std::vector;
+
using base::TimeDelta;
using browser_sync::AllStatus;
using browser_sync::Cryptographer;
@@ -82,1061 +53,42 @@ using browser_sync::JsArgList;
using browser_sync::JsBackend;
using browser_sync::JsEventDetails;
using browser_sync::JsEventHandler;
+using browser_sync::JsEventHandler;
using browser_sync::JsReplyHandler;
using browser_sync::JsSyncManagerObserver;
using browser_sync::JsTransactionObserver;
-using browser_sync::MakeWeakHandle;
-using browser_sync::WeakHandle;
+using browser_sync::ModelSafeWorkerRegistrar;
+using browser_sync::kNigoriTag;
using browser_sync::KeyParams;
using browser_sync::ModelSafeRoutingInfo;
-using browser_sync::ModelSafeWorker;
-using browser_sync::ModelSafeWorkerRegistrar;
using browser_sync::ServerConnectionEvent;
using browser_sync::ServerConnectionEventListener;
using browser_sync::SyncEngineEvent;
using browser_sync::SyncEngineEventListener;
-using browser_sync::Syncer;
using browser_sync::SyncScheduler;
-using browser_sync::kNigoriTag;
+using browser_sync::Syncer;
+using browser_sync::WeakHandle;
using browser_sync::sessions::SyncSessionContext;
-using std::list;
-using std::hex;
-using std::string;
-using std::vector;
-using syncable::Directory;
using syncable::DirectoryManager;
-using syncable::Entry;
using syncable::EntryKernelMutationSet;
-using syncable::kEncryptedString;
using syncable::ModelType;
using syncable::ModelTypeBitSet;
-using syncable::WriterTag;
using syncable::SPECIFICS;
-using sync_pb::AutofillProfileSpecifics;
-
-namespace {
typedef GoogleServiceAuthError AuthError;
-static const int kThreadExitTimeoutMsec = 60000;
-static const int kSSLPort = 443;
+namespace {
+
static const int kSyncSchedulerDelayMsec = 250;
#if defined(OS_CHROMEOS)
static const int kChromeOSNetworkChangeReactionDelayHackMsec = 5000;
#endif // OS_CHROMEOS
-} // namespace
+} // namespace
namespace sync_api {
-static const FilePath::CharType kBookmarkSyncUserSettingsDatabase[] =
- FILE_PATH_LITERAL("BookmarkSyncSettings.sqlite3");
-static const char kDefaultNameForNewNodes[] = " ";
-
-// The list of names which are reserved for use by the server.
-static const char* kForbiddenServerNames[] = { "", ".", ".." };
-
-//////////////////////////////////////////////////////////////////////////
-// Static helper functions.
-
-// Helper function to look up the int64 metahandle of an object given the ID
-// string.
-static int64 IdToMetahandle(syncable::BaseTransaction* trans,
- const syncable::Id& id) {
- syncable::Entry entry(trans, syncable::GET_BY_ID, id);
- if (!entry.good())
- return kInvalidId;
- return entry.Get(syncable::META_HANDLE);
-}
-
-// Checks whether |name| is a server-illegal name followed by zero or more space
-// characters. The three server-illegal names are the empty string, dot, and
-// dot-dot. Very long names (>255 bytes in UTF-8 Normalization Form C) are
-// also illegal, but are not considered here.
-static bool IsNameServerIllegalAfterTrimming(const std::string& name) {
- size_t untrimmed_count = name.find_last_not_of(' ') + 1;
- for (size_t i = 0; i < arraysize(kForbiddenServerNames); ++i) {
- if (name.compare(0, untrimmed_count, kForbiddenServerNames[i]) == 0)
- return true;
- }
- return false;
-}
-
-static bool EndsWithSpace(const std::string& string) {
- return !string.empty() && *string.rbegin() == ' ';
-}
-
-// When taking a name from the syncapi, append a space if it matches the
-// pattern of a server-illegal name followed by zero or more spaces.
-static void SyncAPINameToServerName(const std::wstring& sync_api_name,
- std::string* out) {
- *out = WideToUTF8(sync_api_name);
- if (IsNameServerIllegalAfterTrimming(*out))
- out->append(" ");
-}
-
-// In the reverse direction, if a server name matches the pattern of a
-// server-illegal name followed by one or more spaces, remove the trailing
-// space.
-static void ServerNameToSyncAPIName(const std::string& server_name,
- std::string* out) {
- CHECK(out);
- int length_to_copy = server_name.length();
- if (IsNameServerIllegalAfterTrimming(server_name) &&
- EndsWithSpace(server_name)) {
- --length_to_copy;
- }
- *out = std::string(server_name.c_str(), length_to_copy);
-}
-
-// Compare the values of two EntitySpecifics, accounting for encryption.
-static bool AreSpecificsEqual(const browser_sync::Cryptographer* cryptographer,
- const sync_pb::EntitySpecifics& left,
- const sync_pb::EntitySpecifics& right) {
- // Note that we can't compare encrypted strings directly as they are seeded
- // with a random value.
- std::string left_plaintext, right_plaintext;
- if (left.has_encrypted()) {
- if (!cryptographer->CanDecrypt(left.encrypted())) {
- NOTREACHED() << "Attempting to compare undecryptable data.";
- return false;
- }
- left_plaintext = cryptographer->DecryptToString(left.encrypted());
- } else {
- left_plaintext = left.SerializeAsString();
- }
- if (right.has_encrypted()) {
- if (!cryptographer->CanDecrypt(right.encrypted())) {
- NOTREACHED() << "Attempting to compare undecryptable data.";
- return false;
- }
- right_plaintext = cryptographer->DecryptToString(right.encrypted());
- } else {
- right_plaintext = right.SerializeAsString();
- }
- if (left_plaintext == right_plaintext) {
- return true;
- }
- return false;
-}
-
-// Helper function that converts a PassphraseRequiredReason value to a string.
-std::string PassphraseRequiredReasonToString(
- PassphraseRequiredReason reason) {
- switch (reason) {
- case REASON_PASSPHRASE_NOT_REQUIRED:
- return "REASON_PASSPHRASE_NOT_REQUIRED";
- case REASON_ENCRYPTION:
- return "REASON_ENCRYPTION";
- case REASON_DECRYPTION:
- return "REASON_DECRYPTION";
- case REASON_SET_PASSPHRASE_FAILED:
- return "REASON_SET_PASSPHRASE_FAILED";
- default:
- NOTREACHED();
- return "INVALID_REASON";
- }
-}
-
-// Helper function to determine if initial sync had ended for types.
-bool InitialSyncEndedForTypes(syncable::ModelTypeSet types,
- sync_api::UserShare* share) {
- syncable::ScopedDirLookup lookup(share->dir_manager.get(),
- share->name);
- if (!lookup.good()) {
- DCHECK(false) << "ScopedDirLookup failed when checking initial sync";
- return false;
- }
-
- for (syncable::ModelTypeSet::const_iterator i = types.begin();
- i != types.end(); ++i) {
- if (!lookup->initial_sync_ended_for_type(*i))
- return false;
- }
- return true;
-}
-
-
-UserShare::UserShare() {}
-
-UserShare::~UserShare() {}
-
-////////////////////////////////////
-// BaseNode member definitions.
-
-BaseNode::BaseNode() : password_data_(new sync_pb::PasswordSpecificsData) {}
-
-BaseNode::~BaseNode() {}
-
-std::string BaseNode::GenerateSyncableHash(
- syncable::ModelType model_type, const std::string& client_tag) {
- // blank PB with just the extension in it has termination symbol,
- // handy for delimiter
- sync_pb::EntitySpecifics serialized_type;
- syncable::AddDefaultExtensionValue(model_type, &serialized_type);
- std::string hash_input;
- serialized_type.AppendToString(&hash_input);
- hash_input.append(client_tag);
-
- std::string encode_output;
- CHECK(base::Base64Encode(base::SHA1HashString(hash_input), &encode_output));
- return encode_output;
-}
-
-sync_pb::PasswordSpecificsData* DecryptPasswordSpecifics(
- const sync_pb::EntitySpecifics& specifics, Cryptographer* crypto) {
- if (!specifics.HasExtension(sync_pb::password))
- return NULL;
- const sync_pb::PasswordSpecifics& password_specifics =
- specifics.GetExtension(sync_pb::password);
- if (!password_specifics.has_encrypted())
- return NULL;
- const sync_pb::EncryptedData& encrypted = password_specifics.encrypted();
- scoped_ptr<sync_pb::PasswordSpecificsData> data(
- new sync_pb::PasswordSpecificsData);
- if (!crypto->Decrypt(encrypted, data.get()))
- return NULL;
- return data.release();
-}
-
-bool BaseNode::DecryptIfNecessary() {
- if (!GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty())
- return true; // Ignore unique folders.
- const sync_pb::EntitySpecifics& specifics =
- GetEntry()->Get(syncable::SPECIFICS);
- if (specifics.HasExtension(sync_pb::password)) {
- // Passwords have their own legacy encryption structure.
- scoped_ptr<sync_pb::PasswordSpecificsData> data(DecryptPasswordSpecifics(
- specifics, GetTransaction()->GetCryptographer()));
- if (!data.get()) {
- LOG(ERROR) << "Failed to decrypt password specifics.";
- return false;
- }
- password_data_.swap(data);
- return true;
- }
-
- // We assume any node with the encrypted field set has encrypted data.
- if (!specifics.has_encrypted())
- return true;
-
- const sync_pb::EncryptedData& encrypted =
- specifics.encrypted();
- std::string plaintext_data = GetTransaction()->GetCryptographer()->
- DecryptToString(encrypted);
- if (plaintext_data.length() == 0 ||
- !unencrypted_data_.ParseFromString(plaintext_data)) {
- LOG(ERROR) << "Failed to decrypt encrypted node of type " <<
- syncable::ModelTypeToString(GetModelType()) << ".";
- return false;
- }
- VLOG(2) << "Decrypted specifics of type "
- << syncable::ModelTypeToString(GetModelType())
- << " with content: " << plaintext_data;
- return true;
-}
-
-const sync_pb::EntitySpecifics& BaseNode::GetUnencryptedSpecifics(
- const syncable::Entry* entry) const {
- const sync_pb::EntitySpecifics& specifics = entry->Get(SPECIFICS);
- if (specifics.has_encrypted()) {
- DCHECK(syncable::GetModelTypeFromSpecifics(unencrypted_data_) !=
- syncable::UNSPECIFIED);
- return unencrypted_data_;
- } else {
- DCHECK(syncable::GetModelTypeFromSpecifics(unencrypted_data_) ==
- syncable::UNSPECIFIED);
- return specifics;
- }
-}
-
-int64 BaseNode::GetParentId() const {
- return IdToMetahandle(GetTransaction()->GetWrappedTrans(),
- GetEntry()->Get(syncable::PARENT_ID));
-}
-
-int64 BaseNode::GetId() const {
- return GetEntry()->Get(syncable::META_HANDLE);
-}
-
-int64 BaseNode::GetModificationTime() const {
- return GetEntry()->Get(syncable::MTIME);
-}
-
-bool BaseNode::GetIsFolder() const {
- return GetEntry()->Get(syncable::IS_DIR);
-}
-
-std::string BaseNode::GetTitle() const {
- std::string result;
- // TODO(zea): refactor bookmarks to not need this functionality.
- if (syncable::BOOKMARKS == GetModelType() &&
- GetEntry()->Get(syncable::SPECIFICS).has_encrypted()) {
- // Special case for legacy bookmarks dealing with encryption.
- ServerNameToSyncAPIName(GetBookmarkSpecifics().title(), &result);
- } else {
- ServerNameToSyncAPIName(GetEntry()->Get(syncable::NON_UNIQUE_NAME),
- &result);
- }
- return result;
-}
-
-GURL BaseNode::GetURL() const {
- return GURL(GetBookmarkSpecifics().url());
-}
-
-int64 BaseNode::GetPredecessorId() const {
- syncable::Id id_string = GetEntry()->Get(syncable::PREV_ID);
- if (id_string.IsRoot())
- return kInvalidId;
- return IdToMetahandle(GetTransaction()->GetWrappedTrans(), id_string);
-}
-
-int64 BaseNode::GetSuccessorId() const {
- syncable::Id id_string = GetEntry()->Get(syncable::NEXT_ID);
- if (id_string.IsRoot())
- return kInvalidId;
- return IdToMetahandle(GetTransaction()->GetWrappedTrans(), id_string);
-}
-
-int64 BaseNode::GetFirstChildId() const {
- syncable::Directory* dir = GetTransaction()->GetLookup();
- syncable::BaseTransaction* trans = GetTransaction()->GetWrappedTrans();
- syncable::Id id_string =
- dir->GetFirstChildId(trans, GetEntry()->Get(syncable::ID));
- if (id_string.IsRoot())
- return kInvalidId;
- return IdToMetahandle(GetTransaction()->GetWrappedTrans(), id_string);
-}
-
-DictionaryValue* BaseNode::GetSummaryAsValue() const {
- DictionaryValue* node_info = new DictionaryValue();
- node_info->SetString("id", base::Int64ToString(GetId()));
- node_info->SetBoolean("isFolder", GetIsFolder());
- node_info->SetString("title", GetTitle());
- node_info->Set("type", ModelTypeToValue(GetModelType()));
- return node_info;
-}
-
-DictionaryValue* BaseNode::GetDetailsAsValue() const {
- DictionaryValue* node_info = GetSummaryAsValue();
- // TODO(akalin): Return time in a better format.
- node_info->SetString("modificationTime",
- base::Int64ToString(GetModificationTime()));
- node_info->SetString("parentId", base::Int64ToString(GetParentId()));
- // Specifics are already in the Entry value, so no need to duplicate
- // it here.
- node_info->SetString("externalId",
- base::Int64ToString(GetExternalId()));
- node_info->SetString("predecessorId",
- base::Int64ToString(GetPredecessorId()));
- node_info->SetString("successorId",
- base::Int64ToString(GetSuccessorId()));
- node_info->SetString("firstChildId",
- base::Int64ToString(GetFirstChildId()));
- node_info->Set("entry", GetEntry()->ToValue());
- return node_info;
-}
-
-void BaseNode::GetFaviconBytes(std::vector<unsigned char>* output) const {
- if (!output)
- return;
- const std::string& favicon = GetBookmarkSpecifics().favicon();
- output->assign(reinterpret_cast<const unsigned char*>(favicon.data()),
- reinterpret_cast<const unsigned char*>(favicon.data() +
- favicon.length()));
-}
-
-int64 BaseNode::GetExternalId() const {
- return GetEntry()->Get(syncable::LOCAL_EXTERNAL_ID);
-}
-
-const sync_pb::AppSpecifics& BaseNode::GetAppSpecifics() const {
- DCHECK_EQ(syncable::APPS, GetModelType());
- return GetEntitySpecifics().GetExtension(sync_pb::app);
-}
-
-const sync_pb::AutofillSpecifics& BaseNode::GetAutofillSpecifics() const {
- DCHECK_EQ(syncable::AUTOFILL, GetModelType());
- return GetEntitySpecifics().GetExtension(sync_pb::autofill);
-}
-
-const AutofillProfileSpecifics& BaseNode::GetAutofillProfileSpecifics() const {
- DCHECK_EQ(GetModelType(), syncable::AUTOFILL_PROFILE);
- return GetEntitySpecifics().GetExtension(sync_pb::autofill_profile);
-}
-
-const sync_pb::BookmarkSpecifics& BaseNode::GetBookmarkSpecifics() const {
- DCHECK_EQ(syncable::BOOKMARKS, GetModelType());
- return GetEntitySpecifics().GetExtension(sync_pb::bookmark);
-}
-
-const sync_pb::NigoriSpecifics& BaseNode::GetNigoriSpecifics() const {
- DCHECK_EQ(syncable::NIGORI, GetModelType());
- return GetEntitySpecifics().GetExtension(sync_pb::nigori);
-}
-
-const sync_pb::PasswordSpecificsData& BaseNode::GetPasswordSpecifics() const {
- DCHECK_EQ(syncable::PASSWORDS, GetModelType());
- return *password_data_;
-}
-
-const sync_pb::ThemeSpecifics& BaseNode::GetThemeSpecifics() const {
- DCHECK_EQ(syncable::THEMES, GetModelType());
- return GetEntitySpecifics().GetExtension(sync_pb::theme);
-}
-
-const sync_pb::TypedUrlSpecifics& BaseNode::GetTypedUrlSpecifics() const {
- DCHECK_EQ(syncable::TYPED_URLS, GetModelType());
- return GetEntitySpecifics().GetExtension(sync_pb::typed_url);
-}
-
-const sync_pb::ExtensionSpecifics& BaseNode::GetExtensionSpecifics() const {
- DCHECK_EQ(syncable::EXTENSIONS, GetModelType());
- return GetEntitySpecifics().GetExtension(sync_pb::extension);
-}
-
-const sync_pb::SessionSpecifics& BaseNode::GetSessionSpecifics() const {
- DCHECK_EQ(syncable::SESSIONS, GetModelType());
- return GetEntitySpecifics().GetExtension(sync_pb::session);
-}
-
-const sync_pb::EntitySpecifics& BaseNode::GetEntitySpecifics() const {
- return GetUnencryptedSpecifics(GetEntry());
-}
-
-syncable::ModelType BaseNode::GetModelType() const {
- return GetEntry()->GetModelType();
-}
-
-void BaseNode::SetUnencryptedSpecifics(
- const sync_pb::EntitySpecifics& specifics) {
- syncable::ModelType type = syncable::GetModelTypeFromSpecifics(specifics);
- DCHECK_NE(syncable::UNSPECIFIED, type);
- if (GetModelType() != syncable::UNSPECIFIED) {
- DCHECK_EQ(GetModelType(), type);
- }
- unencrypted_data_.CopyFrom(specifics);
-}
-
-////////////////////////////////////
-// WriteNode member definitions
-// Static.
-bool WriteNode::UpdateEntryWithEncryption(
- browser_sync::Cryptographer* cryptographer,
- const sync_pb::EntitySpecifics& new_specifics,
- syncable::MutableEntry* entry) {
- syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics);
- DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE);
- syncable::ModelTypeSet encrypted_types = cryptographer->GetEncryptedTypes();
-
- sync_pb::EntitySpecifics generated_specifics;
- if (type == syncable::PASSWORDS || // Has own encryption scheme.
- type == syncable::NIGORI || // Encrypted separately.
- encrypted_types.count(type) == 0 ||
- new_specifics.has_encrypted()) {
- // No encryption required.
- generated_specifics.CopyFrom(new_specifics);
- } else {
- // Encrypt new_specifics into generated_specifics.
- if (VLOG_IS_ON(2)) {
- scoped_ptr<DictionaryValue> value(entry->ToValue());
- std::string info;
- base::JSONWriter::Write(value.get(), true, &info);
- VLOG(2) << "Encrypting specifics of type "
- << syncable::ModelTypeToString(type)
- << " with content: "
- << info;
- }
- if (!cryptographer->is_initialized())
- return false;
- syncable::AddDefaultExtensionValue(type, &generated_specifics);
- if (!cryptographer->Encrypt(new_specifics,
- generated_specifics.mutable_encrypted())) {
- NOTREACHED() << "Could not encrypt data for node of type "
- << syncable::ModelTypeToString(type);
- return false;
- }
- }
-
- const sync_pb::EntitySpecifics& old_specifics = entry->Get(SPECIFICS);
- if (AreSpecificsEqual(cryptographer, old_specifics, generated_specifics)) {
- // Even if the data is the same but the old specifics are encrypted with an
- // old key, we should go ahead and re-encrypt with the new key.
- if ((!old_specifics.has_encrypted() &&
- !generated_specifics.has_encrypted()) ||
- cryptographer->CanDecryptUsingDefaultKey(old_specifics.encrypted())) {
- VLOG(2) << "Specifics of type " << syncable::ModelTypeToString(type)
- << " already match, dropping change.";
- return true;
- }
- // TODO(zea): Add some way to keep track of how often we're reencrypting
- // because of a passphrase change.
- }
-
- if (generated_specifics.has_encrypted()) {
- // Overwrite the possibly sensitive non-specifics data.
- entry->Put(syncable::NON_UNIQUE_NAME, kEncryptedString);
- // For bookmarks we actually put bogus data into the unencrypted specifics,
- // else the server will try to do it for us.
- if (type == syncable::BOOKMARKS) {
- sync_pb::BookmarkSpecifics* bookmark_specifics =
- generated_specifics.MutableExtension(sync_pb::bookmark);
- if (!entry->Get(syncable::IS_DIR))
- bookmark_specifics->set_url(kEncryptedString);
- bookmark_specifics->set_title(kEncryptedString);
- }
- }
- entry->Put(syncable::SPECIFICS, generated_specifics);
- syncable::MarkForSyncing(entry);
- return true;
-}
-
-void WriteNode::SetIsFolder(bool folder) {
- if (entry_->Get(syncable::IS_DIR) == folder)
- return; // Skip redundant changes.
-
- entry_->Put(syncable::IS_DIR, folder);
- MarkForSyncing();
-}
-
-void WriteNode::SetTitle(const std::wstring& title) {
- std::string server_legal_name;
- SyncAPINameToServerName(title, &server_legal_name);
-
- string old_name = entry_->Get(syncable::NON_UNIQUE_NAME);
-
- if (server_legal_name == old_name)
- return; // Skip redundant changes.
-
- // Only set NON_UNIQUE_NAME to the title if we're not encrypted.
- if (GetEntitySpecifics().has_encrypted())
- entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString);
- else
- entry_->Put(syncable::NON_UNIQUE_NAME, server_legal_name);
-
- // For bookmarks, we also set the title field in the specifics.
- // TODO(zea): refactor bookmarks to not need this functionality.
- if (GetModelType() == syncable::BOOKMARKS) {
- sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
- new_value.set_title(server_legal_name);
- SetBookmarkSpecifics(new_value); // Does it's own encryption checking.
- }
-
- MarkForSyncing();
-}
-
-void WriteNode::SetURL(const GURL& url) {
- sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
- new_value.set_url(url.spec());
- SetBookmarkSpecifics(new_value);
-}
-
-void WriteNode::SetAppSpecifics(
- const sync_pb::AppSpecifics& new_value) {
- sync_pb::EntitySpecifics entity_specifics;
- entity_specifics.MutableExtension(sync_pb::app)->CopyFrom(new_value);
- SetEntitySpecifics(entity_specifics);
-}
-
-void WriteNode::SetAutofillSpecifics(
- const sync_pb::AutofillSpecifics& new_value) {
- sync_pb::EntitySpecifics entity_specifics;
- entity_specifics.MutableExtension(sync_pb::autofill)->CopyFrom(new_value);
- SetEntitySpecifics(entity_specifics);
-}
-
-void WriteNode::SetAutofillProfileSpecifics(
- const sync_pb::AutofillProfileSpecifics& new_value) {
- sync_pb::EntitySpecifics entity_specifics;
- entity_specifics.MutableExtension(sync_pb::autofill_profile)->
- CopyFrom(new_value);
- SetEntitySpecifics(entity_specifics);
-}
-
-void WriteNode::SetBookmarkSpecifics(
- const sync_pb::BookmarkSpecifics& new_value) {
- sync_pb::EntitySpecifics entity_specifics;
- entity_specifics.MutableExtension(sync_pb::bookmark)->CopyFrom(new_value);
- SetEntitySpecifics(entity_specifics);
-}
-
-void WriteNode::SetNigoriSpecifics(
- const sync_pb::NigoriSpecifics& new_value) {
- sync_pb::EntitySpecifics entity_specifics;
- entity_specifics.MutableExtension(sync_pb::nigori)->CopyFrom(new_value);
- SetEntitySpecifics(entity_specifics);
-}
-
-void WriteNode::SetPasswordSpecifics(
- const sync_pb::PasswordSpecificsData& data) {
- DCHECK_EQ(syncable::PASSWORDS, GetModelType());
-
- Cryptographer* cryptographer = GetTransaction()->GetCryptographer();
-
- // Idempotency check to prevent unnecessary syncing: if the plaintexts match
- // and the old ciphertext is encrypted with the most current key, there's
- // nothing to do here. Because each encryption is seeded with a different
- // random value, checking for equivalence post-encryption doesn't suffice.
- const sync_pb::EncryptedData& old_ciphertext =
- GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::password).encrypted();
- scoped_ptr<sync_pb::PasswordSpecificsData> old_plaintext(
- DecryptPasswordSpecifics(GetEntry()->Get(SPECIFICS), cryptographer));
- if (old_plaintext.get() &&
- old_plaintext->SerializeAsString() == data.SerializeAsString() &&
- cryptographer->CanDecryptUsingDefaultKey(old_ciphertext)) {
- return;
- }
-
- sync_pb::PasswordSpecifics new_value;
- if (!cryptographer->Encrypt(data, new_value.mutable_encrypted())) {
- NOTREACHED() << "Failed to encrypt password, possibly due to sync node "
- << "corruption";
- return;
- }
-
- sync_pb::EntitySpecifics entity_specifics;
- entity_specifics.MutableExtension(sync_pb::password)->CopyFrom(new_value);
- SetEntitySpecifics(entity_specifics);
-}
-
-void WriteNode::SetThemeSpecifics(
- const sync_pb::ThemeSpecifics& new_value) {
- sync_pb::EntitySpecifics entity_specifics;
- entity_specifics.MutableExtension(sync_pb::theme)->CopyFrom(new_value);
- SetEntitySpecifics(entity_specifics);
-}
-
-void WriteNode::SetSessionSpecifics(
- const sync_pb::SessionSpecifics& new_value) {
- sync_pb::EntitySpecifics entity_specifics;
- entity_specifics.MutableExtension(sync_pb::session)->CopyFrom(new_value);
- SetEntitySpecifics(entity_specifics);
-}
-
-void WriteNode::SetEntitySpecifics(
- const sync_pb::EntitySpecifics& new_value) {
- syncable::ModelType new_specifics_type =
- syncable::GetModelTypeFromSpecifics(new_value);
- DCHECK_NE(new_specifics_type, syncable::UNSPECIFIED);
- VLOG(1) << "Writing entity specifics of type "
- << syncable::ModelTypeToString(new_specifics_type);
- // GetModelType() can be unspecified if this is the first time this
- // node is being initialized (see PutModelType()). Otherwise, it
- // should match |new_specifics_type|.
- if (GetModelType() != syncable::UNSPECIFIED) {
- DCHECK_EQ(new_specifics_type, GetModelType());
- }
- browser_sync::Cryptographer* cryptographer =
- GetTransaction()->GetCryptographer();
-
- // Preserve unknown fields.
- const sync_pb::EntitySpecifics& old_specifics = entry_->Get(SPECIFICS);
- sync_pb::EntitySpecifics new_specifics;
- new_specifics.CopyFrom(new_value);
- new_specifics.mutable_unknown_fields()->MergeFrom(
- old_specifics.unknown_fields());
-
- // Will update the entry if encryption was necessary.
- if (!UpdateEntryWithEncryption(cryptographer, new_specifics, entry_)) {
- return;
- }
- if (entry_->Get(SPECIFICS).has_encrypted()) {
- // EncryptIfNecessary already updated the entry for us and marked for
- // syncing if it was needed. Now we just make a copy of the unencrypted
- // specifics so that if this node is updated, we do not have to decrypt the
- // old data. Note that this only modifies the node's local data, not the
- // entry itself.
- SetUnencryptedSpecifics(new_value);
- }
-
- DCHECK_EQ(new_specifics_type, GetModelType());
-}
-
-void WriteNode::ResetFromSpecifics() {
- SetEntitySpecifics(GetEntitySpecifics());
-}
-
-void WriteNode::SetTypedUrlSpecifics(
- const sync_pb::TypedUrlSpecifics& new_value) {
- sync_pb::EntitySpecifics entity_specifics;
- entity_specifics.MutableExtension(sync_pb::typed_url)->CopyFrom(new_value);
- SetEntitySpecifics(entity_specifics);
-}
-
-void WriteNode::SetExtensionSpecifics(
- const sync_pb::ExtensionSpecifics& new_value) {
- sync_pb::EntitySpecifics entity_specifics;
- entity_specifics.MutableExtension(sync_pb::extension)->CopyFrom(new_value);
- SetEntitySpecifics(entity_specifics);
-}
-
-void WriteNode::SetExternalId(int64 id) {
- if (GetExternalId() != id)
- entry_->Put(syncable::LOCAL_EXTERNAL_ID, id);
-}
-
-WriteNode::WriteNode(WriteTransaction* transaction)
- : entry_(NULL), transaction_(transaction) {
- DCHECK(transaction);
-}
-
-WriteNode::~WriteNode() {
- delete entry_;
-}
-
-// Find an existing node matching the ID |id|, and bind this WriteNode to it.
-// Return true on success.
-bool WriteNode::InitByIdLookup(int64 id) {
- DCHECK(!entry_) << "Init called twice";
- DCHECK_NE(id, kInvalidId);
- entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
- syncable::GET_BY_HANDLE, id);
- return (entry_->good() && !entry_->Get(syncable::IS_DEL) &&
- DecryptIfNecessary());
-}
-
-// Find a node by client tag, and bind this WriteNode to it.
-// Return true if the write node was found, and was not deleted.
-// Undeleting a deleted node is possible by ClientTag.
-bool WriteNode::InitByClientTagLookup(syncable::ModelType model_type,
- const std::string& tag) {
- DCHECK(!entry_) << "Init called twice";
- if (tag.empty())
- return false;
-
- const std::string hash = GenerateSyncableHash(model_type, tag);
-
- entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
- syncable::GET_BY_CLIENT_TAG, hash);
- return (entry_->good() && !entry_->Get(syncable::IS_DEL) &&
- DecryptIfNecessary());
-}
-
-bool WriteNode::InitByTagLookup(const std::string& tag) {
- DCHECK(!entry_) << "Init called twice";
- if (tag.empty())
- return false;
- entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
- syncable::GET_BY_SERVER_TAG, tag);
- if (!entry_->good())
- return false;
- if (entry_->Get(syncable::IS_DEL))
- return false;
- syncable::ModelType model_type = GetModelType();
- DCHECK_EQ(syncable::NIGORI, model_type);
- return true;
-}
-
-void WriteNode::PutModelType(syncable::ModelType model_type) {
- // Set an empty specifics of the appropriate datatype. The presence
- // of the specific extension will identify the model type.
- DCHECK(GetModelType() == model_type ||
- GetModelType() == syncable::UNSPECIFIED); // Immutable once set.
-
- sync_pb::EntitySpecifics specifics;
- syncable::AddDefaultExtensionValue(model_type, &specifics);
- SetEntitySpecifics(specifics);
-}
-
-// Create a new node with default properties, and bind this WriteNode to it.
-// Return true on success.
-bool WriteNode::InitByCreation(syncable::ModelType model_type,
- const BaseNode& parent,
- const BaseNode* predecessor) {
- DCHECK(!entry_) << "Init called twice";
- // |predecessor| must be a child of |parent| or NULL.
- if (predecessor && predecessor->GetParentId() != parent.GetId()) {
- DCHECK(false);
- return false;
- }
-
- syncable::Id parent_id = parent.GetEntry()->Get(syncable::ID);
-
- // Start out with a dummy name. We expect
- // the caller to set a meaningful name after creation.
- string dummy(kDefaultNameForNewNodes);
-
- entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
- syncable::CREATE, parent_id, dummy);
-
- if (!entry_->good())
- return false;
-
- // Entries are untitled folders by default.
- entry_->Put(syncable::IS_DIR, true);
-
- PutModelType(model_type);
-
- // Now set the predecessor, which sets IS_UNSYNCED as necessary.
- PutPredecessor(predecessor);
-
- return true;
-}
-
-// Create a new node with default properties and a client defined unique tag,
-// and bind this WriteNode to it.
-// Return true on success. If the tag exists in the database, then
-// we will attempt to undelete the node.
-// TODO(chron): Code datatype into hash tag.
-// TODO(chron): Is model type ever lost?
-bool WriteNode::InitUniqueByCreation(syncable::ModelType model_type,
- const BaseNode& parent,
- const std::string& tag) {
- DCHECK(!entry_) << "Init called twice";
-
- const std::string hash = GenerateSyncableHash(model_type, tag);
-
- syncable::Id parent_id = parent.GetEntry()->Get(syncable::ID);
-
- // Start out with a dummy name. We expect
- // the caller to set a meaningful name after creation.
- string dummy(kDefaultNameForNewNodes);
-
- // Check if we have this locally and need to undelete it.
- scoped_ptr<syncable::MutableEntry> existing_entry(
- new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
- syncable::GET_BY_CLIENT_TAG, hash));
-
- if (existing_entry->good()) {
- if (existing_entry->Get(syncable::IS_DEL)) {
- // Rules for undelete:
- // BASE_VERSION: Must keep the same.
- // ID: Essential to keep the same.
- // META_HANDLE: Must be the same, so we can't "split" the entry.
- // IS_DEL: Must be set to false, will cause reindexing.
- // This one is weird because IS_DEL is true for "update only"
- // items. It should be OK to undelete an update only.
- // MTIME/CTIME: Seems reasonable to just leave them alone.
- // IS_UNSYNCED: Must set this to true or face database insurrection.
- // We do this below this block.
- // IS_UNAPPLIED_UPDATE: Either keep it the same or also set BASE_VERSION
- // to SERVER_VERSION. We keep it the same here.
- // IS_DIR: We'll leave it the same.
- // SPECIFICS: Reset it.
-
- existing_entry->Put(syncable::IS_DEL, false);
-
- // Client tags are immutable and must be paired with the ID.
- // If a server update comes down with an ID and client tag combo,
- // and it already exists, always overwrite it and store only one copy.
- // We have to undelete entries because we can't disassociate IDs from
- // tags and updates.
-
- existing_entry->Put(syncable::NON_UNIQUE_NAME, dummy);
- existing_entry->Put(syncable::PARENT_ID, parent_id);
- entry_ = existing_entry.release();
- } else {
- return false;
- }
- } else {
- entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
- syncable::CREATE, parent_id, dummy);
- if (!entry_->good()) {
- return false;
- }
-
- // Only set IS_DIR for new entries. Don't bitflip undeleted ones.
- entry_->Put(syncable::UNIQUE_CLIENT_TAG, hash);
- }
-
- // We don't support directory and tag combinations.
- entry_->Put(syncable::IS_DIR, false);
-
- // Will clear specifics data.
- PutModelType(model_type);
-
- // Now set the predecessor, which sets IS_UNSYNCED as necessary.
- PutPredecessor(NULL);
-
- return true;
-}
-
-bool WriteNode::SetPosition(const BaseNode& new_parent,
- const BaseNode* predecessor) {
- // |predecessor| must be a child of |new_parent| or NULL.
- if (predecessor && predecessor->GetParentId() != new_parent.GetId()) {
- DCHECK(false);
- return false;
- }
-
- syncable::Id new_parent_id = new_parent.GetEntry()->Get(syncable::ID);
-
- // Filter out redundant changes if both the parent and the predecessor match.
- if (new_parent_id == entry_->Get(syncable::PARENT_ID)) {
- const syncable::Id& old = entry_->Get(syncable::PREV_ID);
- if ((!predecessor && old.IsRoot()) ||
- (predecessor && (old == predecessor->GetEntry()->Get(syncable::ID)))) {
- return true;
- }
- }
-
- // Atomically change the parent. This will fail if it would
- // introduce a cycle in the hierarchy.
- if (!entry_->Put(syncable::PARENT_ID, new_parent_id))
- return false;
-
- // Now set the predecessor, which sets IS_UNSYNCED as necessary.
- PutPredecessor(predecessor);
-
- return true;
-}
-
-const syncable::Entry* WriteNode::GetEntry() const {
- return entry_;
-}
-
-const BaseTransaction* WriteNode::GetTransaction() const {
- return transaction_;
-}
-
-void WriteNode::Remove() {
- entry_->Put(syncable::IS_DEL, true);
- MarkForSyncing();
-}
-
-void WriteNode::PutPredecessor(const BaseNode* predecessor) {
- syncable::Id predecessor_id = predecessor ?
- predecessor->GetEntry()->Get(syncable::ID) : syncable::Id();
- entry_->PutPredecessor(predecessor_id);
- // Mark this entry as unsynced, to wake up the syncer.
- MarkForSyncing();
-}
-
-void WriteNode::SetFaviconBytes(const vector<unsigned char>& bytes) {
- sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
- new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size());
- SetBookmarkSpecifics(new_value);
-}
-
-void WriteNode::MarkForSyncing() {
- syncable::MarkForSyncing(entry_);
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ReadNode member definitions
-ReadNode::ReadNode(const BaseTransaction* transaction)
- : entry_(NULL), transaction_(transaction) {
- DCHECK(transaction);
-}
-
-ReadNode::ReadNode() {
- entry_ = NULL;
- transaction_ = NULL;
-}
-
-ReadNode::~ReadNode() {
- delete entry_;
-}
-
-void ReadNode::InitByRootLookup() {
- DCHECK(!entry_) << "Init called twice";
- syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
- entry_ = new syncable::Entry(trans, syncable::GET_BY_ID, trans->root_id());
- if (!entry_->good())
- DCHECK(false) << "Could not lookup root node for reading.";
-}
-
-bool ReadNode::InitByIdLookup(int64 id) {
- DCHECK(!entry_) << "Init called twice";
- DCHECK_NE(id, kInvalidId);
- syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
- entry_ = new syncable::Entry(trans, syncable::GET_BY_HANDLE, id);
- if (!entry_->good())
- return false;
- if (entry_->Get(syncable::IS_DEL))
- return false;
- syncable::ModelType model_type = GetModelType();
- LOG_IF(WARNING, model_type == syncable::UNSPECIFIED ||
- model_type == syncable::TOP_LEVEL_FOLDER)
- << "SyncAPI InitByIdLookup referencing unusual object.";
- return DecryptIfNecessary();
-}
-
-bool ReadNode::InitByClientTagLookup(syncable::ModelType model_type,
- const std::string& tag) {
- DCHECK(!entry_) << "Init called twice";
- if (tag.empty())
- return false;
-
- const std::string hash = GenerateSyncableHash(model_type, tag);
-
- entry_ = new syncable::Entry(transaction_->GetWrappedTrans(),
- syncable::GET_BY_CLIENT_TAG, hash);
- return (entry_->good() && !entry_->Get(syncable::IS_DEL) &&
- DecryptIfNecessary());
-}
-
-const syncable::Entry* ReadNode::GetEntry() const {
- return entry_;
-}
-
-const BaseTransaction* ReadNode::GetTransaction() const {
- return transaction_;
-}
-
-bool ReadNode::InitByTagLookup(const std::string& tag) {
- DCHECK(!entry_) << "Init called twice";
- if (tag.empty())
- return false;
- syncable::BaseTransaction* trans = transaction_->GetWrappedTrans();
- entry_ = new syncable::Entry(trans, syncable::GET_BY_SERVER_TAG, tag);
- if (!entry_->good())
- return false;
- if (entry_->Get(syncable::IS_DEL))
- return false;
- syncable::ModelType model_type = GetModelType();
- LOG_IF(WARNING, model_type == syncable::UNSPECIFIED ||
- model_type == syncable::TOP_LEVEL_FOLDER)
- << "SyncAPI InitByTagLookup referencing unusually typed object.";
- return DecryptIfNecessary();
-}
-
-//////////////////////////////////////////////////////////////////////////
-// ReadTransaction member definitions
-ReadTransaction::ReadTransaction(const tracked_objects::Location& from_here,
- UserShare* share)
- : BaseTransaction(share),
- transaction_(NULL),
- close_transaction_(true) {
- transaction_ = new syncable::ReadTransaction(from_here, GetLookup());
-}
-
-ReadTransaction::ReadTransaction(UserShare* share,
- syncable::BaseTransaction* trans)
- : BaseTransaction(share),
- transaction_(trans),
- close_transaction_(false) {}
-
-ReadTransaction::~ReadTransaction() {
- if (close_transaction_) {
- delete transaction_;
- }
-}
-
-syncable::BaseTransaction* ReadTransaction::GetWrappedTrans() const {
- return transaction_;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// WriteTransaction member definitions
-WriteTransaction::WriteTransaction(const tracked_objects::Location& from_here,
- UserShare* share)
- : BaseTransaction(share),
- transaction_(NULL) {
- transaction_ = new syncable::WriteTransaction(from_here, syncable::SYNCAPI,
- GetLookup());
-}
-
-WriteTransaction::~WriteTransaction() {
- delete transaction_;
-}
-
-syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const {
- return transaction_;
-}
-
SyncManager::ChangeRecord::ChangeRecord()
: id(kInvalidId), action(ACTION_ADD) {}
@@ -1204,12 +156,6 @@ const sync_pb::PasswordSpecificsData&
return unencrypted_;
}
-syncable::ModelTypeSet GetEncryptedTypes(
- const sync_api::BaseTransaction* trans) {
- Cryptographer* cryptographer = trans->GetCryptographer();
- return cryptographer->GetEncryptedTypes();
-}
-
//////////////////////////////////////////////////////////////////////////
// SyncManager's implementation: SyncManager::SyncInternal
class SyncManager::SyncInternal
@@ -1709,7 +655,6 @@ void SyncManager::UpdateEnabledTypes() {
data_->UpdateEnabledTypes();
}
-
bool SyncManager::InitialSyncEndedForAllEnabledTypes() {
return data_->InitialSyncEndedForAllEnabledTypes();
}
@@ -2548,7 +1493,6 @@ void SyncManager::SyncInternal::RequestNudge(
ModelTypeBitSet(), location);
}
-
void SyncManager::SyncInternal::RequestNudgeForDataType(
const tracked_objects::Location& nudge_location,
const ModelType& type) {
@@ -2956,7 +1900,6 @@ void SyncManager::SyncInternal::StoreState(
lookup->SaveChanges();
}
-
// Note: it is possible that an observer will remove itself after we have made
// a copy, but before the copy is consumed. This could theoretically result
// in accessing a garbage pointer, but can only occur when an about:sync window
@@ -3014,21 +1957,6 @@ void SyncManager::SyncInternal::SaveChanges() {
lookup->SaveChanges();
}
-//////////////////////////////////////////////////////////////////////////
-// BaseTransaction member definitions
-BaseTransaction::BaseTransaction(UserShare* share)
- : lookup_(NULL) {
- DCHECK(share && share->dir_manager.get());
- lookup_ = new syncable::ScopedDirLookup(share->dir_manager.get(),
- share->name);
- cryptographer_ = share->dir_manager->GetCryptographer(this);
- if (!(lookup_->good()))
- DCHECK(false) << "ScopedDirLookup failed on valid DirManager.";
-}
-BaseTransaction::~BaseTransaction() {
- delete lookup_;
-}
-
UserShare* SyncManager::GetUserShare() const {
return data_->GetUserShare();
}
@@ -3080,4 +2008,40 @@ void SyncManager::TriggerOnIncomingNotificationForTest(
data_->OnIncomingNotification(model_types_with_payloads);
}
+// Helper function that converts a PassphraseRequiredReason value to a string.
+std::string PassphraseRequiredReasonToString(
+ PassphraseRequiredReason reason) {
+ switch (reason) {
+ case REASON_PASSPHRASE_NOT_REQUIRED:
+ return "REASON_PASSPHRASE_NOT_REQUIRED";
+ case REASON_ENCRYPTION:
+ return "REASON_ENCRYPTION";
+ case REASON_DECRYPTION:
+ return "REASON_DECRYPTION";
+ case REASON_SET_PASSPHRASE_FAILED:
+ return "REASON_SET_PASSPHRASE_FAILED";
+ default:
+ NOTREACHED();
+ return "INVALID_REASON";
+ }
+}
+
+// Helper function to determine if initial sync had ended for types.
+bool InitialSyncEndedForTypes(syncable::ModelTypeSet types,
+ sync_api::UserShare* share) {
+ syncable::ScopedDirLookup lookup(share->dir_manager.get(),
+ share->name);
+ if (!lookup.good()) {
+ DCHECK(false) << "ScopedDirLookup failed when checking initial sync";
+ return false;
+ }
+
+ for (syncable::ModelTypeSet::const_iterator i = types.begin();
+ i != types.end(); ++i) {
+ if (!lookup->initial_sync_ended_for_type(*i))
+ return false;
+ }
+ return true;
+}
+
} // namespace sync_api
diff --git a/chrome/browser/sync/internal_api/sync_manager.h b/chrome/browser/sync/internal_api/sync_manager.h
new file mode 100644
index 0000000..14350a4
--- /dev/null
+++ b/chrome/browser/sync/internal_api/sync_manager.h
@@ -0,0 +1,546 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_
+#define CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/callback_old.h"
+#include "base/memory/linked_ptr.h"
+#include "chrome/browser/sync/engine/configure_reason.h"
+#include "chrome/browser/sync/protocol/password_specifics.pb.h"
+#include "chrome/browser/sync/syncable/model_type.h"
+#include "chrome/browser/sync/weak_handle.h"
+#include "chrome/common/net/gaia/google_service_auth_error.h"
+
+class FilePath;
+
+namespace base {
+class DictionaryValue;
+} // namespace base
+
+namespace browser_sync {
+class JsBackend;
+class JsEventHandler;
+class ModelSafeWorkerRegistrar;
+
+namespace sessions {
+struct SyncSessionSnapshot;
+} // namespace sessions
+} // namespace browser_sync
+
+namespace sync_notifier {
+class SyncNotifier;
+} // namespace sync_notifier
+
+namespace sync_pb {
+class PasswordSpecificsData;
+} // namespace sync_pb
+
+namespace sync_api {
+
+class BaseTransaction;
+class HttpPostProviderFactory;
+struct UserShare;
+
+// Reasons due to which browser_sync::Cryptographer might require a passphrase.
+enum PassphraseRequiredReason {
+ REASON_PASSPHRASE_NOT_REQUIRED = 0, // Initial value.
+ REASON_ENCRYPTION = 1, // The cryptographer requires a
+ // passphrase for its first attempt at
+ // encryption. Happens only during
+ // migration or upgrade.
+ REASON_DECRYPTION = 2, // The cryptographer requires a
+ // passphrase for its first attempt at
+ // decryption.
+ REASON_SET_PASSPHRASE_FAILED = 3, // The cryptographer requires a new
+ // passphrase because its attempt at
+ // decryption with the cached passphrase
+ // was unsuccessful.
+};
+
+// Contains everything needed to talk to and identify a user account.
+struct SyncCredentials {
+ std::string email;
+ std::string sync_token;
+};
+
+// SyncManager encapsulates syncable::DirectoryManager and serves as the parent
+// of all other objects in the sync API. SyncManager is thread-safe. If
+// multiple threads interact with the same local sync repository (i.e. the
+// same sqlite database), they should share a single SyncManager instance. The
+// caller should typically create one SyncManager for the lifetime of a user
+// session.
+class SyncManager {
+ public:
+ // SyncInternal contains the implementation of SyncManager, while abstracting
+ // internal types from clients of the interface.
+ class SyncInternal;
+
+ // TODO(zea): One day get passwords playing nicely with the rest of encryption
+ // and get rid of this.
+ class ExtraPasswordChangeRecordData {
+ public:
+ ExtraPasswordChangeRecordData();
+ explicit ExtraPasswordChangeRecordData(
+ const sync_pb::PasswordSpecificsData& data);
+ virtual ~ExtraPasswordChangeRecordData();
+
+ // Transfers ownership of the DictionaryValue to the caller.
+ virtual base::DictionaryValue* ToValue() const;
+
+ const sync_pb::PasswordSpecificsData& unencrypted() const;
+ private:
+ sync_pb::PasswordSpecificsData unencrypted_;
+ };
+
+ // ChangeRecord indicates a single item that changed as a result of a sync
+ // operation. This gives the sync id of the node that changed, and the type
+ // of change. To get the actual property values after an ADD or UPDATE, the
+ // client should get the node with InitByIdLookup(), using the provided id.
+ struct ChangeRecord {
+ enum Action {
+ ACTION_ADD,
+ ACTION_DELETE,
+ ACTION_UPDATE,
+ };
+ ChangeRecord();
+ ~ChangeRecord();
+
+ // Transfers ownership of the DictionaryValue to the caller.
+ base::DictionaryValue* ToValue(const BaseTransaction* trans) const;
+
+ int64 id;
+ Action action;
+ sync_pb::EntitySpecifics specifics;
+ linked_ptr<ExtraPasswordChangeRecordData> extra;
+ };
+
+ // Status encapsulates detailed state about the internals of the SyncManager.
+ struct Status {
+ // Summary is a distilled set of important information that the end-user may
+ // wish to be informed about (through UI, for example). Note that if a
+ // summary state requires user interaction (such as auth failures), more
+ // detailed information may be contained in additional status fields.
+ enum Summary {
+ // The internal instance is in an unrecognizable state. This should not
+ // happen.
+ INVALID = 0,
+ // Can't connect to server, but there are no pending changes in
+ // our local cache.
+ OFFLINE,
+ // Can't connect to server, and there are pending changes in our
+ // local cache.
+ OFFLINE_UNSYNCED,
+ // Connected and syncing.
+ SYNCING,
+ // Connected, no pending changes.
+ READY,
+ // Internal sync error.
+ CONFLICT,
+ // Can't connect to server, and we haven't completed the initial
+ // sync yet. So there's nothing we can do but wait for the server.
+ OFFLINE_UNUSABLE,
+
+ SUMMARY_STATUS_COUNT,
+ };
+
+ Status();
+ ~Status();
+
+ Summary summary;
+ bool authenticated; // Successfully authenticated via GAIA.
+ bool server_up; // True if we have received at least one good
+ // reply from the server.
+ bool server_reachable; // True if we received any reply from the server.
+ bool server_broken; // True of the syncer is stopped because of server
+ // issues.
+ bool notifications_enabled; // True only if subscribed for notifications.
+
+ // Notifications counters updated by the actions in synapi.
+ int notifications_received;
+ int notifiable_commits;
+
+ // The max number of consecutive errors from any component.
+ int max_consecutive_errors;
+
+ int unsynced_count;
+
+ int conflicting_count;
+ bool syncing;
+ // True after a client has done a first sync.
+ bool initial_sync_ended;
+ // True if any syncer is stuck.
+ bool syncer_stuck;
+
+ // Total updates available. If zero, nothing left to download.
+ int64 updates_available;
+ // Total updates received by the syncer since browser start.
+ int updates_received;
+
+ // Of updates_received, how many were tombstones.
+ int tombstone_updates_received;
+ bool disk_full;
+
+ // Total number of overwrites due to conflict resolver since browser start.
+ int num_local_overwrites_total;
+ int num_server_overwrites_total;
+
+ // Count of empty and non empty getupdates;
+ int nonempty_get_updates;
+ int empty_get_updates;
+
+ // Count of useless and useful syncs we perform.
+ int useless_sync_cycles;
+ int useful_sync_cycles;
+
+ // Encryption related.
+ syncable::ModelTypeSet encrypted_types;
+ bool cryptographer_ready;
+ bool crypto_has_pending_keys;
+ };
+
+ // An interface the embedding application implements to receive notifications
+ // from the SyncManager. Register an observer via SyncManager::AddObserver.
+ // This observer is an event driven model as the events may be raised from
+ // different internal threads, and simply providing an "OnStatusChanged" type
+ // notification complicates things such as trying to determine "what changed",
+ // if different members of the Status object are modified from different
+ // threads. This way, the event is explicit, and it is safe for the Observer
+ // to dispatch to a native thread or synchronize accordingly.
+ class Observer {
+ public:
+ // Notify the observer that changes have been applied to the sync model.
+ //
+ // This will be invoked on the same thread as on which ApplyChanges was
+ // called. |changes| is an array of size |change_count|, and contains the
+ // ID of each individual item that was changed. |changes| exists only for
+ // the duration of the call. If items of multiple data types change at
+ // the same time, this method is invoked once per data type and |changes|
+ // is restricted to items of the ModelType indicated by |model_type|.
+ // Because the observer is passed a |trans|, the observer can assume a
+ // read lock on the sync model that will be released after the function
+ // returns.
+ //
+ // The SyncManager constructs |changes| in the following guaranteed order:
+ //
+ // 1. Deletions, from leaves up to parents.
+ // 2. Updates to existing items with synced parents & predecessors.
+ // 3. New items with synced parents & predecessors.
+ // 4. Items with parents & predecessors in |changes|.
+ // 5. Repeat #4 until all items are in |changes|.
+ //
+ // Thus, an implementation of OnChangesApplied should be able to
+ // process the change records in the order without having to worry about
+ // forward dependencies. But since deletions come before reparent
+ // operations, a delete may temporarily orphan a node that is
+ // updated later in the list.
+ virtual void OnChangesApplied(syncable::ModelType model_type,
+ const BaseTransaction* trans,
+ const ChangeRecord* changes,
+ int change_count) = 0;
+
+ // OnChangesComplete gets called when the TransactionComplete event is
+ // posted (after OnChangesApplied finishes), after the transaction lock
+ // and the change channel mutex are released.
+ //
+ // The purpose of this function is to support processors that require
+ // split-transactions changes. For example, if a model processor wants to
+ // perform blocking I/O due to a change, it should calculate the changes
+ // while holding the transaction lock (from within OnChangesApplied), buffer
+ // those changes, let the transaction fall out of scope, and then commit
+ // those changes from within OnChangesComplete (postponing the blocking
+ // I/O to when it no longer holds any lock).
+ virtual void OnChangesComplete(syncable::ModelType model_type) = 0;
+
+ // A round-trip sync-cycle took place and the syncer has resolved any
+ // conflicts that may have arisen.
+ virtual void OnSyncCycleCompleted(
+ const browser_sync::sessions::SyncSessionSnapshot* snapshot) = 0;
+
+ // Called when user interaction may be required due to an auth problem.
+ virtual void OnAuthError(const GoogleServiceAuthError& auth_error) = 0;
+
+ // Called when a new auth token is provided by the sync server.
+ virtual void OnUpdatedToken(const std::string& token) = 0;
+
+ // Called when user interaction is required to obtain a valid passphrase.
+ // - If the passphrase is required for encryption, |reason| will be
+ // REASON_ENCRYPTION.
+ // - If the passphrase is required for the decryption of data that has
+ // already been encrypted, |reason| will be REASON_DECRYPTION.
+ // - If the passphrase is required because decryption failed, and a new
+ // passphrase is required, |reason| will be REASON_SET_PASSPHRASE_FAILED.
+ virtual void OnPassphraseRequired(PassphraseRequiredReason reason) = 0;
+
+ // Called when the passphrase provided by the user has been accepted and is
+ // now used to encrypt sync data. |bootstrap_token| is an opaque base64
+ // encoded representation of the key generated by the accepted passphrase,
+ // and is provided to the observer for persistence purposes and use in a
+ // future initialization of sync (e.g. after restart).
+ virtual void OnPassphraseAccepted(const std::string& bootstrap_token) = 0;
+
+ // Called when initialization is complete to the point that SyncManager can
+ // process changes. This does not necessarily mean authentication succeeded
+ // or that the SyncManager is online.
+ // IMPORTANT: Creating any type of transaction before receiving this
+ // notification is illegal!
+ // WARNING: Calling methods on the SyncManager before receiving this
+ // message, unless otherwise specified, produces undefined behavior.
+ //
+ // |js_backend| is what about:sync interacts with. It can emit
+ // the following events:
+
+ /**
+ * @param {{ enabled: boolean }} details A dictionary containing:
+ * - enabled: whether or not notifications are enabled.
+ */
+ // function onNotificationStateChange(details);
+
+ /**
+ * @param {{ changedTypes: Array.<string> }} details A dictionary
+ * containing:
+ * - changedTypes: a list of types (as strings) for which there
+ are new updates.
+ */
+ // function onIncomingNotification(details);
+
+ // Also, it responds to the following messages (all other messages
+ // are ignored):
+
+ /**
+ * Gets the current notification state.
+ *
+ * @param {function(boolean)} callback Called with whether or not
+ * notifications are enabled.
+ */
+ // function getNotificationState(callback);
+
+ /**
+ * Gets details about the root node.
+ *
+ * @param {function(!Object)} callback Called with details about the
+ * root node.
+ */
+ // TODO(akalin): Change this to getRootNodeId or eliminate it
+ // entirely.
+ // function getRootNodeDetails(callback);
+
+ /**
+ * Gets summary information for a list of ids.
+ *
+ * @param {Array.<string>} idList List of 64-bit ids in decimal
+ * string form.
+ * @param {Array.<{id: string, title: string, isFolder: boolean}>}
+ * callback Called with summaries for the nodes in idList that
+ * exist.
+ */
+ // function getNodeSummariesById(idList, callback);
+
+ /**
+ * Gets detailed information for a list of ids.
+ *
+ * @param {Array.<string>} idList List of 64-bit ids in decimal
+ * string form.
+ * @param {Array.<!Object>} callback Called with detailed
+ * information for the nodes in idList that exist.
+ */
+ // function getNodeDetailsById(idList, callback);
+
+ /**
+ * Gets child ids for a given id.
+ *
+ * @param {string} id 64-bit id in decimal string form of the parent
+ * node.
+ * @param {Array.<string>} callback Called with the (possibly empty)
+ * list of child ids.
+ */
+ // function getChildNodeIds(id);
+
+ virtual void OnInitializationComplete(
+ const browser_sync::WeakHandle<browser_sync::JsBackend>&
+ js_backend) = 0;
+
+ // We are no longer permitted to communicate with the server. Sync should
+ // be disabled and state cleaned up at once. This can happen for a number
+ // of reasons, e.g. swapping from a test instance to production, or a
+ // global stop syncing operation has wiped the store.
+ virtual void OnStopSyncingPermanently() = 0;
+
+ // After a request to clear server data, these callbacks are invoked to
+ // indicate success or failure.
+ virtual void OnClearServerDataSucceeded() = 0;
+ virtual void OnClearServerDataFailed() = 0;
+
+ // Called after we finish encrypting all appropriate datatypes.
+ virtual void OnEncryptionComplete(
+ const syncable::ModelTypeSet& encrypted_types) = 0;
+
+ protected:
+ virtual ~Observer();
+ };
+
+ typedef Callback0::Type ModeChangeCallback;
+
+ // Create an uninitialized SyncManager. Callers must Init() before using.
+ explicit SyncManager(const std::string& name);
+ virtual ~SyncManager();
+
+ // Initialize the sync manager. |database_location| specifies the path of
+ // the directory in which to locate a sqlite repository storing the syncer
+ // backend state. Initialization will open the database, or create it if it
+ // does not already exist. Returns false on failure.
+ // |event_handler| is the JsEventHandler used to propagate events to
+ // chrome://sync-internals. |event_handler| may be uninitialized.
+ // |sync_server_and_path| and |sync_server_port| represent the Chrome sync
+ // server to use, and |use_ssl| specifies whether to communicate securely;
+ // the default is false.
+ // |post_factory| will be owned internally and used to create
+ // instances of an HttpPostProvider.
+ // |model_safe_worker| ownership is given to the SyncManager.
+ // |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent
+ // HTTP header. Used internally when collecting stats to classify clients.
+ // |sync_notifier| is owned and used to listen for notifications.
+ bool Init(const FilePath& database_location,
+ const browser_sync::WeakHandle<browser_sync::JsEventHandler>&
+ event_handler,
+ const std::string& sync_server_and_path,
+ int sync_server_port,
+ bool use_ssl,
+ HttpPostProviderFactory* post_factory,
+ browser_sync::ModelSafeWorkerRegistrar* registrar,
+ const std::string& user_agent,
+ const SyncCredentials& credentials,
+ sync_notifier::SyncNotifier* sync_notifier,
+ const std::string& restored_key_for_bootstrapping,
+ bool setup_for_test_mode);
+
+ // Returns the username last used for a successful authentication.
+ // Returns empty if there is no such username.
+ const std::string& GetAuthenticatedUsername();
+
+ // Check if the database has been populated with a full "initial" download of
+ // sync items for each data type currently present in the routing info.
+ // Prerequisite for calling this is that OnInitializationComplete has been
+ // called.
+ bool InitialSyncEndedForAllEnabledTypes();
+
+ // Update tokens that we're using in Sync. Email must stay the same.
+ void UpdateCredentials(const SyncCredentials& credentials);
+
+ // Called when the user disables or enables a sync type.
+ void UpdateEnabledTypes();
+
+ // Put the syncer in normal mode ready to perform nudges and polls.
+ void StartSyncingNormally();
+
+ // Attempt to set the passphrase. If the passphrase is valid,
+ // OnPassphraseAccepted will be fired to notify the ProfileSyncService and the
+ // syncer will be nudged so that any update that was waiting for this
+ // passphrase gets applied as soon as possible.
+ // If the passphrase in invalid, OnPassphraseRequired will be fired.
+ // Calling this metdod again is the appropriate course of action to "retry"
+ // with a new passphrase.
+ // |is_explicit| is true if the call is in response to the user explicitly
+ // setting a passphrase as opposed to implicitly (from the users' perspective)
+ // using their Google Account password. An implicit SetPassphrase will *not*
+ // *not* override an explicit passphrase set previously.
+ void SetPassphrase(const std::string& passphrase, bool is_explicit);
+
+ // Set the datatypes we want to encrypt and encrypt any nodes as necessary.
+ // Note: |encrypted_types| will be unioned with the current set of encrypted
+ // types, as we do not currently support decrypting datatypes.
+ void EncryptDataTypes(const syncable::ModelTypeSet& encrypted_types);
+
+ // Puts the SyncScheduler into a mode where no normal nudge or poll traffic
+ // will occur, but calls to RequestConfig will be supported. If |callback|
+ // is provided, it will be invoked (from the internal SyncScheduler) when
+ // the thread has changed to configuration mode.
+ void StartConfigurationMode(ModeChangeCallback* callback);
+
+ // Switches the mode of operation to CONFIGURATION_MODE and
+ // schedules a config task to fetch updates for |types|.
+ void RequestConfig(const syncable::ModelTypeBitSet& types,
+ sync_api::ConfigureReason reason);
+
+ void RequestCleanupDisabledTypes();
+
+ // Request a clearing of all data on the server
+ void RequestClearServerData();
+
+ // Adds a listener to be notified of sync events.
+ // NOTE: It is OK (in fact, it's probably a good idea) to call this before
+ // having received OnInitializationCompleted.
+ void AddObserver(Observer* observer);
+
+ // Remove the given observer. Make sure to call this if the
+ // Observer is being destroyed so the SyncManager doesn't
+ // potentially dereference garbage.
+ void RemoveObserver(Observer* observer);
+
+ // Status-related getters. Typically GetStatusSummary will suffice, but
+ // GetDetailedSyncStatus can be useful for gathering debug-level details of
+ // the internals of the sync engine.
+ Status::Summary GetStatusSummary() const;
+ Status GetDetailedStatus() const;
+
+ // Whether or not the Nigori node is encrypted using an explicit passphrase.
+ bool IsUsingExplicitPassphrase();
+
+ // Get the internal implementation for use by BaseTransaction, etc.
+ SyncInternal* GetImpl() const;
+
+ // Call periodically from a database-safe thread to persist recent changes
+ // to the syncapi model.
+ void SaveChanges();
+
+ void RequestEarlyExit();
+
+ // Issue a final SaveChanges, close sqlite handles, and stop running threads.
+ // Must be called from the same thread that called Init().
+ void Shutdown();
+
+ UserShare* GetUserShare() const;
+
+ // Inform the cryptographer of the most recent passphrase and set of encrypted
+ // types (from nigori node), then ensure all data that needs encryption is
+ // encrypted with the appropriate passphrase.
+ // Note: opens a transaction and can trigger ON_PASSPHRASE_REQUIRED, so must
+ // only be called after syncapi has been initialized.
+ void RefreshEncryption();
+
+ syncable::ModelTypeSet GetEncryptedDataTypes() const;
+
+ // Uses a read-only transaction to determine if the directory being synced has
+ // any remaining unsynced items.
+ bool HasUnsyncedItems() const;
+
+ // Logs the list of unsynced meta handles.
+ void LogUnsyncedItems(int level) const;
+
+ // Functions used for testing.
+
+ void TriggerOnNotificationStateChangeForTest(
+ bool notifications_enabled);
+
+ void TriggerOnIncomingNotificationForTest(
+ const syncable::ModelTypeBitSet& model_types);
+
+ private:
+ // An opaque pointer to the nested private class.
+ SyncInternal* data_;
+
+ DISALLOW_COPY_AND_ASSIGN(SyncManager);
+};
+
+bool InitialSyncEndedForTypes(syncable::ModelTypeSet types, UserShare* share);
+
+// Returns the string representation of a PassphraseRequiredReason value.
+std::string PassphraseRequiredReasonToString(PassphraseRequiredReason reason);
+
+} // namespace sync_api
+
+#endif // CHROME_BROWSER_SYNC_INTERNAL_API_SYNC_MANAGER_H_
diff --git a/chrome/browser/sync/engine/syncapi_mock.h b/chrome/browser/sync/internal_api/syncapi_mock.h
index 8e71aa8..dd56d7a 100644
--- a/chrome/browser/sync/engine/syncapi_mock.h
+++ b/chrome/browser/sync/internal_api/syncapi_mock.h
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_MOCK_H_
-#define CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_MOCK_H_
+#ifndef CHROME_BROWSER_SYNC_INTERNAL_API_SYNCAPI_MOCK_H_
+#define CHROME_BROWSER_SYNC_INTERNAL_API_SYNCAPI_MOCK_H_
#pragma once
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/syncable/syncable_mock.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -23,5 +23,5 @@ class MockWriteTransaction : public sync_api::WriteTransaction {
}
};
-#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_MOCK_H_
+#endif // CHROME_BROWSER_SYNC_INTERNAL_API_SYNCAPI_MOCK_H_
diff --git a/chrome/browser/sync/engine/syncapi_unittest.cc b/chrome/browser/sync/internal_api/syncapi_unittest.cc
index cc3fdba..17f77e9 100644
--- a/chrome/browser/sync/engine/syncapi_unittest.cc
+++ b/chrome/browser/sync/internal_api/syncapi_unittest.cc
@@ -25,7 +25,11 @@
#include "chrome/browser/sync/engine/http_post_provider_interface.h"
#include "chrome/browser/sync/engine/model_safe_worker.h"
#include "chrome/browser/sync/engine/nigori_util.h"
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/js/js_arg_list.h"
#include "chrome/browser/sync/js/js_backend.h"
#include "chrome/browser/sync/js/js_event_handler.h"
@@ -35,8 +39,8 @@
#include "chrome/browser/sync/notifier/sync_notifier_observer.h"
#include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
#include "chrome/browser/sync/protocol/password_specifics.pb.h"
-#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/protocol/proto_value_conversions.h"
+#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/sessions/sync_session.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
diff --git a/chrome/browser/sync/internal_api/user_share.cc b/chrome/browser/sync/internal_api/user_share.cc
new file mode 100644
index 0000000..3cb70a0
--- /dev/null
+++ b/chrome/browser/sync/internal_api/user_share.cc
@@ -0,0 +1,15 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/internal_api/user_share.h"
+
+#include "chrome/browser/sync/syncable/directory_manager.h"
+
+namespace sync_api {
+
+UserShare::UserShare() {}
+
+UserShare::~UserShare() {}
+
+}
diff --git a/chrome/browser/sync/internal_api/user_share.h b/chrome/browser/sync/internal_api/user_share.h
new file mode 100644
index 0000000..edc0932
--- /dev/null
+++ b/chrome/browser/sync/internal_api/user_share.h
@@ -0,0 +1,37 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_INTERNAL_API_USER_SHARE_H_
+#define CHROME_BROWSER_SYNC_INTERNAL_API_USER_SHARE_H_
+#pragma once
+
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+
+namespace syncable {
+class DirectoryManager;
+}
+
+namespace sync_api {
+
+// A UserShare encapsulates the syncable pieces that represent an authenticated
+// user and their data (share).
+// This encompasses all pieces required to build transaction objects on the
+// syncable share.
+struct UserShare {
+ UserShare();
+ ~UserShare();
+
+ // The DirectoryManager itself, which is the parent of Transactions and can
+ // be shared across multiple threads (unlike Directory).
+ scoped_ptr<syncable::DirectoryManager> dir_manager;
+
+ // The username of the sync user.
+ std::string name;
+};
+
+}
+
+#endif // CHROME_BROWSER_SYNC_INTERNAL_API_USER_SHARE_H_
diff --git a/chrome/browser/sync/internal_api/write_node.cc b/chrome/browser/sync/internal_api/write_node.cc
new file mode 100644
index 0000000..875d644
--- /dev/null
+++ b/chrome/browser/sync/internal_api/write_node.cc
@@ -0,0 +1,538 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/internal_api/write_node.h"
+
+#include "base/json/json_writer.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/sync/engine/nigori_util.h"
+#include "chrome/browser/sync/engine/syncapi_internal.h"
+#include "chrome/browser/sync/internal_api/base_transaction.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
+#include "chrome/browser/sync/protocol/app_specifics.pb.h"
+#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
+#include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
+#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
+#include "chrome/browser/sync/protocol/password_specifics.pb.h"
+#include "chrome/browser/sync/protocol/session_specifics.pb.h"
+#include "chrome/browser/sync/protocol/theme_specifics.pb.h"
+#include "chrome/browser/sync/protocol/typed_url_specifics.pb.h"
+#include "chrome/browser/sync/syncable/syncable.h"
+#include "chrome/browser/sync/util/cryptographer.h"
+
+using browser_sync::Cryptographer;
+using std::string;
+using std::vector;
+using syncable::kEncryptedString;
+using syncable::SPECIFICS;
+
+namespace sync_api {
+
+static const char kDefaultNameForNewNodes[] = " ";
+
+//////////////////////////////////////////////////////////////////////////
+// Static helper functions.
+
+// When taking a name from the syncapi, append a space if it matches the
+// pattern of a server-illegal name followed by zero or more spaces.
+static void SyncAPINameToServerName(const std::wstring& sync_api_name,
+ std::string* out) {
+ *out = WideToUTF8(sync_api_name);
+ if (IsNameServerIllegalAfterTrimming(*out))
+ out->append(" ");
+}
+
+bool WriteNode::UpdateEntryWithEncryption(
+ browser_sync::Cryptographer* cryptographer,
+ const sync_pb::EntitySpecifics& new_specifics,
+ syncable::MutableEntry* entry) {
+ syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics);
+ DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE);
+ syncable::ModelTypeSet encrypted_types = cryptographer->GetEncryptedTypes();
+
+ sync_pb::EntitySpecifics generated_specifics;
+ if (type == syncable::PASSWORDS || // Has own encryption scheme.
+ type == syncable::NIGORI || // Encrypted separately.
+ encrypted_types.count(type) == 0 ||
+ new_specifics.has_encrypted()) {
+ // No encryption required.
+ generated_specifics.CopyFrom(new_specifics);
+ } else {
+ // Encrypt new_specifics into generated_specifics.
+ if (VLOG_IS_ON(2)) {
+ scoped_ptr<DictionaryValue> value(entry->ToValue());
+ std::string info;
+ base::JSONWriter::Write(value.get(), true, &info);
+ VLOG(2) << "Encrypting specifics of type "
+ << syncable::ModelTypeToString(type)
+ << " with content: "
+ << info;
+ }
+ if (!cryptographer->is_initialized())
+ return false;
+ syncable::AddDefaultExtensionValue(type, &generated_specifics);
+ if (!cryptographer->Encrypt(new_specifics,
+ generated_specifics.mutable_encrypted())) {
+ NOTREACHED() << "Could not encrypt data for node of type "
+ << syncable::ModelTypeToString(type);
+ return false;
+ }
+ }
+
+ const sync_pb::EntitySpecifics& old_specifics = entry->Get(SPECIFICS);
+ if (AreSpecificsEqual(cryptographer, old_specifics, generated_specifics)) {
+ // Even if the data is the same but the old specifics are encrypted with an
+ // old key, we should go ahead and re-encrypt with the new key.
+ if ((!old_specifics.has_encrypted() &&
+ !generated_specifics.has_encrypted()) ||
+ cryptographer->CanDecryptUsingDefaultKey(old_specifics.encrypted())) {
+ VLOG(2) << "Specifics of type " << syncable::ModelTypeToString(type)
+ << " already match, dropping change.";
+ return true;
+ }
+ // TODO(zea): Add some way to keep track of how often we're reencrypting
+ // because of a passphrase change.
+ }
+
+ if (generated_specifics.has_encrypted()) {
+ // Overwrite the possibly sensitive non-specifics data.
+ entry->Put(syncable::NON_UNIQUE_NAME, kEncryptedString);
+ // For bookmarks we actually put bogus data into the unencrypted specifics,
+ // else the server will try to do it for us.
+ if (type == syncable::BOOKMARKS) {
+ sync_pb::BookmarkSpecifics* bookmark_specifics =
+ generated_specifics.MutableExtension(sync_pb::bookmark);
+ if (!entry->Get(syncable::IS_DIR))
+ bookmark_specifics->set_url(kEncryptedString);
+ bookmark_specifics->set_title(kEncryptedString);
+ }
+ }
+ entry->Put(syncable::SPECIFICS, generated_specifics);
+ syncable::MarkForSyncing(entry);
+ return true;
+}
+
+void WriteNode::SetIsFolder(bool folder) {
+ if (entry_->Get(syncable::IS_DIR) == folder)
+ return; // Skip redundant changes.
+
+ entry_->Put(syncable::IS_DIR, folder);
+ MarkForSyncing();
+}
+
+void WriteNode::SetTitle(const std::wstring& title) {
+ std::string server_legal_name;
+ SyncAPINameToServerName(title, &server_legal_name);
+
+ string old_name = entry_->Get(syncable::NON_UNIQUE_NAME);
+
+ if (server_legal_name == old_name)
+ return; // Skip redundant changes.
+
+ // Only set NON_UNIQUE_NAME to the title if we're not encrypted.
+ if (GetEntitySpecifics().has_encrypted())
+ entry_->Put(syncable::NON_UNIQUE_NAME, kEncryptedString);
+ else
+ entry_->Put(syncable::NON_UNIQUE_NAME, server_legal_name);
+
+ // For bookmarks, we also set the title field in the specifics.
+ // TODO(zea): refactor bookmarks to not need this functionality.
+ if (GetModelType() == syncable::BOOKMARKS) {
+ sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
+ new_value.set_title(server_legal_name);
+ SetBookmarkSpecifics(new_value); // Does it's own encryption checking.
+ }
+
+ MarkForSyncing();
+}
+
+void WriteNode::SetURL(const GURL& url) {
+ sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
+ new_value.set_url(url.spec());
+ SetBookmarkSpecifics(new_value);
+}
+
+void WriteNode::SetAppSpecifics(
+ const sync_pb::AppSpecifics& new_value) {
+ sync_pb::EntitySpecifics entity_specifics;
+ entity_specifics.MutableExtension(sync_pb::app)->CopyFrom(new_value);
+ SetEntitySpecifics(entity_specifics);
+}
+
+void WriteNode::SetAutofillSpecifics(
+ const sync_pb::AutofillSpecifics& new_value) {
+ sync_pb::EntitySpecifics entity_specifics;
+ entity_specifics.MutableExtension(sync_pb::autofill)->CopyFrom(new_value);
+ SetEntitySpecifics(entity_specifics);
+}
+
+void WriteNode::SetAutofillProfileSpecifics(
+ const sync_pb::AutofillProfileSpecifics& new_value) {
+ sync_pb::EntitySpecifics entity_specifics;
+ entity_specifics.MutableExtension(sync_pb::autofill_profile)->
+ CopyFrom(new_value);
+ SetEntitySpecifics(entity_specifics);
+}
+
+void WriteNode::SetBookmarkSpecifics(
+ const sync_pb::BookmarkSpecifics& new_value) {
+ sync_pb::EntitySpecifics entity_specifics;
+ entity_specifics.MutableExtension(sync_pb::bookmark)->CopyFrom(new_value);
+ SetEntitySpecifics(entity_specifics);
+}
+
+void WriteNode::SetNigoriSpecifics(
+ const sync_pb::NigoriSpecifics& new_value) {
+ sync_pb::EntitySpecifics entity_specifics;
+ entity_specifics.MutableExtension(sync_pb::nigori)->CopyFrom(new_value);
+ SetEntitySpecifics(entity_specifics);
+}
+
+void WriteNode::SetPasswordSpecifics(
+ const sync_pb::PasswordSpecificsData& data) {
+ DCHECK_EQ(syncable::PASSWORDS, GetModelType());
+
+ Cryptographer* cryptographer = GetTransaction()->GetCryptographer();
+
+ // Idempotency check to prevent unnecessary syncing: if the plaintexts match
+ // and the old ciphertext is encrypted with the most current key, there's
+ // nothing to do here. Because each encryption is seeded with a different
+ // random value, checking for equivalence post-encryption doesn't suffice.
+ const sync_pb::EncryptedData& old_ciphertext =
+ GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::password).encrypted();
+ scoped_ptr<sync_pb::PasswordSpecificsData> old_plaintext(
+ DecryptPasswordSpecifics(GetEntry()->Get(SPECIFICS), cryptographer));
+ if (old_plaintext.get() &&
+ old_plaintext->SerializeAsString() == data.SerializeAsString() &&
+ cryptographer->CanDecryptUsingDefaultKey(old_ciphertext)) {
+ return;
+ }
+
+ sync_pb::PasswordSpecifics new_value;
+ if (!cryptographer->Encrypt(data, new_value.mutable_encrypted())) {
+ NOTREACHED() << "Failed to encrypt password, possibly due to sync node "
+ << "corruption";
+ return;
+ }
+
+ sync_pb::EntitySpecifics entity_specifics;
+ entity_specifics.MutableExtension(sync_pb::password)->CopyFrom(new_value);
+ SetEntitySpecifics(entity_specifics);
+}
+
+void WriteNode::SetThemeSpecifics(
+ const sync_pb::ThemeSpecifics& new_value) {
+ sync_pb::EntitySpecifics entity_specifics;
+ entity_specifics.MutableExtension(sync_pb::theme)->CopyFrom(new_value);
+ SetEntitySpecifics(entity_specifics);
+}
+
+void WriteNode::SetSessionSpecifics(
+ const sync_pb::SessionSpecifics& new_value) {
+ sync_pb::EntitySpecifics entity_specifics;
+ entity_specifics.MutableExtension(sync_pb::session)->CopyFrom(new_value);
+ SetEntitySpecifics(entity_specifics);
+}
+
+void WriteNode::SetEntitySpecifics(
+ const sync_pb::EntitySpecifics& new_value) {
+ syncable::ModelType new_specifics_type =
+ syncable::GetModelTypeFromSpecifics(new_value);
+ DCHECK_NE(new_specifics_type, syncable::UNSPECIFIED);
+ VLOG(1) << "Writing entity specifics of type "
+ << syncable::ModelTypeToString(new_specifics_type);
+ // GetModelType() can be unspecified if this is the first time this
+ // node is being initialized (see PutModelType()). Otherwise, it
+ // should match |new_specifics_type|.
+ if (GetModelType() != syncable::UNSPECIFIED) {
+ DCHECK_EQ(new_specifics_type, GetModelType());
+ }
+ browser_sync::Cryptographer* cryptographer =
+ GetTransaction()->GetCryptographer();
+
+ // Preserve unknown fields.
+ const sync_pb::EntitySpecifics& old_specifics = entry_->Get(SPECIFICS);
+ sync_pb::EntitySpecifics new_specifics;
+ new_specifics.CopyFrom(new_value);
+ new_specifics.mutable_unknown_fields()->MergeFrom(
+ old_specifics.unknown_fields());
+
+ // Will update the entry if encryption was necessary.
+ if (!UpdateEntryWithEncryption(cryptographer, new_specifics, entry_)) {
+ return;
+ }
+ if (entry_->Get(SPECIFICS).has_encrypted()) {
+ // EncryptIfNecessary already updated the entry for us and marked for
+ // syncing if it was needed. Now we just make a copy of the unencrypted
+ // specifics so that if this node is updated, we do not have to decrypt the
+ // old data. Note that this only modifies the node's local data, not the
+ // entry itself.
+ SetUnencryptedSpecifics(new_value);
+ }
+
+ DCHECK_EQ(new_specifics_type, GetModelType());
+}
+
+void WriteNode::ResetFromSpecifics() {
+ SetEntitySpecifics(GetEntitySpecifics());
+}
+
+void WriteNode::SetTypedUrlSpecifics(
+ const sync_pb::TypedUrlSpecifics& new_value) {
+ sync_pb::EntitySpecifics entity_specifics;
+ entity_specifics.MutableExtension(sync_pb::typed_url)->CopyFrom(new_value);
+ SetEntitySpecifics(entity_specifics);
+}
+
+void WriteNode::SetExtensionSpecifics(
+ const sync_pb::ExtensionSpecifics& new_value) {
+ sync_pb::EntitySpecifics entity_specifics;
+ entity_specifics.MutableExtension(sync_pb::extension)->CopyFrom(new_value);
+ SetEntitySpecifics(entity_specifics);
+}
+
+void WriteNode::SetExternalId(int64 id) {
+ if (GetExternalId() != id)
+ entry_->Put(syncable::LOCAL_EXTERNAL_ID, id);
+}
+
+WriteNode::WriteNode(WriteTransaction* transaction)
+ : entry_(NULL), transaction_(transaction) {
+ DCHECK(transaction);
+}
+
+WriteNode::~WriteNode() {
+ delete entry_;
+}
+
+// Find an existing node matching the ID |id|, and bind this WriteNode to it.
+// Return true on success.
+bool WriteNode::InitByIdLookup(int64 id) {
+ DCHECK(!entry_) << "Init called twice";
+ DCHECK_NE(id, kInvalidId);
+ entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
+ syncable::GET_BY_HANDLE, id);
+ return (entry_->good() && !entry_->Get(syncable::IS_DEL) &&
+ DecryptIfNecessary());
+}
+
+// Find a node by client tag, and bind this WriteNode to it.
+// Return true if the write node was found, and was not deleted.
+// Undeleting a deleted node is possible by ClientTag.
+bool WriteNode::InitByClientTagLookup(syncable::ModelType model_type,
+ const std::string& tag) {
+ DCHECK(!entry_) << "Init called twice";
+ if (tag.empty())
+ return false;
+
+ const std::string hash = GenerateSyncableHash(model_type, tag);
+
+ entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
+ syncable::GET_BY_CLIENT_TAG, hash);
+ return (entry_->good() && !entry_->Get(syncable::IS_DEL) &&
+ DecryptIfNecessary());
+}
+
+bool WriteNode::InitByTagLookup(const std::string& tag) {
+ DCHECK(!entry_) << "Init called twice";
+ if (tag.empty())
+ return false;
+ entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
+ syncable::GET_BY_SERVER_TAG, tag);
+ if (!entry_->good())
+ return false;
+ if (entry_->Get(syncable::IS_DEL))
+ return false;
+ syncable::ModelType model_type = GetModelType();
+ DCHECK_EQ(syncable::NIGORI, model_type);
+ return true;
+}
+
+void WriteNode::PutModelType(syncable::ModelType model_type) {
+ // Set an empty specifics of the appropriate datatype. The presence
+ // of the specific extension will identify the model type.
+ DCHECK(GetModelType() == model_type ||
+ GetModelType() == syncable::UNSPECIFIED); // Immutable once set.
+
+ sync_pb::EntitySpecifics specifics;
+ syncable::AddDefaultExtensionValue(model_type, &specifics);
+ SetEntitySpecifics(specifics);
+}
+
+// Create a new node with default properties, and bind this WriteNode to it.
+// Return true on success.
+bool WriteNode::InitByCreation(syncable::ModelType model_type,
+ const BaseNode& parent,
+ const BaseNode* predecessor) {
+ DCHECK(!entry_) << "Init called twice";
+ // |predecessor| must be a child of |parent| or NULL.
+ if (predecessor && predecessor->GetParentId() != parent.GetId()) {
+ DCHECK(false);
+ return false;
+ }
+
+ syncable::Id parent_id = parent.GetEntry()->Get(syncable::ID);
+
+ // Start out with a dummy name. We expect
+ // the caller to set a meaningful name after creation.
+ string dummy(kDefaultNameForNewNodes);
+
+ entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
+ syncable::CREATE, parent_id, dummy);
+
+ if (!entry_->good())
+ return false;
+
+ // Entries are untitled folders by default.
+ entry_->Put(syncable::IS_DIR, true);
+
+ PutModelType(model_type);
+
+ // Now set the predecessor, which sets IS_UNSYNCED as necessary.
+ PutPredecessor(predecessor);
+
+ return true;
+}
+
+// Create a new node with default properties and a client defined unique tag,
+// and bind this WriteNode to it.
+// Return true on success. If the tag exists in the database, then
+// we will attempt to undelete the node.
+// TODO(chron): Code datatype into hash tag.
+// TODO(chron): Is model type ever lost?
+bool WriteNode::InitUniqueByCreation(syncable::ModelType model_type,
+ const BaseNode& parent,
+ const std::string& tag) {
+ DCHECK(!entry_) << "Init called twice";
+
+ const std::string hash = GenerateSyncableHash(model_type, tag);
+
+ syncable::Id parent_id = parent.GetEntry()->Get(syncable::ID);
+
+ // Start out with a dummy name. We expect
+ // the caller to set a meaningful name after creation.
+ string dummy(kDefaultNameForNewNodes);
+
+ // Check if we have this locally and need to undelete it.
+ scoped_ptr<syncable::MutableEntry> existing_entry(
+ new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
+ syncable::GET_BY_CLIENT_TAG, hash));
+
+ if (existing_entry->good()) {
+ if (existing_entry->Get(syncable::IS_DEL)) {
+ // Rules for undelete:
+ // BASE_VERSION: Must keep the same.
+ // ID: Essential to keep the same.
+ // META_HANDLE: Must be the same, so we can't "split" the entry.
+ // IS_DEL: Must be set to false, will cause reindexing.
+ // This one is weird because IS_DEL is true for "update only"
+ // items. It should be OK to undelete an update only.
+ // MTIME/CTIME: Seems reasonable to just leave them alone.
+ // IS_UNSYNCED: Must set this to true or face database insurrection.
+ // We do this below this block.
+ // IS_UNAPPLIED_UPDATE: Either keep it the same or also set BASE_VERSION
+ // to SERVER_VERSION. We keep it the same here.
+ // IS_DIR: We'll leave it the same.
+ // SPECIFICS: Reset it.
+
+ existing_entry->Put(syncable::IS_DEL, false);
+
+ // Client tags are immutable and must be paired with the ID.
+ // If a server update comes down with an ID and client tag combo,
+ // and it already exists, always overwrite it and store only one copy.
+ // We have to undelete entries because we can't disassociate IDs from
+ // tags and updates.
+
+ existing_entry->Put(syncable::NON_UNIQUE_NAME, dummy);
+ existing_entry->Put(syncable::PARENT_ID, parent_id);
+ entry_ = existing_entry.release();
+ } else {
+ return false;
+ }
+ } else {
+ entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(),
+ syncable::CREATE, parent_id, dummy);
+ if (!entry_->good()) {
+ return false;
+ }
+
+ // Only set IS_DIR for new entries. Don't bitflip undeleted ones.
+ entry_->Put(syncable::UNIQUE_CLIENT_TAG, hash);
+ }
+
+ // We don't support directory and tag combinations.
+ entry_->Put(syncable::IS_DIR, false);
+
+ // Will clear specifics data.
+ PutModelType(model_type);
+
+ // Now set the predecessor, which sets IS_UNSYNCED as necessary.
+ PutPredecessor(NULL);
+
+ return true;
+}
+
+bool WriteNode::SetPosition(const BaseNode& new_parent,
+ const BaseNode* predecessor) {
+ // |predecessor| must be a child of |new_parent| or NULL.
+ if (predecessor && predecessor->GetParentId() != new_parent.GetId()) {
+ DCHECK(false);
+ return false;
+ }
+
+ syncable::Id new_parent_id = new_parent.GetEntry()->Get(syncable::ID);
+
+ // Filter out redundant changes if both the parent and the predecessor match.
+ if (new_parent_id == entry_->Get(syncable::PARENT_ID)) {
+ const syncable::Id& old = entry_->Get(syncable::PREV_ID);
+ if ((!predecessor && old.IsRoot()) ||
+ (predecessor && (old == predecessor->GetEntry()->Get(syncable::ID)))) {
+ return true;
+ }
+ }
+
+ // Atomically change the parent. This will fail if it would
+ // introduce a cycle in the hierarchy.
+ if (!entry_->Put(syncable::PARENT_ID, new_parent_id))
+ return false;
+
+ // Now set the predecessor, which sets IS_UNSYNCED as necessary.
+ PutPredecessor(predecessor);
+
+ return true;
+}
+
+const syncable::Entry* WriteNode::GetEntry() const {
+ return entry_;
+}
+
+const BaseTransaction* WriteNode::GetTransaction() const {
+ return transaction_;
+}
+
+void WriteNode::Remove() {
+ entry_->Put(syncable::IS_DEL, true);
+ MarkForSyncing();
+}
+
+void WriteNode::PutPredecessor(const BaseNode* predecessor) {
+ syncable::Id predecessor_id = predecessor ?
+ predecessor->GetEntry()->Get(syncable::ID) : syncable::Id();
+ entry_->PutPredecessor(predecessor_id);
+ // Mark this entry as unsynced, to wake up the syncer.
+ MarkForSyncing();
+}
+
+void WriteNode::SetFaviconBytes(const vector<unsigned char>& bytes) {
+ sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
+ new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size());
+ SetBookmarkSpecifics(new_value);
+}
+
+void WriteNode::MarkForSyncing() {
+ syncable::MarkForSyncing(entry_);
+}
+
+} // namespace sync_api
diff --git a/chrome/browser/sync/internal_api/write_node.h b/chrome/browser/sync/internal_api/write_node.h
new file mode 100644
index 0000000..75e4f21
--- /dev/null
+++ b/chrome/browser/sync/internal_api/write_node.h
@@ -0,0 +1,193 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_INTERNAL_API_WRITE_NODE_H_
+#define CHROME_BROWSER_SYNC_INTERNAL_API_WRITE_NODE_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "chrome/browser/sync/internal_api/base_node.h"
+#include "chrome/browser/sync/syncable/model_type.h"
+
+namespace browser_sync {
+class Cryptographer;
+}
+
+namespace syncable {
+class Entry;
+class MutableEntry;
+}
+
+namespace sync_pb {
+class AppSpecifics;
+class AutofillSpecifics;
+class AutofillProfileSpecifics;
+class BookmarkSpecifics;
+class EntitySpecifics;
+class ExtensionSpecifics;
+class SessionSpecifics;
+class NigoriSpecifics;
+class PreferenceSpecifics;
+class PasswordSpecificsData;
+class ThemeSpecifics;
+class TypedUrlSpecifics;
+}
+
+namespace sync_api {
+
+class WriteTransaction;
+
+// WriteNode extends BaseNode to add mutation, and wraps
+// syncable::MutableEntry. A WriteTransaction is needed to create a WriteNode.
+class WriteNode : public BaseNode {
+ public:
+ // Create a WriteNode using the given transaction.
+ explicit WriteNode(WriteTransaction* transaction);
+ virtual ~WriteNode();
+
+ // A client must use one (and only one) of the following Init variants to
+ // populate the node.
+
+ // BaseNode implementation.
+ virtual bool InitByIdLookup(int64 id);
+ virtual bool InitByClientTagLookup(syncable::ModelType model_type,
+ const std::string& tag);
+
+ // Create a new node with the specified parent and predecessor. |model_type|
+ // dictates the type of the item, and controls which EntitySpecifics proto
+ // extension can be used with this item. Use a NULL |predecessor|
+ // to indicate that this is to be the first child.
+ // |predecessor| must be a child of |new_parent| or NULL. Returns false on
+ // failure.
+ bool InitByCreation(syncable::ModelType model_type,
+ const BaseNode& parent,
+ const BaseNode* predecessor);
+
+ // Create nodes using this function if they're unique items that
+ // you want to fetch using client_tag. Note that the behavior of these
+ // items is slightly different than that of normal items.
+ // Most importantly, if it exists locally, this function will
+ // actually undelete it
+ // Client unique tagged nodes must NOT be folders.
+ bool InitUniqueByCreation(syncable::ModelType model_type,
+ const BaseNode& parent,
+ const std::string& client_tag);
+
+ // Each server-created permanent node is tagged with a unique string.
+ // Look up the node with the particular tag. If it does not exist,
+ // return false.
+ bool InitByTagLookup(const std::string& tag);
+
+ // These Set() functions correspond to the Get() functions of BaseNode.
+ void SetIsFolder(bool folder);
+ void SetTitle(const std::wstring& title);
+
+ // External ID is a client-only field, so setting it doesn't cause the item to
+ // be synced again.
+ void SetExternalId(int64 external_id);
+
+ // Remove this node and its children.
+ void Remove();
+
+ // Set a new parent and position. Position is specified by |predecessor|; if
+ // it is NULL, the node is moved to the first position. |predecessor| must
+ // be a child of |new_parent| or NULL. Returns false on failure..
+ bool SetPosition(const BaseNode& new_parent, const BaseNode* predecessor);
+
+ // Set the bookmark specifics (url and favicon).
+ // Should only be called if GetModelType() == BOOKMARK.
+ void SetBookmarkSpecifics(const sync_pb::BookmarkSpecifics& specifics);
+
+ // Legacy, bookmark-specific setters that wrap SetBookmarkSpecifics() above.
+ // Should only be called if GetModelType() == BOOKMARK.
+ // TODO(ncarter): Remove these two datatype-specific accessors.
+ void SetURL(const GURL& url);
+ void SetFaviconBytes(const std::vector<unsigned char>& bytes);
+
+ // Generic set specifics method. Will extract the model type from |specifics|.
+ void SetEntitySpecifics(const sync_pb::EntitySpecifics& specifics);
+
+ // Resets the EntitySpecifics for this node based on the unencrypted data.
+ // Will encrypt if necessary.
+ void ResetFromSpecifics();
+
+ // TODO(sync): Remove the setters below when the corresponding data
+ // types are ported to the new sync service API.
+
+ // Set the app specifics (id, update url, enabled state, etc).
+ // Should only be called if GetModelType() == APPS.
+ void SetAppSpecifics(const sync_pb::AppSpecifics& specifics);
+
+ // Set the autofill specifics (name and value).
+ // Should only be called if GetModelType() == AUTOFILL.
+ void SetAutofillSpecifics(const sync_pb::AutofillSpecifics& specifics);
+
+ void SetAutofillProfileSpecifics(
+ const sync_pb::AutofillProfileSpecifics& specifics);
+
+ // Set the nigori specifics.
+ // Should only be called if GetModelType() == NIGORI.
+ void SetNigoriSpecifics(const sync_pb::NigoriSpecifics& specifics);
+
+ // Set the password specifics.
+ // Should only be called if GetModelType() == PASSWORD.
+ void SetPasswordSpecifics(const sync_pb::PasswordSpecificsData& specifics);
+
+ // Set the theme specifics (name and value).
+ // Should only be called if GetModelType() == THEME.
+ void SetThemeSpecifics(const sync_pb::ThemeSpecifics& specifics);
+
+ // Set the typed_url specifics (url, title, typed_count, etc).
+ // Should only be called if GetModelType() == TYPED_URLS.
+ void SetTypedUrlSpecifics(const sync_pb::TypedUrlSpecifics& specifics);
+
+ // Set the extension specifics (id, update url, enabled state, etc).
+ // Should only be called if GetModelType() == EXTENSIONS.
+ void SetExtensionSpecifics(const sync_pb::ExtensionSpecifics& specifics);
+
+ // Set the session specifics (windows, tabs, navigations etc.).
+ // Should only be called if GetModelType() == SESSIONS.
+ void SetSessionSpecifics(const sync_pb::SessionSpecifics& specifics);
+
+ // Stores |new_specifics| into |entry|, encrypting if necessary.
+ // Returns false if an error encrypting occurred (does not modify |entry|).
+ // Note: gracefully handles new_specifics aliasing with entry->Get(SPECIFICS).
+ static bool UpdateEntryWithEncryption(
+ browser_sync::Cryptographer* cryptographer,
+ const sync_pb::EntitySpecifics& new_specifics,
+ syncable::MutableEntry* entry);
+
+ // Implementation of BaseNode's abstract virtual accessors.
+ virtual const syncable::Entry* GetEntry() const;
+
+ virtual const BaseTransaction* GetTransaction() const;
+
+ private:
+ void* operator new(size_t size); // Node is meant for stack use only.
+
+ // Helper to set model type. This will clear any specifics data.
+ void PutModelType(syncable::ModelType model_type);
+
+ // Helper to set the previous node.
+ void PutPredecessor(const BaseNode* predecessor);
+
+ // Sets IS_UNSYNCED and SYNCING to ensure this entry is considered in an
+ // upcoming commit pass.
+ void MarkForSyncing();
+
+ // The underlying syncable object which this class wraps.
+ syncable::MutableEntry* entry_;
+
+ // The sync API transaction that is the parent of this node.
+ WriteTransaction* transaction_;
+
+ DISALLOW_COPY_AND_ASSIGN(WriteNode);
+};
+
+} // namespace sync_api
+
+#endif // CHROME_BROWSER_SYNC_INTERNAL_API_WRITE_NODE_H_
diff --git a/chrome/browser/sync/internal_api/write_transaction.cc b/chrome/browser/sync/internal_api/write_transaction.cc
new file mode 100644
index 0000000..1bed02b
--- /dev/null
+++ b/chrome/browser/sync/internal_api/write_transaction.cc
@@ -0,0 +1,29 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/internal_api/write_transaction.h"
+
+#include "chrome/browser/sync/syncable/syncable.h"
+
+namespace sync_api {
+
+//////////////////////////////////////////////////////////////////////////
+// WriteTransaction member definitions
+WriteTransaction::WriteTransaction(const tracked_objects::Location& from_here,
+ UserShare* share)
+ : BaseTransaction(share),
+ transaction_(NULL) {
+ transaction_ = new syncable::WriteTransaction(from_here, syncable::SYNCAPI,
+ GetLookup());
+}
+
+WriteTransaction::~WriteTransaction() {
+ delete transaction_;
+}
+
+syncable::BaseTransaction* WriteTransaction::GetWrappedTrans() const {
+ return transaction_;
+}
+
+} // namespace sync_api
diff --git a/chrome/browser/sync/internal_api/write_transaction.h b/chrome/browser/sync/internal_api/write_transaction.h
new file mode 100644
index 0000000..e90abc7
--- /dev/null
+++ b/chrome/browser/sync/internal_api/write_transaction.h
@@ -0,0 +1,56 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_INTERNAL_API_WRITE_TRANSACTION_H_
+#define CHROME_BROWSER_SYNC_INTERNAL_API_WRITE_TRANSACTION_H_
+
+#include "base/basictypes.h"
+#include "chrome/browser/sync/internal_api/base_transaction.h"
+
+namespace syncable {
+class BaseTransaction;
+class WriteTransaction;
+} // namespace syncable
+
+namespace tracked_objects {
+class Location;
+} // namespace tracked_objects
+
+namespace sync_api {
+
+// Sync API's WriteTransaction is a read/write BaseTransaction. It wraps
+// a syncable::WriteTransaction.
+//
+// NOTE: Only a single model type can be mutated for a given
+// WriteTransaction.
+class WriteTransaction : public BaseTransaction {
+ public:
+ // Start a new read/write transaction.
+ WriteTransaction(const tracked_objects::Location& from_here,
+ UserShare* share);
+ virtual ~WriteTransaction();
+
+ // Provide access to the syncable.h transaction from the API WriteNode.
+ virtual syncable::BaseTransaction* GetWrappedTrans() const;
+ syncable::WriteTransaction* GetWrappedWriteTrans() { return transaction_; }
+
+ protected:
+ WriteTransaction() {}
+
+ void SetTransaction(syncable::WriteTransaction* trans) {
+ transaction_ = trans;
+ }
+
+ private:
+ void* operator new(size_t size); // Transaction is meant for stack use only.
+
+ // The underlying syncable object which this class wraps.
+ syncable::WriteTransaction* transaction_;
+
+ DISALLOW_COPY_AND_ASSIGN(WriteTransaction);
+};
+
+} // namespace sync_api
+
+#endif // CHROME_BROWSER_SYNC_INTERNAL_API_WRITE_TRANSACTION_H_
diff --git a/chrome/browser/sync/js/DEPS b/chrome/browser/sync/js/DEPS
index 0123cb9..3b29013 100644
--- a/chrome/browser/sync/js/DEPS
+++ b/chrome/browser/sync/js/DEPS
@@ -4,9 +4,7 @@ include_rules = [
"+chrome/browser/sync/js",
- # The following should live in their own "includes" directory(ies).
- # Bug 19878.
- "+chrome/browser/sync/engine/syncapi.h",
+ "+chrome/browser/sync/internal_api",
"+chrome/browser/sync/sessions/session_state.h",
"+chrome/browser/sync/syncable/model_type.h",
"+chrome/browser/sync/syncable/transaction_observer.h",
diff --git a/chrome/browser/sync/js/js_sync_manager_observer.h b/chrome/browser/sync/js/js_sync_manager_observer.h
index cc7c8c0..a4b364a 100644
--- a/chrome/browser/sync/js/js_sync_manager_observer.h
+++ b/chrome/browser/sync/js/js_sync_manager_observer.h
@@ -9,7 +9,7 @@
#include <string>
#include "base/basictypes.h"
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "chrome/browser/sync/weak_handle.h"
namespace tracked_objects {
diff --git a/chrome/browser/sync/js/js_sync_manager_observer_unittest.cc b/chrome/browser/sync/js/js_sync_manager_observer_unittest.cc
index a29b9aa..4ffd253 100644
--- a/chrome/browser/sync/js/js_sync_manager_observer_unittest.cc
+++ b/chrome/browser/sync/js/js_sync_manager_observer_unittest.cc
@@ -10,7 +10,10 @@
#include "base/message_loop.h"
#include "base/tracked.h"
#include "base/values.h"
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/js/js_arg_list.h"
#include "chrome/browser/sync/js/js_event_details.h"
#include "chrome/browser/sync/js/js_test_util.h"
diff --git a/chrome/browser/sync/notifier/DEPS b/chrome/browser/sync/notifier/DEPS
index ab0257a..96351bd 100644
--- a/chrome/browser/sync/notifier/DEPS
+++ b/chrome/browser/sync/notifier/DEPS
@@ -16,4 +16,6 @@ include_rules = [
"+talk/base",
# sync_notifier depends on the xmpp part of libjingle.
"+talk/xmpp",
+
+ "-chrome/browser/sync/internal_api",
]
diff --git a/chrome/browser/sync/profile_sync_factory_impl_unittest.cc b/chrome/browser/sync/profile_sync_factory_impl_unittest.cc
index 953ed64..414e3a9 100644
--- a/chrome/browser/sync/profile_sync_factory_impl_unittest.cc
+++ b/chrome/browser/sync/profile_sync_factory_impl_unittest.cc
@@ -4,19 +4,18 @@
#include <vector>
-#include "testing/gtest/include/gtest/gtest.h"
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/data_type_controller.h"
-#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_factory_impl.h"
+#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_browser_process_test.h"
#include "chrome/test/base/testing_profile.h"
#include "content/browser/browser_thread.h"
+#include "testing/gtest/include/gtest/gtest.h"
using browser_sync::DataTypeController;
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index 6f3d07f..70da3a1 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -27,11 +27,11 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/backend_migrator.h"
#include "chrome/browser/sync/engine/configure_reason.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/change_processor.h"
#include "chrome/browser/sync/glue/data_type_controller.h"
#include "chrome/browser/sync/glue/data_type_manager.h"
#include "chrome/browser/sync/glue/session_data_type_controller.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "chrome/browser/sync/js/js_arg_list.h"
#include "chrome/browser/sync/js/js_event_details.h"
#include "chrome/browser/sync/profile_sync_factory.h"
diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h
index 558c548..d32b737 100644
--- a/chrome/browser/sync/profile_sync_service.h
+++ b/chrome/browser/sync/profile_sync_service.h
@@ -23,10 +23,11 @@
#include "chrome/browser/sync/engine/model_safe_worker.h"
#include "chrome/browser/sync/glue/data_type_controller.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
#include "chrome/browser/sync/profile_sync_service_observer.h"
+#include "chrome/browser/sync/syncable/model_type.h"
#include "chrome/browser/sync/sync_js_controller.h"
#include "chrome/browser/sync/sync_setup_wizard.h"
-#include "chrome/browser/sync/syncable/model_type.h"
#include "chrome/browser/sync/unrecoverable_error_handler.h"
#include "chrome/common/net/gaia/google_service_auth_error.h"
#include "content/common/content_notification_types.h"
diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
index f00e7ba..df1fbfd 100644
--- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
@@ -21,7 +21,6 @@
#include "chrome/browser/autofill/autofill_common_test.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
#include "chrome/browser/sync/engine/model_changing_syncer_command.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/autofill_change_processor.h"
#include "chrome/browser/sync/glue/autofill_data_type_controller.h"
#include "chrome/browser/sync/glue/autofill_model_associator.h"
@@ -29,6 +28,10 @@
#include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h"
#include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
#include "chrome/browser/sync/glue/data_type_controller.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_test_util.h"
diff --git a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
index 790aaae..2f1e2ad 100644
--- a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc
@@ -22,9 +22,13 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
#include "chrome/browser/sync/api/sync_error.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/bookmark_change_processor.h"
#include "chrome/browser/sync/glue/bookmark_model_associator.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_browser_process_test.h"
diff --git a/chrome/browser/sync/profile_sync_service_password_unittest.cc b/chrome/browser/sync/profile_sync_service_password_unittest.cc
index b61c860..175018a 100644
--- a/chrome/browser/sync/profile_sync_service_password_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc
@@ -15,10 +15,13 @@
#include "chrome/browser/password_manager/password_store.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/password_change_processor.h"
#include "chrome/browser/sync/glue/password_data_type_controller.h"
#include "chrome/browser/sync/glue/password_model_associator.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_factory.h"
#include "chrome/browser/sync/profile_sync_factory_mock.h"
#include "chrome/browser/sync/profile_sync_service.h"
diff --git a/chrome/browser/sync/profile_sync_service_preference_unittest.cc b/chrome/browser/sync/profile_sync_service_preference_unittest.cc
index 41c6ba7..c577462 100644
--- a/chrome/browser/sync/profile_sync_service_preference_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_preference_unittest.cc
@@ -14,11 +14,15 @@
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
#include "chrome/browser/sync/api/sync_data.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/generic_change_processor.h"
#include "chrome/browser/sync/glue/preference_data_type_controller.h"
-#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/glue/syncable_service_adapter.h"
+#include "chrome/browser/sync/glue/sync_backend_host.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_test_util.h"
#include "chrome/browser/sync/protocol/preference_specifics.pb.h"
#include "chrome/browser/sync/syncable/model_type.h"
diff --git a/chrome/browser/sync/profile_sync_service_session_unittest.cc b/chrome/browser/sync/profile_sync_service_session_unittest.cc
index 509dfe1..fa2a5ec 100644
--- a/chrome/browser/sync/profile_sync_service_session_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc
@@ -11,15 +11,18 @@
#include "base/stl_util.h"
#include "base/task.h"
#include "base/tracked.h"
-#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
+#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_test_helper.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/session_change_processor.h"
#include "chrome/browser/sync/glue/session_data_type_controller.h"
#include "chrome/browser/sync/glue/session_model_associator.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/sync_manager.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_factory_mock.h"
#include "chrome/browser/sync/profile_sync_test_util.h"
#include "chrome/browser/sync/protocol/session_specifics.pb.h"
diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
index d7dfe13..432aeb4 100644
--- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
@@ -16,12 +16,15 @@
#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/glue/sync_backend_host_mock.h"
#include "chrome/browser/sync/glue/typed_url_change_processor.h"
#include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
#include "chrome/browser/sync/glue/typed_url_model_associator.h"
+#include "chrome/browser/sync/internal_api/read_node.h"
+#include "chrome/browser/sync/internal_api/read_transaction.h"
+#include "chrome/browser/sync/internal_api/write_node.h"
+#include "chrome/browser/sync/internal_api/write_transaction.h"
#include "chrome/browser/sync/profile_sync_factory.h"
#include "chrome/browser/sync/profile_sync_factory_mock.h"
#include "chrome/browser/sync/profile_sync_service.h"
diff --git a/chrome/browser/sync/protocol/DEPS b/chrome/browser/sync/protocol/DEPS
index 7f28a59..fdf9fa3 100644
--- a/chrome/browser/sync/protocol/DEPS
+++ b/chrome/browser/sync/protocol/DEPS
@@ -2,5 +2,7 @@ include_rules = [
"-chrome",
"+chrome/browser/sync/protocol",
"+chrome/browser/sync/syncable/model_type.h",
+
+ "-chrome/browser/sync/internal_api",
]
diff --git a/chrome/browser/sync/sessions/DEPS b/chrome/browser/sync/sessions/DEPS
index cb4f078..0d7660a 100644
--- a/chrome/browser/sync/sessions/DEPS
+++ b/chrome/browser/sync/sessions/DEPS
@@ -8,5 +8,7 @@ include_rules = [
"+chrome/browser/sync/sessions",
"+chrome/browser/sync/syncable",
"+chrome/browser/sync/util",
+
+ "-chrome/browser/sync/internal_api",
]
diff --git a/chrome/browser/sync/sync_setup_wizard_unittest.cc b/chrome/browser/sync/sync_setup_wizard_unittest.cc
index 9611dc7..3b2a86e 100644
--- a/chrome/browser/sync/sync_setup_wizard_unittest.cc
+++ b/chrome/browser/sync/sync_setup_wizard_unittest.cc
@@ -9,7 +9,6 @@
#include "base/stl_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/profile_sync_factory_mock.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/signin_manager.h"
diff --git a/chrome/browser/sync/syncable/DEPS b/chrome/browser/sync/syncable/DEPS
index 710d381..032cd30 100644
--- a/chrome/browser/sync/syncable/DEPS
+++ b/chrome/browser/sync/syncable/DEPS
@@ -16,5 +16,7 @@ include_rules = [
"+chrome/common/random.h",
"+chrome/common/sqlite_utils.h",
+
+ "-chrome/browser/sync/internal_api",
]
diff --git a/chrome/browser/sync/syncable/model_type_payload_map.cc b/chrome/browser/sync/syncable/model_type_payload_map.cc
index 2507a2b..288d8ff 100644
--- a/chrome/browser/sync/syncable/model_type_payload_map.cc
+++ b/chrome/browser/sync/syncable/model_type_payload_map.cc
@@ -7,7 +7,7 @@
#include "chrome/browser/sync/engine/model_safe_worker.h"
#include "base/json/json_writer.h"
-#include "base/scoped_ptr.h"
+#include "base/memory/scoped_ptr.h"
#include "base/values.h"
using browser_sync::ModelSafeRoutingInfo;
diff --git a/chrome/browser/sync/syncable/syncable.cc b/chrome/browser/sync/syncable/syncable.cc
index cf30b99..4ece5bd 100644
--- a/chrome/browser/sync/syncable/syncable.cc
+++ b/chrome/browser/sync/syncable/syncable.cc
@@ -27,14 +27,14 @@
#include <set>
#include <string>
-#include "base/hash_tables.h"
#include "base/file_util.h"
+#include "base/hash_tables.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/perftimer.h"
+#include "base/stl_util.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
-#include "base/stl_util.h"
#include "base/time.h"
#include "base/tracked.h"
#include "base/utf_string_conversions.h"
@@ -45,10 +45,10 @@
#include "chrome/browser/sync/syncable/directory_change_delegate.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/model_type.h"
-#include "chrome/browser/sync/syncable/syncable-inl.h"
#include "chrome/browser/sync/syncable/syncable_changes_version.h"
#include "chrome/browser/sync/syncable/syncable_columns.h"
#include "chrome/browser/sync/syncable/syncable_enum_conversions.h"
+#include "chrome/browser/sync/syncable/syncable-inl.h"
#include "chrome/browser/sync/syncable/transaction_observer.h"
#include "chrome/browser/sync/util/logging.h"
#include "net/base/escape.h"
diff --git a/chrome/browser/sync/test_profile_sync_service.cc b/chrome/browser/sync/test_profile_sync_service.cc
index 22737a1..4fd70fa 100644
--- a/chrome/browser/sync/test_profile_sync_service.cc
+++ b/chrome/browser/sync/test_profile_sync_service.cc
@@ -5,9 +5,9 @@
#include "chrome/browser/sync/test_profile_sync_service.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/data_type_controller.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
+#include "chrome/browser/sync/internal_api/user_share.h"
#include "chrome/browser/sync/js/js_reply_handler.h"
#include "chrome/browser/sync/profile_sync_factory.h"
#include "chrome/browser/sync/sessions/session_state.h"
diff --git a/chrome/browser/ui/webui/ntp/foreign_session_handler.cc b/chrome/browser/ui/webui/ntp/foreign_session_handler.cc
index e0e968b..cbab342 100644
--- a/chrome/browser/ui/webui/ntp/foreign_session_handler.cc
+++ b/chrome/browser/ui/webui/ntp/foreign_session_handler.cc
@@ -13,13 +13,12 @@
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_restore.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/url_constants.h"
#include "content/common/notification_details.h"
#include "content/common/notification_service.h"
-#include "chrome/common/url_constants.h"
namespace browser_sync {
diff --git a/chrome/browser/ui/webui/sessions_ui.cc b/chrome/browser/ui/webui/sessions_ui.cc
index 9bbabbd..4522ddf 100644
--- a/chrome/browser/ui/webui/sessions_ui.cc
+++ b/chrome/browser/ui/webui/sessions_ui.cc
@@ -7,7 +7,6 @@
#include <algorithm>
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/session_model_associator.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
@@ -26,7 +25,6 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
-
namespace {
ChromeWebUIDataSource* CreateSessionsUIHTMLSource() {
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index dd4d302..9b220b3 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -505,11 +505,27 @@
'target_name': 'syncapi_core',
'type': 'static_library',
'sources': [
+ 'browser/sync/engine/configure_reason.h'
'browser/sync/engine/http_post_provider_factory.h',
'browser/sync/engine/http_post_provider_interface.h',
- 'browser/sync/engine/syncapi.cc',
- 'browser/sync/engine/syncapi.h',
- 'browser/sync/engine/configure_reason.h'
+ 'browser/sync/engine/syncapi_internal.cc',
+ 'browser/sync/engine/syncapi_internal.h',
+ 'browser/sync/internal_api/base_node.cc',
+ 'browser/sync/internal_api/base_node.h',
+ 'browser/sync/internal_api/base_transaction.cc',
+ 'browser/sync/internal_api/base_transaction.h',
+ 'browser/sync/internal_api/read_node.cc',
+ 'browser/sync/internal_api/read_node.h',
+ 'browser/sync/internal_api/read_transaction.cc',
+ 'browser/sync/internal_api/read_transaction.h',
+ 'browser/sync/internal_api/sync_manager.cc',
+ 'browser/sync/internal_api/sync_manager.h',
+ 'browser/sync/internal_api/user_share.cc',
+ 'browser/sync/internal_api/user_share.h',
+ 'browser/sync/internal_api/write_node.cc',
+ 'browser/sync/internal_api/write_node.h',
+ 'browser/sync/internal_api/write_transaction.cc',
+ 'browser/sync/internal_api/write_transaction.h',
],
'include_dirs': [
'..',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 0fe71e1..91d2f10 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1658,8 +1658,8 @@
'browser/sync/abstract_profile_sync_service_test.cc',
'browser/sync/abstract_profile_sync_service_test.h',
'browser/sync/backend_migrator_unittest.cc',
- 'browser/sync/engine/read_node_mock.cc',
- 'browser/sync/engine/read_node_mock.h',
+ 'browser/sync/internal_api/read_node_mock.cc',
+ 'browser/sync/internal_api/read_node_mock.h',
'browser/sync/glue/autofill_data_type_controller_unittest.cc',
'browser/sync/glue/autofill_model_associator_unittest.cc',
'browser/sync/glue/autofill_profile_model_associator_unittest.cc',
@@ -3138,14 +3138,14 @@
'browser/sync/engine/mock_model_safe_workers.h',
'browser/sync/engine/nigori_util_unittest.cc',
'browser/sync/engine/process_commit_response_command_unittest.cc',
- 'browser/sync/engine/syncapi_unittest.cc',
'browser/sync/engine/syncer_proto_util_unittest.cc',
'browser/sync/engine/sync_scheduler_unittest.cc',
'browser/sync/engine/sync_scheduler_whitebox_unittest.cc',
'browser/sync/engine/syncer_unittest.cc',
'browser/sync/engine/syncproto_unittest.cc',
- 'browser/sync/engine/syncapi_mock.h',
'browser/sync/engine/verify_updates_command_unittest.cc',
+ 'browser/sync/internal_api/syncapi_mock.h',
+ 'browser/sync/internal_api/syncapi_unittest.cc',
'browser/sync/js/js_arg_list_unittest.cc',
'browser/sync/js/js_event_details_unittest.cc',
'browser/sync/js/js_sync_manager_observer_unittest.cc',
diff --git a/chrome/test/sync/engine/test_user_share.h b/chrome/test/sync/engine/test_user_share.h
index 00d73d1..969decd 100644
--- a/chrome/test/sync/engine/test_user_share.h
+++ b/chrome/test/sync/engine/test_user_share.h
@@ -32,7 +32,7 @@
#pragma once
#include "base/basictypes.h"
-#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/internal_api/user_share.h"
#include "chrome/test/sync/engine/test_directory_setter_upper.h"
namespace browser_sync {