From 3f8556a0cf934ee6e2e4a37b22b05dbf0a9c4a90 Mon Sep 17 00:00:00 2001 From: "tim@chromium.org" Date: Thu, 7 Jun 2012 17:50:19 +0000 Subject: sync: create internal_api/public to house sync/ files needed by chrome/browser/sync. Note on sync.gyp changes and .cc file moves: most files in /public have .h and their .cc side by side, as they are simple implementations. In some cases like model_type.cc (and others in a follow up patch, like sync_manager.cc) have only their header exposed in /public while the impl stays behind, because it needs to include things from within sync/, and /public has a strict include DEPS policy. This is in accordance with other /public folders (like content/). Cleans up DEPS files in sync + c/b/sync. Adds sync/{engine, sessions, syncable} to public/. There is more to come (moving things in internal_api/ into public). Not touching /notifier as that is in flux at the moment. BUG=131130 TEST= Review URL: https://chromiumcodereview.appspot.com/10532019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141038 0039d316-1c4b-4281-b951-d872f2087c98 --- sync/api/DEPS | 2 +- sync/api/sync_data.cc | 2 +- sync/api/sync_data.h | 2 +- sync/api/sync_error.cc | 2 +- sync/api/sync_error.h | 2 +- sync/api/syncable_service.h | 2 +- sync/engine/DEPS | 4 + sync/engine/cleanup_disabled_types_command.cc | 2 +- .../cleanup_disabled_types_command_unittest.cc | 4 +- sync/engine/clear_data_command.h | 4 +- sync/engine/commit.h | 2 +- sync/engine/download_updates_command.cc | 2 +- sync/engine/download_updates_command.h | 4 +- sync/engine/model_changing_syncer_command.h | 2 +- .../model_changing_syncer_command_unittest.cc | 2 +- sync/engine/model_safe_worker.cc | 75 ------ sync/engine/model_safe_worker.h | 87 ------- sync/engine/model_safe_worker_unittest.cc | 55 ---- sync/engine/nigori_util.h | 2 +- sync/engine/passive_model_worker.cc | 28 -- sync/engine/passive_model_worker.h | 40 --- sync/engine/polling_constants.cc | 26 -- sync/engine/polling_constants.h | 20 -- sync/engine/process_updates_command_unittest.cc | 2 +- sync/engine/resolve_conflicts_command_unittest.cc | 2 +- sync/engine/store_timestamps_command.cc | 2 +- sync/engine/sync_engine_event.h | 4 +- sync/engine/sync_scheduler.h | 4 +- sync/engine/syncer.h | 2 +- sync/engine/syncer_command.h | 2 +- sync/engine/syncer_proto_util.cc | 2 +- sync/engine/syncer_proto_util.h | 4 +- sync/engine/syncer_proto_util_unittest.cc | 10 +- sync/engine/syncer_unittest.cc | 6 +- sync/engine/syncer_util.cc | 2 +- sync/engine/syncproto.h | 2 +- sync/engine/update_applicator.h | 2 +- sync/engine/verify_updates_command.cc | 2 +- sync/engine/verify_updates_command.h | 2 +- sync/engine/verify_updates_command_unittest.cc | 2 +- sync/internal_api/all_status.cc | 2 +- sync/internal_api/all_status.h | 4 +- sync/internal_api/base_node.h | 2 +- sync/internal_api/change_reorder_buffer.cc | 2 +- sync/internal_api/debug_info_event_listener.h | 2 +- .../js_mutation_event_observer_unittest.cc | 2 +- sync/internal_api/js_sync_manager_observer.cc | 4 +- .../js_sync_manager_observer_unittest.cc | 5 +- sync/internal_api/public/DEPS | 5 + .../public/engine/model_safe_worker.cc | 75 ++++++ .../internal_api/public/engine/model_safe_worker.h | 87 +++++++ .../public/engine/model_safe_worker_unittest.cc | 55 ++++ .../public/engine/passive_model_worker.cc | 28 ++ .../public/engine/passive_model_worker.h | 40 +++ .../public/engine/polling_constants.cc | 26 ++ .../internal_api/public/engine/polling_constants.h | 20 ++ .../internal_api/public/sessions/error_counters.cc | 17 ++ sync/internal_api/public/sessions/error_counters.h | 33 +++ .../public/sessions/sync_session_snapshot.cc | 173 +++++++++++++ .../public/sessions/sync_session_snapshot.h | 101 ++++++++ .../public/sessions/sync_source_info.cc | 36 +++ .../public/sessions/sync_source_info.h | 42 +++ sync/internal_api/public/sessions/syncer_status.cc | 44 ++++ sync/internal_api/public/sessions/syncer_status.h | 50 ++++ sync/internal_api/public/syncable/model_type.h | 175 +++++++++++++ .../public/syncable/model_type_payload_map.cc | 105 ++++++++ .../public/syncable/model_type_payload_map.h | 60 +++++ .../syncable/model_type_payload_map_unittest.cc | 46 ++++ .../public/syncable/model_type_test_util.cc | 52 ++++ .../public/syncable/model_type_test_util.h | 26 ++ sync/internal_api/public/util/enum_set.h | 286 +++++++++++++++++++++ sync/internal_api/public/util/enum_set_unittest.cc | 195 ++++++++++++++ sync/internal_api/public/util/syncer_error.cc | 36 +++ sync/internal_api/public/util/syncer_error.h | 46 ++++ sync/internal_api/read_node.h | 2 +- sync/internal_api/sync_manager.cc | 6 +- sync/internal_api/sync_manager.h | 4 +- sync/internal_api/syncapi_unittest.cc | 6 +- sync/internal_api/write_node.h | 2 +- sync/notifier/DEPS | 3 +- sync/notifier/chrome_invalidation_client.cc | 2 +- sync/notifier/chrome_invalidation_client.h | 4 +- .../chrome_invalidation_client_unittest.cc | 4 +- sync/notifier/invalidation_notifier.cc | 2 +- sync/notifier/invalidation_notifier.h | 2 +- sync/notifier/invalidation_notifier_unittest.cc | 4 +- sync/notifier/invalidation_state_tracker.h | 2 +- sync/notifier/invalidation_util.h | 2 +- .../non_blocking_invalidation_notifier_unittest.cc | 4 +- sync/notifier/p2p_notifier.cc | 2 +- sync/notifier/p2p_notifier.h | 2 +- sync/notifier/p2p_notifier_unittest.cc | 2 +- sync/notifier/registration_manager.cc | 2 +- sync/notifier/registration_manager.h | 2 +- sync/notifier/registration_manager_unittest.cc | 2 +- sync/notifier/sync_notifier.h | 2 +- sync/notifier/sync_notifier_factory_unittest.cc | 4 +- sync/notifier/sync_notifier_observer.h | 2 +- sync/protocol/DEPS | 2 +- sync/protocol/proto_value_conversions_unittest.cc | 2 +- sync/protocol/sync_protocol_error.h | 2 +- sync/sessions/DEPS | 3 + sync/sessions/error_counters.cc | 17 -- sync/sessions/error_counters.h | 33 --- sync/sessions/ordered_commit_set.h | 4 +- sync/sessions/session_state.h | 5 +- sync/sessions/session_state_unittest.cc | 8 +- sync/sessions/status_controller.cc | 2 +- sync/sessions/sync_session.cc | 2 +- sync/sessions/sync_session.h | 6 +- sync/sessions/sync_session_context.h | 4 +- sync/sessions/sync_session_context_unittest.cc | 2 +- sync/sessions/sync_session_snapshot.cc | 173 ------------- sync/sessions/sync_session_snapshot.h | 101 -------- sync/sessions/sync_session_unittest.cc | 2 +- sync/sessions/sync_source_info.cc | 36 --- sync/sessions/sync_source_info.h | 42 --- sync/sessions/syncer_status.cc | 44 ---- sync/sessions/syncer_status.h | 50 ---- sync/sync.gyp | 50 ++-- sync/syncable/DEPS | 5 +- sync/syncable/directory_backing_store.h | 2 +- sync/syncable/directory_change_delegate.h | 2 +- sync/syncable/model_type.cc | 2 +- sync/syncable/model_type.h | 175 ------------- sync/syncable/model_type_payload_map.cc | 105 -------- sync/syncable/model_type_payload_map.h | 60 ----- sync/syncable/model_type_payload_map_unittest.cc | 46 ---- sync/syncable/model_type_test_util.cc | 52 ---- sync/syncable/model_type_test_util.h | 26 -- sync/syncable/model_type_unittest.cc | 2 +- sync/syncable/syncable.cc | 8 +- sync/syncable/syncable.h | 6 +- sync/syncable/transaction_observer.h | 2 +- sync/test/engine/fake_model_worker.h | 4 +- sync/test/engine/mock_connection_manager.h | 4 +- sync/test/engine/syncer_command_test.h | 6 +- sync/tools/DEPS | 3 +- sync/tools/sync_listen_notifications.cc | 4 +- sync/util/DEPS | 3 +- sync/util/cryptographer.h | 4 +- sync/util/cryptographer_unittest.cc | 4 +- sync/util/data_type_histogram.h | 2 +- sync/util/enum_set.h | 286 --------------------- sync/util/enum_set_unittest.cc | 195 -------------- sync/util/experiments.h | 2 +- sync/util/syncer_error.cc | 36 --- sync/util/syncer_error.h | 46 ---- 148 files changed, 2030 insertions(+), 2026 deletions(-) delete mode 100644 sync/engine/model_safe_worker.cc delete mode 100644 sync/engine/model_safe_worker.h delete mode 100644 sync/engine/model_safe_worker_unittest.cc delete mode 100644 sync/engine/passive_model_worker.cc delete mode 100644 sync/engine/passive_model_worker.h delete mode 100644 sync/engine/polling_constants.cc delete mode 100644 sync/engine/polling_constants.h create mode 100644 sync/internal_api/public/DEPS create mode 100644 sync/internal_api/public/engine/model_safe_worker.cc create mode 100644 sync/internal_api/public/engine/model_safe_worker.h create mode 100644 sync/internal_api/public/engine/model_safe_worker_unittest.cc create mode 100644 sync/internal_api/public/engine/passive_model_worker.cc create mode 100644 sync/internal_api/public/engine/passive_model_worker.h create mode 100644 sync/internal_api/public/engine/polling_constants.cc create mode 100644 sync/internal_api/public/engine/polling_constants.h create mode 100644 sync/internal_api/public/sessions/error_counters.cc create mode 100644 sync/internal_api/public/sessions/error_counters.h create mode 100644 sync/internal_api/public/sessions/sync_session_snapshot.cc create mode 100644 sync/internal_api/public/sessions/sync_session_snapshot.h create mode 100644 sync/internal_api/public/sessions/sync_source_info.cc create mode 100644 sync/internal_api/public/sessions/sync_source_info.h create mode 100644 sync/internal_api/public/sessions/syncer_status.cc create mode 100644 sync/internal_api/public/sessions/syncer_status.h create mode 100644 sync/internal_api/public/syncable/model_type.h create mode 100644 sync/internal_api/public/syncable/model_type_payload_map.cc create mode 100644 sync/internal_api/public/syncable/model_type_payload_map.h create mode 100644 sync/internal_api/public/syncable/model_type_payload_map_unittest.cc create mode 100644 sync/internal_api/public/syncable/model_type_test_util.cc create mode 100644 sync/internal_api/public/syncable/model_type_test_util.h create mode 100644 sync/internal_api/public/util/enum_set.h create mode 100644 sync/internal_api/public/util/enum_set_unittest.cc create mode 100644 sync/internal_api/public/util/syncer_error.cc create mode 100644 sync/internal_api/public/util/syncer_error.h delete mode 100644 sync/sessions/error_counters.cc delete mode 100644 sync/sessions/error_counters.h delete mode 100644 sync/sessions/sync_session_snapshot.cc delete mode 100644 sync/sessions/sync_session_snapshot.h delete mode 100644 sync/sessions/sync_source_info.cc delete mode 100644 sync/sessions/sync_source_info.h delete mode 100644 sync/sessions/syncer_status.cc delete mode 100644 sync/sessions/syncer_status.h delete mode 100644 sync/syncable/model_type.h delete mode 100644 sync/syncable/model_type_payload_map.cc delete mode 100644 sync/syncable/model_type_payload_map.h delete mode 100644 sync/syncable/model_type_payload_map_unittest.cc delete mode 100644 sync/syncable/model_type_test_util.cc delete mode 100644 sync/syncable/model_type_test_util.h delete mode 100644 sync/util/enum_set.h delete mode 100644 sync/util/enum_set_unittest.cc delete mode 100644 sync/util/syncer_error.cc delete mode 100644 sync/util/syncer_error.h (limited to 'sync') diff --git a/sync/api/DEPS b/sync/api/DEPS index 157d02f..f6dca6a 100644 --- a/sync/api/DEPS +++ b/sync/api/DEPS @@ -1,6 +1,6 @@ include_rules = [ "+sync/internal_api/base_node.h", + "+sync/internal_api/public", "+sync/protocol", - "+sync/syncable/model_type.h", "+sync/util/immutable.h", ] diff --git a/sync/api/sync_data.cc b/sync/api/sync_data.cc index 679c547..bf2aa0b 100644 --- a/sync/api/sync_data.cc +++ b/sync/api/sync_data.cc @@ -11,9 +11,9 @@ #include "base/string_number_conversions.h" #include "base/values.h" #include "sync/internal_api/base_node.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/proto_value_conversions.h" #include "sync/protocol/sync.pb.h" -#include "sync/syncable/model_type.h" void SyncData::ImmutableSyncEntityTraits::InitializeWrapper( Wrapper* wrapper) { diff --git a/sync/api/sync_data.h b/sync/api/sync_data.h index cef132b..1626f50 100644 --- a/sync/api/sync_data.h +++ b/sync/api/sync_data.h @@ -11,7 +11,7 @@ #include #include "base/basictypes.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/util/immutable.h" namespace sync_pb { diff --git a/sync/api/sync_error.cc b/sync/api/sync_error.cc index 49bf74b..501fa53 100644 --- a/sync/api/sync_error.cc +++ b/sync/api/sync_error.cc @@ -8,7 +8,7 @@ #include "base/location.h" #include "base/logging.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" SyncError::SyncError() { Clear(); diff --git a/sync/api/sync_error.h b/sync/api/sync_error.h index 2b6dc93..2bdb9eb 100644 --- a/sync/api/sync_error.h +++ b/sync/api/sync_error.h @@ -10,7 +10,7 @@ #include #include "base/memory/scoped_ptr.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" namespace tracked_objects { class Location; diff --git a/sync/api/syncable_service.h b/sync/api/syncable_service.h index bfcab3a..b499a28 100644 --- a/sync/api/syncable_service.h +++ b/sync/api/syncable_service.h @@ -14,7 +14,7 @@ #include "sync/api/sync_change_processor.h" #include "sync/api/sync_data.h" #include "sync/api/sync_error.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" class SyncErrorFactory; diff --git a/sync/engine/DEPS b/sync/engine/DEPS index a22ed7d..af825b6 100644 --- a/sync/engine/DEPS +++ b/sync/engine/DEPS @@ -1,5 +1,9 @@ include_rules = [ "+googleurl", + "+sync/internal_api/public/engine", + "+sync/internal_api/public/sessions", + "+sync/internal_api/public/syncable", + "+sync/internal_api/public/util", "+sync/protocol", "+sync/sessions", "+sync/syncable", diff --git a/sync/engine/cleanup_disabled_types_command.cc b/sync/engine/cleanup_disabled_types_command.cc index 35e61cd..4a774b7 100644 --- a/sync/engine/cleanup_disabled_types_command.cc +++ b/sync/engine/cleanup_disabled_types_command.cc @@ -6,9 +6,9 @@ #include +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/sessions/sync_session.h" #include "sync/sessions/sync_session_context.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable.h" namespace browser_sync { diff --git a/sync/engine/cleanup_disabled_types_command_unittest.cc b/sync/engine/cleanup_disabled_types_command_unittest.cc index daa1365..665c68c 100644 --- a/sync/engine/cleanup_disabled_types_command_unittest.cc +++ b/sync/engine/cleanup_disabled_types_command_unittest.cc @@ -6,11 +6,11 @@ #include "sync/engine/cleanup_disabled_types_command.h" +#include "sync/internal_api/public/syncable/model_type_test_util.h" #include "sync/sessions/sync_session.h" -#include "sync/syncable/model_type_test_util.h" #include "sync/test/engine/syncer_command_test.h" -#include "testing/gtest/include/gtest/gtest.h" #include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" namespace browser_sync { diff --git a/sync/engine/clear_data_command.h b/sync/engine/clear_data_command.h index 5302871..258a99c 100644 --- a/sync/engine/clear_data_command.h +++ b/sync/engine/clear_data_command.h @@ -7,9 +7,9 @@ #pragma once #include "base/basictypes.h" -#include "sync/engine/model_safe_worker.h" #include "sync/engine/syncer_command.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/syncable/model_type.h" namespace browser_sync { diff --git a/sync/engine/commit.h b/sync/engine/commit.h index f5ccd79..f03ceb0 100644 --- a/sync/engine/commit.h +++ b/sync/engine/commit.h @@ -6,7 +6,7 @@ #define SYNC_ENGINE_COMMIT_H_ #pragma once -#include "sync/util/syncer_error.h" +#include "sync/internal_api/public/util/syncer_error.h" namespace browser_sync { diff --git a/sync/engine/download_updates_command.cc b/sync/engine/download_updates_command.cc index 385649c..ef41a76 100644 --- a/sync/engine/download_updates_command.cc +++ b/sync/engine/download_updates_command.cc @@ -10,7 +10,7 @@ #include "sync/engine/syncer.h" #include "sync/engine/syncer_proto_util.h" #include "sync/engine/syncproto.h" -#include "sync/syncable/model_type_payload_map.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/syncable/syncable.h" using sync_pb::DebugInfo; diff --git a/sync/engine/download_updates_command.h b/sync/engine/download_updates_command.h index 9e71610..5eddcce 100644 --- a/sync/engine/download_updates_command.h +++ b/sync/engine/download_updates_command.h @@ -9,10 +9,10 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/gtest_prod_util.h" -#include "sync/engine/model_safe_worker.h" #include "sync/engine/syncer_command.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/sync.pb.h" -#include "sync/syncable/model_type.h" namespace sync_pb { class EntitySpecifics; diff --git a/sync/engine/model_changing_syncer_command.h b/sync/engine/model_changing_syncer_command.h index d09e4b7..e2e8956 100644 --- a/sync/engine/model_changing_syncer_command.h +++ b/sync/engine/model_changing_syncer_command.h @@ -7,8 +7,8 @@ #pragma once #include "base/compiler_specific.h" -#include "sync/engine/model_safe_worker.h" #include "sync/engine/syncer_command.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" namespace browser_sync { namespace sessions { diff --git a/sync/engine/model_changing_syncer_command_unittest.cc b/sync/engine/model_changing_syncer_command_unittest.cc index 615ee51..1f1d93d 100644 --- a/sync/engine/model_changing_syncer_command_unittest.cc +++ b/sync/engine/model_changing_syncer_command_unittest.cc @@ -6,8 +6,8 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "sync/engine/model_changing_syncer_command.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/sessions/sync_session.h" -#include "sync/syncable/model_type.h" #include "sync/test/engine/fake_model_worker.h" #include "sync/test/engine/syncer_command_test.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/sync/engine/model_safe_worker.cc b/sync/engine/model_safe_worker.cc deleted file mode 100644 index a5aa04f..0000000 --- a/sync/engine/model_safe_worker.cc +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2012 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 "sync/engine/model_safe_worker.h" - -#include "base/json/json_writer.h" -#include "base/memory/scoped_ptr.h" -#include "base/values.h" - -namespace browser_sync { - -base::DictionaryValue* ModelSafeRoutingInfoToValue( - const ModelSafeRoutingInfo& routing_info) { - base::DictionaryValue* dict = new base::DictionaryValue(); - for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); - it != routing_info.end(); ++it) { - dict->SetString(syncable::ModelTypeToString(it->first), - ModelSafeGroupToString(it->second)); - } - return dict; -} - -std::string ModelSafeRoutingInfoToString( - const ModelSafeRoutingInfo& routing_info) { - scoped_ptr dict(ModelSafeRoutingInfoToValue(routing_info)); - std::string json; - base::JSONWriter::Write(dict.get(), &json); - return json; -} - -syncable::ModelTypeSet GetRoutingInfoTypes( - const ModelSafeRoutingInfo& routing_info) { - syncable::ModelTypeSet types; - for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); - it != routing_info.end(); ++it) { - types.Put(it->first); - } - return types; -} - -ModelSafeGroup GetGroupForModelType(const syncable::ModelType type, - const ModelSafeRoutingInfo& routes) { - ModelSafeRoutingInfo::const_iterator it = routes.find(type); - if (it == routes.end()) { - if (type != syncable::UNSPECIFIED && type != syncable::TOP_LEVEL_FOLDER) - LOG(WARNING) << "Entry does not belong to active ModelSafeGroup!"; - return GROUP_PASSIVE; - } - return it->second; -} - -std::string ModelSafeGroupToString(ModelSafeGroup group) { - switch (group) { - case GROUP_UI: - return "GROUP_UI"; - case GROUP_DB: - return "GROUP_DB"; - case GROUP_FILE: - return "GROUP_FILE"; - case GROUP_HISTORY: - return "GROUP_HISTORY"; - case GROUP_PASSIVE: - return "GROUP_PASSIVE"; - case GROUP_PASSWORD: - return "GROUP_PASSWORD"; - default: - NOTREACHED(); - return "INVALID"; - } -} - -ModelSafeWorker::~ModelSafeWorker() {} - -} // namespace browser_sync diff --git a/sync/engine/model_safe_worker.h b/sync/engine/model_safe_worker.h deleted file mode 100644 index e3f3964..0000000 --- a/sync/engine/model_safe_worker.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) 2012 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 SYNC_ENGINE_MODEL_SAFE_WORKER_H_ -#define SYNC_ENGINE_MODEL_SAFE_WORKER_H_ -#pragma once - -#include -#include -#include - -#include "base/callback.h" -#include "base/memory/ref_counted.h" -#include "sync/syncable/model_type.h" -#include "sync/util/syncer_error.h" - -namespace base { -class DictionaryValue; -} // namespace - -namespace browser_sync { - -typedef base::Callback WorkCallback; - -enum ModelSafeGroup { - GROUP_PASSIVE = 0, // Models that are just "passively" being synced; e.g. - // changes to these models don't need to be pushed to a - // native model. - GROUP_UI, // Models that live on UI thread and are being synced. - GROUP_DB, // Models that live on DB thread and are being synced. - GROUP_FILE, // Models that live on FILE thread and are being synced. - GROUP_HISTORY, // Models that live on history thread and are being - // synced. - GROUP_PASSWORD, // Models that live on the password thread and are - // being synced. On windows and linux, this runs on the - // DB thread. - MODEL_SAFE_GROUP_COUNT, -}; - -std::string ModelSafeGroupToString(ModelSafeGroup group); - -// The Syncer uses a ModelSafeWorker for all tasks that could potentially -// modify syncable entries (e.g under a WriteTransaction). The ModelSafeWorker -// only knows how to do one thing, and that is take some work (in a fully -// pre-bound callback) and have it performed (as in Run()) from a thread which -// is guaranteed to be "model-safe", where "safe" refers to not allowing us to -// cause an embedding application model to fall out of sync with the -// syncable::Directory due to a race. -class ModelSafeWorker : public base::RefCountedThreadSafe { - public: - // Any time the Syncer performs model modifications (e.g employing a - // WriteTransaction), it should be done by this method to ensure it is done - // from a model-safe thread. - virtual SyncerError DoWorkAndWaitUntilDone(const WorkCallback& work) = 0; - - virtual ModelSafeGroup GetModelSafeGroup() = 0; - - protected: - virtual ~ModelSafeWorker(); - - private: - friend class base::RefCountedThreadSafe; -}; - -// A map that details which ModelSafeGroup each syncable::ModelType -// belongs to. Routing info can change in response to the user enabling / -// disabling sync for certain types, as well as model association completions. -typedef std::map - ModelSafeRoutingInfo; - -// Caller takes ownership of return value. -base::DictionaryValue* ModelSafeRoutingInfoToValue( - const ModelSafeRoutingInfo& routing_info); - -std::string ModelSafeRoutingInfoToString( - const ModelSafeRoutingInfo& routing_info); - -syncable::ModelTypeSet GetRoutingInfoTypes( - const ModelSafeRoutingInfo& routing_info); - -ModelSafeGroup GetGroupForModelType(const syncable::ModelType type, - const ModelSafeRoutingInfo& routes); - -} // namespace browser_sync - -#endif // SYNC_ENGINE_MODEL_SAFE_WORKER_H_ diff --git a/sync/engine/model_safe_worker_unittest.cc b/sync/engine/model_safe_worker_unittest.cc deleted file mode 100644 index 741c724..0000000 --- a/sync/engine/model_safe_worker_unittest.cc +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2012 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 "sync/engine/model_safe_worker.h" - -#include "base/memory/scoped_ptr.h" -#include "base/values.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace browser_sync { -namespace { - -class ModelSafeWorkerTest : public ::testing::Test { -}; - -TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToValue) { - ModelSafeRoutingInfo routing_info; - routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; - routing_info[syncable::NIGORI] = GROUP_UI; - routing_info[syncable::PREFERENCES] = GROUP_DB; - DictionaryValue expected_value; - expected_value.SetString("Bookmarks", "GROUP_PASSIVE"); - expected_value.SetString("Encryption keys", "GROUP_UI"); - expected_value.SetString("Preferences", "GROUP_DB"); - scoped_ptr value( - ModelSafeRoutingInfoToValue(routing_info)); - EXPECT_TRUE(value->Equals(&expected_value)); -} - -TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToString) { - ModelSafeRoutingInfo routing_info; - routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; - routing_info[syncable::NIGORI] = GROUP_UI; - routing_info[syncable::PREFERENCES] = GROUP_DB; - EXPECT_EQ( - "{\"Bookmarks\":\"GROUP_PASSIVE\",\"Encryption keys\":\"GROUP_UI\"," - "\"Preferences\":\"GROUP_DB\"}", - ModelSafeRoutingInfoToString(routing_info)); -} - -TEST_F(ModelSafeWorkerTest, GetRoutingInfoTypes) { - ModelSafeRoutingInfo routing_info; - routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; - routing_info[syncable::NIGORI] = GROUP_UI; - routing_info[syncable::PREFERENCES] = GROUP_DB; - const syncable::ModelTypeSet expected_types( - syncable::BOOKMARKS, - syncable::NIGORI, - syncable::PREFERENCES); - EXPECT_TRUE(GetRoutingInfoTypes(routing_info).Equals(expected_types)); -} - -} // namespace -} // namespace browser_sync diff --git a/sync/engine/nigori_util.h b/sync/engine/nigori_util.h index 67174c3..2adcc9f 100644 --- a/sync/engine/nigori_util.h +++ b/sync/engine/nigori_util.h @@ -9,8 +9,8 @@ #pragma once #include "base/compiler_specific.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/nigori_specifics.pb.h" -#include "sync/syncable/model_type.h" namespace browser_sync { class Cryptographer; diff --git a/sync/engine/passive_model_worker.cc b/sync/engine/passive_model_worker.cc deleted file mode 100644 index 0b0d423..0000000 --- a/sync/engine/passive_model_worker.cc +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2012 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 "sync/engine/passive_model_worker.h" - -#include "base/message_loop.h" - -namespace browser_sync { - -PassiveModelWorker::PassiveModelWorker(const MessageLoop* sync_loop) - : sync_loop_(sync_loop) {} - -PassiveModelWorker::~PassiveModelWorker() { -} - -SyncerError PassiveModelWorker::DoWorkAndWaitUntilDone( - const WorkCallback& work) { - DCHECK_EQ(MessageLoop::current(), sync_loop_); - // Simply do the work on the current thread. - return work.Run(); -} - -ModelSafeGroup PassiveModelWorker::GetModelSafeGroup() { - return GROUP_PASSIVE; -} - -} // namespace browser_sync diff --git a/sync/engine/passive_model_worker.h b/sync/engine/passive_model_worker.h deleted file mode 100644 index a8b89f7..0000000 --- a/sync/engine/passive_model_worker.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2012 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 SYNC_ENGINE_PASSIVE_MODEL_WORKER_H_ -#define SYNC_ENGINE_PASSIVE_MODEL_WORKER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "sync/engine/model_safe_worker.h" -#include "sync/util/syncer_error.h" - -class MessageLoop; - -namespace browser_sync { - -// Implementation of ModelSafeWorker for passive types. All work is -// done on the same thread DoWorkAndWaitUntilDone (i.e., the sync -// thread). -class PassiveModelWorker : public ModelSafeWorker { - public: - explicit PassiveModelWorker(const MessageLoop* sync_loop); - - // ModelSafeWorker implementation. Called on the sync thread. - virtual SyncerError DoWorkAndWaitUntilDone( - const WorkCallback& work) OVERRIDE; - virtual ModelSafeGroup GetModelSafeGroup() OVERRIDE; - - private: - virtual ~PassiveModelWorker(); - - const MessageLoop* const sync_loop_; - - DISALLOW_COPY_AND_ASSIGN(PassiveModelWorker); -}; - -} // namespace browser_sync - -#endif // SYNC_ENGINE_PASSIVE_MODEL_WORKER_H_ diff --git a/sync/engine/polling_constants.cc b/sync/engine/polling_constants.cc deleted file mode 100644 index c1f8e37..0000000 --- a/sync/engine/polling_constants.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2012 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/basictypes.h" -#include "sync/engine/polling_constants.h" - -namespace browser_sync { - -// Server can overwrite these values via client commands. -// Standard short poll. This is used when XMPP is off. -// We use high values here to ensure that failure to receive poll updates from -// the server doesn't result in rapid-fire polling from the client due to low -// local limits. -const int64 kDefaultShortPollIntervalSeconds = 3600 * 8; -// Long poll is used when XMPP is on. -const int64 kDefaultLongPollIntervalSeconds = 3600 * 12; - -// Maximum interval for exponential backoff. -const int64 kMaxBackoffSeconds = 60 * 60 * 4; // 4 hours. - -// Backoff interval randomization factor. -const int kBackoffRandomizationFactor = 2; - -} // namespace browser_sync - diff --git a/sync/engine/polling_constants.h b/sync/engine/polling_constants.h deleted file mode 100644 index ff6650c..0000000 --- a/sync/engine/polling_constants.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2012 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. -// -// Constants used by SyncerThread when polling servers for updates. - -#ifndef SYNC_ENGINE_POLLING_CONSTANTS_H_ -#define SYNC_ENGINE_POLLING_CONSTANTS_H_ -#pragma once - -namespace browser_sync { - -extern const int64 kDefaultShortPollIntervalSeconds; -extern const int64 kDefaultLongPollIntervalSeconds; -extern const int64 kMaxBackoffSeconds; -extern const int kBackoffRandomizationFactor; - -} // namespace browser_sync - -#endif // SYNC_ENGINE_POLLING_CONSTANTS_H_ diff --git a/sync/engine/process_updates_command_unittest.cc b/sync/engine/process_updates_command_unittest.cc index 1c6a786..448daea 100644 --- a/sync/engine/process_updates_command_unittest.cc +++ b/sync/engine/process_updates_command_unittest.cc @@ -5,9 +5,9 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" #include "sync/engine/process_updates_command.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/sessions/session_state.h" #include "sync/sessions/sync_session.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable_id.h" #include "sync/test/engine/fake_model_worker.h" #include "sync/test/engine/syncer_command_test.h" diff --git a/sync/engine/resolve_conflicts_command_unittest.cc b/sync/engine/resolve_conflicts_command_unittest.cc index 079683a..0265317 100644 --- a/sync/engine/resolve_conflicts_command_unittest.cc +++ b/sync/engine/resolve_conflicts_command_unittest.cc @@ -5,8 +5,8 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" #include "sync/engine/resolve_conflicts_command.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/sessions/sync_session.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable_id.h" #include "sync/test/engine/fake_model_worker.h" #include "sync/test/engine/syncer_command_test.h" diff --git a/sync/engine/store_timestamps_command.cc b/sync/engine/store_timestamps_command.cc index e35e6c7..e942328 100644 --- a/sync/engine/store_timestamps_command.cc +++ b/sync/engine/store_timestamps_command.cc @@ -4,9 +4,9 @@ #include "sync/engine/store_timestamps_command.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/sessions/status_controller.h" #include "sync/sessions/sync_session.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable.h" namespace browser_sync { diff --git a/sync/engine/sync_engine_event.h b/sync/engine/sync_engine_event.h index 9198ded..e9c52a7 100644 --- a/sync/engine/sync_engine_event.h +++ b/sync/engine/sync_engine_event.h @@ -9,9 +9,7 @@ #include #include "base/observer_list.h" -#include "sync/sessions/session_state.h" -#include "sync/sessions/sync_session_snapshot.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/sessions/sync_session_snapshot.h" namespace syncable { class Id; diff --git a/sync/engine/sync_scheduler.h b/sync/engine/sync_scheduler.h index dfd63e4..bdf07bc 100644 --- a/sync/engine/sync_scheduler.h +++ b/sync/engine/sync_scheduler.h @@ -20,11 +20,11 @@ #include "base/timer.h" #include "sync/engine/net/server_connection_manager.h" #include "sync/engine/nudge_source.h" -#include "sync/engine/polling_constants.h" #include "sync/engine/syncer.h" +#include "sync/internal_api/public/engine/polling_constants.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/sessions/sync_session.h" #include "sync/sessions/sync_session_context.h" -#include "sync/syncable/model_type_payload_map.h" #include "sync/util/weak_handle.h" class MessageLoop; diff --git a/sync/engine/syncer.h b/sync/engine/syncer.h index a5b7fc8..6092f64 100644 --- a/sync/engine/syncer.h +++ b/sync/engine/syncer.h @@ -15,8 +15,8 @@ #include "sync/engine/conflict_resolver.h" #include "sync/engine/syncer_types.h" #include "sync/engine/syncproto.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/sessions/sync_session.h" -#include "sync/syncable/model_type.h" #include "sync/util/extensions_activity_monitor.h" namespace syncable { diff --git a/sync/engine/syncer_command.h b/sync/engine/syncer_command.h index 8095467..949d8fd 100644 --- a/sync/engine/syncer_command.h +++ b/sync/engine/syncer_command.h @@ -8,7 +8,7 @@ #include "base/basictypes.h" -#include "sync/util/syncer_error.h" +#include "sync/internal_api/public/util/syncer_error.h" namespace browser_sync { diff --git a/sync/engine/syncer_proto_util.cc b/sync/engine/syncer_proto_util.cc index 23bdf45..bdadda1 100644 --- a/sync/engine/syncer_proto_util.cc +++ b/sync/engine/syncer_proto_util.cc @@ -10,11 +10,11 @@ #include "sync/engine/syncer.h" #include "sync/engine/syncer_types.h" #include "sync/engine/traffic_logger.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/sync.pb.h" #include "sync/protocol/sync_enums.pb.h" #include "sync/protocol/sync_protocol_error.h" #include "sync/sessions/sync_session.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable-inl.h" #include "sync/syncable/syncable.h" #include "sync/util/time.h" diff --git a/sync/engine/syncer_proto_util.h b/sync/engine/syncer_proto_util.h index e8086b5..14a3791 100644 --- a/sync/engine/syncer_proto_util.h +++ b/sync/engine/syncer_proto_util.h @@ -10,10 +10,10 @@ #include "base/gtest_prod_util.h" #include "base/time.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/util/syncer_error.h" #include "sync/sessions/sync_session.h" #include "sync/syncable/blob.h" -#include "sync/syncable/model_type.h" -#include "sync/util/syncer_error.h" namespace syncable { class Directory; diff --git a/sync/engine/syncer_proto_util_unittest.cc b/sync/engine/syncer_proto_util_unittest.cc index d70a07b..a1431ab 100644 --- a/sync/engine/syncer_proto_util_unittest.cc +++ b/sync/engine/syncer_proto_util_unittest.cc @@ -11,17 +11,17 @@ #include "base/message_loop.h" #include "base/time.h" #include "sync/engine/syncproto.h" +#include "sync/internal_api/public/syncable/model_type_test_util.h" +#include "sync/protocol/bookmark_specifics.pb.h" +#include "sync/protocol/password_specifics.pb.h" +#include "sync/protocol/sync.pb.h" +#include "sync/protocol/sync_enums.pb.h" #include "sync/sessions/session_state.h" #include "sync/sessions/sync_session_context.h" #include "sync/syncable/blob.h" -#include "sync/syncable/model_type_test_util.h" #include "sync/syncable/syncable.h" #include "sync/test/engine/mock_connection_manager.h" #include "sync/test/engine/test_directory_setter_upper.h" -#include "sync/protocol/bookmark_specifics.pb.h" -#include "sync/protocol/password_specifics.pb.h" -#include "sync/protocol/sync.pb.h" -#include "sync/protocol/sync_enums.pb.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc index 0f698f4..65742eb3 100644 --- a/sync/engine/syncer_unittest.cc +++ b/sync/engine/syncer_unittest.cc @@ -24,22 +24,22 @@ #include "base/time.h" #include "build/build_config.h" #include "sync/engine/get_commit_ids_command.h" -#include "sync/engine/model_safe_worker.h" #include "sync/engine/net/server_connection_manager.h" #include "sync/engine/nigori_util.h" #include "sync/engine/process_updates_command.h" +#include "sync/engine/sync_scheduler.h" #include "sync/engine/syncer.h" #include "sync/engine/syncer_proto_util.h" #include "sync/engine/syncer_util.h" #include "sync/engine/syncproto.h" #include "sync/engine/traffic_recorder.h" -#include "sync/engine/sync_scheduler.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/bookmark_specifics.pb.h" #include "sync/protocol/nigori_specifics.pb.h" #include "sync/protocol/preference_specifics.pb.h" #include "sync/protocol/sync.pb.h" #include "sync/sessions/sync_session_context.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable.h" #include "sync/test/engine/fake_model_worker.h" #include "sync/test/engine/mock_connection_manager.h" diff --git a/sync/engine/syncer_util.cc b/sync/engine/syncer_util.cc index 710a11b..4f184bd 100644 --- a/sync/engine/syncer_util.cc +++ b/sync/engine/syncer_util.cc @@ -16,11 +16,11 @@ #include "sync/engine/syncer_proto_util.h" #include "sync/engine/syncer_types.h" #include "sync/engine/syncproto.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/bookmark_specifics.pb.h" #include "sync/protocol/nigori_specifics.pb.h" #include "sync/protocol/password_specifics.pb.h" #include "sync/protocol/sync.pb.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable.h" #include "sync/syncable/syncable_changes_version.h" #include "sync/util/cryptographer.h" diff --git a/sync/engine/syncproto.h b/sync/engine/syncproto.h index 101585f..0f4e21c 100644 --- a/sync/engine/syncproto.h +++ b/sync/engine/syncproto.h @@ -8,8 +8,8 @@ #define SYNC_ENGINE_SYNCPROTO_H_ #pragma once +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/sync.pb.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable_id.h" namespace browser_sync { diff --git a/sync/engine/update_applicator.h b/sync/engine/update_applicator.h index 024ccfa..0e28180 100644 --- a/sync/engine/update_applicator.h +++ b/sync/engine/update_applicator.h @@ -16,7 +16,7 @@ #include "base/basictypes.h" #include "base/port.h" -#include "sync/engine/model_safe_worker.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" #include "sync/syncable/syncable.h" namespace browser_sync { diff --git a/sync/engine/verify_updates_command.cc b/sync/engine/verify_updates_command.cc index f590b94..0ba0d16 100644 --- a/sync/engine/verify_updates_command.cc +++ b/sync/engine/verify_updates_command.cc @@ -7,12 +7,12 @@ #include #include "base/location.h" -#include "sync/engine/model_safe_worker.h" #include "sync/engine/syncer.h" #include "sync/engine/syncer_proto_util.h" #include "sync/engine/syncer_types.h" #include "sync/engine/syncer_util.h" #include "sync/engine/syncproto.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" #include "sync/protocol/bookmark_specifics.pb.h" #include "sync/syncable/syncable.h" diff --git a/sync/engine/verify_updates_command.h b/sync/engine/verify_updates_command.h index 8ccc471..09376f2 100644 --- a/sync/engine/verify_updates_command.h +++ b/sync/engine/verify_updates_command.h @@ -9,9 +9,9 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "sync/engine/model_changing_syncer_command.h" -#include "sync/engine/model_safe_worker.h" #include "sync/engine/syncer_types.h" #include "sync/engine/syncproto.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" namespace syncable { class WriteTransaction; diff --git a/sync/engine/verify_updates_command_unittest.cc b/sync/engine/verify_updates_command_unittest.cc index 20a6cf6..5f7356e 100644 --- a/sync/engine/verify_updates_command_unittest.cc +++ b/sync/engine/verify_updates_command_unittest.cc @@ -4,13 +4,13 @@ #include "base/location.h" #include "sync/engine/verify_updates_command.h" +#include "sync/protocol/bookmark_specifics.pb.h" #include "sync/sessions/session_state.h" #include "sync/sessions/sync_session.h" #include "sync/syncable/syncable.h" #include "sync/syncable/syncable_id.h" #include "sync/test/engine/fake_model_worker.h" #include "sync/test/engine/syncer_command_test.h" -#include "sync/protocol/bookmark_specifics.pb.h" #include "testing/gtest/include/gtest/gtest.h" namespace browser_sync { diff --git a/sync/internal_api/all_status.cc b/sync/internal_api/all_status.cc index 194f26b..a8a7efd 100644 --- a/sync/internal_api/all_status.cc +++ b/sync/internal_api/all_status.cc @@ -9,8 +9,8 @@ #include "base/logging.h" #include "base/port.h" #include "sync/engine/net/server_connection_manager.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/sessions/session_state.h" -#include "sync/syncable/model_type.h" namespace browser_sync { diff --git a/sync/internal_api/all_status.h b/sync/internal_api/all_status.h index 0f1d5b0..f60b9ea 100644 --- a/sync/internal_api/all_status.h +++ b/sync/internal_api/all_status.h @@ -14,10 +14,10 @@ #include "base/compiler_specific.h" #include "base/synchronization/lock.h" -#include "sync/engine/syncer_types.h" #include "sync/engine/sync_engine_event.h" +#include "sync/engine/syncer_types.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/internal_api/sync_manager.h" -#include "sync/syncable/model_type.h" namespace browser_sync { diff --git a/sync/internal_api/base_node.h b/sync/internal_api/base_node.h index 42c3b80..f59753f 100644 --- a/sync/internal_api/base_node.h +++ b/sync/internal_api/base_node.h @@ -13,8 +13,8 @@ #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" #include "googleurl/src/gurl.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/sync.pb.h" -#include "sync/syncable/model_type.h" // Forward declarations of internal class types so that sync API objects // may have opaque pointers to these types. diff --git a/sync/internal_api/change_reorder_buffer.cc b/sync/internal_api/change_reorder_buffer.cc index 7fbada4..b92a590 100644 --- a/sync/internal_api/change_reorder_buffer.cc +++ b/sync/internal_api/change_reorder_buffer.cc @@ -10,8 +10,8 @@ #include // for pair<> #include +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/internal_api/read_node.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable.h" using std::numeric_limits; diff --git a/sync/internal_api/debug_info_event_listener.h b/sync/internal_api/debug_info_event_listener.h index 64a90f9..06c420b 100644 --- a/sync/internal_api/debug_info_event_listener.h +++ b/sync/internal_api/debug_info_event_listener.h @@ -9,12 +9,12 @@ #include #include "base/compiler_specific.h" +#include "sync/internal_api/public/sessions/sync_session_snapshot.h" #include "sync/internal_api/sync_manager.h" #include "sync/js/js_backend.h" #include "sync/protocol/sync.pb.h" #include "sync/sessions/debug_info_getter.h" #include "sync/sessions/session_state.h" -#include "sync/sessions/sync_session_snapshot.h" #include "sync/util/weak_handle.h" namespace sync_api { diff --git a/sync/internal_api/js_mutation_event_observer_unittest.cc b/sync/internal_api/js_mutation_event_observer_unittest.cc index 4092b82..1e65f4b 100644 --- a/sync/internal_api/js_mutation_event_observer_unittest.cc +++ b/sync/internal_api/js_mutation_event_observer_unittest.cc @@ -7,9 +7,9 @@ #include "base/basictypes.h" #include "base/message_loop.h" #include "base/values.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/js/js_event_details.h" #include "sync/js/js_test_util.h" -#include "sync/syncable/model_type.h" #include "sync/util/weak_handle.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/sync/internal_api/js_sync_manager_observer.cc b/sync/internal_api/js_sync_manager_observer.cc index 1541680..e392ddf 100644 --- a/sync/internal_api/js_sync_manager_observer.cc +++ b/sync/internal_api/js_sync_manager_observer.cc @@ -11,12 +11,12 @@ #include "base/string_number_conversions.h" #include "base/values.h" #include "sync/internal_api/change_record.h" +#include "sync/internal_api/public/sessions/sync_session_snapshot.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/js/js_arg_list.h" #include "sync/js/js_event_details.h" #include "sync/js/js_event_handler.h" #include "sync/sessions/session_state.h" -#include "sync/sessions/sync_session_snapshot.h" -#include "sync/syncable/model_type.h" namespace browser_sync { diff --git a/sync/internal_api/js_sync_manager_observer_unittest.cc b/sync/internal_api/js_sync_manager_observer_unittest.cc index d796b3c..5b28223 100644 --- a/sync/internal_api/js_sync_manager_observer_unittest.cc +++ b/sync/internal_api/js_sync_manager_observer_unittest.cc @@ -8,12 +8,11 @@ #include "base/location.h" #include "base/message_loop.h" #include "base/values.h" +#include "sync/internal_api/public/sessions/sync_session_snapshot.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/js/js_event_details.h" #include "sync/js/js_test_util.h" #include "sync/protocol/sync_protocol_error.h" -#include "sync/sessions/sync_session_snapshot.h" -#include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" #include "sync/util/weak_handle.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/sync/internal_api/public/DEPS b/sync/internal_api/public/DEPS new file mode 100644 index 0000000..2a51ace --- /dev/null +++ b/sync/internal_api/public/DEPS @@ -0,0 +1,5 @@ +include_rules = [ + "-sync", + "+sync/internal_api/public", + "+sync/protocol", +] diff --git a/sync/internal_api/public/engine/model_safe_worker.cc b/sync/internal_api/public/engine/model_safe_worker.cc new file mode 100644 index 0000000..2718acc --- /dev/null +++ b/sync/internal_api/public/engine/model_safe_worker.cc @@ -0,0 +1,75 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/engine/model_safe_worker.h" + +#include "base/json/json_writer.h" +#include "base/memory/scoped_ptr.h" +#include "base/values.h" + +namespace browser_sync { + +base::DictionaryValue* ModelSafeRoutingInfoToValue( + const ModelSafeRoutingInfo& routing_info) { + base::DictionaryValue* dict = new base::DictionaryValue(); + for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); + it != routing_info.end(); ++it) { + dict->SetString(syncable::ModelTypeToString(it->first), + ModelSafeGroupToString(it->second)); + } + return dict; +} + +std::string ModelSafeRoutingInfoToString( + const ModelSafeRoutingInfo& routing_info) { + scoped_ptr dict(ModelSafeRoutingInfoToValue(routing_info)); + std::string json; + base::JSONWriter::Write(dict.get(), &json); + return json; +} + +syncable::ModelTypeSet GetRoutingInfoTypes( + const ModelSafeRoutingInfo& routing_info) { + syncable::ModelTypeSet types; + for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); + it != routing_info.end(); ++it) { + types.Put(it->first); + } + return types; +} + +ModelSafeGroup GetGroupForModelType(const syncable::ModelType type, + const ModelSafeRoutingInfo& routes) { + ModelSafeRoutingInfo::const_iterator it = routes.find(type); + if (it == routes.end()) { + if (type != syncable::UNSPECIFIED && type != syncable::TOP_LEVEL_FOLDER) + LOG(WARNING) << "Entry does not belong to active ModelSafeGroup!"; + return GROUP_PASSIVE; + } + return it->second; +} + +std::string ModelSafeGroupToString(ModelSafeGroup group) { + switch (group) { + case GROUP_UI: + return "GROUP_UI"; + case GROUP_DB: + return "GROUP_DB"; + case GROUP_FILE: + return "GROUP_FILE"; + case GROUP_HISTORY: + return "GROUP_HISTORY"; + case GROUP_PASSIVE: + return "GROUP_PASSIVE"; + case GROUP_PASSWORD: + return "GROUP_PASSWORD"; + default: + NOTREACHED(); + return "INVALID"; + } +} + +ModelSafeWorker::~ModelSafeWorker() {} + +} // namespace browser_sync diff --git a/sync/internal_api/public/engine/model_safe_worker.h b/sync/internal_api/public/engine/model_safe_worker.h new file mode 100644 index 0000000..1a6c371 --- /dev/null +++ b/sync/internal_api/public/engine/model_safe_worker.h @@ -0,0 +1,87 @@ +// Copyright (c) 2012 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 SYNC_INTERNAL_API_PUBLIC_ENGINE_MODEL_SAFE_WORKER_H_ +#define SYNC_INTERNAL_API_PUBLIC_ENGINE_MODEL_SAFE_WORKER_H_ +#pragma once + +#include +#include +#include + +#include "base/callback.h" +#include "base/memory/ref_counted.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/util/syncer_error.h" + +namespace base { +class DictionaryValue; +} // namespace + +namespace browser_sync { + +typedef base::Callback WorkCallback; + +enum ModelSafeGroup { + GROUP_PASSIVE = 0, // Models that are just "passively" being synced; e.g. + // changes to these models don't need to be pushed to a + // native model. + GROUP_UI, // Models that live on UI thread and are being synced. + GROUP_DB, // Models that live on DB thread and are being synced. + GROUP_FILE, // Models that live on FILE thread and are being synced. + GROUP_HISTORY, // Models that live on history thread and are being + // synced. + GROUP_PASSWORD, // Models that live on the password thread and are + // being synced. On windows and linux, this runs on the + // DB thread. + MODEL_SAFE_GROUP_COUNT, +}; + +std::string ModelSafeGroupToString(ModelSafeGroup group); + +// The Syncer uses a ModelSafeWorker for all tasks that could potentially +// modify syncable entries (e.g under a WriteTransaction). The ModelSafeWorker +// only knows how to do one thing, and that is take some work (in a fully +// pre-bound callback) and have it performed (as in Run()) from a thread which +// is guaranteed to be "model-safe", where "safe" refers to not allowing us to +// cause an embedding application model to fall out of sync with the +// syncable::Directory due to a race. +class ModelSafeWorker : public base::RefCountedThreadSafe { + public: + // Any time the Syncer performs model modifications (e.g employing a + // WriteTransaction), it should be done by this method to ensure it is done + // from a model-safe thread. + virtual SyncerError DoWorkAndWaitUntilDone(const WorkCallback& work) = 0; + + virtual ModelSafeGroup GetModelSafeGroup() = 0; + + protected: + virtual ~ModelSafeWorker(); + + private: + friend class base::RefCountedThreadSafe; +}; + +// A map that details which ModelSafeGroup each syncable::ModelType +// belongs to. Routing info can change in response to the user enabling / +// disabling sync for certain types, as well as model association completions. +typedef std::map + ModelSafeRoutingInfo; + +// Caller takes ownership of return value. +base::DictionaryValue* ModelSafeRoutingInfoToValue( + const ModelSafeRoutingInfo& routing_info); + +std::string ModelSafeRoutingInfoToString( + const ModelSafeRoutingInfo& routing_info); + +syncable::ModelTypeSet GetRoutingInfoTypes( + const ModelSafeRoutingInfo& routing_info); + +ModelSafeGroup GetGroupForModelType(const syncable::ModelType type, + const ModelSafeRoutingInfo& routes); + +} // namespace browser_sync + +#endif // SYNC_INTERNAL_API_PUBLIC_ENGINE_MODEL_SAFE_WORKER_H_ diff --git a/sync/internal_api/public/engine/model_safe_worker_unittest.cc b/sync/internal_api/public/engine/model_safe_worker_unittest.cc new file mode 100644 index 0000000..5304c13 --- /dev/null +++ b/sync/internal_api/public/engine/model_safe_worker_unittest.cc @@ -0,0 +1,55 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/engine/model_safe_worker.h" + +#include "base/memory/scoped_ptr.h" +#include "base/values.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace browser_sync { +namespace { + +class ModelSafeWorkerTest : public ::testing::Test { +}; + +TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToValue) { + ModelSafeRoutingInfo routing_info; + routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; + routing_info[syncable::NIGORI] = GROUP_UI; + routing_info[syncable::PREFERENCES] = GROUP_DB; + DictionaryValue expected_value; + expected_value.SetString("Bookmarks", "GROUP_PASSIVE"); + expected_value.SetString("Encryption keys", "GROUP_UI"); + expected_value.SetString("Preferences", "GROUP_DB"); + scoped_ptr value( + ModelSafeRoutingInfoToValue(routing_info)); + EXPECT_TRUE(value->Equals(&expected_value)); +} + +TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToString) { + ModelSafeRoutingInfo routing_info; + routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; + routing_info[syncable::NIGORI] = GROUP_UI; + routing_info[syncable::PREFERENCES] = GROUP_DB; + EXPECT_EQ( + "{\"Bookmarks\":\"GROUP_PASSIVE\",\"Encryption keys\":\"GROUP_UI\"," + "\"Preferences\":\"GROUP_DB\"}", + ModelSafeRoutingInfoToString(routing_info)); +} + +TEST_F(ModelSafeWorkerTest, GetRoutingInfoTypes) { + ModelSafeRoutingInfo routing_info; + routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; + routing_info[syncable::NIGORI] = GROUP_UI; + routing_info[syncable::PREFERENCES] = GROUP_DB; + const syncable::ModelTypeSet expected_types( + syncable::BOOKMARKS, + syncable::NIGORI, + syncable::PREFERENCES); + EXPECT_TRUE(GetRoutingInfoTypes(routing_info).Equals(expected_types)); +} + +} // namespace +} // namespace browser_sync diff --git a/sync/internal_api/public/engine/passive_model_worker.cc b/sync/internal_api/public/engine/passive_model_worker.cc new file mode 100644 index 0000000..26fccc1 --- /dev/null +++ b/sync/internal_api/public/engine/passive_model_worker.cc @@ -0,0 +1,28 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/engine/passive_model_worker.h" + +#include "base/message_loop.h" + +namespace browser_sync { + +PassiveModelWorker::PassiveModelWorker(const MessageLoop* sync_loop) + : sync_loop_(sync_loop) {} + +PassiveModelWorker::~PassiveModelWorker() { +} + +SyncerError PassiveModelWorker::DoWorkAndWaitUntilDone( + const WorkCallback& work) { + DCHECK_EQ(MessageLoop::current(), sync_loop_); + // Simply do the work on the current thread. + return work.Run(); +} + +ModelSafeGroup PassiveModelWorker::GetModelSafeGroup() { + return GROUP_PASSIVE; +} + +} // namespace browser_sync diff --git a/sync/internal_api/public/engine/passive_model_worker.h b/sync/internal_api/public/engine/passive_model_worker.h new file mode 100644 index 0000000..7c0ddf3 --- /dev/null +++ b/sync/internal_api/public/engine/passive_model_worker.h @@ -0,0 +1,40 @@ +// Copyright (c) 2012 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 SYNC_INTERNAL_API_PUBLIC_ENGINE_PASSIVE_MODEL_WORKER_H_ +#define SYNC_INTERNAL_API_PUBLIC_ENGINE_PASSIVE_MODEL_WORKER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/util/syncer_error.h" + +class MessageLoop; + +namespace browser_sync { + +// Implementation of ModelSafeWorker for passive types. All work is +// done on the same thread DoWorkAndWaitUntilDone (i.e., the sync +// thread). +class PassiveModelWorker : public ModelSafeWorker { + public: + explicit PassiveModelWorker(const MessageLoop* sync_loop); + + // ModelSafeWorker implementation. Called on the sync thread. + virtual SyncerError DoWorkAndWaitUntilDone( + const WorkCallback& work) OVERRIDE; + virtual ModelSafeGroup GetModelSafeGroup() OVERRIDE; + + private: + virtual ~PassiveModelWorker(); + + const MessageLoop* const sync_loop_; + + DISALLOW_COPY_AND_ASSIGN(PassiveModelWorker); +}; + +} // namespace browser_sync + +#endif // SYNC_INTERNAL_API_PUBLIC_ENGINE_PASSIVE_MODEL_WORKER_H_ diff --git a/sync/internal_api/public/engine/polling_constants.cc b/sync/internal_api/public/engine/polling_constants.cc new file mode 100644 index 0000000..d7fe753 --- /dev/null +++ b/sync/internal_api/public/engine/polling_constants.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2012 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/basictypes.h" +#include "sync/internal_api/public/engine/polling_constants.h" + +namespace browser_sync { + +// Server can overwrite these values via client commands. +// Standard short poll. This is used when XMPP is off. +// We use high values here to ensure that failure to receive poll updates from +// the server doesn't result in rapid-fire polling from the client due to low +// local limits. +const int64 kDefaultShortPollIntervalSeconds = 3600 * 8; +// Long poll is used when XMPP is on. +const int64 kDefaultLongPollIntervalSeconds = 3600 * 12; + +// Maximum interval for exponential backoff. +const int64 kMaxBackoffSeconds = 60 * 60 * 4; // 4 hours. + +// Backoff interval randomization factor. +const int kBackoffRandomizationFactor = 2; + +} // namespace browser_sync + diff --git a/sync/internal_api/public/engine/polling_constants.h b/sync/internal_api/public/engine/polling_constants.h new file mode 100644 index 0000000..9adfe92 --- /dev/null +++ b/sync/internal_api/public/engine/polling_constants.h @@ -0,0 +1,20 @@ +// Copyright (c) 2012 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. +// +// Constants used by SyncScheduler when polling servers for updates. + +#ifndef SYNC_INTERNAL_API_PUBLIC_ENGINE_POLLING_CONSTANTS_H_ +#define SYNC_INTERNAL_API_PUBLIC_ENGINE_POLLING_CONSTANTS_H_ +#pragma once + +namespace browser_sync { + +extern const int64 kDefaultShortPollIntervalSeconds; +extern const int64 kDefaultLongPollIntervalSeconds; +extern const int64 kMaxBackoffSeconds; +extern const int kBackoffRandomizationFactor; + +} // namespace browser_sync + +#endif // SYNC_INTERNAL_API_PUBLIC_ENGINE_POLLING_CONSTANTS_H_ diff --git a/sync/internal_api/public/sessions/error_counters.cc b/sync/internal_api/public/sessions/error_counters.cc new file mode 100644 index 0000000..72ed2d1 --- /dev/null +++ b/sync/internal_api/public/sessions/error_counters.cc @@ -0,0 +1,17 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/sessions/error_counters.h" + +namespace browser_sync { +namespace sessions { + +ErrorCounters::ErrorCounters() + : last_download_updates_result(UNSET), + last_post_commit_result(UNSET), + last_process_commit_response_result(UNSET) { +} + +} // namespace sessions +} // namespace browser_sync diff --git a/sync/internal_api/public/sessions/error_counters.h b/sync/internal_api/public/sessions/error_counters.h new file mode 100644 index 0000000..a2f528c --- /dev/null +++ b/sync/internal_api/public/sessions/error_counters.h @@ -0,0 +1,33 @@ +// Copyright (c) 2012 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 SYNC_INTERNAL_API_PUBLIC_SESSIONS_ERROR_COUNTERS_H_ +#define SYNC_INTERNAL_API_PUBLIC_SESSIONS_ERROR_COUNTERS_H_ +#pragma once + +#include "base/basictypes.h" +#include "sync/internal_api/public/util/syncer_error.h" +#include "sync/protocol/sync_protocol_error.h" + +namespace browser_sync { +namespace sessions { + +// Counters for various errors that can occur repeatedly during a sync session. +// TODO(lipalani) : Rename this structure to Error. +struct ErrorCounters { + ErrorCounters(); + + // Any protocol errors that we received during this sync session. + SyncProtocolError sync_protocol_error; + + // Records the most recent results of PostCommit and GetUpdates commands. + SyncerError last_download_updates_result; + SyncerError last_post_commit_result; + SyncerError last_process_commit_response_result; +}; + +} // namespace sessions +} // namespace browser_sync + +#endif // SYNC_INTERNAL_API_PUBLIC_SESSIONS_ERROR_COUNTERS_H_ diff --git a/sync/internal_api/public/sessions/sync_session_snapshot.cc b/sync/internal_api/public/sessions/sync_session_snapshot.cc new file mode 100644 index 0000000..d058a4f --- /dev/null +++ b/sync/internal_api/public/sessions/sync_session_snapshot.cc @@ -0,0 +1,173 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/sessions/sync_session_snapshot.h" + +#include "base/json/json_writer.h" +#include "base/values.h" + +namespace browser_sync { +namespace sessions { + +SyncSessionSnapshot::SyncSessionSnapshot() + : num_server_changes_remaining_(0), + is_share_usable_(false), + has_more_to_sync_(false), + is_silenced_(false), + num_encryption_conflicts_(0), + num_hierarchy_conflicts_(0), + num_simple_conflicts_(0), + num_server_conflicts_(0), + notifications_enabled_(false), + num_entries_(0), + retry_scheduled_(false) { +} + +SyncSessionSnapshot::SyncSessionSnapshot( + const SyncerStatus& syncer_status, + const ErrorCounters& errors, + int64 num_server_changes_remaining, + bool is_share_usable, + syncable::ModelTypeSet initial_sync_ended, + const syncable::ModelTypePayloadMap& download_progress_markers, + bool more_to_sync, + bool is_silenced, + int num_encryption_conflicts, + int num_hierarchy_conflicts, + int num_simple_conflicts, + int num_server_conflicts, + const SyncSourceInfo& source, + bool notifications_enabled, + size_t num_entries, + base::Time sync_start_time, + bool retry_scheduled) + : syncer_status_(syncer_status), + errors_(errors), + num_server_changes_remaining_(num_server_changes_remaining), + is_share_usable_(is_share_usable), + initial_sync_ended_(initial_sync_ended), + download_progress_markers_(download_progress_markers), + has_more_to_sync_(more_to_sync), + is_silenced_(is_silenced), + num_encryption_conflicts_(num_encryption_conflicts), + num_hierarchy_conflicts_(num_hierarchy_conflicts), + num_simple_conflicts_(num_simple_conflicts), + num_server_conflicts_(num_server_conflicts), + source_(source), + notifications_enabled_(notifications_enabled), + num_entries_(num_entries), + sync_start_time_(sync_start_time), + retry_scheduled_(retry_scheduled) { +} + +SyncSessionSnapshot::~SyncSessionSnapshot() {} + +DictionaryValue* SyncSessionSnapshot::ToValue() const { + DictionaryValue* value = new DictionaryValue(); + value->Set("syncerStatus", syncer_status_.ToValue()); + // We don't care too much if we lose precision here. + value->SetInteger("numServerChangesRemaining", + static_cast(num_server_changes_remaining_)); + value->SetBoolean("isShareUsable", is_share_usable_); + value->Set("initialSyncEnded", + syncable::ModelTypeSetToValue(initial_sync_ended_)); + value->Set("downloadProgressMarkers", + syncable::ModelTypePayloadMapToValue(download_progress_markers_)); + value->SetBoolean("hasMoreToSync", has_more_to_sync_); + value->SetBoolean("isSilenced", is_silenced_); + // We don't care too much if we lose precision here, also. + value->SetInteger("numEncryptionConflicts", + num_encryption_conflicts_); + value->SetInteger("numHierarchyConflicts", + num_hierarchy_conflicts_); + value->SetInteger("numSimpleConflicts", + num_simple_conflicts_); + value->SetInteger("numServerConflicts", + num_server_conflicts_); + value->SetInteger("numEntries", num_entries_); + value->Set("source", source_.ToValue()); + value->SetBoolean("notificationsEnabled", notifications_enabled_); + return value; +} + +std::string SyncSessionSnapshot::ToString() const { + scoped_ptr value(ToValue()); + std::string json; + base::JSONWriter::WriteWithOptions(value.get(), + base::JSONWriter::OPTIONS_PRETTY_PRINT, + &json); + return json; +} + +SyncerStatus SyncSessionSnapshot::syncer_status() const { + return syncer_status_; +} + +ErrorCounters SyncSessionSnapshot::errors() const { + return errors_; +} + +int64 SyncSessionSnapshot::num_server_changes_remaining() const { + return num_server_changes_remaining_; +} + +bool SyncSessionSnapshot::is_share_usable() const { + return is_share_usable_; +} + +syncable::ModelTypeSet SyncSessionSnapshot::initial_sync_ended() const { + return initial_sync_ended_; +} + +syncable::ModelTypePayloadMap + SyncSessionSnapshot::download_progress_markers() const { + return download_progress_markers_; +} + +bool SyncSessionSnapshot::has_more_to_sync() const { + return has_more_to_sync_; +} + +bool SyncSessionSnapshot::is_silenced() const { + return is_silenced_; +} + +int SyncSessionSnapshot::num_encryption_conflicts() const { + return num_encryption_conflicts_; +} + +int SyncSessionSnapshot::num_hierarchy_conflicts() const { + return num_hierarchy_conflicts_; +} + +int SyncSessionSnapshot::num_simple_conflicts() const { + return num_simple_conflicts_; +} + +int SyncSessionSnapshot::num_server_conflicts() const { + return num_server_conflicts_; +} + +SyncSourceInfo SyncSessionSnapshot::source() const { + return source_; +} + +bool SyncSessionSnapshot::notifications_enabled() const { + return notifications_enabled_; +} + +size_t SyncSessionSnapshot::num_entries() const { + return num_entries_; +} + +base::Time SyncSessionSnapshot::sync_start_time() const { + return sync_start_time_; +} + +bool SyncSessionSnapshot::retry_scheduled() const { + return retry_scheduled_; +} + +} // namespace sessions +} // namespace browser_sync diff --git a/sync/internal_api/public/sessions/sync_session_snapshot.h b/sync/internal_api/public/sessions/sync_session_snapshot.h new file mode 100644 index 0000000..9ed9465 --- /dev/null +++ b/sync/internal_api/public/sessions/sync_session_snapshot.h @@ -0,0 +1,101 @@ +// Copyright (c) 2012 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 SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNC_SESSION_SNAPSHOT_H_ +#define SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNC_SESSION_SNAPSHOT_H_ +#pragma once + +#include + +#include "base/basictypes.h" +#include "base/time.h" +#include "sync/internal_api/public/sessions/error_counters.h" +#include "sync/internal_api/public/sessions/sync_source_info.h" +#include "sync/internal_api/public/sessions/syncer_status.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" + +namespace base { +class DictionaryValue; +} + +namespace browser_sync { +namespace sessions { + +// An immutable snapshot of state from a SyncSession. Convenient to use as +// part of notifications as it is inherently thread-safe. +// TODO(zea): if copying this all over the place starts getting expensive, +// consider passing around immutable references instead of values. +// Default copy and assign welcome. +class SyncSessionSnapshot { + public: + SyncSessionSnapshot(); + SyncSessionSnapshot( + const SyncerStatus& syncer_status, + const ErrorCounters& errors, + int64 num_server_changes_remaining, + bool is_share_usable, + syncable::ModelTypeSet initial_sync_ended, + const syncable::ModelTypePayloadMap& download_progress_markers, + bool more_to_sync, + bool is_silenced, + int num_encryption_conflicts, + int num_hierarchy_conflicts, + int num_simple_conflicts, + int num_server_conflicts, + const SyncSourceInfo& source, + bool notifications_enabled, + size_t num_entries, + base::Time sync_start_time, + bool retry_scheduled); + ~SyncSessionSnapshot(); + + // Caller takes ownership of the returned dictionary. + base::DictionaryValue* ToValue() const; + + std::string ToString() const; + + SyncerStatus syncer_status() const; + ErrorCounters errors() const; + int64 num_server_changes_remaining() const; + bool is_share_usable() const; + syncable::ModelTypeSet initial_sync_ended() const; + syncable::ModelTypePayloadMap download_progress_markers() const; + bool has_more_to_sync() const; + bool is_silenced() const; + int num_encryption_conflicts() const; + int num_hierarchy_conflicts() const; + int num_simple_conflicts() const; + int num_server_conflicts() const; + bool did_commit_items() const; + SyncSourceInfo source() const; + bool notifications_enabled() const; + size_t num_entries() const; + base::Time sync_start_time() const; + bool retry_scheduled() const; + + private: + SyncerStatus syncer_status_; + ErrorCounters errors_; + int64 num_server_changes_remaining_; + bool is_share_usable_; + syncable::ModelTypeSet initial_sync_ended_; + syncable::ModelTypePayloadMap download_progress_markers_; + bool has_more_to_sync_; + bool is_silenced_; + int num_encryption_conflicts_; + int num_hierarchy_conflicts_; + int num_simple_conflicts_; + int num_server_conflicts_; + SyncSourceInfo source_; + bool notifications_enabled_; + size_t num_entries_; + base::Time sync_start_time_; + bool retry_scheduled_; +}; + +} // namespace sessions +} // namespace browser_sync + +#endif // SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNC_SESSION_SNAPSHOT_H_ diff --git a/sync/internal_api/public/sessions/sync_source_info.cc b/sync/internal_api/public/sessions/sync_source_info.cc new file mode 100644 index 0000000..191199b --- /dev/null +++ b/sync/internal_api/public/sessions/sync_source_info.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/sessions/sync_source_info.h" + +#include "base/values.h" +#include "sync/protocol/proto_enum_conversions.h" + +namespace browser_sync { +namespace sessions { + +SyncSourceInfo::SyncSourceInfo() + : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN) {} + +SyncSourceInfo::SyncSourceInfo( + const syncable::ModelTypePayloadMap& t) + : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN), types(t) {} + +SyncSourceInfo::SyncSourceInfo( + const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, + const syncable::ModelTypePayloadMap& t) + : updates_source(u), types(t) {} + +SyncSourceInfo::~SyncSourceInfo() {} + +DictionaryValue* SyncSourceInfo::ToValue() const { + DictionaryValue* value = new DictionaryValue(); + value->SetString("updatesSource", + GetUpdatesSourceString(updates_source)); + value->Set("types", syncable::ModelTypePayloadMapToValue(types)); + return value; +} + +} // namespace sessions +} // namespace browser_sync diff --git a/sync/internal_api/public/sessions/sync_source_info.h b/sync/internal_api/public/sessions/sync_source_info.h new file mode 100644 index 0000000..838e094 --- /dev/null +++ b/sync/internal_api/public/sessions/sync_source_info.h @@ -0,0 +1,42 @@ +// Copyright (c) 2012 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 SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNC_SOURCE_INFO_H_ +#define SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNC_SOURCE_INFO_H_ +#pragma once + +#include "base/basictypes.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" +#include "sync/protocol/sync.pb.h" + +namespace base { +class DictionaryValue; +} + +namespace browser_sync { +namespace sessions { + +// A container for the source of a sync session. This includes the update +// source, the datatypes triggering the sync session, and possible session +// specific payloads which should be sent to the server. +struct SyncSourceInfo { + SyncSourceInfo(); + explicit SyncSourceInfo(const syncable::ModelTypePayloadMap& t); + SyncSourceInfo( + const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, + const syncable::ModelTypePayloadMap& t); + ~SyncSourceInfo(); + + // Caller takes ownership of the returned dictionary. + base::DictionaryValue* ToValue() const; + + sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source; + syncable::ModelTypePayloadMap types; +}; + +} // namespace sessions +} // namespace browser_sync + +#endif // SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNC_SOURCE_INFO_H_ diff --git a/sync/internal_api/public/sessions/syncer_status.cc b/sync/internal_api/public/sessions/syncer_status.cc new file mode 100644 index 0000000..efa0c43 --- /dev/null +++ b/sync/internal_api/public/sessions/syncer_status.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/sessions/syncer_status.h" + +#include "base/values.h" + +namespace browser_sync { +namespace sessions { + +SyncerStatus::SyncerStatus() + : invalid_store(false), + num_successful_commits(0), + num_successful_bookmark_commits(0), + num_updates_downloaded_total(0), + num_tombstone_updates_downloaded_total(0), + num_reflected_updates_downloaded_total(0), + num_local_overwrites(0), + num_server_overwrites(0) { +} + +SyncerStatus::~SyncerStatus() { +} + +DictionaryValue* SyncerStatus::ToValue() const { + DictionaryValue* value = new DictionaryValue(); + value->SetBoolean("invalidStore", invalid_store); + value->SetInteger("numSuccessfulCommits", num_successful_commits); + value->SetInteger("numSuccessfulBookmarkCommits", + num_successful_bookmark_commits); + value->SetInteger("numUpdatesDownloadedTotal", + num_updates_downloaded_total); + value->SetInteger("numTombstoneUpdatesDownloadedTotal", + num_tombstone_updates_downloaded_total); + value->SetInteger("numReflectedUpdatesDownloadedTotal", + num_reflected_updates_downloaded_total); + value->SetInteger("numLocalOverwrites", num_local_overwrites); + value->SetInteger("numServerOverwrites", num_server_overwrites); + return value; +} + +} // namespace sessions +} // namespace browser_sync diff --git a/sync/internal_api/public/sessions/syncer_status.h b/sync/internal_api/public/sessions/syncer_status.h new file mode 100644 index 0000000..7331ca3 --- /dev/null +++ b/sync/internal_api/public/sessions/syncer_status.h @@ -0,0 +1,50 @@ +// Copyright (c) 2012 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 SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNCER_STATUS_H_ +#define SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNCER_STATUS_H_ +#pragma once + +#include "base/basictypes.h" +#include "sync/internal_api/public/syncable/model_type.h" + +namespace base { +class DictionaryValue; +} + +namespace browser_sync { +namespace sessions { + +// Data pertaining to the status of an active Syncer object. +struct SyncerStatus { + SyncerStatus(); + ~SyncerStatus(); + + // Caller takes ownership of the returned dictionary. + base::DictionaryValue* ToValue() const; + + // True when we get such an INVALID_STORE error from the server. + bool invalid_store; + int num_successful_commits; + // This is needed for monitoring extensions activity. + int num_successful_bookmark_commits; + + // Download event counters. + int num_updates_downloaded_total; + int num_tombstone_updates_downloaded_total; + int num_reflected_updates_downloaded_total; + + // If the syncer encountered a MIGRATION_DONE code, these are the types that + // the client must now "migrate", by purging and re-downloading all updates. + syncable::ModelTypeSet types_needing_local_migration; + + // Overwrites due to conflict resolution counters. + int num_local_overwrites; + int num_server_overwrites; +}; + +} // namespace sessions +} // namespace browser_sync + +#endif // SYNC_INTERNAL_API_PUBLIC_SESSIONS_SYNCER_STATUS_H_ diff --git a/sync/internal_api/public/syncable/model_type.h b/sync/internal_api/public/syncable/model_type.h new file mode 100644 index 0000000..b7b5fe3 --- /dev/null +++ b/sync/internal_api/public/syncable/model_type.h @@ -0,0 +1,175 @@ +// Copyright (c) 2012 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. + +// Enumerate the various item subtypes that are supported by sync. +// Each sync object is expected to have an immutable object type. +// An object's type is inferred from the type of data it holds. + +#ifndef SYNC_INTERNAL_API_PUBLIC_SYNCABLE_MODEL_TYPE_H_ +#define SYNC_INTERNAL_API_PUBLIC_SYNCABLE_MODEL_TYPE_H_ +#pragma once + +#include +#include + +#include "base/logging.h" +#include "base/time.h" +#include "sync/internal_api/public/util/enum_set.h" + +namespace base { +class ListValue; +class StringValue; +class Value; +} + +namespace sync_pb { +class EntitySpecifics; +class SyncEntity; +} + +namespace syncable { + +enum ModelType { + // Object type unknown. Objects may transition through + // the unknown state during their initial creation, before + // their properties are set. After deletion, object types + // are generally preserved. + UNSPECIFIED, + // A permanent folder whose children may be of mixed + // datatypes (e.g. the "Google Chrome" folder). + TOP_LEVEL_FOLDER, + + // ------------------------------------ Start of "real" model types. + // The model types declared before here are somewhat special, as they + // they do not correspond to any browser data model. The remaining types + // are bona fide model types; all have a related browser data model and + // can be represented in the protocol using a specific Message type in the + // EntitySpecifics protocol buffer. + // + // A bookmark folder or a bookmark URL object. + BOOKMARKS, + FIRST_REAL_MODEL_TYPE = BOOKMARKS, // Declared 2nd, for debugger prettiness. + + // A preference folder or a preference object. + PREFERENCES, + // A password folder or password object. + PASSWORDS, + // An AutofillProfile Object + AUTOFILL_PROFILE, + // An autofill folder or an autofill object. + AUTOFILL, + + // A themes folder or a themes object. + THEMES, + // A typed_url folder or a typed_url object. + TYPED_URLS, + // An extension folder or an extension object. + EXTENSIONS, + // An object representing a set of Nigori keys. + NIGORI, + // An object representing a custom search engine. + SEARCH_ENGINES, + // An object representing a browser session. + SESSIONS, + // An app folder or an app object. + APPS, + // An app setting from the extension settings API. + APP_SETTINGS, + // An extension setting from the extension settings API. + EXTENSION_SETTINGS, + // App notifications. + APP_NOTIFICATIONS, + LAST_REAL_MODEL_TYPE = APP_NOTIFICATIONS, + + // If you are adding a new sync datatype that is exposed to the user via the + // sync preferences UI, be sure to update the list in + // chrome/browser/sync/user_selectable_sync_type.h so that the UMA histograms + // for sync include your new type. + + MODEL_TYPE_COUNT, +}; + +typedef browser_sync::EnumSet< + ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE> ModelTypeSet; +typedef browser_sync::EnumSet< + ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> FullModelTypeSet; + +inline ModelType ModelTypeFromInt(int i) { + DCHECK_GE(i, 0); + DCHECK_LT(i, MODEL_TYPE_COUNT); + return static_cast(i); +} + +void AddDefaultFieldValue(syncable::ModelType datatype, + sync_pb::EntitySpecifics* specifics); + +// Extract the model type of a SyncEntity protocol buffer. ModelType is a +// local concept: the enum is not in the protocol. The SyncEntity's ModelType +// is inferred from the presence of particular datatype field in the +// entity specifics. +ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); + +// Extract the model type from an EntitySpecifics field. Note that there +// are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; +// prefer using GetModelType where possible. +ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics); + +// If this returns false, we shouldn't bother maintaining a position +// value (sibling ordering) for this item. +bool ShouldMaintainPosition(ModelType model_type); + +// Determine a model type from the field number of its associated +// EntitySpecifics field. +ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); + +// Return the field number of the EntitySpecifics field associated with +// a model type. +int GetSpecificsFieldNumberFromModelType(ModelType model_type); + +// TODO(sync): The functions below badly need some cleanup. + +// Returns a pointer to a string with application lifetime that represents +// the name of |model_type|. +const char* ModelTypeToString(ModelType model_type); + +// Handles all model types, and not just real ones. +// +// Caller takes ownership of returned value. +base::StringValue* ModelTypeToValue(ModelType model_type); + +// Converts a Value into a ModelType - complement to ModelTypeToValue(). +ModelType ModelTypeFromValue(const base::Value& value); + +// Returns the ModelType corresponding to the name |model_type_string|. +ModelType ModelTypeFromString(const std::string& model_type_string); + +std::string ModelTypeSetToString(ModelTypeSet model_types); + +// Caller takes ownership of returned list. +base::ListValue* ModelTypeSetToValue(ModelTypeSet model_types); + +ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value); + +// Returns a string corresponding to the syncable tag for this datatype. +std::string ModelTypeToRootTag(ModelType type); + +// Convert a real model type to a notification type (used for +// subscribing to server-issued notifications). Returns true iff +// |model_type| was a real model type and |notification_type| was +// filled in. +bool RealModelTypeToNotificationType(ModelType model_type, + std::string* notification_type); + +// Converts a notification type to a real model type. Returns true +// iff |notification_type| was the notification type of a real model +// type and |model_type| was filled in. +bool NotificationTypeToRealModelType(const std::string& notification_type, + ModelType* model_type); + +// Returns true if |model_type| is a real datatype +bool IsRealDataType(ModelType model_type); + +} // namespace syncable + +#endif // SYNC_INTERNAL_API_PUBLIC_SYNCABLE_MODEL_TYPE_H_ diff --git a/sync/internal_api/public/syncable/model_type_payload_map.cc b/sync/internal_api/public/syncable/model_type_payload_map.cc new file mode 100644 index 0000000..cff4c92 --- /dev/null +++ b/sync/internal_api/public/syncable/model_type_payload_map.cc @@ -0,0 +1,105 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/syncable/model_type_payload_map.h" + +#include + +#include "base/base64.h" +#include "base/json/json_writer.h" +#include "base/memory/scoped_ptr.h" +#include "base/values.h" + +using browser_sync::ModelSafeRoutingInfo; +namespace syncable { + +ModelTypePayloadMap ModelTypePayloadMapFromEnumSet( + syncable::ModelTypeSet types, + const std::string& payload) { + ModelTypePayloadMap types_with_payloads; + for (syncable::ModelTypeSet::Iterator it = types.First(); + it.Good(); it.Inc()) { + types_with_payloads[it.Get()] = payload; + } + return types_with_payloads; +} + +ModelTypeSet ModelTypePayloadMapToEnumSet( + const ModelTypePayloadMap& payload_map) { + ModelTypeSet types; + for (ModelTypePayloadMap::const_iterator it = payload_map.begin(); + it != payload_map.end(); ++it) { + types.Put(it->first); + } + return types; +} + +ModelTypePayloadMap ModelTypePayloadMapFromRoutingInfo( + const browser_sync::ModelSafeRoutingInfo& routes, + const std::string& payload) { + ModelTypePayloadMap types_with_payloads; + for (browser_sync::ModelSafeRoutingInfo::const_iterator i = routes.begin(); + i != routes.end(); ++i) { + types_with_payloads[i->first] = payload; + } + return types_with_payloads; +} + +std::string ModelTypePayloadMapToString( + const ModelTypePayloadMap& type_payloads) { + scoped_ptr value( + ModelTypePayloadMapToValue(type_payloads)); + std::string json; + base::JSONWriter::Write(value.get(), &json); + return json; +} + +DictionaryValue* ModelTypePayloadMapToValue( + const ModelTypePayloadMap& type_payloads) { + DictionaryValue* value = new DictionaryValue(); + for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); + it != type_payloads.end(); ++it) { + // TODO(akalin): Unpack the value into a protobuf. + std::string base64_marker; + bool encoded = base::Base64Encode(it->second, &base64_marker); + DCHECK(encoded); + value->SetString(syncable::ModelTypeToString(it->first), base64_marker); + } + return value; +} + +void CoalescePayloads(ModelTypePayloadMap* original, + const ModelTypePayloadMap& update) { + for (ModelTypePayloadMap::const_iterator i = update.begin(); + i != update.end(); ++i) { + if (original->count(i->first) == 0) { + // If this datatype isn't already in our map, add it with + // whatever payload it has. + (*original)[i->first] = i->second; + } else if (i->second.length() > 0) { + // If this datatype is already in our map, we only overwrite the + // payload if the new one is non-empty. + (*original)[i->first] = i->second; + } + } +} + +void PurgeStalePayload(ModelTypePayloadMap* original, + const ModelSafeRoutingInfo& routing_info) { + std::vector iterators_to_delete; + for (ModelTypePayloadMap::iterator i = original->begin(); + i != original->end(); ++i) { + if (routing_info.end() == routing_info.find(i->first)) { + iterators_to_delete.push_back(i); + } + } + + for (std::vector::iterator + it = iterators_to_delete.begin(); it != iterators_to_delete.end(); + ++it) { + original->erase(*it); + } +} + +} // namespace syncable diff --git a/sync/internal_api/public/syncable/model_type_payload_map.h b/sync/internal_api/public/syncable/model_type_payload_map.h new file mode 100644 index 0000000..1bf3884 --- /dev/null +++ b/sync/internal_api/public/syncable/model_type_payload_map.h @@ -0,0 +1,60 @@ +// Copyright (c) 2012 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. +// +// Definition of ModelTypePayloadMap and various utility functions. + +#ifndef SYNC_INTERNAL_PUBLIC_API_SYNCABLE_MODEL_TYPE_PAYLOAD_MAP_H_ +#define SYNC_INTERNAL_PUBLIC_API_SYNCABLE_MODEL_TYPE_PAYLOAD_MAP_H_ +#pragma once + +#include +#include + +#include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/syncable/model_type.h" + +namespace base { +class DictionaryValue; +} + +namespace syncable { + +// A container that contains a set of datatypes with possible string +// payloads. +typedef std::map ModelTypePayloadMap; + +// Helper functions for building ModelTypePayloadMaps. + +// Make a TypePayloadMap from all the types in a ModelTypeSet using a +// default payload. +ModelTypePayloadMap ModelTypePayloadMapFromEnumSet( + ModelTypeSet model_types, const std::string& payload); + +ModelTypeSet ModelTypePayloadMapToEnumSet( + const ModelTypePayloadMap& payload_map); + +// Make a TypePayloadMap for all the enabled types in a +// ModelSafeRoutingInfo using a default payload. +ModelTypePayloadMap ModelTypePayloadMapFromRoutingInfo( + const browser_sync::ModelSafeRoutingInfo& routes, + const std::string& payload); + +std::string ModelTypePayloadMapToString( + const ModelTypePayloadMap& model_type_payloads); + +// Caller takes ownership of the returned dictionary. +base::DictionaryValue* ModelTypePayloadMapToValue( + const ModelTypePayloadMap& model_type_payloads); + +// Coalesce |update| into |original|, overwriting only when |update| has +// a non-empty payload. +void CoalescePayloads(ModelTypePayloadMap* original, + const ModelTypePayloadMap& update); + +void PurgeStalePayload(ModelTypePayloadMap* original, + const browser_sync::ModelSafeRoutingInfo& routing_info); + +} // namespace syncable + +#endif // SYNC_INTERNAL_PUBLIC_API_SYNCABLE_MODEL_TYPE_PAYLOAD_MAP_H_ diff --git a/sync/internal_api/public/syncable/model_type_payload_map_unittest.cc b/sync/internal_api/public/syncable/model_type_payload_map_unittest.cc new file mode 100644 index 0000000..4a18b34 --- /dev/null +++ b/sync/internal_api/public/syncable/model_type_payload_map_unittest.cc @@ -0,0 +1,46 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/syncable/model_type_payload_map.h" + +#include + +#include "base/base64.h" +#include "base/memory/scoped_ptr.h" +#include "base/test/values_test_util.h" +#include "base/values.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace syncable { +namespace { + +using base::ExpectDictStringValue; + +class ModelTypePayloadMapTest : public testing::Test {}; + +TEST_F(ModelTypePayloadMapTest, TypePayloadMapToSet) { + ModelTypePayloadMap payloads; + payloads[BOOKMARKS] = "bookmarkpayload"; + payloads[APPS] = ""; + + const ModelTypeSet types(BOOKMARKS, APPS); + EXPECT_TRUE(ModelTypePayloadMapToEnumSet(payloads).Equals(types)); +} + +TEST_F(ModelTypePayloadMapTest, TypePayloadMapToValue) { + ModelTypePayloadMap payloads; + std::string encoded; + payloads[BOOKMARKS] = "bookmarkpayload"; + base::Base64Encode(payloads[BOOKMARKS], &encoded); + payloads[APPS] = ""; + + scoped_ptr value(ModelTypePayloadMapToValue(payloads)); + EXPECT_EQ(2u, value->size()); + ExpectDictStringValue(encoded, *value, "Bookmarks"); + ExpectDictStringValue("", *value, "Apps"); + EXPECT_FALSE(value->HasKey("Preferences")); +} + +} // namespace +} // namespace syncable diff --git a/sync/internal_api/public/syncable/model_type_test_util.cc b/sync/internal_api/public/syncable/model_type_test_util.cc new file mode 100644 index 0000000..36d1673 --- /dev/null +++ b/sync/internal_api/public/syncable/model_type_test_util.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/syncable/model_type_test_util.h" + +namespace syncable { + +void PrintTo(ModelTypeSet model_types, ::std::ostream* os) { + *os << ModelTypeSetToString(model_types); +} + +namespace { + +// Matcher implementation for HasModelTypes(). +class HasModelTypesMatcher + : public ::testing::MatcherInterface { + public: + explicit HasModelTypesMatcher(ModelTypeSet expected_types) + : expected_types_(expected_types) {} + + virtual ~HasModelTypesMatcher() {} + + virtual bool MatchAndExplain( + ModelTypeSet model_types, + ::testing::MatchResultListener* listener) const { + // No need to annotate listener since we already define PrintTo(). + return model_types.Equals(expected_types_); + } + + virtual void DescribeTo(::std::ostream* os) const { + *os << "has model types " << ModelTypeSetToString(expected_types_); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + *os << "doesn't have model types " + << ModelTypeSetToString(expected_types_); + } + + private: + const ModelTypeSet expected_types_; + + DISALLOW_COPY_AND_ASSIGN(HasModelTypesMatcher); +}; + +} // namespace + +::testing::Matcher HasModelTypes(ModelTypeSet expected_types) { + return ::testing::MakeMatcher(new HasModelTypesMatcher(expected_types)); +} + +} // namespace syncable diff --git a/sync/internal_api/public/syncable/model_type_test_util.h b/sync/internal_api/public/syncable/model_type_test_util.h new file mode 100644 index 0000000..173212f --- /dev/null +++ b/sync/internal_api/public/syncable/model_type_test_util.h @@ -0,0 +1,26 @@ +// Copyright (c) 2012 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 SYNC_INTERNAL_PUBLIC_API_SYNCABLE_MODEL_TYPE_TEST_UTIL_H_ +#define SYNC_INTERNAL_PUBLIC_API_SYNCABLE_MODEL_TYPE_TEST_UTIL_H_ +#pragma once + +#include + +#include "sync/internal_api/public/syncable/model_type.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace syncable { + +// Defined for googletest. Forwards to ModelTypeSetToString(). +void PrintTo(ModelTypeSet model_types, ::std::ostream* os); + +// A gmock matcher for ModelTypeSet. Use like: +// +// EXPECT_CALL(mock, ProcessModelTypes(HasModelTypes(expected_types))); +::testing::Matcher HasModelTypes(ModelTypeSet expected_types); + +} // namespace syncable + +#endif // SYNC_INTERNAL_PUBLIC_API_SYNCABLE_MODEL_TYPE_TEST_UTIL_H_ diff --git a/sync/internal_api/public/util/enum_set.h b/sync/internal_api/public/util/enum_set.h new file mode 100644 index 0000000..de270d8 --- /dev/null +++ b/sync/internal_api/public/util/enum_set.h @@ -0,0 +1,286 @@ +// Copyright (c) 2012 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 SYNC_INTERNAL_API_PUBLIC_UTIL_ENUM_SET_H_ +#define SYNC_INTERNAL_API_PUBLIC_UTIL_ENUM_SET_H_ +#pragma once + +#include +#include +#include + +#include "base/basictypes.h" +#include "base/logging.h" + +namespace browser_sync { + +// Forward declarations needed for friend declarations. +template +class EnumSet; + +template +EnumSet Union(EnumSet set1, + EnumSet set2); + +template +EnumSet Intersection(EnumSet set1, + EnumSet set2); + +template +EnumSet Difference(EnumSet set1, + EnumSet set2); + +// An EnumSet is a set that can hold enum values between a min and a +// max value (inclusive of both). It's essentially a wrapper around +// std::bitset<> with stronger type enforcement, more descriptive +// member function names, and an iterator interface. +// +// If you're working with enums with a small number of possible values +// (say, fewer than 64), you can efficiently pass around an EnumSet +// for that enum around by value. + +template +class EnumSet { + public: + typedef E EnumType; + static const E kMinValue = MinEnumValue; + static const E kMaxValue = MaxEnumValue; + static const size_t kValueCount = kMaxValue - kMinValue + 1; + COMPILE_ASSERT(kMinValue < kMaxValue, + min_value_must_be_less_than_max_value); + + private: + // Declaration needed by Iterator. + typedef std::bitset EnumBitSet; + + public: + // Iterator is a forward-only read-only iterator for EnumSet. Its + // interface is deliberately distinct from an STL iterator as its + // semantics are substantially different. + // + // Example usage: + // + // for (EnumSet<...>::Iterator it = enums.First(); it.Good(); it.Inc()) { + // Process(it.Get()); + // } + // + // The iterator must not be outlived by the set. In particular, the + // following is an error: + // + // EnumSet<...> SomeFn() { ... } + // + // /* ERROR */ + // for (EnumSet<...>::Iterator it = SomeFun().First(); ... + // + // Also, there are no guarantees as to what will happen if you + // modify an EnumSet while traversing it with an iterator. + class Iterator { + public: + // A default-constructed iterator can't do anything except check + // Good(). You need to call First() on an EnumSet to get a usable + // iterator. + Iterator() : enums_(NULL), i_(kValueCount) {} + ~Iterator() {} + + // Copy constructor and assignment welcome. + + // Returns true iff the iterator points to an EnumSet and it + // hasn't yet traversed the EnumSet entirely. + bool Good() const { + return enums_ && i_ < kValueCount && enums_->test(i_); + } + + // Returns the value the iterator currently points to. Good() + // must hold. + E Get() const { + CHECK(Good()); + return FromIndex(i_); + } + + // Moves the iterator to the next value in the EnumSet. Good() + // must hold. Takes linear time. + void Inc() { + CHECK(Good()); + i_ = FindNext(i_ + 1); + } + + private: + friend Iterator EnumSet::First() const; + + explicit Iterator(const EnumBitSet& enums) + : enums_(&enums), i_(FindNext(0)) {} + + size_t FindNext(size_t i) { + while ((i < kValueCount) && !enums_->test(i)) { + ++i; + } + return i; + } + + const EnumBitSet* enums_; + size_t i_; + }; + + // You can construct an EnumSet with 0, 1, 2, or 3 initial values. + + EnumSet() {} + + explicit EnumSet(E value) { + Put(value); + } + + EnumSet(E value1, E value2) { + Put(value1); + Put(value2); + } + + EnumSet(E value1, E value2, E value3) { + Put(value1); + Put(value2); + Put(value3); + } + + // Returns an EnumSet with all possible values. + static EnumSet All() { + EnumBitSet enums; + enums.set(); + return EnumSet(enums); + } + + ~EnumSet() {} + + // Copy constructor and assignment welcome. + + // Set operations. Put, Retain, and Remove are basically + // self-mutating versions of Union, Intersection, and Difference + // (defined below). + + // Adds the given value (which must be in range) to our set. + void Put(E value) { + enums_.set(ToIndex(value)); + } + + // Adds all values in the given set to our set. + void PutAll(EnumSet other) { + enums_ |= other.enums_; + } + + // There's no real need for a Retain(E) member function. + + // Removes all values not in the given set from our set. + void RetainAll(EnumSet other) { + enums_ &= other.enums_; + } + + // If the given value is in range, removes it from our set. + void Remove(E value) { + if (InRange(value)) { + enums_.reset(ToIndex(value)); + } + } + + // Removes all values in the given set from our set. + void RemoveAll(EnumSet other) { + enums_ &= ~other.enums_; + } + + // Removes all values from our set. + void Clear() { + enums_.reset(); + } + + // Returns true iff the given value is in range and a member of our + // set. + bool Has(E value) const { + return InRange(value) && enums_.test(ToIndex(value)); + } + + // Returns true iff the given set is a subset of our set. + bool HasAll(EnumSet other) const { + return (enums_ & other.enums_) == other.enums_; + } + + // Returns true iff our set and the given set contain exactly the + // same values. + bool Equals(const EnumSet& other) const { + return enums_ == other.enums_; + } + + // Returns true iff our set is empty. + bool Empty() const { + return !enums_.any(); + } + + // Returns how many values our set has. + size_t Size() const { + return enums_.count(); + } + + // Returns an iterator pointing to the first element (if any). + Iterator First() const { + return Iterator(enums_); + } + + private: + friend EnumSet Union( + EnumSet set1, EnumSet set2); + friend EnumSet Intersection( + EnumSet set1, EnumSet set2); + friend EnumSet Difference( + EnumSet set1, EnumSet set2); + + explicit EnumSet(EnumBitSet enums) : enums_(enums) {} + + static bool InRange(E value) { + return (value >= MinEnumValue) && (value <= MaxEnumValue); + } + + // Converts a value to/from an index into |enums_|. + + static size_t ToIndex(E value) { + DCHECK_GE(value, MinEnumValue); + DCHECK_LE(value, MaxEnumValue); + return value - MinEnumValue; + } + + static E FromIndex(size_t i) { + DCHECK_LT(i, kValueCount); + return static_cast(MinEnumValue + i); + } + + EnumBitSet enums_; +}; + +template +const E EnumSet::kMinValue; + +template +const E EnumSet::kMaxValue; + +template +const size_t EnumSet::kValueCount; + +// The usual set operations. + +template +EnumSet Union(EnumSet set1, + EnumSet set2) { + return EnumSet(set1.enums_ | set2.enums_); +} + +template +EnumSet Intersection(EnumSet set1, + EnumSet set2) { + return EnumSet(set1.enums_ & set2.enums_); +} + +template +EnumSet Difference(EnumSet set1, + EnumSet set2) { + return EnumSet(set1.enums_ & ~set2.enums_); +} + +} // namespace browser_sync + +#endif // SYNC_INTERNAL_API_PUBLIC_UTIL_ENUM_SET_H_ diff --git a/sync/internal_api/public/util/enum_set_unittest.cc b/sync/internal_api/public/util/enum_set_unittest.cc new file mode 100644 index 0000000..2caa1de --- /dev/null +++ b/sync/internal_api/public/util/enum_set_unittest.cc @@ -0,0 +1,195 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/util/enum_set.h" + +#include "base/basictypes.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace browser_sync { +namespace { + +enum TestEnum { + TEST_0, + TEST_MIN = TEST_0, + TEST_1, + TEST_2, + TEST_3, + TEST_4, + TEST_MAX = TEST_4, + TEST_5 +}; + +typedef EnumSet TestEnumSet; + +class EnumSetTest : public ::testing::Test {}; + +TEST_F(EnumSetTest, ClassConstants) { + TestEnumSet enums; + EXPECT_EQ(TEST_MIN, TestEnumSet::kMinValue); + EXPECT_EQ(TEST_MAX, TestEnumSet::kMaxValue); + EXPECT_EQ(static_cast(5), TestEnumSet::kValueCount); +} + +TEST_F(EnumSetTest, DefaultConstructor) { + const TestEnumSet enums; + EXPECT_TRUE(enums.Empty()); + EXPECT_EQ(static_cast(0), enums.Size()); + EXPECT_FALSE(enums.Has(TEST_0)); + EXPECT_FALSE(enums.Has(TEST_1)); + EXPECT_FALSE(enums.Has(TEST_2)); + EXPECT_FALSE(enums.Has(TEST_3)); + EXPECT_FALSE(enums.Has(TEST_4)); +} + +TEST_F(EnumSetTest, OneArgConstructor) { + const TestEnumSet enums(TEST_3); + EXPECT_FALSE(enums.Empty()); + EXPECT_EQ(static_cast(1), enums.Size()); + EXPECT_FALSE(enums.Has(TEST_0)); + EXPECT_FALSE(enums.Has(TEST_1)); + EXPECT_FALSE(enums.Has(TEST_2)); + EXPECT_TRUE(enums.Has(TEST_3)); + EXPECT_FALSE(enums.Has(TEST_4)); +} + +TEST_F(EnumSetTest, TwoArgConstructor) { + const TestEnumSet enums(TEST_3, TEST_1); + EXPECT_FALSE(enums.Empty()); + EXPECT_EQ(static_cast(2), enums.Size()); + EXPECT_FALSE(enums.Has(TEST_0)); + EXPECT_TRUE(enums.Has(TEST_1)); + EXPECT_FALSE(enums.Has(TEST_2)); + EXPECT_TRUE(enums.Has(TEST_3)); + EXPECT_FALSE(enums.Has(TEST_4)); +} + +TEST_F(EnumSetTest, ThreeArgConstructor) { + const TestEnumSet enums(TEST_3, TEST_1, TEST_0); + EXPECT_FALSE(enums.Empty()); + EXPECT_EQ(static_cast(3), enums.Size()); + EXPECT_TRUE(enums.Has(TEST_0)); + EXPECT_TRUE(enums.Has(TEST_1)); + EXPECT_FALSE(enums.Has(TEST_2)); + EXPECT_TRUE(enums.Has(TEST_3)); + EXPECT_FALSE(enums.Has(TEST_4)); +} + +TEST_F(EnumSetTest, All) { + const TestEnumSet enums(TestEnumSet::All()); + EXPECT_FALSE(enums.Empty()); + EXPECT_EQ(static_cast(5), enums.Size()); + EXPECT_TRUE(enums.Has(TEST_0)); + EXPECT_TRUE(enums.Has(TEST_1)); + EXPECT_TRUE(enums.Has(TEST_2)); + EXPECT_TRUE(enums.Has(TEST_3)); + EXPECT_TRUE(enums.Has(TEST_4)); +} + +TEST_F(EnumSetTest, Put) { + TestEnumSet enums(TEST_3); + enums.Put(TEST_2); + EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_2, TEST_3))); + enums.Put(TEST_4); + EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_2, TEST_3, TEST_4))); +} + +TEST_F(EnumSetTest, PutAll) { + TestEnumSet enums(TEST_3, TEST_4); + enums.PutAll(TestEnumSet(TEST_2, TEST_3)); + EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_2, TEST_3, TEST_4))); +} + +TEST_F(EnumSetTest, RetainAll) { + TestEnumSet enums(TEST_3, TEST_4); + enums.RetainAll(TestEnumSet(TEST_2, TEST_3)); + EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_3))); +} + +TEST_F(EnumSetTest, Remove) { + TestEnumSet enums(TEST_3, TEST_4); + enums.Remove(TEST_0); + enums.Remove(TEST_2); + EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_3, TEST_4))); + enums.Remove(TEST_3); + EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_4))); + enums.Remove(TEST_4); + enums.Remove(TEST_5); + EXPECT_TRUE(enums.Empty()); +} + +TEST_F(EnumSetTest, RemoveAll) { + TestEnumSet enums(TEST_3, TEST_4); + enums.RemoveAll(TestEnumSet(TEST_2, TEST_3)); + EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_4))); +} + +TEST_F(EnumSetTest, Clear) { + TestEnumSet enums(TEST_3, TEST_4); + enums.Clear(); + EXPECT_TRUE(enums.Empty()); +} + +TEST_F(EnumSetTest, Has) { + const TestEnumSet enums(TEST_3, TEST_4); + EXPECT_FALSE(enums.Has(TEST_0)); + EXPECT_FALSE(enums.Has(TEST_1)); + EXPECT_FALSE(enums.Has(TEST_2)); + EXPECT_TRUE(enums.Has(TEST_3)); + EXPECT_TRUE(enums.Has(TEST_4)); + EXPECT_FALSE(enums.Has(TEST_5)); +} + +TEST_F(EnumSetTest, HasAll) { + const TestEnumSet enums1(TEST_3, TEST_4); + const TestEnumSet enums2(TEST_2, TEST_3); + const TestEnumSet enums3 = Union(enums1, enums2); + EXPECT_TRUE(enums1.HasAll(enums1)); + EXPECT_FALSE(enums1.HasAll(enums2)); + EXPECT_FALSE(enums1.HasAll(enums3)); + + EXPECT_FALSE(enums2.HasAll(enums1)); + EXPECT_TRUE(enums2.HasAll(enums2)); + EXPECT_FALSE(enums2.HasAll(enums3)); + + EXPECT_TRUE(enums3.HasAll(enums1)); + EXPECT_TRUE(enums3.HasAll(enums2)); + EXPECT_TRUE(enums3.HasAll(enums3)); +} + +TEST_F(EnumSetTest, Iterators) { + const TestEnumSet enums1(TEST_3, TEST_4); + TestEnumSet enums2; + for (TestEnumSet::Iterator it = enums1.First(); it.Good(); it.Inc()) { + enums2.Put(it.Get()); + } + EXPECT_TRUE(enums1.Equals(enums2)); +} + +TEST_F(EnumSetTest, Union) { + const TestEnumSet enums1(TEST_3, TEST_4); + const TestEnumSet enums2(TEST_2, TEST_3); + const TestEnumSet enums3 = Union(enums1, enums2); + + EXPECT_TRUE(enums3.Equals(TestEnumSet(TEST_2, TEST_3, TEST_4))); +} + +TEST_F(EnumSetTest, Intersection) { + const TestEnumSet enums1(TEST_3, TEST_4); + const TestEnumSet enums2(TEST_2, TEST_3); + const TestEnumSet enums3 = Intersection(enums1, enums2); + + EXPECT_TRUE(enums3.Equals(TestEnumSet(TEST_3))); +} + +TEST_F(EnumSetTest, Difference) { + const TestEnumSet enums1(TEST_3, TEST_4); + const TestEnumSet enums2(TEST_2, TEST_3); + const TestEnumSet enums3 = Difference(enums1, enums2); + + EXPECT_TRUE(enums3.Equals(TestEnumSet(TEST_4))); +} + +} // namespace +} // namespace browser_sync diff --git a/sync/internal_api/public/util/syncer_error.cc b/sync/internal_api/public/util/syncer_error.cc new file mode 100644 index 0000000..b4ba578 --- /dev/null +++ b/sync/internal_api/public/util/syncer_error.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2012 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 "sync/internal_api/public/util/syncer_error.h" + +#include "base/logging.h" + +namespace browser_sync { + +#define ENUM_CASE(x) case x: return #x; break; +const char* GetSyncerErrorString(SyncerError value) { + switch (value) { + ENUM_CASE(UNSET); + ENUM_CASE(DIRECTORY_LOOKUP_FAILED); + ENUM_CASE(NETWORK_CONNECTION_UNAVAILABLE); + ENUM_CASE(NETWORK_IO_ERROR); + ENUM_CASE(SYNC_SERVER_ERROR); + ENUM_CASE(SYNC_AUTH_ERROR); + ENUM_CASE(SERVER_RETURN_INVALID_CREDENTIAL); + ENUM_CASE(SERVER_RETURN_UNKNOWN_ERROR); + ENUM_CASE(SERVER_RETURN_THROTTLED); + ENUM_CASE(SERVER_RETURN_TRANSIENT_ERROR); + ENUM_CASE(SERVER_RETURN_MIGRATION_DONE); + ENUM_CASE(SERVER_RETURN_CLEAR_PENDING); + ENUM_CASE(SERVER_RETURN_NOT_MY_BIRTHDAY); + ENUM_CASE(SERVER_RESPONSE_VALIDATION_FAILED); + ENUM_CASE(SYNCER_OK); + } + NOTREACHED(); + return "INVALID"; +} +#undef ENUM_CASE + +} // namespace browser_sync + diff --git a/sync/internal_api/public/util/syncer_error.h b/sync/internal_api/public/util/syncer_error.h new file mode 100644 index 0000000..aa6ebb3 --- /dev/null +++ b/sync/internal_api/public/util/syncer_error.h @@ -0,0 +1,46 @@ +// Copyright (c) 2012 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 SYNC_INTERNAL_API_PUBLIC_UTIL_SYNCER_ERROR_H_ +#define SYNC_INTERNAL_API_PUBLIC_UTIL_SYNCER_ERROR_H_ +#pragma once + +namespace browser_sync { + +// This enum describes all the ways a SyncerCommand can fail. +// +// SyncerCommands do many different things, but they share a common function +// signature. This enum, the return value for all SyncerCommands, must be able +// to describe any possible failure for all SyncerComand. +// +// For convenience, functions which are invoked only by SyncerCommands may also +// return a SyncerError. It saves us having to write a conversion function, and +// it makes refactoring easier. +enum SyncerError { + UNSET = 0, // Default value. + DIRECTORY_LOOKUP_FAILED, // Local directory lookup failure. + + NETWORK_CONNECTION_UNAVAILABLE, // Connectivity failure. + NETWORK_IO_ERROR, // Response buffer read error. + SYNC_SERVER_ERROR, // Non auth HTTP error. + SYNC_AUTH_ERROR, // HTTP auth error. + + // Based on values returned by server. Most are defined in sync.proto. + SERVER_RETURN_INVALID_CREDENTIAL, + SERVER_RETURN_UNKNOWN_ERROR, + SERVER_RETURN_THROTTLED, + SERVER_RETURN_TRANSIENT_ERROR, + SERVER_RETURN_MIGRATION_DONE, + SERVER_RETURN_CLEAR_PENDING, + SERVER_RETURN_NOT_MY_BIRTHDAY, + SERVER_RESPONSE_VALIDATION_FAILED, + + SYNCER_OK +}; + +const char * GetSyncerErrorString(SyncerError); + +} // namespace browser_sync + +#endif // SYNC_INTERNAL_API_PUBLIC_UTIL_SYNCER_ERROR_H_ diff --git a/sync/internal_api/read_node.h b/sync/internal_api/read_node.h index ea48660..98638de 100644 --- a/sync/internal_api/read_node.h +++ b/sync/internal_api/read_node.h @@ -11,7 +11,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "sync/internal_api/base_node.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" namespace sync_api { diff --git a/sync/internal_api/sync_manager.cc b/sync/internal_api/sync_manager.cc index 4a5ade2..1e8b7dd 100644 --- a/sync/internal_api/sync_manager.cc +++ b/sync/internal_api/sync_manager.cc @@ -20,7 +20,6 @@ #include "net/base/network_change_notifier.h" #include "sync/engine/net/server_connection_manager.h" #include "sync/engine/nigori_util.h" -#include "sync/engine/polling_constants.h" #include "sync/engine/sync_scheduler.h" #include "sync/engine/syncer_types.h" #include "sync/internal_api/all_status.h" @@ -30,6 +29,9 @@ #include "sync/internal_api/debug_info_event_listener.h" #include "sync/internal_api/js_mutation_event_observer.h" #include "sync/internal_api/js_sync_manager_observer.h" +#include "sync/internal_api/public/engine/polling_constants.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/internal_api/read_node.h" #include "sync/internal_api/read_transaction.h" #include "sync/internal_api/syncapi_internal.h" @@ -48,8 +50,6 @@ #include "sync/protocol/proto_value_conversions.h" #include "sync/protocol/sync.pb.h" #include "sync/syncable/directory_change_delegate.h" -#include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" #include "sync/syncable/syncable.h" #include "sync/util/cryptographer.h" #include "sync/util/experiments.h" diff --git a/sync/internal_api/sync_manager.h b/sync/internal_api/sync_manager.h index 73229ab..80cda3f 100644 --- a/sync/internal_api/sync_manager.h +++ b/sync/internal_api/sync_manager.h @@ -15,11 +15,11 @@ #include "base/task_runner.h" #include "base/threading/thread_checker.h" #include "base/time.h" -#include "sync/engine/model_safe_worker.h" #include "sync/internal_api/change_record.h" #include "sync/internal_api/configure_reason.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/sync_protocol_error.h" -#include "sync/syncable/model_type.h" #include "sync/util/report_unrecoverable_error_function.h" #include "sync/util/unrecoverable_error_handler.h" #include "sync/util/weak_handle.h" diff --git a/sync/internal_api/syncapi_unittest.cc b/sync/internal_api/syncapi_unittest.cc index 5c70618..e8fa2bd 100644 --- a/sync/internal_api/syncapi_unittest.cc +++ b/sync/internal_api/syncapi_unittest.cc @@ -23,12 +23,13 @@ #include "base/test/values_test_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "sync/engine/model_safe_worker.h" #include "sync/engine/nigori_util.h" -#include "sync/engine/polling_constants.h" #include "sync/internal_api/change_record.h" #include "sync/internal_api/http_post_provider_factory.h" #include "sync/internal_api/http_post_provider_interface.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/engine/polling_constants.h" +#include "sync/internal_api/public/syncable/model_type_test_util.h" #include "sync/internal_api/read_node.h" #include "sync/internal_api/read_transaction.h" #include "sync/internal_api/sync_manager.h" @@ -51,7 +52,6 @@ #include "sync/protocol/proto_value_conversions.h" #include "sync/protocol/sync.pb.h" #include "sync/sessions/sync_session.h" -#include "sync/syncable/model_type_test_util.h" #include "sync/syncable/syncable.h" #include "sync/syncable/syncable_id.h" #include "sync/test/fake_encryptor.h" diff --git a/sync/internal_api/write_node.h b/sync/internal_api/write_node.h index a87a377..d297ac8 100644 --- a/sync/internal_api/write_node.h +++ b/sync/internal_api/write_node.h @@ -12,7 +12,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "sync/internal_api/base_node.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" namespace browser_sync { class Cryptographer; diff --git a/sync/notifier/DEPS b/sync/notifier/DEPS index fe689b9..4c55aa9 100644 --- a/sync/notifier/DEPS +++ b/sync/notifier/DEPS @@ -5,8 +5,7 @@ include_rules = [ "+net/url_request/url_request_context.h", "+net/url_request/url_request_test_util.h", - "+sync/syncable/model_type.h", - "+sync/syncable/model_type_payload_map.h", + "+sync/internal_api/public/syncable", "+sync/protocol/service_constants.h", "+sync/util", diff --git a/sync/notifier/chrome_invalidation_client.cc b/sync/notifier/chrome_invalidation_client.cc index 401335c..5ddb56b 100644 --- a/sync/notifier/chrome_invalidation_client.cc +++ b/sync/notifier/chrome_invalidation_client.cc @@ -15,9 +15,9 @@ #include "google/cacheinvalidation/include/types.h" #include "google/cacheinvalidation/v2/types.pb.h" #include "jingle/notifier/listener/push_client.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/notifier/invalidation_util.h" #include "sync/notifier/registration_manager.h" -#include "sync/syncable/model_type.h" namespace { diff --git a/sync/notifier/chrome_invalidation_client.h b/sync/notifier/chrome_invalidation_client.h index 4e6cdaa..acfc001 100644 --- a/sync/notifier/chrome_invalidation_client.h +++ b/sync/notifier/chrome_invalidation_client.h @@ -17,11 +17,11 @@ #include "base/memory/weak_ptr.h" #include "base/threading/non_thread_safe.h" #include "google/cacheinvalidation/include/invalidation-listener.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/notifier/chrome_system_resources.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/state_writer.h" -#include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" #include "sync/util/weak_handle.h" namespace buzz { diff --git a/sync/notifier/chrome_invalidation_client_unittest.cc b/sync/notifier/chrome_invalidation_client_unittest.cc index 4de8ce0..92f697f12 100644 --- a/sync/notifier/chrome_invalidation_client_unittest.cc +++ b/sync/notifier/chrome_invalidation_client_unittest.cc @@ -9,10 +9,10 @@ #include "google/cacheinvalidation/include/types.h" #include "google/cacheinvalidation/v2/types.pb.h" #include "jingle/notifier/listener/fake_push_client.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/notifier/chrome_invalidation_client.h" #include "sync/notifier/mock_invalidation_state_tracker.h" -#include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" #include "sync/util/weak_handle.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/sync/notifier/invalidation_notifier.cc b/sync/notifier/invalidation_notifier.cc index e188adb..6f5c382 100644 --- a/sync/notifier/invalidation_notifier.cc +++ b/sync/notifier/invalidation_notifier.cc @@ -9,8 +9,8 @@ #include "base/metrics/histogram.h" #include "jingle/notifier/listener/push_client.h" #include "net/url_request/url_request_context.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/notifier/sync_notifier_observer.h" -#include "sync/syncable/model_type_payload_map.h" #include "talk/xmpp/jid.h" #include "talk/xmpp/xmppclientsettings.h" diff --git a/sync/notifier/invalidation_notifier.h b/sync/notifier/invalidation_notifier.h index aebf833..01108f5 100644 --- a/sync/notifier/invalidation_notifier.h +++ b/sync/notifier/invalidation_notifier.h @@ -20,10 +20,10 @@ #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" #include "base/threading/non_thread_safe.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/notifier/chrome_invalidation_client.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/sync_notifier.h" -#include "sync/syncable/model_type.h" #include "sync/util/weak_handle.h" namespace notifier { diff --git a/sync/notifier/invalidation_notifier_unittest.cc b/sync/notifier/invalidation_notifier_unittest.cc index c5f7132..8219ad8 100644 --- a/sync/notifier/invalidation_notifier_unittest.cc +++ b/sync/notifier/invalidation_notifier_unittest.cc @@ -10,11 +10,11 @@ #include "jingle/notifier/base/notifier_options.h" #include "jingle/notifier/listener/fake_push_client.h" #include "net/url_request/url_request_test_util.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/mock_invalidation_state_tracker.h" #include "sync/notifier/mock_sync_notifier_observer.h" -#include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" #include "sync/util/weak_handle.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/sync/notifier/invalidation_state_tracker.h b/sync/notifier/invalidation_state_tracker.h index bfa27c9..5e46b06 100644 --- a/sync/notifier/invalidation_state_tracker.h +++ b/sync/notifier/invalidation_state_tracker.h @@ -11,7 +11,7 @@ #include #include "base/basictypes.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" namespace sync_notifier { diff --git a/sync/notifier/invalidation_util.h b/sync/notifier/invalidation_util.h index 80c032d..220fa44 100644 --- a/sync/notifier/invalidation_util.h +++ b/sync/notifier/invalidation_util.h @@ -11,7 +11,7 @@ #include #include "google/cacheinvalidation/deps/callback.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" namespace invalidation { diff --git a/sync/notifier/non_blocking_invalidation_notifier_unittest.cc b/sync/notifier/non_blocking_invalidation_notifier_unittest.cc index af93d17..4ac2504 100644 --- a/sync/notifier/non_blocking_invalidation_notifier_unittest.cc +++ b/sync/notifier/non_blocking_invalidation_notifier_unittest.cc @@ -10,10 +10,10 @@ #include "base/threading/thread.h" #include "jingle/notifier/base/fake_base_task.h" #include "net/url_request/url_request_test_util.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/mock_sync_notifier_observer.h" -#include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" #include "sync/util/weak_handle.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/sync/notifier/p2p_notifier.cc b/sync/notifier/p2p_notifier.cc index 70b35fe..2eae246 100644 --- a/sync/notifier/p2p_notifier.cc +++ b/sync/notifier/p2p_notifier.cc @@ -11,8 +11,8 @@ #include "base/logging.h" #include "base/values.h" #include "jingle/notifier/listener/push_client.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/notifier/sync_notifier_observer.h" -#include "sync/syncable/model_type_payload_map.h" namespace sync_notifier { diff --git a/sync/notifier/p2p_notifier.h b/sync/notifier/p2p_notifier.h index f7b882e..341bc8b 100644 --- a/sync/notifier/p2p_notifier.h +++ b/sync/notifier/p2p_notifier.h @@ -17,8 +17,8 @@ #include "base/observer_list.h" #include "base/threading/non_thread_safe.h" #include "jingle/notifier/listener/push_client_observer.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/notifier/sync_notifier.h" -#include "sync/syncable/model_type.h" namespace notifier { class PushClient; diff --git a/sync/notifier/p2p_notifier_unittest.cc b/sync/notifier/p2p_notifier_unittest.cc index fe1a623..28ec600 100644 --- a/sync/notifier/p2p_notifier_unittest.cc +++ b/sync/notifier/p2p_notifier_unittest.cc @@ -7,8 +7,8 @@ #include #include "jingle/notifier/listener/fake_push_client.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/notifier/mock_sync_notifier_observer.h" -#include "sync/syncable/model_type.h" #include "testing/gtest/include/gtest/gtest.h" namespace sync_notifier { diff --git a/sync/notifier/registration_manager.cc b/sync/notifier/registration_manager.cc index de844c5..8e04916 100644 --- a/sync/notifier/registration_manager.cc +++ b/sync/notifier/registration_manager.cc @@ -11,8 +11,8 @@ #include "base/rand_util.h" #include "google/cacheinvalidation/include/invalidation-client.h" #include "google/cacheinvalidation/include/types.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/notifier/invalidation_util.h" -#include "sync/syncable/model_type.h" namespace sync_notifier { diff --git a/sync/notifier/registration_manager.h b/sync/notifier/registration_manager.h index e8639d0..44e7cf3 100644 --- a/sync/notifier/registration_manager.h +++ b/sync/notifier/registration_manager.h @@ -16,7 +16,7 @@ #include "base/threading/non_thread_safe.h" #include "base/time.h" #include "base/timer.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" // For invalidation::InvalidationListener::RegistrationState. #include "google/cacheinvalidation/include/invalidation-listener.h" diff --git a/sync/notifier/registration_manager_unittest.cc b/sync/notifier/registration_manager_unittest.cc index 21172f8..2c143ce 100644 --- a/sync/notifier/registration_manager_unittest.cc +++ b/sync/notifier/registration_manager_unittest.cc @@ -13,8 +13,8 @@ #include "base/basictypes.h" #include "base/message_loop.h" #include "google/cacheinvalidation/include/invalidation-client.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/notifier/invalidation_util.h" -#include "sync/syncable/model_type.h" #include "testing/gtest/include/gtest/gtest.h" namespace sync_notifier { diff --git a/sync/notifier/sync_notifier.h b/sync/notifier/sync_notifier.h index a973538..94f5fc2 100644 --- a/sync/notifier/sync_notifier.h +++ b/sync/notifier/sync_notifier.h @@ -11,7 +11,7 @@ #include -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" namespace sync_notifier { class SyncNotifierObserver; diff --git a/sync/notifier/sync_notifier_factory_unittest.cc b/sync/notifier/sync_notifier_factory_unittest.cc index f7e16f4..b0f31e9 100644 --- a/sync/notifier/sync_notifier_factory_unittest.cc +++ b/sync/notifier/sync_notifier_factory_unittest.cc @@ -14,11 +14,11 @@ #include "jingle/notifier/base/notification_method.h" #include "jingle/notifier/base/notifier_options.h" #include "net/url_request/url_request_test_util.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/mock_sync_notifier_observer.h" #include "sync/notifier/sync_notifier.h" -#include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/sync/notifier/sync_notifier_observer.h b/sync/notifier/sync_notifier_observer.h index 1130c9e..a6a629f 100644 --- a/sync/notifier/sync_notifier_observer.h +++ b/sync/notifier/sync_notifier_observer.h @@ -8,7 +8,7 @@ #include -#include "sync/syncable/model_type_payload_map.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" namespace sync_notifier { diff --git a/sync/protocol/DEPS b/sync/protocol/DEPS index a21ff1a..d60f62f 100644 --- a/sync/protocol/DEPS +++ b/sync/protocol/DEPS @@ -1,3 +1,3 @@ include_rules = [ - "+sync/syncable/model_type.h", + "+sync/internal_api/public/syncable", ] diff --git a/sync/protocol/proto_value_conversions_unittest.cc b/sync/protocol/proto_value_conversions_unittest.cc index 59eb3a8..4c4c6a7 100644 --- a/sync/protocol/proto_value_conversions_unittest.cc +++ b/sync/protocol/proto_value_conversions_unittest.cc @@ -8,6 +8,7 @@ #include "base/memory/scoped_ptr.h" #include "base/values.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/app_notification_specifics.pb.h" #include "sync/protocol/app_setting_specifics.pb.h" #include "sync/protocol/app_specifics.pb.h" @@ -24,7 +25,6 @@ #include "sync/protocol/sync.pb.h" #include "sync/protocol/theme_specifics.pb.h" #include "sync/protocol/typed_url_specifics.pb.h" -#include "sync/syncable/model_type.h" #include "testing/gtest/include/gtest/gtest.h" namespace browser_sync { diff --git a/sync/protocol/sync_protocol_error.h b/sync/protocol/sync_protocol_error.h index 9ae5317..be43980 100644 --- a/sync/protocol/sync_protocol_error.h +++ b/sync/protocol/sync_protocol_error.h @@ -8,7 +8,7 @@ #include #include "base/values.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" namespace browser_sync{ diff --git a/sync/sessions/DEPS b/sync/sessions/DEPS index a320b0d..81c88ab 100644 --- a/sync/sessions/DEPS +++ b/sync/sessions/DEPS @@ -1,5 +1,8 @@ include_rules = [ "+sync/engine", + "+sync/internal_api/public/engine", + "+sync/internal_api/public/sessions", + "+sync/internal_api/public/syncable", "+sync/protocol", "+sync/syncable", "+sync/test", diff --git a/sync/sessions/error_counters.cc b/sync/sessions/error_counters.cc deleted file mode 100644 index c227b82..0000000 --- a/sync/sessions/error_counters.cc +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2012 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 "sync/sessions/error_counters.h" - -namespace browser_sync { -namespace sessions { - -ErrorCounters::ErrorCounters() - : last_download_updates_result(UNSET), - last_post_commit_result(UNSET), - last_process_commit_response_result(UNSET) { -} - -} // namespace sessions -} // namespace browser_sync diff --git a/sync/sessions/error_counters.h b/sync/sessions/error_counters.h deleted file mode 100644 index c2f532f..0000000 --- a/sync/sessions/error_counters.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2012 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 SYNC_SESSIONS_ERROR_COUNTERS_H_ -#define SYNC_SESSIONS_ERROR_COUNTERS_H_ -#pragma once - -#include "base/basictypes.h" -#include "sync/protocol/sync_protocol_error.h" -#include "sync/util/syncer_error.h" - -namespace browser_sync { -namespace sessions { - -// Counters for various errors that can occur repeatedly during a sync session. -// TODO(lipalani) : Rename this structure to Error. -struct ErrorCounters { - ErrorCounters(); - - // Any protocol errors that we received during this sync session. - SyncProtocolError sync_protocol_error; - - // Records the most recent results of PostCommit and GetUpdates commands. - SyncerError last_download_updates_result; - SyncerError last_post_commit_result; - SyncerError last_process_commit_response_result; -}; - -} // namespace sessions -} // namespace browser_sync - -#endif // SYNC_SESSIONS_ERROR_COUNTERS_H_ diff --git a/sync/sessions/ordered_commit_set.h b/sync/sessions/ordered_commit_set.h index f8e6938..e29737f 100644 --- a/sync/sessions/ordered_commit_set.h +++ b/sync/sessions/ordered_commit_set.h @@ -10,8 +10,8 @@ #include #include -#include "sync/engine/model_safe_worker.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/syncable/syncable_id.h" namespace browser_sync { diff --git a/sync/sessions/session_state.h b/sync/sessions/session_state.h index 2bd6fe5..ae55acb 100644 --- a/sync/sessions/session_state.h +++ b/sync/sessions/session_state.h @@ -19,9 +19,8 @@ #include "base/basictypes.h" #include "sync/engine/syncer_types.h" #include "sync/engine/syncproto.h" -#include "sync/sessions/error_counters.h" -#include "sync/sessions/syncer_status.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/sessions/error_counters.h" +#include "sync/internal_api/public/sessions/syncer_status.h" #include "sync/syncable/syncable_id.h" namespace browser_sync { diff --git a/sync/sessions/session_state_unittest.cc b/sync/sessions/session_state_unittest.cc index e6a9d34..a1a0898 100644 --- a/sync/sessions/session_state_unittest.cc +++ b/sync/sessions/session_state_unittest.cc @@ -11,10 +11,10 @@ #include "base/test/values_test_util.h" #include "base/time.h" #include "base/values.h" -#include "sync/sessions/error_counters.h" -#include "sync/sessions/sync_session_snapshot.h" -#include "sync/sessions/sync_source_info.h" -#include "sync/sessions/syncer_status.h" +#include "sync/internal_api/public/sessions/error_counters.h" +#include "sync/internal_api/public/sessions/sync_session_snapshot.h" +#include "sync/internal_api/public/sessions/sync_source_info.h" +#include "sync/internal_api/public/sessions/syncer_status.h" #include "testing/gtest/include/gtest/gtest.h" namespace browser_sync { diff --git a/sync/sessions/status_controller.cc b/sync/sessions/status_controller.cc index a88d93c..8f6c9ee 100644 --- a/sync/sessions/status_controller.cc +++ b/sync/sessions/status_controller.cc @@ -7,8 +7,8 @@ #include #include "base/basictypes.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/sync_protocol_error.h" -#include "sync/syncable/model_type.h" namespace browser_sync { namespace sessions { diff --git a/sync/sessions/sync_session.cc b/sync/sessions/sync_session.cc index e219412..ac874d1 100644 --- a/sync/sessions/sync_session.cc +++ b/sync/sessions/sync_session.cc @@ -8,7 +8,7 @@ #include #include "base/logging.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/syncable/syncable.h" namespace browser_sync { diff --git a/sync/sessions/sync_session.h b/sync/sessions/sync_session.h index 8b15d35..c903be9 100644 --- a/sync/sessions/sync_session.h +++ b/sync/sessions/sync_session.h @@ -24,13 +24,13 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/time.h" -#include "sync/engine/model_safe_worker.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/sessions/sync_session_snapshot.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/sessions/ordered_commit_set.h" #include "sync/sessions/session_state.h" #include "sync/sessions/status_controller.h" #include "sync/sessions/sync_session_context.h" -#include "sync/sessions/sync_session_snapshot.h" -#include "sync/syncable/model_type.h" #include "sync/util/extensions_activity_monitor.h" namespace syncable { diff --git a/sync/sessions/sync_session_context.h b/sync/sessions/sync_session_context.h index f8de52e..b1fc297 100644 --- a/sync/sessions/sync_session_context.h +++ b/sync/sessions/sync_session_context.h @@ -25,10 +25,10 @@ #include "base/gtest_prod_util.h" #include "base/time.h" -#include "sync/engine/model_safe_worker.h" -#include "sync/engine/syncer_types.h" #include "sync/engine/sync_engine_event.h" +#include "sync/engine/syncer_types.h" #include "sync/engine/traffic_recorder.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" #include "sync/sessions/debug_info_getter.h" namespace syncable { diff --git a/sync/sessions/sync_session_context_unittest.cc b/sync/sessions/sync_session_context_unittest.cc index 0e1fbf3..1b0a11a 100644 --- a/sync/sessions/sync_session_context_unittest.cc +++ b/sync/sessions/sync_session_context_unittest.cc @@ -4,7 +4,7 @@ #include "sync/sessions/sync_session_context.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "testing/gtest/include/gtest/gtest.h" namespace browser_sync { diff --git a/sync/sessions/sync_session_snapshot.cc b/sync/sessions/sync_session_snapshot.cc deleted file mode 100644 index 588b840..0000000 --- a/sync/sessions/sync_session_snapshot.cc +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright (c) 2012 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 "sync/sessions/sync_session_snapshot.h" - -#include "base/json/json_writer.h" -#include "base/values.h" - -namespace browser_sync { -namespace sessions { - -SyncSessionSnapshot::SyncSessionSnapshot() - : num_server_changes_remaining_(0), - is_share_usable_(false), - has_more_to_sync_(false), - is_silenced_(false), - num_encryption_conflicts_(0), - num_hierarchy_conflicts_(0), - num_simple_conflicts_(0), - num_server_conflicts_(0), - notifications_enabled_(false), - num_entries_(0), - retry_scheduled_(false) { -} - -SyncSessionSnapshot::SyncSessionSnapshot( - const SyncerStatus& syncer_status, - const ErrorCounters& errors, - int64 num_server_changes_remaining, - bool is_share_usable, - syncable::ModelTypeSet initial_sync_ended, - const syncable::ModelTypePayloadMap& download_progress_markers, - bool more_to_sync, - bool is_silenced, - int num_encryption_conflicts, - int num_hierarchy_conflicts, - int num_simple_conflicts, - int num_server_conflicts, - const SyncSourceInfo& source, - bool notifications_enabled, - size_t num_entries, - base::Time sync_start_time, - bool retry_scheduled) - : syncer_status_(syncer_status), - errors_(errors), - num_server_changes_remaining_(num_server_changes_remaining), - is_share_usable_(is_share_usable), - initial_sync_ended_(initial_sync_ended), - download_progress_markers_(download_progress_markers), - has_more_to_sync_(more_to_sync), - is_silenced_(is_silenced), - num_encryption_conflicts_(num_encryption_conflicts), - num_hierarchy_conflicts_(num_hierarchy_conflicts), - num_simple_conflicts_(num_simple_conflicts), - num_server_conflicts_(num_server_conflicts), - source_(source), - notifications_enabled_(notifications_enabled), - num_entries_(num_entries), - sync_start_time_(sync_start_time), - retry_scheduled_(retry_scheduled) { -} - -SyncSessionSnapshot::~SyncSessionSnapshot() {} - -DictionaryValue* SyncSessionSnapshot::ToValue() const { - DictionaryValue* value = new DictionaryValue(); - value->Set("syncerStatus", syncer_status_.ToValue()); - // We don't care too much if we lose precision here. - value->SetInteger("numServerChangesRemaining", - static_cast(num_server_changes_remaining_)); - value->SetBoolean("isShareUsable", is_share_usable_); - value->Set("initialSyncEnded", - syncable::ModelTypeSetToValue(initial_sync_ended_)); - value->Set("downloadProgressMarkers", - syncable::ModelTypePayloadMapToValue(download_progress_markers_)); - value->SetBoolean("hasMoreToSync", has_more_to_sync_); - value->SetBoolean("isSilenced", is_silenced_); - // We don't care too much if we lose precision here, also. - value->SetInteger("numEncryptionConflicts", - num_encryption_conflicts_); - value->SetInteger("numHierarchyConflicts", - num_hierarchy_conflicts_); - value->SetInteger("numSimpleConflicts", - num_simple_conflicts_); - value->SetInteger("numServerConflicts", - num_server_conflicts_); - value->SetInteger("numEntries", num_entries_); - value->Set("source", source_.ToValue()); - value->SetBoolean("notificationsEnabled", notifications_enabled_); - return value; -} - -std::string SyncSessionSnapshot::ToString() const { - scoped_ptr value(ToValue()); - std::string json; - base::JSONWriter::WriteWithOptions(value.get(), - base::JSONWriter::OPTIONS_PRETTY_PRINT, - &json); - return json; -} - -SyncerStatus SyncSessionSnapshot::syncer_status() const { - return syncer_status_; -} - -ErrorCounters SyncSessionSnapshot::errors() const { - return errors_; -} - -int64 SyncSessionSnapshot::num_server_changes_remaining() const { - return num_server_changes_remaining_; -} - -bool SyncSessionSnapshot::is_share_usable() const { - return is_share_usable_; -} - -syncable::ModelTypeSet SyncSessionSnapshot::initial_sync_ended() const { - return initial_sync_ended_; -} - -syncable::ModelTypePayloadMap - SyncSessionSnapshot::download_progress_markers() const { - return download_progress_markers_; -} - -bool SyncSessionSnapshot::has_more_to_sync() const { - return has_more_to_sync_; -} - -bool SyncSessionSnapshot::is_silenced() const { - return is_silenced_; -} - -int SyncSessionSnapshot::num_encryption_conflicts() const { - return num_encryption_conflicts_; -} - -int SyncSessionSnapshot::num_hierarchy_conflicts() const { - return num_hierarchy_conflicts_; -} - -int SyncSessionSnapshot::num_simple_conflicts() const { - return num_simple_conflicts_; -} - -int SyncSessionSnapshot::num_server_conflicts() const { - return num_server_conflicts_; -} - -SyncSourceInfo SyncSessionSnapshot::source() const { - return source_; -} - -bool SyncSessionSnapshot::notifications_enabled() const { - return notifications_enabled_; -} - -size_t SyncSessionSnapshot::num_entries() const { - return num_entries_; -} - -base::Time SyncSessionSnapshot::sync_start_time() const { - return sync_start_time_; -} - -bool SyncSessionSnapshot::retry_scheduled() const { - return retry_scheduled_; -} - -} // namespace sessions -} // namespace browser_sync diff --git a/sync/sessions/sync_session_snapshot.h b/sync/sessions/sync_session_snapshot.h deleted file mode 100644 index 8da3b80..0000000 --- a/sync/sessions/sync_session_snapshot.h +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) 2012 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 SYNC_SESSIONS_SYNC_SESSION_SNAPSHOT_H_ -#define SYNC_SESSIONS_SYNC_SESSION_SNAPSHOT_H_ -#pragma once - -#include - -#include "base/basictypes.h" -#include "base/time.h" -#include "sync/sessions/error_counters.h" -#include "sync/sessions/sync_source_info.h" -#include "sync/sessions/syncer_status.h" -#include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" - -namespace base { -class DictionaryValue; -} - -namespace browser_sync { -namespace sessions { - -// An immutable snapshot of state from a SyncSession. Convenient to use as -// part of notifications as it is inherently thread-safe. -// TODO(zea): if copying this all over the place starts getting expensive, -// consider passing around immutable references instead of values. -// Default copy and assign welcome. -class SyncSessionSnapshot { - public: - SyncSessionSnapshot(); - SyncSessionSnapshot( - const SyncerStatus& syncer_status, - const ErrorCounters& errors, - int64 num_server_changes_remaining, - bool is_share_usable, - syncable::ModelTypeSet initial_sync_ended, - const syncable::ModelTypePayloadMap& download_progress_markers, - bool more_to_sync, - bool is_silenced, - int num_encryption_conflicts, - int num_hierarchy_conflicts, - int num_simple_conflicts, - int num_server_conflicts, - const SyncSourceInfo& source, - bool notifications_enabled, - size_t num_entries, - base::Time sync_start_time, - bool retry_scheduled); - ~SyncSessionSnapshot(); - - // Caller takes ownership of the returned dictionary. - base::DictionaryValue* ToValue() const; - - std::string ToString() const; - - SyncerStatus syncer_status() const; - ErrorCounters errors() const; - int64 num_server_changes_remaining() const; - bool is_share_usable() const; - syncable::ModelTypeSet initial_sync_ended() const; - syncable::ModelTypePayloadMap download_progress_markers() const; - bool has_more_to_sync() const; - bool is_silenced() const; - int num_encryption_conflicts() const; - int num_hierarchy_conflicts() const; - int num_simple_conflicts() const; - int num_server_conflicts() const; - bool did_commit_items() const; - SyncSourceInfo source() const; - bool notifications_enabled() const; - size_t num_entries() const; - base::Time sync_start_time() const; - bool retry_scheduled() const; - - private: - SyncerStatus syncer_status_; - ErrorCounters errors_; - int64 num_server_changes_remaining_; - bool is_share_usable_; - syncable::ModelTypeSet initial_sync_ended_; - syncable::ModelTypePayloadMap download_progress_markers_; - bool has_more_to_sync_; - bool is_silenced_; - int num_encryption_conflicts_; - int num_hierarchy_conflicts_; - int num_simple_conflicts_; - int num_server_conflicts_; - SyncSourceInfo source_; - bool notifications_enabled_; - size_t num_entries_; - base::Time sync_start_time_; - bool retry_scheduled_; -}; - -} // namespace sessions -} // namespace browser_sync - -#endif // SYNC_SESSIONS_SYNC_SESSION_SNAPSHOT_H_ diff --git a/sync/sessions/sync_session_unittest.cc b/sync/sessions/sync_session_unittest.cc index 012f33d..8c3bd38 100644 --- a/sync/sessions/sync_session_unittest.cc +++ b/sync/sessions/sync_session_unittest.cc @@ -10,9 +10,9 @@ #include "base/message_loop.h" #include "sync/engine/conflict_resolver.h" #include "sync/engine/syncer_types.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/sessions/session_state.h" #include "sync/sessions/status_controller.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable.h" #include "sync/syncable/syncable_id.h" #include "sync/test/engine/fake_model_worker.h" diff --git a/sync/sessions/sync_source_info.cc b/sync/sessions/sync_source_info.cc deleted file mode 100644 index c6c47ab..0000000 --- a/sync/sessions/sync_source_info.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2012 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 "sync/sessions/sync_source_info.h" - -#include "base/values.h" -#include "sync/protocol/proto_enum_conversions.h" - -namespace browser_sync { -namespace sessions { - -SyncSourceInfo::SyncSourceInfo() - : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN) {} - -SyncSourceInfo::SyncSourceInfo( - const syncable::ModelTypePayloadMap& t) - : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN), types(t) {} - -SyncSourceInfo::SyncSourceInfo( - const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, - const syncable::ModelTypePayloadMap& t) - : updates_source(u), types(t) {} - -SyncSourceInfo::~SyncSourceInfo() {} - -DictionaryValue* SyncSourceInfo::ToValue() const { - DictionaryValue* value = new DictionaryValue(); - value->SetString("updatesSource", - GetUpdatesSourceString(updates_source)); - value->Set("types", syncable::ModelTypePayloadMapToValue(types)); - return value; -} - -} // namespace sessions -} // namespace browser_sync diff --git a/sync/sessions/sync_source_info.h b/sync/sessions/sync_source_info.h deleted file mode 100644 index 0eedd40..0000000 --- a/sync/sessions/sync_source_info.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2012 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 SYNC_SESSIONS_SYNC_SOURCE_INFO_H_ -#define SYNC_SESSIONS_SYNC_SOURCE_INFO_H_ -#pragma once - -#include "base/basictypes.h" -#include "sync/engine/syncproto.h" -#include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" - -namespace base { -class DictionaryValue; -} - -namespace browser_sync { -namespace sessions { - -// A container for the source of a sync session. This includes the update -// source, the datatypes triggering the sync session, and possible session -// specific payloads which should be sent to the server. -struct SyncSourceInfo { - SyncSourceInfo(); - explicit SyncSourceInfo(const syncable::ModelTypePayloadMap& t); - SyncSourceInfo( - const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, - const syncable::ModelTypePayloadMap& t); - ~SyncSourceInfo(); - - // Caller takes ownership of the returned dictionary. - base::DictionaryValue* ToValue() const; - - sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source; - syncable::ModelTypePayloadMap types; -}; - -} // namespace sessions -} // namespace browser_sync - -#endif // SYNC_SESSIONS_SYNC_SOURCE_INFO_H_ diff --git a/sync/sessions/syncer_status.cc b/sync/sessions/syncer_status.cc deleted file mode 100644 index ba318e4..0000000 --- a/sync/sessions/syncer_status.cc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2012 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 "sync/sessions/syncer_status.h" - -#include "base/values.h" - -namespace browser_sync { -namespace sessions { - -SyncerStatus::SyncerStatus() - : invalid_store(false), - num_successful_commits(0), - num_successful_bookmark_commits(0), - num_updates_downloaded_total(0), - num_tombstone_updates_downloaded_total(0), - num_reflected_updates_downloaded_total(0), - num_local_overwrites(0), - num_server_overwrites(0) { -} - -SyncerStatus::~SyncerStatus() { -} - -DictionaryValue* SyncerStatus::ToValue() const { - DictionaryValue* value = new DictionaryValue(); - value->SetBoolean("invalidStore", invalid_store); - value->SetInteger("numSuccessfulCommits", num_successful_commits); - value->SetInteger("numSuccessfulBookmarkCommits", - num_successful_bookmark_commits); - value->SetInteger("numUpdatesDownloadedTotal", - num_updates_downloaded_total); - value->SetInteger("numTombstoneUpdatesDownloadedTotal", - num_tombstone_updates_downloaded_total); - value->SetInteger("numReflectedUpdatesDownloadedTotal", - num_reflected_updates_downloaded_total); - value->SetInteger("numLocalOverwrites", num_local_overwrites); - value->SetInteger("numServerOverwrites", num_server_overwrites); - return value; -} - -} // namespace sessions -} // namespace browser_sync diff --git a/sync/sessions/syncer_status.h b/sync/sessions/syncer_status.h deleted file mode 100644 index b862d1f..0000000 --- a/sync/sessions/syncer_status.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2012 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 SYNC_SESSIONS_SYNCER_STATUS_H_ -#define SYNC_SESSIONS_SYNCER_STATUS_H_ -#pragma once - -#include "base/basictypes.h" -#include "sync/syncable/model_type.h" - -namespace base { -class DictionaryValue; -} - -namespace browser_sync { -namespace sessions { - -// Data pertaining to the status of an active Syncer object. -struct SyncerStatus { - SyncerStatus(); - ~SyncerStatus(); - - // Caller takes ownership of the returned dictionary. - base::DictionaryValue* ToValue() const; - - // True when we get such an INVALID_STORE error from the server. - bool invalid_store; - int num_successful_commits; - // This is needed for monitoring extensions activity. - int num_successful_bookmark_commits; - - // Download event counters. - int num_updates_downloaded_total; - int num_tombstone_updates_downloaded_total; - int num_reflected_updates_downloaded_total; - - // If the syncer encountered a MIGRATION_DONE code, these are the types that - // the client must now "migrate", by purging and re-downloading all updates. - syncable::ModelTypeSet types_needing_local_migration; - - // Overwrites due to conflict resolution counters. - int num_local_overwrites; - int num_server_overwrites; -}; - -} // namespace sessions -} // namespace browser_sync - -#endif // SYNC_SESSIONS_SYNCER_STATUS_H_ diff --git a/sync/sync.gyp b/sync/sync.gyp index 780a180..da7dbba 100644 --- a/sync/sync.gyp +++ b/sync/sync.gyp @@ -33,6 +33,26 @@ 'protocol/sync_proto.gyp:sync_proto', ], 'sources': [ + 'internal_api/public/engine/model_safe_worker.cc', + 'internal_api/public/engine/model_safe_worker.h', + 'internal_api/public/engine/passive_model_worker.cc', + 'internal_api/public/engine/passive_model_worker.h', + 'internal_api/public/engine/polling_constants.cc', + 'internal_api/public/engine/polling_constants.h', + 'internal_api/public/sessions/error_counters.cc', + 'internal_api/public/sessions/error_counters.h', + 'internal_api/public/sessions/syncer_status.cc', + 'internal_api/public/sessions/syncer_status.h', + 'internal_api/public/sessions/sync_session_snapshot.cc', + 'internal_api/public/sessions/sync_session_snapshot.h', + 'internal_api/public/sessions/sync_source_info.cc', + 'internal_api/public/sessions/sync_source_info.h', + 'internal_api/public/syncable/model_type.h', + 'internal_api/public/syncable/model_type_payload_map.cc', + 'internal_api/public/syncable/model_type_payload_map.h', + 'internal_api/public/util/enum_set.h', + 'internal_api/public/util/syncer_error.cc', + 'internal_api/public/util/syncer_error.h', 'engine/apply_updates_command.cc', 'engine/apply_updates_command.h', 'engine/build_commit_command.cc', @@ -51,10 +71,6 @@ 'engine/get_commit_ids_command.h', 'engine/model_changing_syncer_command.cc', 'engine/model_changing_syncer_command.h', - 'engine/model_safe_worker.cc', - 'engine/model_safe_worker.h', - 'engine/passive_model_worker.cc', - 'engine/passive_model_worker.h', 'engine/net/server_connection_manager.cc', 'engine/net/server_connection_manager.h', 'engine/net/url_translator.cc', @@ -63,8 +79,6 @@ 'engine/nigori_util.h', 'engine/nudge_source.cc', 'engine/nudge_source.h', - 'engine/polling_constants.cc', - 'engine/polling_constants.h', 'engine/process_commit_response_command.cc', 'engine/process_commit_response_command.h', 'engine/process_updates_command.cc', @@ -112,24 +126,16 @@ 'protocol/sync_protocol_error.cc', 'protocol/sync_protocol_error.h', 'sessions/debug_info_getter.h', - 'sessions/error_counters.cc', - 'sessions/error_counters.h', 'sessions/ordered_commit_set.cc', 'sessions/ordered_commit_set.h', 'sessions/session_state.cc', 'sessions/session_state.h', 'sessions/status_controller.cc', 'sessions/status_controller.h', - 'sessions/syncer_status.cc', - 'sessions/syncer_status.h', 'sessions/sync_session.cc', 'sessions/sync_session.h', 'sessions/sync_session_context.cc', 'sessions/sync_session_context.h', - 'sessions/sync_session_snapshot.cc', - 'sessions/sync_session_snapshot.h', - 'sessions/sync_source_info.cc', - 'sessions/sync_source_info.h', 'syncable/blob.h', 'syncable/directory_backing_store.cc', 'syncable/directory_backing_store.h', @@ -138,9 +144,6 @@ 'syncable/in_memory_directory_backing_store.cc', 'syncable/in_memory_directory_backing_store.h', 'syncable/model_type.cc', - 'syncable/model_type.h', - 'syncable/model_type_payload_map.cc', - 'syncable/model_type_payload_map.h', 'syncable/on_disk_directory_backing_store.cc', 'syncable/on_disk_directory_backing_store.h', 'syncable/syncable.cc', @@ -163,7 +166,6 @@ 'util/data_type_histogram.h', 'util/encryptor.h', - 'util/enum_set.h', 'util/experiments.h', 'util/extensions_activity_monitor.cc', 'util/extensions_activity_monitor.h', @@ -181,8 +183,6 @@ 'util/report_unrecoverable_error_function.h', 'util/session_utils_android.cc', 'util/session_utils_android.h', - 'util/syncer_error.cc', - 'util/syncer_error.h', 'util/time.cc', 'util/time.h', 'util/unrecoverable_error_handler.h', @@ -361,14 +361,14 @@ 'sync', ], 'sources': [ + 'internal_api/public/syncable/model_type_test_util.cc', + 'internal_api/public/syncable/model_type_test_util.h', 'js/js_test_util.cc', 'js/js_test_util.h', 'notifier/mock_invalidation_state_tracker.cc', 'notifier/mock_invalidation_state_tracker.h', 'sessions/test_util.cc', 'sessions/test_util.h', - 'syncable/model_type_test_util.cc', - 'syncable/model_type_test_util.h', 'syncable/syncable_mock.cc', 'syncable/syncable_mock.h', 'test/fake_encryptor.cc', @@ -501,13 +501,15 @@ '..', ], 'sources': [ + 'internal_api/public/engine/model_safe_worker_unittest.cc', + 'internal_api/public/syncable/model_type_payload_map_unittest.cc', + 'internal_api/public/util/enum_set_unittest.cc', 'engine/apply_updates_command_unittest.cc', 'engine/build_commit_command_unittest.cc', 'engine/clear_data_command_unittest.cc', 'engine/cleanup_disabled_types_command_unittest.cc', 'engine/download_updates_command_unittest.cc', 'engine/model_changing_syncer_command_unittest.cc', - 'engine/model_safe_worker_unittest.cc', 'engine/nigori_util_unittest.cc', 'engine/process_commit_response_command_unittest.cc', 'engine/process_updates_command_unittest.cc', @@ -530,7 +532,6 @@ 'sessions/sync_session_context_unittest.cc', 'sessions/sync_session_unittest.cc', 'syncable/directory_backing_store_unittest.cc', - 'syncable/model_type_payload_map_unittest.cc', 'syncable/model_type_unittest.cc', 'syncable/syncable_enum_conversions_unittest.cc', 'syncable/syncable_id_unittest.cc', @@ -538,7 +539,6 @@ 'util/cryptographer_unittest.cc', 'util/data_encryption_win_unittest.cc', 'util/data_type_histogram_unittest.cc', - 'util/enum_set_unittest.cc', 'util/get_session_name_unittest.cc', 'util/immutable_unittest.cc', 'util/nigori_unittest.cc', diff --git a/sync/syncable/DEPS b/sync/syncable/DEPS index cb86572..7b13d73 100644 --- a/sync/syncable/DEPS +++ b/sync/syncable/DEPS @@ -1,13 +1,12 @@ include_rules = [ "+net/base/escape.h", "+sql", + "+sync/internal_api/public/engine", + "+sync/internal_api/public/syncable", "+sync/protocol", "+sync/test", "+sync/util", # this file is weird. "+sync/engine/syncproto.h", - - # maybe this file should live in syncable? - "+sync/engine/model_safe_worker.h", ] diff --git a/sync/syncable/directory_backing_store.h b/sync/syncable/directory_backing_store.h index 4c9bd846..7e86eb9 100644 --- a/sync/syncable/directory_backing_store.h +++ b/sync/syncable/directory_backing_store.h @@ -12,8 +12,8 @@ #include "base/threading/non_thread_safe.h" #include "sql/connection.h" #include "sql/statement.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/syncable/dir_open_result.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable.h" namespace sync_pb { diff --git a/sync/syncable/directory_change_delegate.h b/sync/syncable/directory_change_delegate.h index e3b0f45..a86b770 100644 --- a/sync/syncable/directory_change_delegate.h +++ b/sync/syncable/directory_change_delegate.h @@ -6,7 +6,7 @@ #define SYNC_SYNCABLE_DIRECTORY_CHANGE_DELEGATE_H_ #pragma once -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/syncable/syncable.h" namespace syncable { diff --git a/sync/syncable/model_type.cc b/sync/syncable/model_type.cc index 3b53a90..7589e7f 100644 --- a/sync/syncable/model_type.cc +++ b/sync/syncable/model_type.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 "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "base/string_split.h" #include "base/values.h" diff --git a/sync/syncable/model_type.h b/sync/syncable/model_type.h deleted file mode 100644 index 133af9c..0000000 --- a/sync/syncable/model_type.h +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright (c) 2012 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. - -// Enumerate the various item subtypes that are supported by sync. -// Each sync object is expected to have an immutable object type. -// An object's type is inferred from the type of data it holds. - -#ifndef SYNC_SYNCABLE_MODEL_TYPE_H_ -#define SYNC_SYNCABLE_MODEL_TYPE_H_ -#pragma once - -#include -#include - -#include "base/logging.h" -#include "base/time.h" -#include "sync/util/enum_set.h" - -namespace base { -class ListValue; -class StringValue; -class Value; -} - -namespace sync_pb { -class EntitySpecifics; -class SyncEntity; -} - -namespace syncable { - -enum ModelType { - // Object type unknown. Objects may transition through - // the unknown state during their initial creation, before - // their properties are set. After deletion, object types - // are generally preserved. - UNSPECIFIED, - // A permanent folder whose children may be of mixed - // datatypes (e.g. the "Google Chrome" folder). - TOP_LEVEL_FOLDER, - - // ------------------------------------ Start of "real" model types. - // The model types declared before here are somewhat special, as they - // they do not correspond to any browser data model. The remaining types - // are bona fide model types; all have a related browser data model and - // can be represented in the protocol using a specific Message type in the - // EntitySpecifics protocol buffer. - // - // A bookmark folder or a bookmark URL object. - BOOKMARKS, - FIRST_REAL_MODEL_TYPE = BOOKMARKS, // Declared 2nd, for debugger prettiness. - - // A preference folder or a preference object. - PREFERENCES, - // A password folder or password object. - PASSWORDS, - // An AutofillProfile Object - AUTOFILL_PROFILE, - // An autofill folder or an autofill object. - AUTOFILL, - - // A themes folder or a themes object. - THEMES, - // A typed_url folder or a typed_url object. - TYPED_URLS, - // An extension folder or an extension object. - EXTENSIONS, - // An object representing a set of Nigori keys. - NIGORI, - // An object representing a custom search engine. - SEARCH_ENGINES, - // An object representing a browser session. - SESSIONS, - // An app folder or an app object. - APPS, - // An app setting from the extension settings API. - APP_SETTINGS, - // An extension setting from the extension settings API. - EXTENSION_SETTINGS, - // App notifications. - APP_NOTIFICATIONS, - LAST_REAL_MODEL_TYPE = APP_NOTIFICATIONS, - - // If you are adding a new sync datatype that is exposed to the user via the - // sync preferences UI, be sure to update the list in - // chrome/browser/sync/user_selectable_sync_type.h so that the UMA histograms - // for sync include your new type. - - MODEL_TYPE_COUNT, -}; - -typedef browser_sync::EnumSet< - ModelType, FIRST_REAL_MODEL_TYPE, LAST_REAL_MODEL_TYPE> ModelTypeSet; -typedef browser_sync::EnumSet< - ModelType, UNSPECIFIED, LAST_REAL_MODEL_TYPE> FullModelTypeSet; - -inline ModelType ModelTypeFromInt(int i) { - DCHECK_GE(i, 0); - DCHECK_LT(i, MODEL_TYPE_COUNT); - return static_cast(i); -} - -void AddDefaultFieldValue(syncable::ModelType datatype, - sync_pb::EntitySpecifics* specifics); - -// Extract the model type of a SyncEntity protocol buffer. ModelType is a -// local concept: the enum is not in the protocol. The SyncEntity's ModelType -// is inferred from the presence of particular datatype field in the -// entity specifics. -ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); - -// Extract the model type from an EntitySpecifics field. Note that there -// are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; -// prefer using GetModelType where possible. -ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics); - -// If this returns false, we shouldn't bother maintaining a position -// value (sibling ordering) for this item. -bool ShouldMaintainPosition(ModelType model_type); - -// Determine a model type from the field number of its associated -// EntitySpecifics field. -ModelType GetModelTypeFromSpecificsFieldNumber(int field_number); - -// Return the field number of the EntitySpecifics field associated with -// a model type. -int GetSpecificsFieldNumberFromModelType(ModelType model_type); - -// TODO(sync): The functions below badly need some cleanup. - -// Returns a pointer to a string with application lifetime that represents -// the name of |model_type|. -const char* ModelTypeToString(ModelType model_type); - -// Handles all model types, and not just real ones. -// -// Caller takes ownership of returned value. -base::StringValue* ModelTypeToValue(ModelType model_type); - -// Converts a Value into a ModelType - complement to ModelTypeToValue(). -ModelType ModelTypeFromValue(const base::Value& value); - -// Returns the ModelType corresponding to the name |model_type_string|. -ModelType ModelTypeFromString(const std::string& model_type_string); - -std::string ModelTypeSetToString(ModelTypeSet model_types); - -// Caller takes ownership of returned list. -base::ListValue* ModelTypeSetToValue(ModelTypeSet model_types); - -ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value); - -// Returns a string corresponding to the syncable tag for this datatype. -std::string ModelTypeToRootTag(ModelType type); - -// Convert a real model type to a notification type (used for -// subscribing to server-issued notifications). Returns true iff -// |model_type| was a real model type and |notification_type| was -// filled in. -bool RealModelTypeToNotificationType(ModelType model_type, - std::string* notification_type); - -// Converts a notification type to a real model type. Returns true -// iff |notification_type| was the notification type of a real model -// type and |model_type| was filled in. -bool NotificationTypeToRealModelType(const std::string& notification_type, - ModelType* model_type); - -// Returns true if |model_type| is a real datatype -bool IsRealDataType(ModelType model_type); - -} // namespace syncable - -#endif // SYNC_SYNCABLE_MODEL_TYPE_H_ diff --git a/sync/syncable/model_type_payload_map.cc b/sync/syncable/model_type_payload_map.cc deleted file mode 100644 index 1485cec..0000000 --- a/sync/syncable/model_type_payload_map.cc +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) 2012 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 "sync/syncable/model_type_payload_map.h" - -#include - -#include "base/base64.h" -#include "base/json/json_writer.h" -#include "base/memory/scoped_ptr.h" -#include "base/values.h" - -using browser_sync::ModelSafeRoutingInfo; -namespace syncable { - -ModelTypePayloadMap ModelTypePayloadMapFromEnumSet( - syncable::ModelTypeSet types, - const std::string& payload) { - ModelTypePayloadMap types_with_payloads; - for (syncable::ModelTypeSet::Iterator it = types.First(); - it.Good(); it.Inc()) { - types_with_payloads[it.Get()] = payload; - } - return types_with_payloads; -} - -ModelTypeSet ModelTypePayloadMapToEnumSet( - const ModelTypePayloadMap& payload_map) { - ModelTypeSet types; - for (ModelTypePayloadMap::const_iterator it = payload_map.begin(); - it != payload_map.end(); ++it) { - types.Put(it->first); - } - return types; -} - -ModelTypePayloadMap ModelTypePayloadMapFromRoutingInfo( - const browser_sync::ModelSafeRoutingInfo& routes, - const std::string& payload) { - ModelTypePayloadMap types_with_payloads; - for (browser_sync::ModelSafeRoutingInfo::const_iterator i = routes.begin(); - i != routes.end(); ++i) { - types_with_payloads[i->first] = payload; - } - return types_with_payloads; -} - -std::string ModelTypePayloadMapToString( - const ModelTypePayloadMap& type_payloads) { - scoped_ptr value( - ModelTypePayloadMapToValue(type_payloads)); - std::string json; - base::JSONWriter::Write(value.get(), &json); - return json; -} - -DictionaryValue* ModelTypePayloadMapToValue( - const ModelTypePayloadMap& type_payloads) { - DictionaryValue* value = new DictionaryValue(); - for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); - it != type_payloads.end(); ++it) { - // TODO(akalin): Unpack the value into a protobuf. - std::string base64_marker; - bool encoded = base::Base64Encode(it->second, &base64_marker); - DCHECK(encoded); - value->SetString(syncable::ModelTypeToString(it->first), base64_marker); - } - return value; -} - -void CoalescePayloads(ModelTypePayloadMap* original, - const ModelTypePayloadMap& update) { - for (ModelTypePayloadMap::const_iterator i = update.begin(); - i != update.end(); ++i) { - if (original->count(i->first) == 0) { - // If this datatype isn't already in our map, add it with - // whatever payload it has. - (*original)[i->first] = i->second; - } else if (i->second.length() > 0) { - // If this datatype is already in our map, we only overwrite the - // payload if the new one is non-empty. - (*original)[i->first] = i->second; - } - } -} - -void PurgeStalePayload(ModelTypePayloadMap* original, - const ModelSafeRoutingInfo& routing_info) { - std::vector iterators_to_delete; - for (ModelTypePayloadMap::iterator i = original->begin(); - i != original->end(); ++i) { - if (routing_info.end() == routing_info.find(i->first)) { - iterators_to_delete.push_back(i); - } - } - - for (std::vector::iterator - it = iterators_to_delete.begin(); it != iterators_to_delete.end(); - ++it) { - original->erase(*it); - } -} - -} // namespace syncable diff --git a/sync/syncable/model_type_payload_map.h b/sync/syncable/model_type_payload_map.h deleted file mode 100644 index f46f743..0000000 --- a/sync/syncable/model_type_payload_map.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2012 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. -// -// Definition of ModelTypePayloadMap and various utility functions. - -#ifndef SYNC_SYNCABLE_MODEL_TYPE_PAYLOAD_MAP_H_ -#define SYNC_SYNCABLE_MODEL_TYPE_PAYLOAD_MAP_H_ -#pragma once - -#include -#include - -#include "sync/engine/model_safe_worker.h" -#include "sync/syncable/model_type.h" - -namespace base { -class DictionaryValue; -} - -namespace syncable { - -// A container that contains a set of datatypes with possible string -// payloads. -typedef std::map ModelTypePayloadMap; - -// Helper functions for building ModelTypePayloadMaps. - -// Make a TypePayloadMap from all the types in a ModelTypeSet using a -// default payload. -ModelTypePayloadMap ModelTypePayloadMapFromEnumSet( - ModelTypeSet model_types, const std::string& payload); - -ModelTypeSet ModelTypePayloadMapToEnumSet( - const ModelTypePayloadMap& payload_map); - -// Make a TypePayloadMap for all the enabled types in a -// ModelSafeRoutingInfo using a default payload. -ModelTypePayloadMap ModelTypePayloadMapFromRoutingInfo( - const browser_sync::ModelSafeRoutingInfo& routes, - const std::string& payload); - -std::string ModelTypePayloadMapToString( - const ModelTypePayloadMap& model_type_payloads); - -// Caller takes ownership of the returned dictionary. -base::DictionaryValue* ModelTypePayloadMapToValue( - const ModelTypePayloadMap& model_type_payloads); - -// Coalesce |update| into |original|, overwriting only when |update| has -// a non-empty payload. -void CoalescePayloads(ModelTypePayloadMap* original, - const ModelTypePayloadMap& update); - -void PurgeStalePayload(ModelTypePayloadMap* original, - const browser_sync::ModelSafeRoutingInfo& routing_info); - -} // namespace syncable - -#endif // SYNC_SYNCABLE_MODEL_TYPE_PAYLOAD_MAP_H_ diff --git a/sync/syncable/model_type_payload_map_unittest.cc b/sync/syncable/model_type_payload_map_unittest.cc deleted file mode 100644 index 212c2b7..0000000 --- a/sync/syncable/model_type_payload_map_unittest.cc +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2012 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 "sync/syncable/model_type_payload_map.h" - -#include - -#include "base/base64.h" -#include "base/memory/scoped_ptr.h" -#include "base/test/values_test_util.h" -#include "base/values.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace syncable { -namespace { - -using base::ExpectDictStringValue; - -class ModelTypePayloadMapTest : public testing::Test {}; - -TEST_F(ModelTypePayloadMapTest, TypePayloadMapToSet) { - ModelTypePayloadMap payloads; - payloads[BOOKMARKS] = "bookmarkpayload"; - payloads[APPS] = ""; - - const ModelTypeSet types(BOOKMARKS, APPS); - EXPECT_TRUE(ModelTypePayloadMapToEnumSet(payloads).Equals(types)); -} - -TEST_F(ModelTypePayloadMapTest, TypePayloadMapToValue) { - ModelTypePayloadMap payloads; - std::string encoded; - payloads[BOOKMARKS] = "bookmarkpayload"; - base::Base64Encode(payloads[BOOKMARKS], &encoded); - payloads[APPS] = ""; - - scoped_ptr value(ModelTypePayloadMapToValue(payloads)); - EXPECT_EQ(2u, value->size()); - ExpectDictStringValue(encoded, *value, "Bookmarks"); - ExpectDictStringValue("", *value, "Apps"); - EXPECT_FALSE(value->HasKey("Preferences")); -} - -} // namespace -} // namespace syncable diff --git a/sync/syncable/model_type_test_util.cc b/sync/syncable/model_type_test_util.cc deleted file mode 100644 index a3b6742..0000000 --- a/sync/syncable/model_type_test_util.cc +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2012 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 "sync/syncable/model_type_test_util.h" - -namespace syncable { - -void PrintTo(ModelTypeSet model_types, ::std::ostream* os) { - *os << ModelTypeSetToString(model_types); -} - -namespace { - -// Matcher implementation for HasModelTypes(). -class HasModelTypesMatcher - : public ::testing::MatcherInterface { - public: - explicit HasModelTypesMatcher(ModelTypeSet expected_types) - : expected_types_(expected_types) {} - - virtual ~HasModelTypesMatcher() {} - - virtual bool MatchAndExplain( - ModelTypeSet model_types, - ::testing::MatchResultListener* listener) const { - // No need to annotate listener since we already define PrintTo(). - return model_types.Equals(expected_types_); - } - - virtual void DescribeTo(::std::ostream* os) const { - *os << "has model types " << ModelTypeSetToString(expected_types_); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "doesn't have model types " - << ModelTypeSetToString(expected_types_); - } - - private: - const ModelTypeSet expected_types_; - - DISALLOW_COPY_AND_ASSIGN(HasModelTypesMatcher); -}; - -} // namespace - -::testing::Matcher HasModelTypes(ModelTypeSet expected_types) { - return ::testing::MakeMatcher(new HasModelTypesMatcher(expected_types)); -} - -} // namespace syncable diff --git a/sync/syncable/model_type_test_util.h b/sync/syncable/model_type_test_util.h deleted file mode 100644 index a852a07..0000000 --- a/sync/syncable/model_type_test_util.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2012 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 SYNC_SYNCABLE_MODEL_TYPE_TEST_UTIL_H_ -#define SYNC_SYNCABLE_MODEL_TYPE_TEST_UTIL_H_ -#pragma once - -#include - -#include "sync/syncable/model_type.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace syncable { - -// Defined for googletest. Forwards to ModelTypeSetToString(). -void PrintTo(ModelTypeSet model_types, ::std::ostream* os); - -// A gmock matcher for ModelTypeSet. Use like: -// -// EXPECT_CALL(mock, ProcessModelTypes(HasModelTypes(expected_types))); -::testing::Matcher HasModelTypes(ModelTypeSet expected_types); - -} // namespace syncable - -#endif // SYNC_SYNCABLE_MODEL_TYPE_TEST_UTIL_H_ diff --git a/sync/syncable/model_type_unittest.cc b/sync/syncable/model_type_unittest.cc index a8925b6..c8a53f7 100644 --- a/sync/syncable/model_type_unittest.cc +++ b/sync/syncable/model_type_unittest.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 "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" #include diff --git a/sync/syncable/syncable.cc b/sync/syncable/syncable.cc index a9c1263..7bf16fc 100644 --- a/sync/syncable/syncable.cc +++ b/sync/syncable/syncable.cc @@ -14,9 +14,9 @@ #include #include "base/basictypes.h" -#include "base/debug/trace_event.h" #include "base/compiler_specific.h" #include "base/debug/trace_event.h" +#include "base/debug/trace_event.h" #include "base/file_util.h" #include "base/hash_tables.h" #include "base/location.h" @@ -29,20 +29,20 @@ #include "base/time.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "net/base/escape.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/proto_value_conversions.h" #include "sync/syncable/directory_backing_store.h" #include "sync/syncable/directory_change_delegate.h" #include "sync/syncable/in_memory_directory_backing_store.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/on_disk_directory_backing_store.h" #include "sync/syncable/syncable-inl.h" #include "sync/syncable/syncable_changes_version.h" #include "sync/syncable/syncable_columns.h" #include "sync/syncable/syncable_enum_conversions.h" #include "sync/syncable/transaction_observer.h" -#include "sync/util/logging.h" #include "sync/util/cryptographer.h" -#include "net/base/escape.h" +#include "sync/util/logging.h" namespace { diff --git a/sync/syncable/syncable.h b/sync/syncable/syncable.h index c9acc2e..16aa0a2 100644 --- a/sync/syncable/syncable.h +++ b/sync/syncable/syncable.h @@ -26,17 +26,17 @@ #include "base/memory/ref_counted.h" #include "base/synchronization/lock.h" #include "base/time.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/protocol/sync.pb.h" #include "sync/syncable/blob.h" #include "sync/syncable/dir_open_result.h" -#include "sync/syncable/model_type.h" #include "sync/syncable/syncable_id.h" #include "sync/util/cryptographer.h" #include "sync/util/immutable.h" #include "sync/util/report_unrecoverable_error_function.h" -#include "sync/util/unrecoverable_error_handler.h" #include "sync/util/time.h" +#include "sync/util/unrecoverable_error_handler.h" #include "sync/util/weak_handle.h" -#include "sync/protocol/sync.pb.h" namespace base { class DictionaryValue; diff --git a/sync/syncable/transaction_observer.h b/sync/syncable/transaction_observer.h index bcade47..28db7a0 100644 --- a/sync/syncable/transaction_observer.h +++ b/sync/syncable/transaction_observer.h @@ -6,7 +6,7 @@ #define SYNC_SYNCABLE_TRANSACTION_OBSERVER_H_ #pragma once -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/syncable/syncable.h" namespace syncable { diff --git a/sync/test/engine/fake_model_worker.h b/sync/test/engine/fake_model_worker.h index 861adc7..72ad59e 100644 --- a/sync/test/engine/fake_model_worker.h +++ b/sync/test/engine/fake_model_worker.h @@ -11,8 +11,8 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/threading/non_thread_safe.h" -#include "sync/engine/model_safe_worker.h" -#include "sync/util/syncer_error.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" +#include "sync/internal_api/public/util/syncer_error.h" namespace browser_sync { diff --git a/sync/test/engine/mock_connection_manager.h b/sync/test/engine/mock_connection_manager.h index 66d9aa9..d979a54 100644 --- a/sync/test/engine/mock_connection_manager.h +++ b/sync/test/engine/mock_connection_manager.h @@ -17,8 +17,8 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_vector.h" #include "sync/engine/net/server_connection_manager.h" -#include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/protocol/sync.pb.h" class MockConnectionManager : public browser_sync::ServerConnectionManager { diff --git a/sync/test/engine/syncer_command_test.h b/sync/test/engine/syncer_command_test.h index 1fe919b..713e68c 100644 --- a/sync/test/engine/syncer_command_test.h +++ b/sync/test/engine/syncer_command_test.h @@ -14,18 +14,18 @@ #include "base/memory/ref_counted.h" #include "base/message_loop.h" #include "sync/engine/model_changing_syncer_command.h" -#include "sync/engine/model_safe_worker.h" #include "sync/engine/traffic_recorder.h" +#include "sync/internal_api/public/engine/model_safe_worker.h" #include "sync/sessions/debug_info_getter.h" #include "sync/sessions/sync_session.h" #include "sync/sessions/sync_session_context.h" #include "sync/syncable/syncable_mock.h" -#include "sync/test/engine/mock_connection_manager.h" #include "sync/test/engine/fake_model_worker.h" +#include "sync/test/engine/mock_connection_manager.h" #include "sync/test/engine/test_directory_setter_upper.h" #include "sync/test/fake_extensions_activity_monitor.h" -#include "testing/gtest/include/gtest/gtest.h" #include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" using ::testing::NiceMock; diff --git a/sync/tools/DEPS b/sync/tools/DEPS index d3ae88f..4c7287a 100644 --- a/sync/tools/DEPS +++ b/sync/tools/DEPS @@ -4,6 +4,5 @@ include_rules = [ "+net/base/host_resolver.h", "+net/url_request/url_request_test_util.h", "+sync/notifier", - "+sync/syncable/model_type.h", - "+sync/syncable/model_type_payload_map.h", + "+sync/internal_api/public/syncable", ] diff --git a/sync/tools/sync_listen_notifications.cc b/sync/tools/sync_listen_notifications.cc index 5e5f97a..52e2efa 100644 --- a/sync/tools/sync_listen_notifications.cc +++ b/sync/tools/sync_listen_notifications.cc @@ -20,12 +20,12 @@ #include "net/base/host_port_pair.h" #include "net/base/host_resolver.h" #include "net/url_request/url_request_test_util.h" +#include "sync/internal_api/public/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type_payload_map.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/sync_notifier.h" #include "sync/notifier/sync_notifier_factory.h" #include "sync/notifier/sync_notifier_observer.h" -#include "sync/syncable/model_type.h" -#include "sync/syncable/model_type_payload_map.h" // This is a simple utility that initializes a sync notifier and // listens to any received notifications. diff --git a/sync/util/DEPS b/sync/util/DEPS index f101c9b..a951508 100644 --- a/sync/util/DEPS +++ b/sync/util/DEPS @@ -1,8 +1,7 @@ include_rules = [ "+crypto", + "+sync/internal_api/public/syncable", "+sync/protocol", - "+sync/syncable/model_type.h", - "+sync/syncable/model_type_test_util.h", "+sync/test/fake_encryptor.h", # TODO(kochi): Remove this hack after "Chromebox" hack in get_session_name.cc diff --git a/sync/util/cryptographer.h b/sync/util/cryptographer.h index 12f3412..b711f29 100644 --- a/sync/util/cryptographer.h +++ b/sync/util/cryptographer.h @@ -13,10 +13,10 @@ #include "base/memory/linked_ptr.h" #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" -#include "sync/syncable/model_type.h" -#include "sync/util/nigori.h" +#include "sync/internal_api/public/syncable/model_type.h" #include "sync/protocol/encryption.pb.h" #include "sync/protocol/nigori_specifics.pb.h" +#include "sync/util/nigori.h" namespace browser_sync { diff --git a/sync/util/cryptographer_unittest.cc b/sync/util/cryptographer_unittest.cc index dc38e0f..c999916 100644 --- a/sync/util/cryptographer_unittest.cc +++ b/sync/util/cryptographer_unittest.cc @@ -8,10 +8,10 @@ #include "base/memory/scoped_ptr.h" #include "base/string_util.h" -#include "sync/syncable/model_type_test_util.h" -#include "sync/test/fake_encryptor.h" +#include "sync/internal_api/public/syncable/model_type_test_util.h" #include "sync/protocol/nigori_specifics.pb.h" #include "sync/protocol/password_specifics.pb.h" +#include "sync/test/fake_encryptor.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/sync/util/data_type_histogram.h b/sync/util/data_type_histogram.h index 72ab1b5..869f162 100644 --- a/sync/util/data_type_histogram.h +++ b/sync/util/data_type_histogram.h @@ -8,7 +8,7 @@ #include "base/metrics/histogram.h" #include "base/time.h" -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" // For now, this just implements UMA_HISTOGRAM_LONG_TIMES. This can be adjusted // if we feel the min, max, or bucket count amount are not appropriate. diff --git a/sync/util/enum_set.h b/sync/util/enum_set.h deleted file mode 100644 index d860623..0000000 --- a/sync/util/enum_set.h +++ /dev/null @@ -1,286 +0,0 @@ -// Copyright (c) 2012 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 SYNC_UTIL_ENUM_SET_H_ -#define SYNC_UTIL_ENUM_SET_H_ -#pragma once - -#include -#include -#include - -#include "base/basictypes.h" -#include "base/logging.h" - -namespace browser_sync { - -// Forward declarations needed for friend declarations. -template -class EnumSet; - -template -EnumSet Union(EnumSet set1, - EnumSet set2); - -template -EnumSet Intersection(EnumSet set1, - EnumSet set2); - -template -EnumSet Difference(EnumSet set1, - EnumSet set2); - -// An EnumSet is a set that can hold enum values between a min and a -// max value (inclusive of both). It's essentially a wrapper around -// std::bitset<> with stronger type enforcement, more descriptive -// member function names, and an iterator interface. -// -// If you're working with enums with a small number of possible values -// (say, fewer than 64), you can efficiently pass around an EnumSet -// for that enum around by value. - -template -class EnumSet { - public: - typedef E EnumType; - static const E kMinValue = MinEnumValue; - static const E kMaxValue = MaxEnumValue; - static const size_t kValueCount = kMaxValue - kMinValue + 1; - COMPILE_ASSERT(kMinValue < kMaxValue, - min_value_must_be_less_than_max_value); - - private: - // Declaration needed by Iterator. - typedef std::bitset EnumBitSet; - - public: - // Iterator is a forward-only read-only iterator for EnumSet. Its - // interface is deliberately distinct from an STL iterator as its - // semantics are substantially different. - // - // Example usage: - // - // for (EnumSet<...>::Iterator it = enums.First(); it.Good(); it.Inc()) { - // Process(it.Get()); - // } - // - // The iterator must not be outlived by the set. In particular, the - // following is an error: - // - // EnumSet<...> SomeFn() { ... } - // - // /* ERROR */ - // for (EnumSet<...>::Iterator it = SomeFun().First(); ... - // - // Also, there are no guarantees as to what will happen if you - // modify an EnumSet while traversing it with an iterator. - class Iterator { - public: - // A default-constructed iterator can't do anything except check - // Good(). You need to call First() on an EnumSet to get a usable - // iterator. - Iterator() : enums_(NULL), i_(kValueCount) {} - ~Iterator() {} - - // Copy constructor and assignment welcome. - - // Returns true iff the iterator points to an EnumSet and it - // hasn't yet traversed the EnumSet entirely. - bool Good() const { - return enums_ && i_ < kValueCount && enums_->test(i_); - } - - // Returns the value the iterator currently points to. Good() - // must hold. - E Get() const { - CHECK(Good()); - return FromIndex(i_); - } - - // Moves the iterator to the next value in the EnumSet. Good() - // must hold. Takes linear time. - void Inc() { - CHECK(Good()); - i_ = FindNext(i_ + 1); - } - - private: - friend Iterator EnumSet::First() const; - - explicit Iterator(const EnumBitSet& enums) - : enums_(&enums), i_(FindNext(0)) {} - - size_t FindNext(size_t i) { - while ((i < kValueCount) && !enums_->test(i)) { - ++i; - } - return i; - } - - const EnumBitSet* enums_; - size_t i_; - }; - - // You can construct an EnumSet with 0, 1, 2, or 3 initial values. - - EnumSet() {} - - explicit EnumSet(E value) { - Put(value); - } - - EnumSet(E value1, E value2) { - Put(value1); - Put(value2); - } - - EnumSet(E value1, E value2, E value3) { - Put(value1); - Put(value2); - Put(value3); - } - - // Returns an EnumSet with all possible values. - static EnumSet All() { - EnumBitSet enums; - enums.set(); - return EnumSet(enums); - } - - ~EnumSet() {} - - // Copy constructor and assignment welcome. - - // Set operations. Put, Retain, and Remove are basically - // self-mutating versions of Union, Intersection, and Difference - // (defined below). - - // Adds the given value (which must be in range) to our set. - void Put(E value) { - enums_.set(ToIndex(value)); - } - - // Adds all values in the given set to our set. - void PutAll(EnumSet other) { - enums_ |= other.enums_; - } - - // There's no real need for a Retain(E) member function. - - // Removes all values not in the given set from our set. - void RetainAll(EnumSet other) { - enums_ &= other.enums_; - } - - // If the given value is in range, removes it from our set. - void Remove(E value) { - if (InRange(value)) { - enums_.reset(ToIndex(value)); - } - } - - // Removes all values in the given set from our set. - void RemoveAll(EnumSet other) { - enums_ &= ~other.enums_; - } - - // Removes all values from our set. - void Clear() { - enums_.reset(); - } - - // Returns true iff the given value is in range and a member of our - // set. - bool Has(E value) const { - return InRange(value) && enums_.test(ToIndex(value)); - } - - // Returns true iff the given set is a subset of our set. - bool HasAll(EnumSet other) const { - return (enums_ & other.enums_) == other.enums_; - } - - // Returns true iff our set and the given set contain exactly the - // same values. - bool Equals(const EnumSet& other) const { - return enums_ == other.enums_; - } - - // Returns true iff our set is empty. - bool Empty() const { - return !enums_.any(); - } - - // Returns how many values our set has. - size_t Size() const { - return enums_.count(); - } - - // Returns an iterator pointing to the first element (if any). - Iterator First() const { - return Iterator(enums_); - } - - private: - friend EnumSet Union( - EnumSet set1, EnumSet set2); - friend EnumSet Intersection( - EnumSet set1, EnumSet set2); - friend EnumSet Difference( - EnumSet set1, EnumSet set2); - - explicit EnumSet(EnumBitSet enums) : enums_(enums) {} - - static bool InRange(E value) { - return (value >= MinEnumValue) && (value <= MaxEnumValue); - } - - // Converts a value to/from an index into |enums_|. - - static size_t ToIndex(E value) { - DCHECK_GE(value, MinEnumValue); - DCHECK_LE(value, MaxEnumValue); - return value - MinEnumValue; - } - - static E FromIndex(size_t i) { - DCHECK_LT(i, kValueCount); - return static_cast(MinEnumValue + i); - } - - EnumBitSet enums_; -}; - -template -const E EnumSet::kMinValue; - -template -const E EnumSet::kMaxValue; - -template -const size_t EnumSet::kValueCount; - -// The usual set operations. - -template -EnumSet Union(EnumSet set1, - EnumSet set2) { - return EnumSet(set1.enums_ | set2.enums_); -} - -template -EnumSet Intersection(EnumSet set1, - EnumSet set2) { - return EnumSet(set1.enums_ & set2.enums_); -} - -template -EnumSet Difference(EnumSet set1, - EnumSet set2) { - return EnumSet(set1.enums_ & ~set2.enums_); -} - -} // namespace browser_sync - -#endif // SYNC_UTIL_ENUM_SET_H_ diff --git a/sync/util/enum_set_unittest.cc b/sync/util/enum_set_unittest.cc deleted file mode 100644 index 8c32c0a..0000000 --- a/sync/util/enum_set_unittest.cc +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2012 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 "sync/util/enum_set.h" - -#include "base/basictypes.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace browser_sync { -namespace { - -enum TestEnum { - TEST_0, - TEST_MIN = TEST_0, - TEST_1, - TEST_2, - TEST_3, - TEST_4, - TEST_MAX = TEST_4, - TEST_5 -}; - -typedef EnumSet TestEnumSet; - -class EnumSetTest : public ::testing::Test {}; - -TEST_F(EnumSetTest, ClassConstants) { - TestEnumSet enums; - EXPECT_EQ(TEST_MIN, TestEnumSet::kMinValue); - EXPECT_EQ(TEST_MAX, TestEnumSet::kMaxValue); - EXPECT_EQ(static_cast(5), TestEnumSet::kValueCount); -} - -TEST_F(EnumSetTest, DefaultConstructor) { - const TestEnumSet enums; - EXPECT_TRUE(enums.Empty()); - EXPECT_EQ(static_cast(0), enums.Size()); - EXPECT_FALSE(enums.Has(TEST_0)); - EXPECT_FALSE(enums.Has(TEST_1)); - EXPECT_FALSE(enums.Has(TEST_2)); - EXPECT_FALSE(enums.Has(TEST_3)); - EXPECT_FALSE(enums.Has(TEST_4)); -} - -TEST_F(EnumSetTest, OneArgConstructor) { - const TestEnumSet enums(TEST_3); - EXPECT_FALSE(enums.Empty()); - EXPECT_EQ(static_cast(1), enums.Size()); - EXPECT_FALSE(enums.Has(TEST_0)); - EXPECT_FALSE(enums.Has(TEST_1)); - EXPECT_FALSE(enums.Has(TEST_2)); - EXPECT_TRUE(enums.Has(TEST_3)); - EXPECT_FALSE(enums.Has(TEST_4)); -} - -TEST_F(EnumSetTest, TwoArgConstructor) { - const TestEnumSet enums(TEST_3, TEST_1); - EXPECT_FALSE(enums.Empty()); - EXPECT_EQ(static_cast(2), enums.Size()); - EXPECT_FALSE(enums.Has(TEST_0)); - EXPECT_TRUE(enums.Has(TEST_1)); - EXPECT_FALSE(enums.Has(TEST_2)); - EXPECT_TRUE(enums.Has(TEST_3)); - EXPECT_FALSE(enums.Has(TEST_4)); -} - -TEST_F(EnumSetTest, ThreeArgConstructor) { - const TestEnumSet enums(TEST_3, TEST_1, TEST_0); - EXPECT_FALSE(enums.Empty()); - EXPECT_EQ(static_cast(3), enums.Size()); - EXPECT_TRUE(enums.Has(TEST_0)); - EXPECT_TRUE(enums.Has(TEST_1)); - EXPECT_FALSE(enums.Has(TEST_2)); - EXPECT_TRUE(enums.Has(TEST_3)); - EXPECT_FALSE(enums.Has(TEST_4)); -} - -TEST_F(EnumSetTest, All) { - const TestEnumSet enums(TestEnumSet::All()); - EXPECT_FALSE(enums.Empty()); - EXPECT_EQ(static_cast(5), enums.Size()); - EXPECT_TRUE(enums.Has(TEST_0)); - EXPECT_TRUE(enums.Has(TEST_1)); - EXPECT_TRUE(enums.Has(TEST_2)); - EXPECT_TRUE(enums.Has(TEST_3)); - EXPECT_TRUE(enums.Has(TEST_4)); -} - -TEST_F(EnumSetTest, Put) { - TestEnumSet enums(TEST_3); - enums.Put(TEST_2); - EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_2, TEST_3))); - enums.Put(TEST_4); - EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_2, TEST_3, TEST_4))); -} - -TEST_F(EnumSetTest, PutAll) { - TestEnumSet enums(TEST_3, TEST_4); - enums.PutAll(TestEnumSet(TEST_2, TEST_3)); - EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_2, TEST_3, TEST_4))); -} - -TEST_F(EnumSetTest, RetainAll) { - TestEnumSet enums(TEST_3, TEST_4); - enums.RetainAll(TestEnumSet(TEST_2, TEST_3)); - EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_3))); -} - -TEST_F(EnumSetTest, Remove) { - TestEnumSet enums(TEST_3, TEST_4); - enums.Remove(TEST_0); - enums.Remove(TEST_2); - EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_3, TEST_4))); - enums.Remove(TEST_3); - EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_4))); - enums.Remove(TEST_4); - enums.Remove(TEST_5); - EXPECT_TRUE(enums.Empty()); -} - -TEST_F(EnumSetTest, RemoveAll) { - TestEnumSet enums(TEST_3, TEST_4); - enums.RemoveAll(TestEnumSet(TEST_2, TEST_3)); - EXPECT_TRUE(enums.Equals(TestEnumSet(TEST_4))); -} - -TEST_F(EnumSetTest, Clear) { - TestEnumSet enums(TEST_3, TEST_4); - enums.Clear(); - EXPECT_TRUE(enums.Empty()); -} - -TEST_F(EnumSetTest, Has) { - const TestEnumSet enums(TEST_3, TEST_4); - EXPECT_FALSE(enums.Has(TEST_0)); - EXPECT_FALSE(enums.Has(TEST_1)); - EXPECT_FALSE(enums.Has(TEST_2)); - EXPECT_TRUE(enums.Has(TEST_3)); - EXPECT_TRUE(enums.Has(TEST_4)); - EXPECT_FALSE(enums.Has(TEST_5)); -} - -TEST_F(EnumSetTest, HasAll) { - const TestEnumSet enums1(TEST_3, TEST_4); - const TestEnumSet enums2(TEST_2, TEST_3); - const TestEnumSet enums3 = Union(enums1, enums2); - EXPECT_TRUE(enums1.HasAll(enums1)); - EXPECT_FALSE(enums1.HasAll(enums2)); - EXPECT_FALSE(enums1.HasAll(enums3)); - - EXPECT_FALSE(enums2.HasAll(enums1)); - EXPECT_TRUE(enums2.HasAll(enums2)); - EXPECT_FALSE(enums2.HasAll(enums3)); - - EXPECT_TRUE(enums3.HasAll(enums1)); - EXPECT_TRUE(enums3.HasAll(enums2)); - EXPECT_TRUE(enums3.HasAll(enums3)); -} - -TEST_F(EnumSetTest, Iterators) { - const TestEnumSet enums1(TEST_3, TEST_4); - TestEnumSet enums2; - for (TestEnumSet::Iterator it = enums1.First(); it.Good(); it.Inc()) { - enums2.Put(it.Get()); - } - EXPECT_TRUE(enums1.Equals(enums2)); -} - -TEST_F(EnumSetTest, Union) { - const TestEnumSet enums1(TEST_3, TEST_4); - const TestEnumSet enums2(TEST_2, TEST_3); - const TestEnumSet enums3 = Union(enums1, enums2); - - EXPECT_TRUE(enums3.Equals(TestEnumSet(TEST_2, TEST_3, TEST_4))); -} - -TEST_F(EnumSetTest, Intersection) { - const TestEnumSet enums1(TEST_3, TEST_4); - const TestEnumSet enums2(TEST_2, TEST_3); - const TestEnumSet enums3 = Intersection(enums1, enums2); - - EXPECT_TRUE(enums3.Equals(TestEnumSet(TEST_3))); -} - -TEST_F(EnumSetTest, Difference) { - const TestEnumSet enums1(TEST_3, TEST_4); - const TestEnumSet enums2(TEST_2, TEST_3); - const TestEnumSet enums3 = Difference(enums1, enums2); - - EXPECT_TRUE(enums3.Equals(TestEnumSet(TEST_4))); -} - -} // namespace -} // namespace browser_sync diff --git a/sync/util/experiments.h b/sync/util/experiments.h index 21b3437..1439e2b 100644 --- a/sync/util/experiments.h +++ b/sync/util/experiments.h @@ -6,7 +6,7 @@ #define SYNC_UTIL_EXPERIMENTS_ #pragma once -#include "sync/syncable/model_type.h" +#include "sync/internal_api/public/syncable/model_type.h" namespace browser_sync { diff --git a/sync/util/syncer_error.cc b/sync/util/syncer_error.cc deleted file mode 100644 index 5f836ce..0000000 --- a/sync/util/syncer_error.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2012 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 "sync/util/syncer_error.h" - -#include "base/logging.h" - -namespace browser_sync { - -#define ENUM_CASE(x) case x: return #x; break; -const char* GetSyncerErrorString(SyncerError value) { - switch (value) { - ENUM_CASE(UNSET); - ENUM_CASE(DIRECTORY_LOOKUP_FAILED); - ENUM_CASE(NETWORK_CONNECTION_UNAVAILABLE); - ENUM_CASE(NETWORK_IO_ERROR); - ENUM_CASE(SYNC_SERVER_ERROR); - ENUM_CASE(SYNC_AUTH_ERROR); - ENUM_CASE(SERVER_RETURN_INVALID_CREDENTIAL); - ENUM_CASE(SERVER_RETURN_UNKNOWN_ERROR); - ENUM_CASE(SERVER_RETURN_THROTTLED); - ENUM_CASE(SERVER_RETURN_TRANSIENT_ERROR); - ENUM_CASE(SERVER_RETURN_MIGRATION_DONE); - ENUM_CASE(SERVER_RETURN_CLEAR_PENDING); - ENUM_CASE(SERVER_RETURN_NOT_MY_BIRTHDAY); - ENUM_CASE(SERVER_RESPONSE_VALIDATION_FAILED); - ENUM_CASE(SYNCER_OK); - } - NOTREACHED(); - return "INVALID"; -} -#undef ENUM_CASE - -} // namespace browser_sync - diff --git a/sync/util/syncer_error.h b/sync/util/syncer_error.h deleted file mode 100644 index 6613f59..0000000 --- a/sync/util/syncer_error.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2012 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 SYNC_INTERNAL_API_INCLUDES_SYNCER_ERROR_H_ -#define SYNC_INTERNAL_API_INCLUDES_SYNCER_ERROR_H_ -#pragma once - -namespace browser_sync { - -// This enum describes all the ways a SyncerCommand can fail. -// -// SyncerCommands do many different things, but they share a common function -// signature. This enum, the return value for all SyncerCommands, must be able -// to describe any possible failure for all SyncerComand. -// -// For convenience, functions which are invoked only by SyncerCommands may also -// return a SyncerError. It saves us having to write a conversion function, and -// it makes refactoring easier. -enum SyncerError { - UNSET = 0, // Default value. - DIRECTORY_LOOKUP_FAILED, // Local directory lookup failure. - - NETWORK_CONNECTION_UNAVAILABLE, // Connectivity failure. - NETWORK_IO_ERROR, // Response buffer read error. - SYNC_SERVER_ERROR, // Non auth HTTP error. - SYNC_AUTH_ERROR, // HTTP auth error. - - // Based on values returned by server. Most are defined in sync.proto. - SERVER_RETURN_INVALID_CREDENTIAL, - SERVER_RETURN_UNKNOWN_ERROR, - SERVER_RETURN_THROTTLED, - SERVER_RETURN_TRANSIENT_ERROR, - SERVER_RETURN_MIGRATION_DONE, - SERVER_RETURN_CLEAR_PENDING, - SERVER_RETURN_NOT_MY_BIRTHDAY, - SERVER_RESPONSE_VALIDATION_FAILED, - - SYNCER_OK -}; - -const char * GetSyncerErrorString(SyncerError); - -} // namespace browser_sync - -#endif // SYNC_INTERNAL_API_INCLUDES_SYNCER_ERROR_H_ -- cgit v1.1