summaryrefslogtreecommitdiffstats
path: root/sync/internal_api
diff options
context:
space:
mode:
Diffstat (limited to 'sync/internal_api')
-rw-r--r--sync/internal_api/base_node.cc4
-rw-r--r--sync/internal_api/base_transaction.cc2
-rw-r--r--sync/internal_api/change_record.cc6
-rw-r--r--sync/internal_api/change_reorder_buffer.cc2
-rw-r--r--sync/internal_api/change_reorder_buffer.h4
-rw-r--r--sync/internal_api/debug_info_event_listener.h4
-rw-r--r--sync/internal_api/js_mutation_event_observer.h4
-rw-r--r--sync/internal_api/js_mutation_event_observer_unittest.cc2
-rw-r--r--sync/internal_api/js_sync_manager_observer.cc2
-rw-r--r--sync/internal_api/js_sync_manager_observer.h4
-rw-r--r--sync/internal_api/js_sync_manager_observer_unittest.cc2
-rw-r--r--sync/internal_api/public/DEPS3
-rw-r--r--sync/internal_api/public/base_node.h (renamed from sync/internal_api/base_node.h)6
-rw-r--r--sync/internal_api/public/base_transaction.h (renamed from sync/internal_api/base_transaction.h)8
-rw-r--r--sync/internal_api/public/change_record.h (renamed from sync/internal_api/change_record.h)8
-rw-r--r--sync/internal_api/public/change_record_unittest.cc (renamed from sync/internal_api/change_record_unittest.cc)2
-rw-r--r--sync/internal_api/public/configure_reason.h (renamed from sync/internal_api/configure_reason.h)6
-rw-r--r--sync/internal_api/public/http_post_provider_factory.h (renamed from sync/internal_api/http_post_provider_factory.h)6
-rw-r--r--sync/internal_api/public/http_post_provider_interface.h (renamed from sync/internal_api/http_post_provider_interface.h)6
-rw-r--r--sync/internal_api/public/read_node.h (renamed from sync/internal_api/read_node.h)8
-rw-r--r--sync/internal_api/public/read_transaction.h (renamed from sync/internal_api/read_transaction.h)8
-rw-r--r--sync/internal_api/public/sync_manager.h (renamed from sync/internal_api/sync_manager.h)16
-rw-r--r--sync/internal_api/public/test/test_user_share.h (renamed from sync/internal_api/test_user_share.h)13
-rw-r--r--sync/internal_api/public/user_share.h (renamed from sync/internal_api/user_share.h)6
-rw-r--r--sync/internal_api/public/util/experiments.h28
-rw-r--r--sync/internal_api/public/util/immutable.h262
-rw-r--r--sync/internal_api/public/util/immutable_unittest.cc250
-rw-r--r--sync/internal_api/public/util/report_unrecoverable_error_function.h19
-rw-r--r--sync/internal_api/public/util/unrecoverable_error_handler.h30
-rw-r--r--sync/internal_api/public/util/unrecoverable_error_info.cc44
-rw-r--r--sync/internal_api/public/util/unrecoverable_error_info.h41
-rw-r--r--sync/internal_api/public/util/weak_handle.cc36
-rw-r--r--sync/internal_api/public/util/weak_handle.h379
-rw-r--r--sync/internal_api/public/util/weak_handle_unittest.cc326
-rw-r--r--sync/internal_api/public/write_node.h (renamed from sync/internal_api/write_node.h)8
-rw-r--r--sync/internal_api/public/write_transaction.h (renamed from sync/internal_api/write_transaction.h)8
-rw-r--r--sync/internal_api/read_node.cc4
-rw-r--r--sync/internal_api/read_transaction.cc2
-rw-r--r--sync/internal_api/sync_manager.cc18
-rw-r--r--sync/internal_api/syncapi_server_connection_manager.cc4
-rw-r--r--sync/internal_api/syncapi_server_connection_manager_unittest.cc4
-rw-r--r--sync/internal_api/syncapi_unittest.cc18
-rw-r--r--sync/internal_api/test/test_user_share.cc (renamed from sync/internal_api/test_user_share.cc)11
-rw-r--r--sync/internal_api/user_share.cc2
-rw-r--r--sync/internal_api/write_node.cc6
-rw-r--r--sync/internal_api/write_transaction.cc2
46 files changed, 1527 insertions, 107 deletions
diff --git a/sync/internal_api/base_node.cc b/sync/internal_api/base_node.cc
index 99f1614..cfcddcd 100644
--- a/sync/internal_api/base_node.cc
+++ b/sync/internal_api/base_node.cc
@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "sync/internal_api/base_node.h"
+#include "sync/internal_api/public/base_node.h"
#include "base/base64.h"
#include "base/sha1.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
-#include "sync/internal_api/base_transaction.h"
+#include "sync/internal_api/public/base_transaction.h"
#include "sync/internal_api/syncapi_internal.h"
#include "sync/protocol/app_specifics.pb.h"
#include "sync/protocol/autofill_specifics.pb.h"
diff --git a/sync/internal_api/base_transaction.cc b/sync/internal_api/base_transaction.cc
index 879e4e3..5fedc64 100644
--- a/sync/internal_api/base_transaction.cc
+++ b/sync/internal_api/base_transaction.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/internal_api/base_transaction.h"
+#include "sync/internal_api/public/base_transaction.h"
#include "sync/syncable/syncable.h"
#include "sync/util/cryptographer.h"
diff --git a/sync/internal_api/change_record.cc b/sync/internal_api/change_record.cc
index 3eefb74..75a57a5 100644
--- a/sync/internal_api/change_record.cc
+++ b/sync/internal_api/change_record.cc
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "sync/internal_api/change_record.h"
+#include "sync/internal_api/public/change_record.h"
#include "base/string_number_conversions.h"
#include "base/values.h"
-#include "sync/internal_api/base_node.h"
-#include "sync/internal_api/read_node.h"
+#include "sync/internal_api/public/base_node.h"
+#include "sync/internal_api/public/read_node.h"
#include "sync/protocol/proto_value_conversions.h"
namespace sync_api {
diff --git a/sync/internal_api/change_reorder_buffer.cc b/sync/internal_api/change_reorder_buffer.cc
index b92a590..34e44f6 100644
--- a/sync/internal_api/change_reorder_buffer.cc
+++ b/sync/internal_api/change_reorder_buffer.cc
@@ -10,8 +10,8 @@
#include <utility> // for pair<>
#include <vector>
+#include "sync/internal_api/public/read_node.h"
#include "sync/internal_api/public/syncable/model_type.h"
-#include "sync/internal_api/read_node.h"
#include "sync/syncable/syncable.h"
using std::numeric_limits;
diff --git a/sync/internal_api/change_reorder_buffer.h b/sync/internal_api/change_reorder_buffer.h
index edb59f3..a6f37a0 100644
--- a/sync/internal_api/change_reorder_buffer.h
+++ b/sync/internal_api/change_reorder_buffer.h
@@ -15,8 +15,8 @@
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
-#include "sync/internal_api/base_transaction.h"
-#include "sync/internal_api/change_record.h"
+#include "sync/internal_api/public/base_transaction.h"
+#include "sync/internal_api/public/change_record.h"
#include "sync/protocol/sync.pb.h"
namespace sync_api {
diff --git a/sync/internal_api/debug_info_event_listener.h b/sync/internal_api/debug_info_event_listener.h
index 06c420b..d18f008 100644
--- a/sync/internal_api/debug_info_event_listener.h
+++ b/sync/internal_api/debug_info_event_listener.h
@@ -10,12 +10,12 @@
#include "base/compiler_specific.h"
#include "sync/internal_api/public/sessions/sync_session_snapshot.h"
-#include "sync/internal_api/sync_manager.h"
+#include "sync/internal_api/public/sync_manager.h"
+#include "sync/internal_api/public/util/weak_handle.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/util/weak_handle.h"
namespace sync_api {
diff --git a/sync/internal_api/js_mutation_event_observer.h b/sync/internal_api/js_mutation_event_observer.h
index 3022fa0..6e70c19 100644
--- a/sync/internal_api/js_mutation_event_observer.h
+++ b/sync/internal_api/js_mutation_event_observer.h
@@ -12,9 +12,9 @@
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h"
-#include "sync/internal_api/sync_manager.h"
+#include "sync/internal_api/public/sync_manager.h"
+#include "sync/internal_api/public/util/weak_handle.h"
#include "sync/syncable/transaction_observer.h"
-#include "sync/util/weak_handle.h"
namespace tracked_objects {
class Location;
diff --git a/sync/internal_api/js_mutation_event_observer_unittest.cc b/sync/internal_api/js_mutation_event_observer_unittest.cc
index 1e65f4b..8d0e30f 100644
--- a/sync/internal_api/js_mutation_event_observer_unittest.cc
+++ b/sync/internal_api/js_mutation_event_observer_unittest.cc
@@ -8,9 +8,9 @@
#include "base/message_loop.h"
#include "base/values.h"
#include "sync/internal_api/public/syncable/model_type.h"
+#include "sync/internal_api/public/util/weak_handle.h"
#include "sync/js/js_event_details.h"
#include "sync/js/js_test_util.h"
-#include "sync/util/weak_handle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace browser_sync {
diff --git a/sync/internal_api/js_sync_manager_observer.cc b/sync/internal_api/js_sync_manager_observer.cc
index e392ddf..ae1449e 100644
--- a/sync/internal_api/js_sync_manager_observer.cc
+++ b/sync/internal_api/js_sync_manager_observer.cc
@@ -10,7 +10,7 @@
#include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/values.h"
-#include "sync/internal_api/change_record.h"
+#include "sync/internal_api/public/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"
diff --git a/sync/internal_api/js_sync_manager_observer.h b/sync/internal_api/js_sync_manager_observer.h
index 02e2e5b..b410eb9 100644
--- a/sync/internal_api/js_sync_manager_observer.h
+++ b/sync/internal_api/js_sync_manager_observer.h
@@ -10,9 +10,9 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "sync/internal_api/sync_manager.h"
+#include "sync/internal_api/public/sync_manager.h"
+#include "sync/internal_api/public/util/weak_handle.h"
#include "sync/protocol/sync_protocol_error.h"
-#include "sync/util/weak_handle.h"
namespace tracked_objects {
class Location;
diff --git a/sync/internal_api/js_sync_manager_observer_unittest.cc b/sync/internal_api/js_sync_manager_observer_unittest.cc
index 5b28223..03404ed 100644
--- a/sync/internal_api/js_sync_manager_observer_unittest.cc
+++ b/sync/internal_api/js_sync_manager_observer_unittest.cc
@@ -10,10 +10,10 @@
#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/internal_api/public/util/weak_handle.h"
#include "sync/js/js_event_details.h"
#include "sync/js/js_test_util.h"
#include "sync/protocol/sync_protocol_error.h"
-#include "sync/util/weak_handle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace browser_sync {
diff --git a/sync/internal_api/public/DEPS b/sync/internal_api/public/DEPS
index 2a51ace..a483090 100644
--- a/sync/internal_api/public/DEPS
+++ b/sync/internal_api/public/DEPS
@@ -2,4 +2,7 @@ include_rules = [
"-sync",
"+sync/internal_api/public",
"+sync/protocol",
+
+ # TODO(tim): Remove. Bug 131130
+ "+sync/util/cryptographer.h"
]
diff --git a/sync/internal_api/base_node.h b/sync/internal_api/public/base_node.h
index f59753f..87de41e 100644
--- a/sync/internal_api/base_node.h
+++ b/sync/internal_api/public/base_node.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_BASE_NODE_H_
-#define SYNC_INTERNAL_API_BASE_NODE_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_BASE_NODE_H_
+#define SYNC_INTERNAL_API_PUBLIC_BASE_NODE_H_
#pragma once
#include <string>
@@ -252,4 +252,4 @@ class BaseNode {
} // namespace sync_api
-#endif // SYNC_INTERNAL_API_BASE_NODE_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_BASE_NODE_H_
diff --git a/sync/internal_api/base_transaction.h b/sync/internal_api/public/base_transaction.h
index f39bca6..77e102a 100644
--- a/sync/internal_api/base_transaction.h
+++ b/sync/internal_api/public/base_transaction.h
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_BASE_TRANSACTION_H_
-#define SYNC_INTERNAL_API_BASE_TRANSACTION_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_BASE_TRANSACTION_H_
+#define SYNC_INTERNAL_API_PUBLIC_BASE_TRANSACTION_H_
#pragma once
-#include "sync/internal_api/user_share.h"
+#include "sync/internal_api/public/user_share.h"
#include "sync/util/cryptographer.h"
@@ -51,4 +51,4 @@ syncable::ModelTypeSet GetEncryptedTypes(
} // namespace sync_api
-#endif // SYNC_INTERNAL_API_BASE_TRANSACTION_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_BASE_TRANSACTION_H_
diff --git a/sync/internal_api/change_record.h b/sync/internal_api/public/change_record.h
index 3d2f4ee..f522a3b 100644
--- a/sync/internal_api/change_record.h
+++ b/sync/internal_api/public/change_record.h
@@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_CHANGE_RECORD_H_
-#define SYNC_INTERNAL_API_CHANGE_RECORD_H_
+#ifndef SYNC_INTERNAL_PUBLIC_API_CHANGE_RECORD_H_
+#define SYNC_INTERNAL_PUBLIC_API_CHANGE_RECORD_H_
#include <vector>
#include "base/basictypes.h"
#include "base/memory/linked_ptr.h"
+#include "sync/internal_api/public/util/immutable.h"
#include "sync/protocol/password_specifics.pb.h"
#include "sync/protocol/sync.pb.h"
-#include "sync/util/immutable.h"
namespace base {
class DictionaryValue;
@@ -64,4 +64,4 @@ typedef browser_sync::Immutable<ChangeRecordList> ImmutableChangeRecordList;
} // namespace sync_api
-#endif // SYNC_INTERNAL_API_CHANGE_RECORD_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_CHANGE_RECORD_H_
diff --git a/sync/internal_api/change_record_unittest.cc b/sync/internal_api/public/change_record_unittest.cc
index 9a1d1d3..4fb1f01 100644
--- a/sync/internal_api/change_record_unittest.cc
+++ b/sync/internal_api/public/change_record_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/internal_api/change_record.h"
+#include "sync/internal_api/public/change_record.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_number_conversions.h"
diff --git a/sync/internal_api/configure_reason.h b/sync/internal_api/public/configure_reason.h
index 6008f5f..37916ac 100644
--- a/sync/internal_api/configure_reason.h
+++ b/sync/internal_api/public/configure_reason.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_CONFIGURE_REASON_H_
-#define SYNC_INTERNAL_API_CONFIGURE_REASON_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_CONFIGURE_REASON_H_
+#define SYNC_INTERNAL_API_PUBLIC_CONFIGURE_REASON_H_
#pragma once
namespace sync_api {
@@ -33,4 +33,4 @@ enum ConfigureReason {
} // namespace sync_api
-#endif // SYNC_INTERNAL_API_CONFIGURE_REASON_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_CONFIGURE_REASON_H_
diff --git a/sync/internal_api/http_post_provider_factory.h b/sync/internal_api/public/http_post_provider_factory.h
index 445fd6a..53d576b 100644
--- a/sync/internal_api/http_post_provider_factory.h
+++ b/sync/internal_api/public/http_post_provider_factory.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_HTTP_POST_PROVIDER_FACTORY_H_
-#define SYNC_INTERNAL_API_HTTP_POST_PROVIDER_FACTORY_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_HTTP_POST_PROVIDER_FACTORY_H_
+#define SYNC_INTERNAL_API_PUBLIC_HTTP_POST_PROVIDER_FACTORY_H_
#pragma once
namespace sync_api {
@@ -31,4 +31,4 @@ class HttpPostProviderFactory {
} // namespace sync_api
-#endif // SYNC_INTERNAL_API_HTTP_POST_PROVIDER_FACTORY_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_HTTP_POST_PROVIDER_FACTORY_H_
diff --git a/sync/internal_api/http_post_provider_interface.h b/sync/internal_api/public/http_post_provider_interface.h
index df31b7f..5aa201a 100644
--- a/sync/internal_api/http_post_provider_interface.h
+++ b/sync/internal_api/public/http_post_provider_interface.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_HTTP_POST_PROVIDER_INTERFACE_H_
-#define SYNC_INTERNAL_API_HTTP_POST_PROVIDER_INTERFACE_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_HTTP_POST_PROVIDER_INTERFACE_H_
+#define SYNC_INTERNAL_API_PUBLIC_HTTP_POST_PROVIDER_INTERFACE_H_
#pragma once
#include <string>
@@ -64,4 +64,4 @@ class HttpPostProviderInterface {
} // namespace sync_api
-#endif // SYNC_INTERNAL_API_HTTP_POST_PROVIDER_INTERFACE_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_HTTP_POST_PROVIDER_INTERFACE_H_
diff --git a/sync/internal_api/read_node.h b/sync/internal_api/public/read_node.h
index 98638de..f57b577 100644
--- a/sync/internal_api/read_node.h
+++ b/sync/internal_api/public/read_node.h
@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_READ_NODE_H_
-#define SYNC_INTERNAL_API_READ_NODE_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_READ_NODE_H_
+#define SYNC_INTERNAL_API_PUBLIC_READ_NODE_H_
#pragma once
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "sync/internal_api/base_node.h"
+#include "sync/internal_api/public/base_node.h"
#include "sync/internal_api/public/syncable/model_type.h"
namespace sync_api {
@@ -63,4 +63,4 @@ class ReadNode : public BaseNode {
} // namespace sync_api
-#endif // SYNC_INTERNAL_API_READ_NODE_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_READ_NODE_H_
diff --git a/sync/internal_api/read_transaction.h b/sync/internal_api/public/read_transaction.h
index e45acc6..fd35373 100644
--- a/sync/internal_api/read_transaction.h
+++ b/sync/internal_api/public/read_transaction.h
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_READ_TRANSACTION_H_
-#define SYNC_INTERNAL_API_READ_TRANSACTION_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_READ_TRANSACTION_H_
+#define SYNC_INTERNAL_API_PUBLIC_READ_TRANSACTION_H_
#include "base/compiler_specific.h"
-#include "sync/internal_api/base_transaction.h"
+#include "sync/internal_api/public/base_transaction.h"
namespace tracked_objects {
class Location;
@@ -43,4 +43,4 @@ class ReadTransaction : public BaseTransaction {
} // namespace sync_api
-#endif // SYNC_INTERNAL_API_READ_TRANSACTION_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_READ_TRANSACTION_H_
diff --git a/sync/internal_api/sync_manager.h b/sync/internal_api/public/sync_manager.h
index 04181fe..f4a42e3 100644
--- a/sync/internal_api/sync_manager.h
+++ b/sync/internal_api/public/sync_manager.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_SYNC_MANAGER_H_
-#define SYNC_INTERNAL_API_SYNC_MANAGER_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_
+#define SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_
#include <string>
#include <vector>
@@ -15,15 +15,15 @@
#include "base/task_runner.h"
#include "base/threading/thread_checker.h"
#include "base/time.h"
-#include "sync/internal_api/change_record.h"
-#include "sync/internal_api/configure_reason.h"
+#include "sync/internal_api/public/change_record.h"
+#include "sync/internal_api/public/configure_reason.h"
#include "sync/internal_api/public/engine/model_safe_worker.h"
#include "sync/internal_api/public/engine/sync_status.h"
#include "sync/internal_api/public/syncable/model_type.h"
+#include "sync/internal_api/public/util/report_unrecoverable_error_function.h"
+#include "sync/internal_api/public/util/unrecoverable_error_handler.h"
+#include "sync/internal_api/public/util/weak_handle.h"
#include "sync/protocol/sync_protocol_error.h"
-#include "sync/util/report_unrecoverable_error_function.h"
-#include "sync/util/unrecoverable_error_handler.h"
-#include "sync/util/weak_handle.h"
namespace browser_sync {
struct ConfigurationParams;
@@ -577,4 +577,4 @@ const char* PassphraseRequiredReasonToString(PassphraseRequiredReason reason);
} // namespace sync_api
-#endif // SYNC_INTERNAL_API_SYNC_MANAGER_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_
diff --git a/sync/internal_api/test_user_share.h b/sync/internal_api/public/test/test_user_share.h
index b212e3c..7386b18 100644
--- a/sync/internal_api/test_user_share.h
+++ b/sync/internal_api/public/test/test_user_share.h
@@ -27,16 +27,17 @@
// }
//
-#ifndef SYNC_INTERNAL_API_TEST_USER_SHARE_H_
-#define SYNC_INTERNAL_API_TEST_USER_SHARE_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_TEST_TEST_USER_SHARE_H_
+#define SYNC_INTERNAL_API_PUBLIC_TEST_TEST_USER_SHARE_H_
#pragma once
#include "base/basictypes.h"
-#include "sync/internal_api/user_share.h"
-#include "sync/test/engine/test_directory_setter_upper.h"
+#include "sync/internal_api/public/user_share.h"
namespace browser_sync {
+class TestDirectorySetterUpper;
+
class TestUserShare {
public:
TestUserShare();
@@ -56,7 +57,7 @@ class TestUserShare {
sync_api::UserShare* user_share();
private:
- TestDirectorySetterUpper dir_maker_;
+ scoped_ptr<TestDirectorySetterUpper> dir_maker_;
scoped_ptr<sync_api::UserShare> user_share_;
DISALLOW_COPY_AND_ASSIGN(TestUserShare);
@@ -64,4 +65,4 @@ class TestUserShare {
} // namespace browser_sync
-#endif // SYNC_INTERNAL_API_TEST_USER_SHARE_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_TEST_TEST_USER_SHARE_H_
diff --git a/sync/internal_api/user_share.h b/sync/internal_api/public/user_share.h
index 275fa42..0fa6a1d 100644
--- a/sync/internal_api/user_share.h
+++ b/sync/internal_api/public/user_share.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_USER_SHARE_H_
-#define SYNC_INTERNAL_API_USER_SHARE_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_USER_SHARE_H_
+#define SYNC_INTERNAL_API_PUBLIC_USER_SHARE_H_
#pragma once
#include <string>
@@ -33,4 +33,4 @@ struct UserShare {
}
-#endif // SYNC_INTERNAL_API_USER_SHARE_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_USER_SHARE_H_
diff --git a/sync/internal_api/public/util/experiments.h b/sync/internal_api/public/util/experiments.h
new file mode 100644
index 0000000..1439e2b
--- /dev/null
+++ b/sync/internal_api/public/util/experiments.h
@@ -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.
+
+#ifndef SYNC_UTIL_EXPERIMENTS_
+#define SYNC_UTIL_EXPERIMENTS_
+#pragma once
+
+#include "sync/internal_api/public/syncable/model_type.h"
+
+namespace browser_sync {
+
+// A structure to hold the enable status of experimental sync features.
+struct Experiments {
+ Experiments() : sync_tab_favicons(false) {}
+
+ bool Matches(const Experiments& rhs) {
+ return (sync_tab_favicons == rhs.sync_tab_favicons);
+ }
+
+ // Enable syncing of favicons within tab sync (only has an effect if tab sync
+ // is already enabled). This takes effect on the next restart.
+ bool sync_tab_favicons;
+};
+
+}
+
+#endif // SYNC_UTIL_EXPERIMENTS_
diff --git a/sync/internal_api/public/util/immutable.h b/sync/internal_api/public/util/immutable.h
new file mode 100644
index 0000000..6624b90
--- /dev/null
+++ b/sync/internal_api/public/util/immutable.h
@@ -0,0 +1,262 @@
+// 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.
+
+// Immutable<T> provides an easy, cheap, and thread-safe way to pass
+// large immutable data around.
+//
+// For example, consider the following code:
+//
+// typedef std::vector<LargeObject> LargeObjectList;
+//
+// void ProcessStuff(const LargeObjectList& stuff) {
+// for (LargeObjectList::const_iterator it = stuff.begin();
+// it != stuff.end(); ++it) {
+// ... process it ...
+// }
+// }
+//
+// ...
+//
+// LargeObjectList my_stuff;
+// ... fill my_stuff with lots of LargeObjects ...
+// some_loop->PostTask(FROM_HERE, base::Bind(&ProcessStuff, my_stuff));
+//
+// The last line incurs the cost of copying my_stuff, which is
+// undesirable. Here's the above code re-written using Immutable<T>:
+//
+// void ProcessStuff(
+// const browser_sync::Immutable<LargeObjectList>& stuff) {
+// for (LargeObjectList::const_iterator it = stuff.Get().begin();
+// it != stuff.Get().end(); ++it) {
+// ... process it ...
+// }
+// }
+//
+// ...
+//
+// LargeObjectList my_stuff;
+// ... fill my_stuff with lots of LargeObjects ...
+// some_loop->PostTask(
+// FROM_HERE, base::Bind(&ProcessStuff, MakeImmutable(&my_stuff)));
+//
+// The last line, which resets my_stuff to a default-initialized
+// state, incurs only the cost of a swap of LargeObjectLists, which is
+// O(1) for most STL container implementations. The data in my_stuff
+// is ref-counted (thread-safely), so it is freed as soon as
+// ProcessStuff is finished.
+//
+// NOTE: By default, Immutable<T> relies on ADL
+// (http://en.wikipedia.org/wiki/Argument-dependent_name_lookup) to
+// find a swap() function for T, falling back to std::swap() when
+// necessary. If you overload swap() for your type in its namespace,
+// or if you specialize std::swap() for your type, (see
+// http://stackoverflow.com/questions/11562/how-to-overload-stdswap
+// for discussion) Immutable<T> should be able to find it.
+//
+// Alternatively, you could explicitly control which swap function is
+// used by providing your own traits class or using one of the
+// pre-defined ones below. See comments on traits below for details.
+//
+// NOTE: Some complexity is necessary in order to use Immutable<T>
+// with forward-declared types. See comments on traits below for
+// details.
+
+#ifndef SYNC_UTIL_IMMUTABLE_H_
+#define SYNC_UTIL_IMMUTABLE_H_
+#pragma once
+
+// For std::swap().
+#include <algorithm>
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+
+namespace browser_sync {
+
+namespace internal {
+// This class is part of the Immutable implementation. DO NOT USE
+// THIS CLASS DIRECTLY YOURSELF.
+
+template <typename T, typename Traits>
+class ImmutableCore
+ : public base::RefCountedThreadSafe<ImmutableCore<T, Traits> > {
+ public:
+ // wrapper_ is always explicitly default-initialized to handle
+ // primitive types and the case where Traits::Wrapper == T.
+
+ ImmutableCore() : wrapper_() {
+ Traits::InitializeWrapper(&wrapper_);
+ }
+
+ explicit ImmutableCore(T* t) : wrapper_() {
+ Traits::InitializeWrapper(&wrapper_);
+ Traits::Swap(Traits::UnwrapMutable(&wrapper_), t);
+ }
+
+ const T& Get() const {
+ return Traits::Unwrap(wrapper_);
+ }
+
+ private:
+ ~ImmutableCore() {
+ Traits::DestroyWrapper(&wrapper_);
+ }
+ friend class base::RefCountedThreadSafe<ImmutableCore<T, Traits> >;
+
+ // This is semantically const, but we can't mark it a such as we
+ // modify it in the constructor.
+ typename Traits::Wrapper wrapper_;
+
+ DISALLOW_COPY_AND_ASSIGN(ImmutableCore);
+};
+
+} // namespace internal
+
+// Traits usage notes
+// ------------------
+// The most common reason to use your own traits class is to provide
+// your own swap method. First, consider the pre-defined traits
+// classes HasSwapMemFn{ByRef,ByPtr} below. If neither of those work,
+// then define your own traits class inheriting from
+// DefaultImmutableTraits<YourType> (to pick up the defaults for
+// everything else) and provide your own Swap() method.
+//
+// Another reason to use your own traits class is to be able to use
+// Immutable<T> with a forward-declared type (important for protobuf
+// classes, when you want to avoid headers pulling in generated
+// headers). (This is why the Traits::Wrapper type exists; normally,
+// Traits::Wrapper is just T itself, but that needs to be changed for
+// forward-declared types.)
+//
+// For example, if you want to do this:
+//
+// my_class.h
+// ----------
+// #include ".../immutable.h"
+//
+// // Forward declaration.
+// class SomeOtherType;
+//
+// class MyClass {
+// ...
+// private:
+// // Doesn't work, as defaults traits class needs SomeOtherType's
+// // definition to be visible.
+// Immutable<SomeOtherType> foo_;
+// };
+//
+// You'll have to do this:
+//
+// my_class.h
+// ----------
+// #include ".../immutable.h"
+//
+// // Forward declaration.
+// class SomeOtherType;
+//
+// class MyClass {
+// ...
+// private:
+// struct ImmutableSomeOtherTypeTraits {
+// // scoped_ptr<SomeOtherType> won't work here, either.
+// typedef SomeOtherType* Wrapper;
+//
+// static void InitializeWrapper(Wrapper* wrapper);
+//
+// static void DestroyWrapper(Wrapper* wrapper);
+// ...
+// };
+//
+// typedef Immutable<SomeOtherType, ImmutableSomeOtherTypeTraits>
+// ImmutableSomeOtherType;
+//
+// ImmutableSomeOtherType foo_;
+// };
+//
+// my_class.cc
+// -----------
+// #include ".../some_other_type.h"
+//
+// void MyClass::ImmutableSomeOtherTypeTraits::InitializeWrapper(
+// Wrapper* wrapper) {
+// *wrapper = new SomeOtherType();
+// }
+//
+// void MyClass::ImmutableSomeOtherTypeTraits::DestroyWrapper(
+// Wrapper* wrapper) {
+// delete *wrapper;
+// }
+//
+// ...
+//
+// Also note that this incurs an additional memory allocation when you
+// create an Immutable<SomeOtherType>.
+
+template <typename T>
+struct DefaultImmutableTraits {
+ typedef T Wrapper;
+
+ static void InitializeWrapper(Wrapper* wrapper) {}
+
+ static void DestroyWrapper(Wrapper* wrapper) {}
+
+ static const T& Unwrap(const Wrapper& wrapper) { return wrapper; }
+
+ static T* UnwrapMutable(Wrapper* wrapper) { return wrapper; }
+
+ static void Swap(T* t1, T* t2) {
+ // Uses ADL (see
+ // http://en.wikipedia.org/wiki/Argument-dependent_name_lookup).
+ using std::swap;
+ swap(*t1, *t2);
+ }
+};
+
+// Most STL containers have by-reference swap() member functions,
+// although they usually already overload std::swap() to use those.
+template <typename T>
+struct HasSwapMemFnByRef : public DefaultImmutableTraits<T> {
+ static void Swap(T* t1, T* t2) {
+ t1->swap(*t2);
+ }
+};
+
+// Most Google-style objects have by-pointer Swap() member functions
+// (for example, generated protocol buffer classes).
+template <typename T>
+struct HasSwapMemFnByPtr : public DefaultImmutableTraits<T> {
+ static void Swap(T* t1, T* t2) {
+ t1->Swap(t2);
+ }
+};
+
+template <typename T, typename Traits = DefaultImmutableTraits<T> >
+class Immutable {
+ public:
+ // Puts the underlying object in a default-initialized state.
+ Immutable() : core_(new internal::ImmutableCore<T, Traits>()) {}
+
+ // Copy constructor and assignment welcome.
+
+ // Resets |t| to a default-initialized state.
+ explicit Immutable(T* t)
+ : core_(new internal::ImmutableCore<T, Traits>(t)) {}
+
+ const T& Get() const {
+ return core_->Get();
+ }
+
+ private:
+ scoped_refptr<const internal::ImmutableCore<T, Traits> > core_;
+};
+
+// Helper function to avoid having to write out template arguments.
+template <typename T>
+Immutable<T> MakeImmutable(T* t) {
+ return Immutable<T>(t);
+}
+
+} // namespace browser_sync
+
+#endif // SYNC_UTIL_IMMUTABLE_H_
diff --git a/sync/internal_api/public/util/immutable_unittest.cc b/sync/internal_api/public/util/immutable_unittest.cc
new file mode 100644
index 0000000..ea0b29b
--- /dev/null
+++ b/sync/internal_api/public/util/immutable_unittest.cc
@@ -0,0 +1,250 @@
+// 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/immutable.h"
+
+#include <algorithm>
+#include <cstddef>
+#include <deque>
+#include <list>
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace browser_sync {
+
+// Helper class that keeps track of the token passed in at
+// construction and how many times that token is copied.
+class TokenCore : public base::RefCounted<TokenCore> {
+ public:
+ explicit TokenCore(const char* token) : token_(token), copy_count_(0) {}
+
+ const char* GetToken() const { return token_; }
+
+ void RecordCopy() { ++copy_count_; }
+
+ int GetCopyCount() const { return copy_count_; }
+
+ private:
+ friend class base::RefCounted<TokenCore>;
+
+ ~TokenCore() {}
+
+ const char* const token_;
+ int copy_count_;
+};
+
+enum SwapBehavior {
+ USE_DEFAULT_SWAP,
+ USE_FAST_SWAP_VIA_ADL,
+ USE_FAST_SWAP_VIA_SPECIALIZATION
+};
+
+const char kEmptyToken[] = "<empty token>";
+
+// Base class for various token classes, differing in swap behavior.
+template <SwapBehavior>
+class TokenBase {
+ public:
+ TokenBase() : core_(new TokenCore(kEmptyToken)) {}
+
+ explicit TokenBase(const char* token) : core_(new TokenCore(token)) {}
+
+ TokenBase(const TokenBase& other) : core_(other.core_) {
+ core_->RecordCopy();
+ }
+
+ TokenBase& operator=(const TokenBase& other) {
+ core_ = other.core_;
+ core_->RecordCopy();
+ return *this;
+ }
+
+ const char* GetToken() const {
+ return core_->GetToken();
+ }
+
+ int GetCopyCount() const {
+ return core_->GetCopyCount();
+ }
+
+ // For associative containers.
+ bool operator<(const TokenBase& other) const {
+ return std::string(GetToken()) < std::string(other.GetToken());
+ }
+
+ // STL-style swap.
+ void swap(TokenBase& other) {
+ using std::swap;
+ swap(other.core_, core_);
+ }
+
+ // Google-style swap.
+ void Swap(TokenBase* other) {
+ using std::swap;
+ swap(other->core_, core_);
+ }
+
+ private:
+ scoped_refptr<TokenCore> core_;
+};
+
+typedef TokenBase<USE_DEFAULT_SWAP> Token;
+typedef TokenBase<USE_FAST_SWAP_VIA_ADL> ADLToken;
+typedef TokenBase<USE_FAST_SWAP_VIA_SPECIALIZATION> SpecializationToken;
+
+void swap(ADLToken& t1, ADLToken& t2) {
+ t1.Swap(&t2);
+}
+
+} // namespace browser_sync
+
+// Allowed by the standard (17.4.3.1/1).
+namespace std {
+
+template <>
+void swap(browser_sync::SpecializationToken& t1,
+ browser_sync::SpecializationToken& t2) {
+ t1.Swap(&t2);
+}
+
+} // namespace
+
+namespace browser_sync {
+namespace {
+
+class ImmutableTest : public ::testing::Test {};
+
+TEST_F(ImmutableTest, Int) {
+ int x = 5;
+ Immutable<int> ix(&x);
+ EXPECT_EQ(5, ix.Get());
+ EXPECT_EQ(0, x);
+}
+
+TEST_F(ImmutableTest, IntCopy) {
+ int x = 5;
+ Immutable<int> ix = Immutable<int>(&x);
+ EXPECT_EQ(5, ix.Get());
+ EXPECT_EQ(0, x);
+}
+
+TEST_F(ImmutableTest, IntAssign) {
+ int x = 5;
+ Immutable<int> ix;
+ EXPECT_EQ(0, ix.Get());
+ ix = Immutable<int>(&x);
+ EXPECT_EQ(5, ix.Get());
+ EXPECT_EQ(0, x);
+}
+
+TEST_F(ImmutableTest, IntMakeImmutable) {
+ int x = 5;
+ Immutable<int> ix = MakeImmutable(&x);
+ EXPECT_EQ(5, ix.Get());
+ EXPECT_EQ(0, x);
+}
+
+template <typename T, typename ImmutableT>
+void RunTokenTest(const char* token, bool expect_copies) {
+ SCOPED_TRACE(token);
+ T t(token);
+ EXPECT_EQ(token, t.GetToken());
+ EXPECT_EQ(0, t.GetCopyCount());
+
+ ImmutableT immutable_t(&t);
+ EXPECT_EQ(token, immutable_t.Get().GetToken());
+ EXPECT_EQ(kEmptyToken, t.GetToken());
+ EXPECT_EQ(expect_copies, immutable_t.Get().GetCopyCount() > 0);
+ EXPECT_EQ(expect_copies, t.GetCopyCount() > 0);
+}
+
+TEST_F(ImmutableTest, Token) {
+ RunTokenTest<Token, Immutable<Token> >("Token", true /* expect_copies */);
+}
+
+TEST_F(ImmutableTest, TokenSwapMemFnByRef) {
+ RunTokenTest<Token, Immutable<Token, HasSwapMemFnByRef<Token> > >(
+ "TokenSwapMemFnByRef", false /* expect_copies */);
+}
+
+TEST_F(ImmutableTest, TokenSwapMemFnByPtr) {
+ RunTokenTest<Token, Immutable<Token, HasSwapMemFnByPtr<Token> > >(
+ "TokenSwapMemFnByPtr", false /* expect_copies */);
+}
+
+TEST_F(ImmutableTest, ADLToken) {
+ RunTokenTest<ADLToken, Immutable<ADLToken> >(
+ "ADLToken", false /* expect_copies */);
+}
+
+TEST_F(ImmutableTest, SpecializationToken) {
+ RunTokenTest<SpecializationToken, Immutable<SpecializationToken> >(
+ "SpecializationToken", false /* expect_copies */);
+}
+
+template <typename C, typename ImmutableC>
+void RunTokenContainerTest(const char* token) {
+ SCOPED_TRACE(token);
+ const Token tokens[] = { Token(), Token(token) };
+ const size_t token_count = arraysize(tokens);
+ C c(tokens, tokens + token_count);
+ const int copy_count = c.begin()->GetCopyCount();
+ EXPECT_GT(copy_count, 0);
+ for (typename C::const_iterator it = c.begin(); it != c.end(); ++it) {
+ EXPECT_EQ(copy_count, it->GetCopyCount());
+ }
+
+ // Make sure that making the container immutable doesn't incur any
+ // copies of the tokens.
+ ImmutableC immutable_c(&c);
+ EXPECT_TRUE(c.empty());
+ ASSERT_EQ(token_count, immutable_c.Get().size());
+ int i = 0;
+ for (typename C::const_iterator it = c.begin(); it != c.end(); ++it) {
+ EXPECT_EQ(tokens[i].GetToken(), it->GetToken());
+ EXPECT_EQ(copy_count, it->GetCopyCount());
+ ++i;
+ }
+}
+
+TEST_F(ImmutableTest, Vector) {
+ RunTokenContainerTest<std::vector<Token>, Immutable<std::vector<Token> > >(
+ "Vector");
+}
+
+TEST_F(ImmutableTest, VectorSwapMemFnByRef) {
+ RunTokenContainerTest<
+ std::vector<Token>,
+ Immutable<std::vector<Token>, HasSwapMemFnByRef<std::vector<Token> > > >(
+ "VectorSwapMemFnByRef");
+}
+
+// http://crbug.com/129128
+#if defined(OS_WIN)
+#define MAYBE_Deque DISABLED_Deque
+#else
+#define MAYBE_Deque Deque
+#endif
+TEST_F(ImmutableTest, MAYBE_Deque) {
+ RunTokenContainerTest<std::deque<Token>, Immutable<std::deque<Token> > >(
+ "Deque");
+}
+
+TEST_F(ImmutableTest, List) {
+ RunTokenContainerTest<std::list<Token>, Immutable<std::list<Token> > >(
+ "List");
+}
+
+TEST_F(ImmutableTest, Set) {
+ RunTokenContainerTest<std::set<Token>, Immutable<std::set<Token> > >(
+ "Set");
+}
+
+} // namespace
+} // namespace browser_sync
diff --git a/sync/internal_api/public/util/report_unrecoverable_error_function.h b/sync/internal_api/public/util/report_unrecoverable_error_function.h
new file mode 100644
index 0000000..ead73f0
--- /dev/null
+++ b/sync/internal_api/public/util/report_unrecoverable_error_function.h
@@ -0,0 +1,19 @@
+// 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_REPORT_UNRECOVERABLE_ERROR_FUNCTION_H_
+#define SYNC_UTIL_REPORT_UNRECOVERABLE_ERROR_FUNCTION_H_
+#pragma once
+
+namespace browser_sync {
+
+// A ReportUnrecoverableErrorFunction is a function that is called
+// immediately when an unrecoverable error is encountered. Unlike
+// UnrecoverableErrorHandler, it should just log the error and any
+// context surrounding it.
+typedef void (*ReportUnrecoverableErrorFunction)(void);
+
+} // namespace browser_sync
+
+#endif // SYNC_UTIL_REPORT_UNRECOVERABLE_ERROR_FUNCTION_H_
diff --git a/sync/internal_api/public/util/unrecoverable_error_handler.h b/sync/internal_api/public/util/unrecoverable_error_handler.h
new file mode 100644
index 0000000..aaca1e9
--- /dev/null
+++ b/sync/internal_api/public/util/unrecoverable_error_handler.h
@@ -0,0 +1,30 @@
+// 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_UNRECOVERABLE_ERROR_HANDLER_H_
+#define SYNC_UTIL_UNRECOVERABLE_ERROR_HANDLER_H_
+#pragma once
+
+#include <string>
+
+#include "base/location.h"
+
+namespace browser_sync {
+
+class UnrecoverableErrorHandler {
+ public:
+ // Call this when normal operation detects that the chrome model and the
+ // syncer model are inconsistent, or similar. The ProfileSyncService will
+ // try to avoid doing any work to avoid crashing or corrupting things
+ // further, and will report an error status if queried.
+ virtual void OnUnrecoverableError(const tracked_objects::Location& from_here,
+ const std::string& message) = 0;
+ protected:
+ virtual ~UnrecoverableErrorHandler() { }
+};
+
+}
+
+#endif // SYNC_UTIL_UNRECOVERABLE_ERROR_HANDLER_H_
+
diff --git a/sync/internal_api/public/util/unrecoverable_error_info.cc b/sync/internal_api/public/util/unrecoverable_error_info.cc
new file mode 100644
index 0000000..369fa3e
--- /dev/null
+++ b/sync/internal_api/public/util/unrecoverable_error_info.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/util/unrecoverable_error_info.h"
+
+namespace browser_sync {
+
+UnrecoverableErrorInfo::UnrecoverableErrorInfo()
+ : is_set_(false) {
+}
+
+UnrecoverableErrorInfo::UnrecoverableErrorInfo(
+ const tracked_objects::Location& location,
+ const std::string& message)
+ : location_(location),
+ message_(message),
+ is_set_(true) {
+}
+
+UnrecoverableErrorInfo::~UnrecoverableErrorInfo() {
+}
+
+void UnrecoverableErrorInfo::Reset(
+ const tracked_objects::Location& location,
+ const std::string& message) {
+ location_ = location;
+ message_ = message;
+ is_set_ = true;
+}
+
+bool UnrecoverableErrorInfo::IsSet() const {
+ return is_set_;
+}
+
+const tracked_objects::Location& UnrecoverableErrorInfo::location() const {
+ return location_;
+}
+
+const std::string& UnrecoverableErrorInfo::message() const {
+ return message_;
+}
+
+} // namespace browser_sync
diff --git a/sync/internal_api/public/util/unrecoverable_error_info.h b/sync/internal_api/public/util/unrecoverable_error_info.h
new file mode 100644
index 0000000..64b780a
--- /dev/null
+++ b/sync/internal_api/public/util/unrecoverable_error_info.h
@@ -0,0 +1,41 @@
+// 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_UNRECOVERABLE_ERROR_INFO_H_
+#define SYNC_UTIL_UNRECOVERABLE_ERROR_INFO_H_
+// TODO(lipalani): Figure out the right location for this class so it is
+// accessible outside of sync engine as well.
+#pragma once
+
+#include <string>
+
+#include "base/location.h"
+
+namespace browser_sync {
+
+class UnrecoverableErrorInfo {
+ public:
+ UnrecoverableErrorInfo();
+ UnrecoverableErrorInfo(
+ const tracked_objects::Location& location,
+ const std::string& message);
+ ~UnrecoverableErrorInfo();
+
+ void Reset(const tracked_objects::Location& location,
+ const std::string& message);
+
+ bool IsSet() const;
+
+ const tracked_objects::Location& location() const;
+ const std::string& message() const;
+
+ private:
+ tracked_objects::Location location_;
+ std::string message_;
+ bool is_set_;
+};
+
+} // namespace browser_sync
+
+#endif // SYNC_UTIL_UNRECOVERABLE_ERROR_INFO_H_
diff --git a/sync/internal_api/public/util/weak_handle.cc b/sync/internal_api/public/util/weak_handle.cc
new file mode 100644
index 0000000..136fc58
--- /dev/null
+++ b/sync/internal_api/public/util/weak_handle.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/weak_handle.h"
+
+#include <sstream>
+
+#include "base/callback.h"
+#include "base/location.h"
+#include "base/message_loop_proxy.h"
+
+namespace browser_sync {
+
+namespace internal {
+
+WeakHandleCoreBase::WeakHandleCoreBase()
+ : owner_loop_proxy_(base::MessageLoopProxy::current()) {}
+
+bool WeakHandleCoreBase::IsOnOwnerThread() const {
+ return owner_loop_proxy_->BelongsToCurrentThread();
+}
+
+WeakHandleCoreBase::~WeakHandleCoreBase() {}
+
+void WeakHandleCoreBase::PostToOwnerThread(
+ const tracked_objects::Location& from_here,
+ const base::Closure& fn) const {
+ if (!owner_loop_proxy_->PostTask(from_here, fn)) {
+ DVLOG(1) << "Could not post task from " << from_here.ToString();
+ }
+}
+
+} // namespace internal
+
+} // namespace base
diff --git a/sync/internal_api/public/util/weak_handle.h b/sync/internal_api/public/util/weak_handle.h
new file mode 100644
index 0000000..653da60
--- /dev/null
+++ b/sync/internal_api/public/util/weak_handle.h
@@ -0,0 +1,379 @@
+// 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.
+
+// Weak handles provides a way to refer to weak pointers from another
+// thread. This is useful because it is not safe to reference a weak
+// pointer from a thread other than the thread on which it was
+// created.
+//
+// Weak handles can be passed across threads, so for example, you can
+// use them to do the "real" work on one thread and get notified on
+// another thread:
+//
+// class FooIOWorker {
+// public:
+// FooIOWorker(const WeakHandle<Foo>& foo) : foo_(foo) {}
+//
+// void OnIOStart() {
+// foo_.Call(FROM_HERE, &Foo::OnIOStart);
+// }
+//
+// void OnIOEvent(IOEvent e) {
+// foo_.Call(FROM_HERE, &Foo::OnIOEvent, e);
+// }
+//
+// void OnIOError(IOError err) {
+// foo_.Call(FROM_HERE, &Foo::OnIOError, err);
+// }
+//
+// private:
+// const WeakHandle<Foo> foo_;
+// };
+//
+// class Foo : public SupportsWeakPtr<Foo>, public NonThreadSafe {
+// public:
+// Foo() {
+// SpawnFooIOWorkerOnIOThread(base::MakeWeakHandle(AsWeakPtr()));
+// }
+//
+// /* Will always be called on the correct thread, and only if this
+// object hasn't been destroyed. */
+// void OnIOStart() { DCHECK(CalledOnValidThread(); ... }
+// void OnIOEvent(IOEvent e) { DCHECK(CalledOnValidThread(); ... }
+// void OnIOError(IOError err) { DCHECK(CalledOnValidThread(); ... }
+// };
+
+#ifndef SYNC_UTIL_WEAK_HANDLE_H_
+#define SYNC_UTIL_WEAK_HANDLE_H_
+#pragma once
+
+#include <cstddef>
+
+#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/callback_forward.h"
+#include "base/compiler_specific.h"
+#include "base/gtest_prod_util.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
+namespace tracked_objects {
+class Location;
+} // namespace tracked_objects
+
+namespace browser_sync {
+
+template <typename T> class WeakHandle;
+
+namespace internal {
+// These classes are part of the WeakHandle implementation. DO NOT
+// USE THESE CLASSES DIRECTLY YOURSELF.
+
+// Adapted from base/callback_internal.h.
+
+template <typename T>
+struct ParamTraits {
+ typedef const T& ForwardType;
+};
+
+template <typename T>
+struct ParamTraits<T&> {
+ typedef T& ForwardType;
+};
+
+template <typename T, size_t n>
+struct ParamTraits<T[n]> {
+ typedef const T* ForwardType;
+};
+
+template <typename T>
+struct ParamTraits<T[]> {
+ typedef const T* ForwardType;
+};
+
+// Base class for WeakHandleCore<T> to avoid template bloat. Handles
+// the interaction with the owner thread and its message loop.
+class WeakHandleCoreBase {
+ public:
+ // Assumes the current thread is the owner thread.
+ WeakHandleCoreBase();
+
+ // May be called on any thread.
+ bool IsOnOwnerThread() const;
+
+ protected:
+ // May be destroyed on any thread.
+ ~WeakHandleCoreBase();
+
+ // May be called on any thread.
+ void PostToOwnerThread(const tracked_objects::Location& from_here,
+ const base::Closure& fn) const;
+
+ private:
+ // May be used on any thread.
+ const scoped_refptr<base::MessageLoopProxy> owner_loop_proxy_;
+
+ DISALLOW_COPY_AND_ASSIGN(WeakHandleCoreBase);
+};
+
+// WeakHandleCore<T> contains all the logic for WeakHandle<T>.
+template <typename T>
+class WeakHandleCore
+ : public WeakHandleCoreBase,
+ public base::RefCountedThreadSafe<WeakHandleCore<T> > {
+ public:
+ // Must be called on |ptr|'s owner thread, which is assumed to be
+ // the current thread.
+ explicit WeakHandleCore(const base::WeakPtr<T>& ptr) : ptr_(ptr) {}
+
+ // Must be called on |ptr_|'s owner thread.
+ base::WeakPtr<T> Get() const {
+ CHECK(IsOnOwnerThread());
+ return ptr_;
+ }
+
+ // Call(...) may be called on any thread, but all its arguments
+ // should be safe to be bound and copied across threads.
+
+ template <typename U>
+ void Call(const tracked_objects::Location& from_here,
+ void (U::*fn)(void)) const {
+ PostToOwnerThread(
+ from_here,
+ Bind(&WeakHandleCore::template DoCall0<U>, this, fn));
+ }
+
+ template <typename U, typename A1>
+ void Call(const tracked_objects::Location& from_here,
+ void (U::*fn)(A1),
+ typename ParamTraits<A1>::ForwardType a1) const {
+ PostToOwnerThread(
+ from_here,
+ Bind(&WeakHandleCore::template DoCall1<U, A1>,
+ this, fn, a1));
+ }
+
+ template <typename U, typename A1, typename A2>
+ void Call(const tracked_objects::Location& from_here,
+ void (U::*fn)(A1, A2),
+ typename ParamTraits<A1>::ForwardType a1,
+ typename ParamTraits<A2>::ForwardType a2) const {
+ PostToOwnerThread(
+ from_here,
+ Bind(&WeakHandleCore::template DoCall2<U, A1, A2>,
+ this, fn, a1, a2));
+ }
+
+ template <typename U, typename A1, typename A2, typename A3>
+ void Call(const tracked_objects::Location& from_here,
+ void (U::*fn)(A1, A2, A3),
+ typename ParamTraits<A1>::ForwardType a1,
+ typename ParamTraits<A2>::ForwardType a2,
+ typename ParamTraits<A3>::ForwardType a3) const {
+ PostToOwnerThread(
+ from_here,
+ Bind(&WeakHandleCore::template DoCall3<U, A1, A2, A3>,
+ this, fn, a1, a2, a3));
+ }
+
+ template <typename U, typename A1, typename A2, typename A3, typename A4>
+ void Call(const tracked_objects::Location& from_here,
+ void (U::*fn)(A1, A2, A3, A4),
+ typename ParamTraits<A1>::ForwardType a1,
+ typename ParamTraits<A2>::ForwardType a2,
+ typename ParamTraits<A3>::ForwardType a3,
+ typename ParamTraits<A4>::ForwardType a4) const {
+ PostToOwnerThread(
+ from_here,
+ Bind(&WeakHandleCore::template DoCall4<U, A1, A2, A3, A4>,
+ this, fn, a1, a2, a3, a4));
+ }
+
+ private:
+ friend class base::RefCountedThreadSafe<WeakHandleCore<T> >;
+
+ // May be destroyed on any thread.
+ ~WeakHandleCore() {}
+
+ // GCC 4.2.1 on OS X gets confused if all the DoCall functions are
+ // named the same, so we distinguish them.
+
+ template <typename U>
+ void DoCall0(void (U::*fn)(void)) const {
+ CHECK(IsOnOwnerThread());
+ if (!Get()) {
+ return;
+ }
+ (Get()->*fn)();
+ }
+
+ template <typename U, typename A1>
+ void DoCall1(void (U::*fn)(A1),
+ typename ParamTraits<A1>::ForwardType a1) const {
+ CHECK(IsOnOwnerThread());
+ if (!Get()) {
+ return;
+ }
+ (Get()->*fn)(a1);
+ }
+
+ template <typename U, typename A1, typename A2>
+ void DoCall2(void (U::*fn)(A1, A2),
+ typename ParamTraits<A1>::ForwardType a1,
+ typename ParamTraits<A2>::ForwardType a2) const {
+ CHECK(IsOnOwnerThread());
+ if (!Get()) {
+ return;
+ }
+ (Get()->*fn)(a1, a2);
+ }
+
+ template <typename U, typename A1, typename A2, typename A3>
+ void DoCall3(void (U::*fn)(A1, A2, A3),
+ typename ParamTraits<A1>::ForwardType a1,
+ typename ParamTraits<A2>::ForwardType a2,
+ typename ParamTraits<A3>::ForwardType a3) const {
+ CHECK(IsOnOwnerThread());
+ if (!Get()) {
+ return;
+ }
+ (Get()->*fn)(a1, a2, a3);
+ }
+
+ template <typename U, typename A1, typename A2, typename A3, typename A4>
+ void DoCall4(void (U::*fn)(A1, A2, A3, A4),
+ typename ParamTraits<A1>::ForwardType a1,
+ typename ParamTraits<A2>::ForwardType a2,
+ typename ParamTraits<A3>::ForwardType a3,
+ typename ParamTraits<A4>::ForwardType a4) const {
+ CHECK(IsOnOwnerThread());
+ if (!Get()) {
+ return;
+ }
+ (Get()->*fn)(a1, a2, a3, a4);
+ }
+
+ // Must be dereferenced only on the owner thread. May be destroyed
+ // from any thread.
+ base::WeakPtr<T> ptr_;
+
+ DISALLOW_COPY_AND_ASSIGN(WeakHandleCore);
+};
+
+} // namespace internal
+
+// May be destroyed on any thread.
+// Copying and assignment are welcome.
+template <typename T>
+class WeakHandle {
+ public:
+ // Creates an uninitialized WeakHandle.
+ WeakHandle() {}
+
+ // Creates an initialized WeakHandle from |ptr|.
+ explicit WeakHandle(const base::WeakPtr<T>& ptr)
+ : core_(new internal::WeakHandleCore<T>(ptr)) {}
+
+ // Allow conversion from WeakHandle<U> to WeakHandle<T> if U is
+ // convertible to T, but we *must* be on |other|'s owner thread.
+ // Note that this doesn't override the regular copy constructor, so
+ // that one can be called on any thread.
+ template <typename U>
+ WeakHandle(const browser_sync::WeakHandle<U>& other) // NOLINT
+ : core_(
+ other.IsInitialized() ?
+ new internal::WeakHandleCore<T>(other.Get()) :
+ NULL) {}
+
+ // Returns true iff this WeakHandle is initialized. Note that being
+ // initialized isn't a guarantee that the underlying object is still
+ // alive.
+ bool IsInitialized() const {
+ return core_.get() != NULL;
+ }
+
+ // Resets to an uninitialized WeakHandle.
+ void Reset() {
+ core_ = NULL;
+ }
+
+ // Must be called only on the underlying object's owner thread.
+ base::WeakPtr<T> Get() const {
+ CHECK(IsInitialized());
+ CHECK(core_->IsOnOwnerThread());
+ return core_->Get();
+ }
+
+ // Call(...) may be called on any thread, but all its arguments
+ // should be safe to be bound and copied across threads.
+
+ template <typename U>
+ void Call(const tracked_objects::Location& from_here,
+ void (U::*fn)(void)) const {
+ CHECK(IsInitialized());
+ core_->Call(from_here, fn);
+ }
+
+ template <typename U, typename A1>
+ void Call(const tracked_objects::Location& from_here,
+ void (U::*fn)(A1),
+ typename internal::ParamTraits<A1>::ForwardType a1) const {
+ CHECK(IsInitialized());
+ core_->Call(from_here, fn, a1);
+ }
+
+ template <typename U, typename A1, typename A2>
+ void Call(const tracked_objects::Location& from_here,
+ void (U::*fn)(A1, A2),
+ typename internal::ParamTraits<A1>::ForwardType a1,
+ typename internal::ParamTraits<A2>::ForwardType a2) const {
+ CHECK(IsInitialized());
+ core_->Call(from_here, fn, a1, a2);
+ }
+
+ template <typename U, typename A1, typename A2, typename A3>
+ void Call(const tracked_objects::Location& from_here,
+ void (U::*fn)(A1, A2, A3),
+ typename internal::ParamTraits<A1>::ForwardType a1,
+ typename internal::ParamTraits<A2>::ForwardType a2,
+ typename internal::ParamTraits<A3>::ForwardType a3) const {
+ CHECK(IsInitialized());
+ core_->Call(from_here, fn, a1, a2, a3);
+ }
+
+ template <typename U, typename A1, typename A2, typename A3, typename A4>
+ void Call(const tracked_objects::Location& from_here,
+ void (U::*fn)(A1, A2, A3, A4),
+ typename internal::ParamTraits<A1>::ForwardType a1,
+ typename internal::ParamTraits<A2>::ForwardType a2,
+ typename internal::ParamTraits<A3>::ForwardType a3,
+ typename internal::ParamTraits<A4>::ForwardType a4) const {
+ CHECK(IsInitialized());
+ core_->Call(from_here, fn, a1, a2, a3, a4);
+ }
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(WeakHandleTest,
+ TypeConversionConstructor);
+ FRIEND_TEST_ALL_PREFIXES(WeakHandleTest,
+ TypeConversionConstructorAssignment);
+
+ scoped_refptr<internal::WeakHandleCore<T> > core_;
+};
+
+// Makes a WeakHandle from a WeakPtr.
+template <typename T>
+WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) {
+ return WeakHandle<T>(ptr);
+}
+
+} // namespace browser_sync
+
+#endif // SYNC_UTIL_WEAK_HANDLE_H_
diff --git a/sync/internal_api/public/util/weak_handle_unittest.cc b/sync/internal_api/public/util/weak_handle_unittest.cc
new file mode 100644
index 0000000..af919ad
--- /dev/null
+++ b/sync/internal_api/public/util/weak_handle_unittest.cc
@@ -0,0 +1,326 @@
+// 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/weak_handle.h"
+
+#include "base/bind.h"
+#include "base/compiler_specific.h"
+#include "base/location.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop.h"
+#include "base/threading/thread.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace browser_sync {
+
+using ::testing::_;
+using ::testing::SaveArg;
+using ::testing::StrictMock;
+
+class Base {
+ public:
+ Base() : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
+
+ WeakHandle<Base> AsWeakHandle() {
+ return MakeWeakHandle(weak_ptr_factory_.GetWeakPtr());
+ }
+
+ void Kill() {
+ weak_ptr_factory_.InvalidateWeakPtrs();
+ }
+
+ MOCK_METHOD0(Test, void());
+ MOCK_METHOD1(Test1, void(const int&));
+ MOCK_METHOD2(Test2, void(const int&, Base*));
+ MOCK_METHOD3(Test3, void(const int&, Base*, float));
+ MOCK_METHOD4(Test4, void(const int&, Base*, float, const char*));
+
+ MOCK_METHOD1(TestWithSelf, void(const WeakHandle<Base>&));
+
+ private:
+ base::WeakPtrFactory<Base> weak_ptr_factory_;
+};
+
+class Derived : public Base, public base::SupportsWeakPtr<Derived> {};
+
+class WeakHandleTest : public ::testing::Test {
+ protected:
+ virtual void TearDown() {
+ // Process any last-minute posted tasks.
+ PumpLoop();
+ }
+
+ void PumpLoop() {
+ message_loop_.RunAllPending();
+ }
+
+ static void CallTestFromOtherThread(tracked_objects::Location from_here,
+ const WeakHandle<Base>& h) {
+ base::Thread t("Test thread");
+ ASSERT_TRUE(t.Start());
+ t.message_loop()->PostTask(
+ from_here, base::Bind(&WeakHandleTest::CallTest, from_here, h));
+ }
+
+ private:
+ static void CallTest(tracked_objects::Location from_here,
+ const WeakHandle<Base>& h) {
+ h.Call(from_here, &Base::Test);
+ }
+
+ MessageLoop message_loop_;
+};
+
+TEST_F(WeakHandleTest, Uninitialized) {
+ // Default.
+ WeakHandle<int> h;
+ EXPECT_FALSE(h.IsInitialized());
+ // Copy.
+ {
+ WeakHandle<int> h2(h);
+ EXPECT_FALSE(h2.IsInitialized());
+ }
+ // Assign.
+ {
+ WeakHandle<int> h2;
+ h2 = h;
+ EXPECT_FALSE(h.IsInitialized());
+ }
+}
+
+TEST_F(WeakHandleTest, InitializedAfterDestroy) {
+ WeakHandle<Base> h;
+ {
+ StrictMock<Base> b;
+ h = b.AsWeakHandle();
+ }
+ EXPECT_TRUE(h.IsInitialized());
+ EXPECT_FALSE(h.Get());
+}
+
+TEST_F(WeakHandleTest, InitializedAfterInvalidate) {
+ StrictMock<Base> b;
+ WeakHandle<Base> h = b.AsWeakHandle();
+ b.Kill();
+ EXPECT_TRUE(h.IsInitialized());
+ EXPECT_FALSE(h.Get());
+}
+
+TEST_F(WeakHandleTest, Call) {
+ StrictMock<Base> b;
+ const char test_str[] = "test";
+ EXPECT_CALL(b, Test());
+ EXPECT_CALL(b, Test1(5));
+ EXPECT_CALL(b, Test2(5, &b));
+ EXPECT_CALL(b, Test3(5, &b, 5));
+ EXPECT_CALL(b, Test4(5, &b, 5, test_str));
+
+ WeakHandle<Base> h = b.AsWeakHandle();
+ EXPECT_TRUE(h.IsInitialized());
+
+ // Should run.
+ h.Call(FROM_HERE, &Base::Test);
+ h.Call(FROM_HERE, &Base::Test1, 5);
+ h.Call(FROM_HERE, &Base::Test2, 5, &b);
+ h.Call(FROM_HERE, &Base::Test3, 5, &b, 5);
+ h.Call(FROM_HERE, &Base::Test4, 5, &b, 5, test_str);
+ PumpLoop();
+}
+
+TEST_F(WeakHandleTest, CallAfterDestroy) {
+ {
+ StrictMock<Base> b;
+ EXPECT_CALL(b, Test()).Times(0);
+
+ WeakHandle<Base> h = b.AsWeakHandle();
+ EXPECT_TRUE(h.IsInitialized());
+
+ // Should not run.
+ h.Call(FROM_HERE, &Base::Test);
+ }
+ PumpLoop();
+}
+
+TEST_F(WeakHandleTest, CallAfterInvalidate) {
+ StrictMock<Base> b;
+ EXPECT_CALL(b, Test()).Times(0);
+
+ WeakHandle<Base> h = b.AsWeakHandle();
+ EXPECT_TRUE(h.IsInitialized());
+
+ // Should not run.
+ h.Call(FROM_HERE, &Base::Test);
+
+ b.Kill();
+ PumpLoop();
+}
+
+TEST_F(WeakHandleTest, CallThreaded) {
+ StrictMock<Base> b;
+ EXPECT_CALL(b, Test());
+
+ WeakHandle<Base> h = b.AsWeakHandle();
+ // Should run.
+ CallTestFromOtherThread(FROM_HERE, h);
+ PumpLoop();
+}
+
+TEST_F(WeakHandleTest, CallAfterDestroyThreaded) {
+ WeakHandle<Base> h;
+ {
+ StrictMock<Base> b;
+ EXPECT_CALL(b, Test()).Times(0);
+ h = b.AsWeakHandle();
+ }
+
+ // Should not run.
+ CallTestFromOtherThread(FROM_HERE, h);
+ PumpLoop();
+}
+
+TEST_F(WeakHandleTest, CallAfterInvalidateThreaded) {
+ StrictMock<Base> b;
+ EXPECT_CALL(b, Test()).Times(0);
+
+ WeakHandle<Base> h = b.AsWeakHandle();
+ b.Kill();
+ // Should not run.
+ CallTestFromOtherThread(FROM_HERE, h);
+ PumpLoop();
+}
+
+TEST_F(WeakHandleTest, DeleteOnOtherThread) {
+ StrictMock<Base> b;
+ EXPECT_CALL(b, Test()).Times(0);
+
+ WeakHandle<Base>* h = new WeakHandle<Base>(b.AsWeakHandle());
+
+ {
+ base::Thread t("Test thread");
+ ASSERT_TRUE(t.Start());
+ t.message_loop()->DeleteSoon(FROM_HERE, h);
+ }
+
+ PumpLoop();
+}
+
+void CallTestWithSelf(const WeakHandle<Base>& b1) {
+ StrictMock<Base> b2;
+ b1.Call(FROM_HERE, &Base::TestWithSelf, b2.AsWeakHandle());
+}
+
+TEST_F(WeakHandleTest, WithDestroyedThread) {
+ StrictMock<Base> b1;
+ WeakHandle<Base> b2;
+ EXPECT_CALL(b1, TestWithSelf(_)).WillOnce(SaveArg<0>(&b2));
+
+ {
+ base::Thread t("Test thread");
+ ASSERT_TRUE(t.Start());
+ t.message_loop()->PostTask(FROM_HERE,
+ base::Bind(&CallTestWithSelf,
+ b1.AsWeakHandle()));
+ }
+
+ // Calls b1.TestWithSelf().
+ PumpLoop();
+
+ // Shouldn't do anything, since the thread is gone.
+ b2.Call(FROM_HERE, &Base::Test);
+
+ // |b2| shouldn't leak when it's destroyed, even if the original
+ // thread is gone.
+}
+
+TEST_F(WeakHandleTest, InitializedAcrossCopyAssign) {
+ StrictMock<Base> b;
+ EXPECT_CALL(b, Test()).Times(3);
+
+ EXPECT_TRUE(b.AsWeakHandle().IsInitialized());
+ b.AsWeakHandle().Call(FROM_HERE, &Base::Test);
+
+ {
+ WeakHandle<Base> h(b.AsWeakHandle());
+ EXPECT_TRUE(h.IsInitialized());
+ h.Call(FROM_HERE, &Base::Test);
+ h.Reset();
+ EXPECT_FALSE(h.IsInitialized());
+ }
+
+ {
+ WeakHandle<Base> h;
+ h = b.AsWeakHandle();
+ EXPECT_TRUE(h.IsInitialized());
+ h.Call(FROM_HERE, &Base::Test);
+ h.Reset();
+ EXPECT_FALSE(h.IsInitialized());
+ }
+
+ PumpLoop();
+}
+
+TEST_F(WeakHandleTest, TypeConversionConstructor) {
+ StrictMock<Derived> d;
+ EXPECT_CALL(d, Test()).Times(2);
+
+ const WeakHandle<Derived> weak_handle = MakeWeakHandle(d.AsWeakPtr());
+
+ // Should trigger type conversion constructor.
+ const WeakHandle<Base> base_weak_handle(weak_handle);
+ // Should trigger regular copy constructor.
+ const WeakHandle<Derived> derived_weak_handle(weak_handle);
+
+ EXPECT_TRUE(base_weak_handle.IsInitialized());
+ base_weak_handle.Call(FROM_HERE, &Base::Test);
+
+ EXPECT_TRUE(derived_weak_handle.IsInitialized());
+ // Copy constructor shouldn't construct a new |core_|.
+ EXPECT_EQ(weak_handle.core_.get(), derived_weak_handle.core_.get());
+ derived_weak_handle.Call(FROM_HERE, &Base::Test);
+
+ PumpLoop();
+}
+
+TEST_F(WeakHandleTest, TypeConversionConstructorMakeWeakHandle) {
+ const base::WeakPtr<Derived> weak_ptr;
+
+ // Should trigger type conversion constructor after MakeWeakHandle.
+ WeakHandle<Base> base_weak_handle(MakeWeakHandle(weak_ptr));
+ // Should trigger regular copy constructor after MakeWeakHandle.
+ const WeakHandle<Derived> derived_weak_handle(MakeWeakHandle(weak_ptr));
+
+ EXPECT_TRUE(base_weak_handle.IsInitialized());
+ EXPECT_TRUE(derived_weak_handle.IsInitialized());
+}
+
+TEST_F(WeakHandleTest, TypeConversionConstructorAssignment) {
+ const WeakHandle<Derived> weak_handle =
+ MakeWeakHandle(Derived().AsWeakPtr());
+
+ // Should trigger type conversion constructor before the assignment.
+ WeakHandle<Base> base_weak_handle;
+ base_weak_handle = weak_handle;
+ // Should trigger regular copy constructor before the assignment.
+ WeakHandle<Derived> derived_weak_handle;
+ derived_weak_handle = weak_handle;
+
+ EXPECT_TRUE(base_weak_handle.IsInitialized());
+ EXPECT_TRUE(derived_weak_handle.IsInitialized());
+ // Copy constructor shouldn't construct a new |core_|.
+ EXPECT_EQ(weak_handle.core_.get(), derived_weak_handle.core_.get());
+}
+
+TEST_F(WeakHandleTest, TypeConversionConstructorUninitialized) {
+ const WeakHandle<Base> base_weak_handle = WeakHandle<Derived>();
+ EXPECT_FALSE(base_weak_handle.IsInitialized());
+}
+
+TEST_F(WeakHandleTest, TypeConversionConstructorUninitializedAssignment) {
+ WeakHandle<Base> base_weak_handle;
+ base_weak_handle = WeakHandle<Derived>();
+ EXPECT_FALSE(base_weak_handle.IsInitialized());
+}
+
+} // namespace browser_sync
diff --git a/sync/internal_api/write_node.h b/sync/internal_api/public/write_node.h
index d297ac8..ba61122 100644
--- a/sync/internal_api/write_node.h
+++ b/sync/internal_api/public/write_node.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_WRITE_NODE_H_
-#define SYNC_INTERNAL_API_WRITE_NODE_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_WRITE_NODE_H_
+#define SYNC_INTERNAL_API_PUBLIC_WRITE_NODE_H_
#pragma once
#include <string>
@@ -11,7 +11,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "sync/internal_api/base_node.h"
+#include "sync/internal_api/public/base_node.h"
#include "sync/internal_api/public/syncable/model_type.h"
namespace browser_sync {
@@ -200,4 +200,4 @@ class WriteNode : public BaseNode {
} // namespace sync_api
-#endif // SYNC_INTERNAL_API_WRITE_NODE_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_WRITE_NODE_H_
diff --git a/sync/internal_api/write_transaction.h b/sync/internal_api/public/write_transaction.h
index 4364cdd1..1321ed1 100644
--- a/sync/internal_api/write_transaction.h
+++ b/sync/internal_api/public/write_transaction.h
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_WRITE_TRANSACTION_H_
-#define SYNC_INTERNAL_API_WRITE_TRANSACTION_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_WRITE_TRANSACTION_H_
+#define SYNC_INTERNAL_API_PUBLIC_WRITE_TRANSACTION_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "sync/internal_api/base_transaction.h"
+#include "sync/internal_api/public/base_transaction.h"
namespace syncable {
class BaseTransaction;
@@ -54,4 +54,4 @@ class WriteTransaction : public BaseTransaction {
} // namespace sync_api
-#endif // SYNC_INTERNAL_API_WRITE_TRANSACTION_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_WRITE_TRANSACTION_H_
diff --git a/sync/internal_api/read_node.cc b/sync/internal_api/read_node.cc
index 00ee6bc..970f981 100644
--- a/sync/internal_api/read_node.cc
+++ b/sync/internal_api/read_node.cc
@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "sync/internal_api/read_node.h"
+#include "sync/internal_api/public/read_node.h"
#include "base/logging.h"
-#include "sync/internal_api/base_transaction.h"
+#include "sync/internal_api/public/base_transaction.h"
#include "sync/syncable/syncable.h"
namespace sync_api {
diff --git a/sync/internal_api/read_transaction.cc b/sync/internal_api/read_transaction.cc
index 5c38f6c..1af6c21 100644
--- a/sync/internal_api/read_transaction.cc
+++ b/sync/internal_api/read_transaction.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/internal_api/read_transaction.h"
+#include "sync/internal_api/public/read_transaction.h"
#include "sync/syncable/syncable.h"
diff --git a/sync/internal_api/sync_manager.cc b/sync/internal_api/sync_manager.cc
index 13b313e..e9d3434 100644
--- a/sync/internal_api/sync_manager.cc
+++ b/sync/internal_api/sync_manager.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/internal_api/sync_manager.h"
+#include "sync/internal_api/public/sync_manager.h"
#include <string>
@@ -25,22 +25,23 @@
#include "sync/engine/sync_scheduler.h"
#include "sync/engine/syncer_types.h"
#include "sync/engine/throttled_data_type_tracker.h"
-#include "sync/internal_api/base_node.h"
#include "sync/internal_api/change_reorder_buffer.h"
-#include "sync/internal_api/configure_reason.h"
#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/base_node.h"
+#include "sync/internal_api/public/configure_reason.h"
#include "sync/internal_api/public/engine/polling_constants.h"
+#include "sync/internal_api/public/read_node.h"
+#include "sync/internal_api/public/read_transaction.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/public/user_share.h"
+#include "sync/internal_api/public/util/experiments.h"
+#include "sync/internal_api/public/write_node.h"
+#include "sync/internal_api/public/write_transaction.h"
#include "sync/internal_api/syncapi_internal.h"
#include "sync/internal_api/syncapi_server_connection_manager.h"
-#include "sync/internal_api/user_share.h"
-#include "sync/internal_api/write_node.h"
-#include "sync/internal_api/write_transaction.h"
#include "sync/js/js_arg_list.h"
#include "sync/js/js_backend.h"
#include "sync/js/js_event_details.h"
@@ -54,7 +55,6 @@
#include "sync/syncable/directory_change_delegate.h"
#include "sync/syncable/syncable.h"
#include "sync/util/cryptographer.h"
-#include "sync/util/experiments.h"
#include "sync/util/get_session_name.h"
#include "sync/util/time.h"
diff --git a/sync/internal_api/syncapi_server_connection_manager.cc b/sync/internal_api/syncapi_server_connection_manager.cc
index ce62d86..ca849ae 100644
--- a/sync/internal_api/syncapi_server_connection_manager.cc
+++ b/sync/internal_api/syncapi_server_connection_manager.cc
@@ -6,8 +6,8 @@
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
-#include "sync/internal_api/http_post_provider_factory.h"
-#include "sync/internal_api/http_post_provider_interface.h"
+#include "sync/internal_api/public/http_post_provider_factory.h"
+#include "sync/internal_api/public/http_post_provider_interface.h"
using browser_sync::HttpResponse;
diff --git a/sync/internal_api/syncapi_server_connection_manager_unittest.cc b/sync/internal_api/syncapi_server_connection_manager_unittest.cc
index 0c81e98..77b5244 100644
--- a/sync/internal_api/syncapi_server_connection_manager_unittest.cc
+++ b/sync/internal_api/syncapi_server_connection_manager_unittest.cc
@@ -12,8 +12,8 @@
#include "base/threading/thread.h"
#include "base/time.h"
#include "net/base/net_errors.h"
-#include "sync/internal_api/http_post_provider_factory.h"
-#include "sync/internal_api/http_post_provider_interface.h"
+#include "sync/internal_api/public/http_post_provider_factory.h"
+#include "sync/internal_api/public/http_post_provider_interface.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::TimeDelta;
diff --git a/sync/internal_api/syncapi_unittest.cc b/sync/internal_api/syncapi_unittest.cc
index 6380db3..1f1079c 100644
--- a/sync/internal_api/syncapi_unittest.cc
+++ b/sync/internal_api/syncapi_unittest.cc
@@ -25,19 +25,19 @@
#include "base/values.h"
#include "sync/engine/nigori_util.h"
#include "sync/engine/sync_scheduler.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/change_record.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/http_post_provider_factory.h"
+#include "sync/internal_api/public/http_post_provider_interface.h"
+#include "sync/internal_api/public/read_node.h"
+#include "sync/internal_api/public/read_transaction.h"
+#include "sync/internal_api/public/sync_manager.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"
+#include "sync/internal_api/public/test/test_user_share.h"
+#include "sync/internal_api/public/write_node.h"
+#include "sync/internal_api/public/write_transaction.h"
#include "sync/internal_api/syncapi_internal.h"
-#include "sync/internal_api/test_user_share.h"
-#include "sync/internal_api/write_node.h"
-#include "sync/internal_api/write_transaction.h"
#include "sync/js/js_arg_list.h"
#include "sync/js/js_backend.h"
#include "sync/js/js_event_handler.h"
diff --git a/sync/internal_api/test_user_share.cc b/sync/internal_api/test/test_user_share.cc
index 743f3d0..c028d66 100644
--- a/sync/internal_api/test_user_share.cc
+++ b/sync/internal_api/test/test_user_share.cc
@@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "sync/internal_api/test_user_share.h"
+#include "sync/internal_api/public/test/test_user_share.h"
#include "base/compiler_specific.h"
+#include "sync/test/engine/test_directory_setter_upper.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace browser_sync {
-TestUserShare::TestUserShare() {}
+TestUserShare::TestUserShare() : dir_maker_(new TestDirectorySetterUpper()) {}
TestUserShare::~TestUserShare() {
if (user_share_.get())
@@ -18,11 +19,11 @@ TestUserShare::~TestUserShare() {
void TestUserShare::SetUp() {
user_share_.reset(new sync_api::UserShare());
- dir_maker_.SetUp();
+ dir_maker_->SetUp();
// The pointer is owned by dir_maker_, we should not be storing it in a
// scoped_ptr. We must be careful to ensure the scoped_ptr never deletes it.
- user_share_->directory.reset(dir_maker_.directory());
+ user_share_->directory.reset(dir_maker_->directory());
}
void TestUserShare::TearDown() {
@@ -30,7 +31,7 @@ void TestUserShare::TearDown() {
ignore_result(user_share_->directory.release());
user_share_.reset();
- dir_maker_.TearDown();
+ dir_maker_->TearDown();
}
sync_api::UserShare* TestUserShare::user_share() {
diff --git a/sync/internal_api/user_share.cc b/sync/internal_api/user_share.cc
index a0a77ba..9bf0b46 100644
--- a/sync/internal_api/user_share.cc
+++ b/sync/internal_api/user_share.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/internal_api/user_share.h"
+#include "sync/internal_api/public/user_share.h"
#include "sync/syncable/syncable.h"
diff --git a/sync/internal_api/write_node.cc b/sync/internal_api/write_node.cc
index 68d3db7..bbd3035 100644
--- a/sync/internal_api/write_node.cc
+++ b/sync/internal_api/write_node.cc
@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "sync/internal_api/write_node.h"
+#include "sync/internal_api/public/write_node.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "sync/engine/nigori_util.h"
-#include "sync/internal_api/base_transaction.h"
+#include "sync/internal_api/public/base_transaction.h"
+#include "sync/internal_api/public/write_transaction.h"
#include "sync/internal_api/syncapi_internal.h"
-#include "sync/internal_api/write_transaction.h"
#include "sync/protocol/app_specifics.pb.h"
#include "sync/protocol/autofill_specifics.pb.h"
#include "sync/protocol/bookmark_specifics.pb.h"
diff --git a/sync/internal_api/write_transaction.cc b/sync/internal_api/write_transaction.cc
index b141b8c..a354bcd 100644
--- a/sync/internal_api/write_transaction.cc
+++ b/sync/internal_api/write_transaction.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/internal_api/write_transaction.h"
+#include "sync/internal_api/public/write_transaction.h"
#include "sync/syncable/syncable.h"