summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/sync/abstract_profile_sync_service_test.cc120
-rw-r--r--chrome/browser/sync/abstract_profile_sync_service_test.h127
-rw-r--r--chrome/browser/sync/glue/autofill_model_associator.cc19
-rw-r--r--chrome/browser/sync/glue/autofill_model_associator.h3
-rw-r--r--chrome/browser/sync/glue/autofill_profile_model_associator.cc15
-rw-r--r--chrome/browser/sync/glue/autofill_profile_model_associator.h3
-rw-r--r--chrome/browser/sync/glue/bookmark_model_associator.cc19
-rw-r--r--chrome/browser/sync/glue/bookmark_model_associator.h6
-rw-r--r--chrome/browser/sync/glue/extension_sync.cc15
-rw-r--r--chrome/browser/sync/glue/password_model_associator.cc9
-rw-r--r--chrome/browser/sync/glue/password_model_associator.h4
-rw-r--r--chrome/browser/sync/glue/preference_model_associator.cc9
-rw-r--r--chrome/browser/sync/glue/preference_model_associator.h4
-rw-r--r--chrome/browser/sync/glue/session_model_associator.cc24
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.cc14
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.h8
-rw-r--r--chrome/browser/sync/glue/theme_model_associator.cc6
-rw-r--r--chrome/browser/sync/glue/typed_url_model_associator.cc9
-rw-r--r--chrome/browser/sync/glue/typed_url_model_associator.h4
-rw-r--r--chrome/browser/sync/profile_sync_service.cc85
-rw-r--r--chrome/browser/sync/profile_sync_service.h60
-rw-r--r--chrome/browser/sync/profile_sync_service_autofill_unittest.cc30
-rw-r--r--chrome/browser/sync/profile_sync_service_harness.cc8
-rw-r--r--chrome/browser/sync/profile_sync_service_password_unittest.cc6
-rw-r--r--chrome/browser/sync/profile_sync_service_preference_unittest.cc18
-rw-r--r--chrome/browser/sync/profile_sync_service_session_unittest.cc17
-rw-r--r--chrome/browser/sync/profile_sync_service_typed_url_unittest.cc5
-rw-r--r--chrome/browser/sync/profile_sync_service_unittest.cc97
-rw-r--r--chrome/browser/sync/profile_sync_test_util.h80
-rw-r--r--chrome/browser/sync/sync_ui_util.cc10
-rw-r--r--chrome/browser/sync/test_profile_sync_service.cc193
-rw-r--r--chrome/browser/sync/test_profile_sync_service.h194
-rw-r--r--chrome/chrome_tests.gypi1
33 files changed, 686 insertions, 536 deletions
diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.cc b/chrome/browser/sync/abstract_profile_sync_service_test.cc
new file mode 100644
index 0000000..26c9094
--- /dev/null
+++ b/chrome/browser/sync/abstract_profile_sync_service_test.cc
@@ -0,0 +1,120 @@
+// Copyright (c) 20111 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
+
+#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/glue/autofill_model_associator.h"
+#include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
+#include "chrome/browser/sync/glue/password_model_associator.h"
+#include "chrome/browser/sync/glue/preference_model_associator.h"
+#include "chrome/browser/sync/glue/session_model_associator.h"
+#include "chrome/browser/sync/glue/typed_url_model_associator.h"
+#include "chrome/browser/sync/protocol/sync.pb.h"
+#include "chrome/browser/sync/syncable/directory_manager.h"
+#include "chrome/browser/sync/syncable/syncable.h"
+#include "chrome/browser/sync/test_profile_sync_service.h"
+#include "chrome/browser/sync/util/cryptographer.h"
+#include "chrome/test/profile_mock.h"
+#include "chrome/test/sync/engine/test_id_factory.h"
+
+using browser_sync::TestIdFactory;
+using sync_api::UserShare;
+using syncable::BASE_VERSION;
+using syncable::CREATE;
+using syncable::DirectoryManager;
+using syncable::IS_DEL;
+using syncable::IS_DIR;
+using syncable::IS_UNAPPLIED_UPDATE;
+using syncable::IS_UNSYNCED;
+using syncable::ModelType;
+using syncable::MutableEntry;
+using syncable::SERVER_IS_DIR;
+using syncable::SERVER_VERSION;
+using syncable::SPECIFICS;
+using syncable::ScopedDirLookup;
+using syncable::UNIQUE_SERVER_TAG;
+using syncable::UNITTEST;
+using syncable::WriteTransaction;
+
+const std::string ProfileSyncServiceTestHelper::GetTagForType(
+ ModelType model_type) {
+ switch (model_type) {
+ case syncable::AUTOFILL:
+ return browser_sync::kAutofillTag;
+ case syncable::AUTOFILL_PROFILE:
+ return browser_sync::kAutofillProfileTag;
+ case syncable::PREFERENCES:
+ return browser_sync::kPreferencesTag;
+ case syncable::PASSWORDS:
+ return browser_sync::kPasswordTag;
+ case syncable::NIGORI:
+ return browser_sync::kNigoriTag;
+ case syncable::TYPED_URLS:
+ return browser_sync::kTypedUrlTag;
+ case syncable::SESSIONS:
+ return browser_sync::kSessionsTag;
+ case syncable::BOOKMARKS:
+ return "google_chrome_bookmarks";
+ default:
+ NOTREACHED();
+ }
+ return std::string();
+}
+
+bool ProfileSyncServiceTestHelper::CreateRoot(
+ ModelType model_type, UserShare* user_share,
+ TestIdFactory* ids) {
+ DirectoryManager* dir_manager = user_share->dir_manager.get();
+
+ ScopedDirLookup dir(dir_manager, user_share->name);
+ if (!dir.good())
+ return false;
+
+ std::string tag_name = GetTagForType(model_type);
+
+ WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__);
+ MutableEntry node(&wtrans,
+ CREATE,
+ wtrans.root_id(),
+ tag_name);
+ node.Put(UNIQUE_SERVER_TAG, tag_name);
+ node.Put(IS_DIR, true);
+ node.Put(SERVER_IS_DIR, false);
+ node.Put(IS_UNSYNCED, false);
+ node.Put(IS_UNAPPLIED_UPDATE, false);
+ node.Put(SERVER_VERSION, 20);
+ node.Put(BASE_VERSION, 20);
+ node.Put(IS_DEL, false);
+ node.Put(syncable::ID, ids->MakeServer(tag_name));
+ sync_pb::EntitySpecifics specifics;
+ syncable::AddDefaultExtensionValue(model_type, &specifics);
+ node.Put(SPECIFICS, specifics);
+
+ return true;
+}
+
+AbstractProfileSyncServiceTest::AbstractProfileSyncServiceTest()
+ : ui_thread_(BrowserThread::UI, &message_loop_) {}
+
+bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) {
+ return ProfileSyncServiceTestHelper::CreateRoot(
+ model_type,
+ service_->GetUserShare(),
+ service_->id_factory());
+}
+
+CreateRootTask::CreateRootTask(
+ AbstractProfileSyncServiceTest* test, ModelType model_type)
+ : test_(test), model_type_(model_type), success_(false) {
+}
+
+CreateRootTask::~CreateRootTask() {}
+void CreateRootTask::Run() {
+ success_ = test_->CreateRoot(model_type_);
+}
+
+bool CreateRootTask::success() {
+ return success_;
+}
diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.h b/chrome/browser/sync/abstract_profile_sync_service_test.h
index a0f1276..522af54 100644
--- a/chrome/browser/sync/abstract_profile_sync_service_test.h
+++ b/chrome/browser/sync/abstract_profile_sync_service_test.h
@@ -13,115 +13,37 @@
#include "base/task.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/net/gaia/token_service.h"
-#include "chrome/browser/sync/engine/syncapi.h"
-#include "chrome/browser/sync/glue/autofill_model_associator.h"
-#include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
-#include "chrome/browser/sync/glue/password_model_associator.h"
-#include "chrome/browser/sync/glue/preference_model_associator.h"
-#include "chrome/browser/sync/glue/session_model_associator.h"
-#include "chrome/browser/sync/glue/typed_url_model_associator.h"
#include "chrome/browser/sync/profile_sync_factory_mock.h"
-#include "chrome/browser/sync/protocol/sync.pb.h"
-#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/model_type.h"
-#include "chrome/browser/sync/syncable/syncable.h"
-#include "chrome/browser/sync/test_profile_sync_service.h"
-#include "chrome/browser/sync/util/cryptographer.h"
-#include "chrome/test/profile_mock.h"
-#include "chrome/test/sync/engine/test_id_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
-using browser_sync::TestIdFactory;
-using sync_api::UserShare;
-using syncable::BASE_VERSION;
-using syncable::CREATE;
-using syncable::DirectoryManager;
-using syncable::IS_DEL;
-using syncable::IS_DIR;
-using syncable::IS_UNAPPLIED_UPDATE;
-using syncable::IS_UNSYNCED;
-using syncable::ModelType;
-using syncable::MutableEntry;
-using syncable::SERVER_IS_DIR;
-using syncable::SERVER_VERSION;
-using syncable::SPECIFICS;
-using syncable::ScopedDirLookup;
-using syncable::UNIQUE_SERVER_TAG;
-using syncable::UNITTEST;
-using syncable::WriteTransaction;
+class ProfileSyncService;
+class TestProfileSyncService;
+
+namespace browser_sync {
+class TestIdFactory;
+} // namespace browser_sync
+
+namespace sync_api {
+struct UserShare;
+} // namespace sync_api
class ProfileSyncServiceTestHelper {
public:
- static const std::string GetTagForType(ModelType model_type) {
- switch (model_type) {
- case syncable::AUTOFILL:
- return browser_sync::kAutofillTag;
- case syncable::AUTOFILL_PROFILE:
- return browser_sync::kAutofillProfileTag;
- case syncable::PREFERENCES:
- return browser_sync::kPreferencesTag;
- case syncable::PASSWORDS:
- return browser_sync::kPasswordTag;
- case syncable::NIGORI:
- return browser_sync::kNigoriTag;
- case syncable::TYPED_URLS:
- return browser_sync::kTypedUrlTag;
- case syncable::SESSIONS:
- return browser_sync::kSessionsTag;
- case syncable::BOOKMARKS:
- return "google_chrome_bookmarks";
- default:
- NOTREACHED();
- }
- return std::string();
- }
-
- static bool CreateRoot(ModelType model_type, ProfileSyncService* service,
- TestIdFactory* ids) {
- UserShare* user_share = service->backend()->GetUserShareHandle();
- DirectoryManager* dir_manager = user_share->dir_manager.get();
-
- ScopedDirLookup dir(dir_manager, user_share->name);
- if (!dir.good())
- return false;
-
- std::string tag_name = GetTagForType(model_type);
-
- WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__);
- MutableEntry node(&wtrans,
- CREATE,
- wtrans.root_id(),
- tag_name);
- node.Put(UNIQUE_SERVER_TAG, tag_name);
- node.Put(IS_DIR, true);
- node.Put(SERVER_IS_DIR, false);
- node.Put(IS_UNSYNCED, false);
- node.Put(IS_UNAPPLIED_UPDATE, false);
- node.Put(SERVER_VERSION, 20);
- node.Put(BASE_VERSION, 20);
- node.Put(IS_DEL, false);
- node.Put(syncable::ID, ids->MakeServer(tag_name));
- sync_pb::EntitySpecifics specifics;
- syncable::AddDefaultExtensionValue(model_type, &specifics);
- node.Put(SPECIFICS, specifics);
-
- return true;
- }
+ static const std::string GetTagForType(syncable::ModelType model_type);
+
+ static bool CreateRoot(syncable::ModelType model_type,
+ sync_api::UserShare* service,
+ browser_sync::TestIdFactory* ids);
};
class AbstractProfileSyncServiceTest : public testing::Test {
public:
- AbstractProfileSyncServiceTest()
- : ui_thread_(BrowserThread::UI, &message_loop_) {}
+ AbstractProfileSyncServiceTest();
- bool CreateRoot(ModelType model_type) {
- return ProfileSyncServiceTestHelper::CreateRoot(model_type,
- service_.get(),
- service_->id_factory());
- }
+ bool CreateRoot(syncable::ModelType model_type);
protected:
-
MessageLoopForUI message_loop_;
BrowserThread ui_thread_;
ProfileSyncFactoryMock factory_;
@@ -131,20 +53,17 @@ class AbstractProfileSyncServiceTest : public testing::Test {
class CreateRootTask : public Task {
public:
- CreateRootTask(AbstractProfileSyncServiceTest* test, ModelType model_type)
- : test_(test), model_type_(model_type), success_(false) {
- }
+ CreateRootTask(AbstractProfileSyncServiceTest* test,
+ syncable::ModelType model_type);
- virtual ~CreateRootTask() {}
- virtual void Run() {
- success_ = test_->CreateRoot(model_type_);
- }
+ virtual ~CreateRootTask();
+ virtual void Run();
- bool success() { return success_; }
+ bool success();
private:
AbstractProfileSyncServiceTest* test_;
- ModelType model_type_;
+ syncable::ModelType model_type_;
bool success_;
};
diff --git a/chrome/browser/sync/glue/autofill_model_associator.cc b/chrome/browser/sync/glue/autofill_model_associator.cc
index 14b9f2b..60c92d2 100644
--- a/chrome/browser/sync/glue/autofill_model_associator.cc
+++ b/chrome/browser/sync/glue/autofill_model_associator.cc
@@ -151,8 +151,7 @@ bool AutofillModelAssociator::AssociateModels() {
DataBundle bundle;
{
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode autofill_root(&trans);
if (!autofill_root.InitByTagLookup(kAutofillTag)) {
@@ -185,12 +184,12 @@ bool AutofillModelAssociator::AssociateModels() {
return false;
}
- if (sync_service_->backend()->GetAutofillMigrationState() !=
+ if (sync_service_->GetAutofillMigrationState() !=
syncable::MIGRATED) {
syncable::AutofillMigrationDebugInfo debug_info;
debug_info.autofill_entries_added_during_migration =
number_of_entries_created_;
- sync_service_->backend()->SetAutofillMigrationDebugInfo(
+ sync_service_->SetAutofillMigrationDebugInfo(
syncable::AutofillMigrationDebugInfo::ENTRIES_ADDED,
debug_info);
}
@@ -383,8 +382,7 @@ bool AutofillModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
<< "might be running against an out-of-date server.";
return false;
}
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode autofill_node(&trans);
if (!autofill_node.InitByIdLookup(autofill_sync_id)) {
@@ -444,8 +442,7 @@ void AutofillModelAssociator::Disassociate(int64 sync_id) {
bool AutofillModelAssociator::GetSyncIdForTaggedNode(const std::string& tag,
int64* sync_id) {
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode sync_node(&trans);
if (!sync_node.InitByTagLookup(tag.c_str()))
return false;
@@ -533,7 +530,7 @@ bool AutofillModelAssociator::HasNotMigratedYet(
// Now read the current value from the directory.
syncable::AutofillMigrationState autofill_migration_state =
- sync_service()->backend()->GetAutofillMigrationState();
+ sync_service_->GetAutofillMigrationState();
DCHECK_NE(autofill_migration_state, syncable::NOT_DETERMINED);
@@ -555,7 +552,7 @@ bool AutofillModelAssociator::HasNotMigratedYet(
browser_sync::kAutofillProfileTag) ||
autofill_profile_root_node.GetFirstChildId()==
static_cast<int64>(0)) {
- sync_service()->backend()->SetAutofillMigrationState(
+ sync_service_->SetAutofillMigrationState(
syncable::NOT_MIGRATED);
VLOG(1) << "[AUTOFILL MIGRATION]"
@@ -565,7 +562,7 @@ bool AutofillModelAssociator::HasNotMigratedYet(
return true;
}
- sync_service()->backend()->SetAutofillMigrationState(syncable::MIGRATED);
+ sync_service_->SetAutofillMigrationState(syncable::MIGRATED);
VLOG(1) << "[AUTOFILL MIGRATION]"
<< "Current autofill migration state is migrated.";
diff --git a/chrome/browser/sync/glue/autofill_model_associator.h b/chrome/browser/sync/glue/autofill_model_associator.h
index a0eee27..09cfcdc 100644
--- a/chrome/browser/sync/glue/autofill_model_associator.h
+++ b/chrome/browser/sync/glue/autofill_model_associator.h
@@ -99,9 +99,6 @@ class AutofillModelAssociator
// TODO(georgey) : add the same processing for CC info (already in protocol
// buffers).
- // Returns sync service instance.
- ProfileSyncService* sync_service() { return sync_service_; }
-
// Is called to determine if we need to upgrade to the new
// autofillprofile2 data type. If so we need to sync up autofillprofile
// first to the latest available changes on the server and then upgrade
diff --git a/chrome/browser/sync/glue/autofill_profile_model_associator.cc b/chrome/browser/sync/glue/autofill_profile_model_associator.cc
index d6a6792..e6e33d7 100644
--- a/chrome/browser/sync/glue/autofill_profile_model_associator.cc
+++ b/chrome/browser/sync/glue/autofill_profile_model_associator.cc
@@ -105,8 +105,7 @@ bool AutofillProfileModelAssociator::TraverseAndAssociateChromeAutoFillProfiles(
bool AutofillProfileModelAssociator::GetSyncIdForTaggedNode(
const std::string& tag,
int64* sync_id) {
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode sync_node(&trans);
if (!sync_node.InitByTagLookup(tag.c_str()))
return false;
@@ -147,8 +146,7 @@ bool AutofillProfileModelAssociator::AssociateModels() {
{
// The write transaction lock is held inside this block.
// We do all the web db operations outside this block.
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode autofill_root(&trans);
if (!autofill_root.InitByTagLookup(kAutofillProfileTag)) {
@@ -172,15 +170,15 @@ bool AutofillProfileModelAssociator::AssociateModels() {
return false;
}
- if (sync_service_->backend()->GetAutofillMigrationState() !=
+ if (sync_service_->GetAutofillMigrationState() !=
syncable::MIGRATED) {
syncable::AutofillMigrationDebugInfo debug_info;
debug_info.autofill_profile_added_during_migration =
number_of_profiles_created_;
- sync_service_->backend()->SetAutofillMigrationDebugInfo(
+ sync_service_->SetAutofillMigrationDebugInfo(
syncable::AutofillMigrationDebugInfo::PROFILES_ADDED,
debug_info);
- sync_service()->backend()->SetAutofillMigrationState(
+ sync_service_->SetAutofillMigrationState(
syncable::MIGRATED);
}
@@ -208,8 +206,7 @@ bool AutofillProfileModelAssociator::MergeField(FormGroup* f,
bool AutofillProfileModelAssociator::SyncModelHasUserCreatedNodes(
bool *has_nodes) {
CHECK_NE(has_nodes, reinterpret_cast<bool*>(NULL));
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode node(&trans);
diff --git a/chrome/browser/sync/glue/autofill_profile_model_associator.h b/chrome/browser/sync/glue/autofill_profile_model_associator.h
index 3286283..fdc67f1 100644
--- a/chrome/browser/sync/glue/autofill_profile_model_associator.h
+++ b/chrome/browser/sync/glue/autofill_profile_model_associator.h
@@ -93,9 +93,6 @@ class AutofillProfileModelAssociator
// only for completeness.
virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id);
- // Returns sync service instance.
- ProfileSyncService* sync_service() { return sync_service_; }
-
static bool OverwriteProfileWithServerData(
AutoFillProfile* merge_into,
const sync_pb::AutofillProfileSpecifics& specifics);
diff --git a/chrome/browser/sync/glue/bookmark_model_associator.cc b/chrome/browser/sync/glue/bookmark_model_associator.cc
index dba6a21..3a5f1bd 100644
--- a/chrome/browser/sync/glue/bookmark_model_associator.cc
+++ b/chrome/browser/sync/glue/bookmark_model_associator.cc
@@ -237,8 +237,7 @@ bool BookmarkModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
return false;
}
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode bookmark_bar_node(&trans);
if (!bookmark_bar_node.InitByIdLookup(bookmark_bar_sync_id)) {
@@ -288,8 +287,7 @@ bool BookmarkModelAssociator::AssociateTaggedPermanentNode(
bool BookmarkModelAssociator::GetSyncIdForTaggedNode(const std::string& tag,
int64* sync_id) {
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode sync_node(&trans);
if (!sync_node.InitByTagLookup(tag.c_str()))
return false;
@@ -355,8 +353,7 @@ bool BookmarkModelAssociator::BuildAssociations() {
dfs_stack.push(other_bookmarks_sync_id);
dfs_stack.push(bookmark_bar_sync_id);
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
while (!dfs_stack.empty()) {
int64 sync_parent_id = dfs_stack.top();
@@ -419,12 +416,12 @@ bool BookmarkModelAssociator::BuildAssociations() {
}
}
- if (sync_service_->backend()->GetAutofillMigrationState() !=
+ if (sync_service_->GetAutofillMigrationState() !=
syncable::MIGRATED) {
syncable::AutofillMigrationDebugInfo debug_info;
debug_info.bookmarks_added_during_migration =
number_of_new_sync_nodes_created_at_association_;
- sync_service_->backend()->SetAutofillMigrationDebugInfo(
+ sync_service_->SetAutofillMigrationDebugInfo(
syncable::AutofillMigrationDebugInfo::BOOKMARK_ADDED,
debug_info);
}
@@ -451,8 +448,7 @@ void BookmarkModelAssociator::PersistAssociations() {
return;
}
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
DirtyAssociationsSyncIds::iterator iter;
for (iter = dirty_associations_sync_ids_.begin();
iter != dirty_associations_sync_ids_.end();
@@ -506,8 +502,7 @@ bool BookmarkModelAssociator::LoadAssociations() {
dfs_stack.push(other_bookmarks_id);
dfs_stack.push(bookmark_bar_id);
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
// Count total number of nodes in sync model so that we can compare that
// with the total number of nodes in the bookmark model.
diff --git a/chrome/browser/sync/glue/bookmark_model_associator.h b/chrome/browser/sync/glue/bookmark_model_associator.h
index 577979f..035f684 100644
--- a/chrome/browser/sync/glue/bookmark_model_associator.h
+++ b/chrome/browser/sync/glue/bookmark_model_associator.h
@@ -83,15 +83,15 @@ class BookmarkModelAssociator
// thread.
}
- // Returns sync service instance.
- ProfileSyncService* sync_service() { return sync_service_; }
-
protected:
// Stores the id of the node with the given tag in |sync_id|.
// Returns of that node was found successfully.
// Tests override this.
virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id);
+ // Used by TestBookmarkModelAssociator.
+ ProfileSyncService* sync_service() { return sync_service_; }
+
private:
typedef std::map<int64, int64> BookmarkIdToSyncIdMap;
typedef std::map<int64, const BookmarkNode*> SyncIdToBookmarkNodeMap;
diff --git a/chrome/browser/sync/glue/extension_sync.cc b/chrome/browser/sync/glue/extension_sync.cc
index 83068df..3933515 100644
--- a/chrome/browser/sync/glue/extension_sync.cc
+++ b/chrome/browser/sync/glue/extension_sync.cc
@@ -23,8 +23,7 @@ bool RootNodeHasChildren(const char* tag,
bool* has_children) {
CHECK(has_children);
*has_children = false;
- sync_api::ReadTransaction trans(
- sync_service->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service->GetUserShare());
sync_api::ReadNode node(&trans);
if (!node.InitByTagLookup(tag)) {
LOG(ERROR) << "Root node with tag " << tag << " does not exist";
@@ -148,8 +147,7 @@ bool SlurpServerData(
const std::set<std::string>& unsynced_extensions,
ProfileSyncService* sync_service,
ExtensionDataMap* extension_data_map) {
- sync_api::WriteTransaction trans(
- sync_service->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service->GetUserShare());
sync_api::ReadNode root(&trans);
if (!root.InitByTagLookup(root_node_tag)) {
LOG(ERROR) << GetRootNodeDoesNotExistError(root_node_tag);
@@ -324,8 +322,7 @@ void NudgeExtensionUpdater(ExtensionService* extensions_service) {
bool FlushExtensionData(const ExtensionSyncTraits& traits,
const ExtensionDataMap& extension_data_map,
ProfileSyncService* sync_service) {
- sync_api::WriteTransaction trans(
- sync_service->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service->GetUserShare());
sync_api::ReadNode root(&trans);
if (!root.InitByTagLookup(traits.root_node_tag)) {
LOG(ERROR) << GetRootNodeDoesNotExistError(traits.root_node_tag);
@@ -388,8 +385,7 @@ bool UpdateServerData(const ExtensionSyncTraits& traits,
ExtensionData extension_data =
ExtensionData::FromData(ExtensionData::CLIENT, client_data);
- sync_api::WriteTransaction trans(
- sync_service->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service->GetUserShare());
sync_api::ReadNode node(&trans);
if (node.InitByClientTagLookup(traits.model_type, id)) {
@@ -428,8 +424,7 @@ bool UpdateServerData(const ExtensionSyncTraits& traits,
void RemoveServerData(const ExtensionSyncTraits& traits,
const std::string& id,
ProfileSyncService* sync_service) {
- sync_api::WriteTransaction trans(
- sync_service->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service->GetUserShare());
sync_api::WriteNode write_node(&trans);
if (write_node.InitByClientTagLookup(traits.model_type, id)) {
write_node.Remove();
diff --git a/chrome/browser/sync/glue/password_model_associator.cc b/chrome/browser/sync/glue/password_model_associator.cc
index d6708b5..3ed5946 100644
--- a/chrome/browser/sync/glue/password_model_associator.cc
+++ b/chrome/browser/sync/glue/password_model_associator.cc
@@ -45,8 +45,7 @@ bool PasswordModelAssociator::AssociateModels() {
abort_association_pending_ = false;
}
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode password_root(&trans);
if (!password_root.InitByTagLookup(kPasswordTag)) {
LOG(ERROR) << "Server did not create the top-level password node. We "
@@ -176,8 +175,7 @@ bool PasswordModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
<< "might be running against an out-of-date server.";
return false;
}
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode password_node(&trans);
if (!password_node.InitByIdLookup(password_sync_id)) {
@@ -241,8 +239,7 @@ void PasswordModelAssociator::Disassociate(int64 sync_id) {
bool PasswordModelAssociator::GetSyncIdForTaggedNode(const std::string& tag,
int64* sync_id) {
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode sync_node(&trans);
if (!sync_node.InitByTagLookup(tag.c_str()))
return false;
diff --git a/chrome/browser/sync/glue/password_model_associator.h b/chrome/browser/sync/glue/password_model_associator.h
index cfe0dab..449bde7 100644
--- a/chrome/browser/sync/glue/password_model_associator.h
+++ b/chrome/browser/sync/glue/password_model_associator.h
@@ -117,10 +117,6 @@ class PasswordModelAssociator
// user requested an abort.
bool IsAbortPending();
- protected:
- // Returns sync service instance.
- ProfileSyncService* sync_service() { return sync_service_; }
-
private:
typedef std::map<std::string, int64> PasswordToSyncIdMap;
typedef std::map<int64, std::string> SyncIdToPasswordMap;
diff --git a/chrome/browser/sync/glue/preference_model_associator.cc b/chrome/browser/sync/glue/preference_model_associator.cc
index 929b3dd..6dfab23 100644
--- a/chrome/browser/sync/glue/preference_model_associator.cc
+++ b/chrome/browser/sync/glue/preference_model_associator.cc
@@ -116,8 +116,7 @@ bool PreferenceModelAssociator::AssociateModels() {
return false;
}
- sync_api::WriteTransaction trans(
- sync_service()->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode root(&trans);
if (!root.InitByIdLookup(root_id)) {
LOG(ERROR) << "Server did not create the top-level preferences node. We "
@@ -149,8 +148,7 @@ bool PreferenceModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
<< "might be running against an out-of-date server.";
return false;
}
- sync_api::ReadTransaction trans(
- sync_service()->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode preferences_node(&trans);
if (!preferences_node.InitByIdLookup(preferences_sync_id)) {
@@ -204,8 +202,7 @@ void PreferenceModelAssociator::Disassociate(int64 sync_id) {
bool PreferenceModelAssociator::GetSyncIdForTaggedNode(const std::string& tag,
int64* sync_id) {
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode sync_node(&trans);
if (!sync_node.InitByTagLookup(tag.c_str()))
return false;
diff --git a/chrome/browser/sync/glue/preference_model_associator.h b/chrome/browser/sync/glue/preference_model_associator.h
index f50bb2c..5924e72 100644
--- a/chrome/browser/sync/glue/preference_model_associator.h
+++ b/chrome/browser/sync/glue/preference_model_associator.h
@@ -109,10 +109,6 @@ class PreferenceModelAssociator
// has been updated.
void AfterUpdateOperations(const std::string& pref_name);
- protected:
- // Returns sync service instance.
- ProfileSyncService* sync_service() { return sync_service_; }
-
private:
typedef std::map<std::string, int64> PreferenceNameToSyncIdMap;
typedef std::map<int64, std::string> SyncIdToPreferenceNameMap;
diff --git a/chrome/browser/sync/glue/session_model_associator.cc b/chrome/browser/sync/glue/session_model_associator.cc
index 8c8cb6d..21b2d91 100644
--- a/chrome/browser/sync/glue/session_model_associator.cc
+++ b/chrome/browser/sync/glue/session_model_associator.cc
@@ -55,8 +55,7 @@ bool SessionModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
DCHECK(CalledOnValidThread());
CHECK(has_nodes);
*has_nodes = false;
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode root(&trans);
if (!root.InitByTagLookup(kSessionsTag)) {
LOG(ERROR) << kNoSessionsFolderError;
@@ -75,8 +74,7 @@ int64 SessionModelAssociator::GetSyncIdFromChromeId(const size_t& id) {
int64 SessionModelAssociator::GetSyncIdFromSessionTag(const std::string& tag) {
DCHECK(CalledOnValidThread());
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode node(&trans);
if (!node.InitByClientTagLookup(syncable::SESSIONS, tag))
return sync_api::kInvalidId;
@@ -134,8 +132,7 @@ void SessionModelAssociator::ReassociateWindows(bool reload_tabs) {
}
}
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
sync_api::WriteNode header_node(&trans);
if (!header_node.InitByIdLookup(local_session_syncid_)) {
LOG(ERROR) << "Failed to load local session header node.";
@@ -210,8 +207,7 @@ void SessionModelAssociator::Associate(const TabContents* tab, int64 sync_id) {
TabLinks t(sync_id, tab);
tab_map_[session_id] = t;
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
WriteTabContentsToSyncModel(*tab, sync_id, &trans);
}
@@ -363,8 +359,7 @@ bool SessionModelAssociator::AssociateModels() {
// Read any available foreign sessions and load any session data we may have.
// If we don't have any local session data in the db, create a header node.
{
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode root(&trans);
if (!root.InitByTagLookup(kSessionsTag)) {
@@ -706,8 +701,7 @@ int64 SessionModelAssociator::TabNodePool::GetFreeTabNode() {
DCHECK_GT(machine_tag_.length(), 0U);
if (tab_pool_fp_ == -1) {
// Tab pool has no free nodes, allocate new one.
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode root(&trans);
if (!root.InitByTagLookup(kSessionsTag)) {
LOG(ERROR) << kNoSessionsFolderError;
@@ -838,8 +832,7 @@ void SessionModelAssociator::OnGotSession(
sync_pb::SessionHeader* header_s = specifics.mutable_header();
PopulateSessionSpecificsHeader(*windows, header_s);
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode root(&trans);
if (!root.InitByTagLookup(kSessionsTag)) {
LOG(ERROR) << kNoSessionsFolderError;
@@ -913,8 +906,7 @@ bool SessionModelAssociator::SyncLocalWindowToSyncModel(
return false;
}
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
if (!WriteSessionTabToSyncModel(*tab, id, &trans)) {
return false;
}
diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc
index 3e600e1..6ff01af 100644
--- a/chrome/browser/sync/glue/sync_backend_host.cc
+++ b/chrome/browser/sync/glue/sync_backend_host.cc
@@ -51,12 +51,12 @@ namespace browser_sync {
using sessions::SyncSessionSnapshot;
using sync_api::SyncCredentials;
-SyncBackendHost::SyncBackendHost(SyncFrontend* frontend, Profile* profile)
+SyncBackendHost::SyncBackendHost(Profile* profile)
: core_(new Core(ALLOW_THIS_IN_INITIALIZER_LIST(this))),
core_thread_("Chrome_SyncCoreThread"),
frontend_loop_(MessageLoop::current()),
profile_(profile),
- frontend_(frontend),
+ frontend_(NULL),
sync_data_folder_path_(
profile_->GetPath().Append(kSyncDataFolderName)),
last_auth_error_(AuthError::None()),
@@ -78,6 +78,7 @@ SyncBackendHost::~SyncBackendHost() {
}
void SyncBackendHost::Initialize(
+ SyncFrontend* frontend,
const GURL& sync_service_url,
const syncable::ModelTypeSet& types,
URLRequestContextGetter* baseline_context_getter,
@@ -87,6 +88,9 @@ void SyncBackendHost::Initialize(
if (!core_thread_.Start())
return;
+ frontend_ = frontend;
+ DCHECK(frontend);
+
// Create a worker for the UI thread and route bookmark changes to it.
// TODO(tim): Pull this into a method to reuse. For now we don't even
// need to lock because we init before the syncapi exists and we tear down
@@ -172,7 +176,7 @@ bool SyncBackendHost::IsUsingExplicitPassphrase() {
bool SyncBackendHost::IsCryptographerReady() const {
return syncapi_initialized_ &&
- GetUserShareHandle()->dir_manager->cryptographer()->is_ready();
+ GetUserShare()->dir_manager->cryptographer()->is_ready();
}
sync_api::HttpPostProviderFactory* SyncBackendHost::MakeHttpBridgeFactory(
@@ -284,7 +288,7 @@ void SyncBackendHost::SetAutofillMigrationDebugInfo(
void SyncBackendHost::ConfigureAutofillMigration() {
if (GetAutofillMigrationState() == syncable::NOT_DETERMINED) {
- sync_api::ReadTransaction trans(GetUserShareHandle());
+ sync_api::ReadTransaction trans(GetUserShare());
sync_api::ReadNode autofil_root_node(&trans);
// Check for the presence of autofill node.
@@ -487,7 +491,7 @@ void SyncBackendHost::Core::NotifyUpdatedToken(const std::string& token) {
Details<const TokenAvailableDetails>(&details));
}
-SyncBackendHost::UserShareHandle SyncBackendHost::GetUserShareHandle() const {
+sync_api::UserShare* SyncBackendHost::GetUserShare() const {
DCHECK(syncapi_initialized_);
return core_->syncapi()->GetUserShare();
}
diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h
index 964f7a5..14ffebb 100644
--- a/chrome/browser/sync/glue/sync_backend_host.h
+++ b/chrome/browser/sync/glue/sync_backend_host.h
@@ -98,7 +98,6 @@ class SyncFrontend {
// that the SyncFrontend is only accessed on the UI loop.
class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar {
public:
- typedef sync_api::UserShare* UserShareHandle;
typedef sync_api::SyncManager::Status::Summary StatusSummary;
typedef sync_api::SyncManager::Status Status;
typedef std::map<ModelSafeGroup,
@@ -107,7 +106,7 @@ class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar {
// Create a SyncBackendHost with a reference to the |frontend| that it serves
// and communicates to via the SyncFrontend interface (on the same thread
// it used to call the constructor).
- SyncBackendHost(SyncFrontend* frontend, Profile* profile);
+ explicit SyncBackendHost(Profile* profile);
// For testing.
// TODO(skrul): Extract an interface so this is not needed.
SyncBackendHost();
@@ -117,7 +116,8 @@ class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar {
// As a fallback when no cached auth information is available, try to
// bootstrap authentication using |lsid|, if it isn't empty.
// Optionally delete the Sync Data folder (if it's corrupt).
- void Initialize(const GURL& service_url,
+ void Initialize(SyncFrontend* frontend,
+ const GURL& service_url,
const syncable::ModelTypeSet& types,
URLRequestContextGetter* baseline_context_getter,
const sync_api::SyncCredentials& credentials,
@@ -193,7 +193,7 @@ class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar {
// Called on |frontend_loop_| to obtain a handle to the UserShare needed
// for creating transactions.
- UserShareHandle GetUserShareHandle() const;
+ sync_api::UserShare* GetUserShare() const;
// Called from any thread to obtain current status information in detailed or
// summarized form.
diff --git a/chrome/browser/sync/glue/theme_model_associator.cc b/chrome/browser/sync/glue/theme_model_associator.cc
index 2dd02c2..6b51af2 100644
--- a/chrome/browser/sync/glue/theme_model_associator.cc
+++ b/chrome/browser/sync/glue/theme_model_associator.cc
@@ -36,8 +36,7 @@ ThemeModelAssociator::ThemeModelAssociator(
ThemeModelAssociator::~ThemeModelAssociator() {}
bool ThemeModelAssociator::AssociateModels() {
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode root(&trans);
if (!root.InitByTagLookup(kThemesTag)) {
LOG(ERROR) << kNoThemesFolderError;
@@ -83,8 +82,7 @@ bool ThemeModelAssociator::DisassociateModels() {
bool ThemeModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
DCHECK(has_nodes);
*has_nodes = false;
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode root(&trans);
if (!root.InitByTagLookup(kThemesTag)) {
LOG(ERROR) << kNoThemesFolderError;
diff --git a/chrome/browser/sync/glue/typed_url_model_associator.cc b/chrome/browser/sync/glue/typed_url_model_associator.cc
index 9c88fc0..02144fc 100644
--- a/chrome/browser/sync/glue/typed_url_model_associator.cc
+++ b/chrome/browser/sync/glue/typed_url_model_associator.cc
@@ -58,8 +58,7 @@ bool TypedUrlModelAssociator::AssociateModels() {
TypedUrlUpdateVector updated_urls;
{
- sync_api::WriteTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode typed_url_root(&trans);
if (!typed_url_root.InitByTagLookup(kTypedUrlTag)) {
LOG(ERROR) << "Server did not create the top-level typed_url node. We "
@@ -216,8 +215,7 @@ bool TypedUrlModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
<< "might be running against an out-of-date server.";
return false;
}
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode typed_url_node(&trans);
if (!typed_url_node.InitByIdLookup(typed_url_sync_id)) {
@@ -274,8 +272,7 @@ void TypedUrlModelAssociator::Disassociate(int64 sync_id) {
bool TypedUrlModelAssociator::GetSyncIdForTaggedNode(const std::string& tag,
int64* sync_id) {
- sync_api::ReadTransaction trans(
- sync_service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode sync_node(&trans);
if (!sync_node.InitByTagLookup(tag.c_str()))
return false;
diff --git a/chrome/browser/sync/glue/typed_url_model_associator.h b/chrome/browser/sync/glue/typed_url_model_associator.h
index 6388de4..0ab3533 100644
--- a/chrome/browser/sync/glue/typed_url_model_associator.h
+++ b/chrome/browser/sync/glue/typed_url_model_associator.h
@@ -124,10 +124,6 @@ class TypedUrlModelAssociator
std::vector<base::Time>* new_visits,
history::VisitVector* removed_visits);
- protected:
- // Returns sync service instance.
- ProfileSyncService* sync_service() { return sync_service_; }
-
private:
typedef std::map<std::string, int64> TypedUrlToSyncIdMap;
typedef std::map<int64, std::string> SyncIdToTypedUrlMap;
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index 4374120..6984997 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -418,7 +418,8 @@ void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) {
SyncCredentials credentials = GetCredentials();
- backend_->Initialize(sync_service_url_,
+ backend_->Initialize(this,
+ sync_service_url_,
types,
profile_->GetRequestContext(),
credentials,
@@ -427,7 +428,7 @@ void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) {
}
void ProfileSyncService::CreateBackend() {
- backend_.reset(new SyncBackendHost(this, profile_));
+ backend_.reset(new SyncBackendHost(profile_));
}
void ProfileSyncService::StartUp() {
@@ -1008,6 +1009,12 @@ bool ProfileSyncService::IsCryptographerReady() const {
return backend_.get() && backend_->IsCryptographerReady();
}
+SyncBackendHost* ProfileSyncService::GetBackendForTest() {
+ // We don't check |backend_initialized_|; we assume the test class
+ // knows what it's doing.
+ return backend_.get();
+}
+
void ProfileSyncService::ConfigureDataTypeManager() {
if (!data_type_manager_.get()) {
data_type_manager_.reset(
@@ -1026,6 +1033,78 @@ void ProfileSyncService::ConfigureDataTypeManager() {
data_type_manager_->Configure(types);
}
+sync_api::UserShare* ProfileSyncService::GetUserShare() const {
+ if (backend_.get() && backend_initialized_) {
+ return backend_->GetUserShare();
+ }
+ NOTREACHED();
+ return NULL;
+}
+
+const browser_sync::sessions::SyncSessionSnapshot*
+ ProfileSyncService::GetLastSessionSnapshot() const {
+ if (backend_.get() && backend_initialized_) {
+ return backend_->GetLastSessionSnapshot();
+ }
+ NOTREACHED();
+ return NULL;
+}
+
+bool ProfileSyncService::HasUnsyncedItems() const {
+ if (backend_.get() && backend_initialized_) {
+ return backend_->HasUnsyncedItems();
+ }
+ NOTREACHED();
+ return false;
+}
+
+void ProfileSyncService::GetModelSafeRoutingInfo(
+ browser_sync::ModelSafeRoutingInfo* out) {
+ if (backend_.get() && backend_initialized_) {
+ backend_->GetModelSafeRoutingInfo(out);
+ } else {
+ NOTREACHED();
+ }
+}
+
+syncable::AutofillMigrationState
+ ProfileSyncService::GetAutofillMigrationState() {
+ if (backend_.get() && backend_initialized_) {
+ return backend_->GetAutofillMigrationState();
+ }
+ NOTREACHED();
+ return syncable::NOT_DETERMINED;
+}
+
+void ProfileSyncService::SetAutofillMigrationState(
+ syncable::AutofillMigrationState state) {
+ if (backend_.get() && backend_initialized_) {
+ backend_->SetAutofillMigrationState(state);
+ } else {
+ NOTREACHED();
+ }
+}
+
+syncable::AutofillMigrationDebugInfo
+ ProfileSyncService::GetAutofillMigrationDebugInfo() {
+ if (backend_.get() && backend_initialized_) {
+ return backend_->GetAutofillMigrationDebugInfo();
+ }
+ NOTREACHED();
+ syncable::AutofillMigrationDebugInfo debug_info = { 0 };
+ return debug_info;
+}
+
+void ProfileSyncService::SetAutofillMigrationDebugInfo(
+ syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set,
+ const syncable::AutofillMigrationDebugInfo& info) {
+ if (backend_.get() && backend_initialized_) {
+ backend_->SetAutofillMigrationDebugInfo(property_to_set, info);
+ } else {
+ NOTREACHED();
+ }
+}
+
void ProfileSyncService::ActivateDataType(
DataTypeController* data_type_controller,
ChangeProcessor* change_processor) {
@@ -1034,7 +1113,7 @@ void ProfileSyncService::ActivateDataType(
return;
}
DCHECK(backend_initialized_);
- change_processor->Start(profile(), backend_->GetUserShareHandle());
+ change_processor->Start(profile(), backend_->GetUserShare());
backend_->ActivateDataType(data_type_controller, change_processor);
}
diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h
index dd91656..5a80811 100644
--- a/chrome/browser/sync/profile_sync_service.h
+++ b/chrome/browser/sync/profile_sync_service.h
@@ -323,7 +323,52 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
const tracked_objects::Location& from_here,
const std::string& message);
- browser_sync::SyncBackendHost* backend() { return backend_.get(); }
+ // The functions below (until ActivateDataType()) should only be
+ // called if sync_initialized() is true.
+
+ // TODO(akalin): This is called mostly by ModelAssociators and
+ // tests. Figure out how to pass the handle to the ModelAssociators
+ // directly, figure out how to expose this to tests, and remove this
+ // function.
+ sync_api::UserShare* GetUserShare() const;
+
+ // TODO(akalin): These two functions are used only by
+ // ProfileSyncServiceHarness. Figure out a different way to expose
+ // this info to that class, and remove these functions.
+
+ const browser_sync::sessions::SyncSessionSnapshot*
+ GetLastSessionSnapshot() const;
+
+ // Returns whether or not the underlying sync engine has made any
+ // local changes to items that have not yet been synced with the
+ // server.
+ bool HasUnsyncedItems() const;
+
+ // Get the current routing information for all enabled model types.
+ // If a model type is not enabled (that is, if the syncer should not
+ // be trying to sync it), it is not in this map.
+ //
+ // TODO(akalin): This function is used by
+ // sync_ui_util::ConstructAboutInformation() and by some test
+ // classes. Figure out a different way to expose this info and
+ // remove this function.
+ void GetModelSafeRoutingInfo(browser_sync::ModelSafeRoutingInfo* out);
+
+ // TODO(akalin): Remove these four functions once we're done with
+ // autofill migration.
+
+ syncable::AutofillMigrationState
+ GetAutofillMigrationState();
+
+ void SetAutofillMigrationState(
+ syncable::AutofillMigrationState state);
+
+ syncable::AutofillMigrationDebugInfo
+ GetAutofillMigrationDebugInfo();
+
+ void SetAutofillMigrationDebugInfo(
+ syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set,
+ const syncable::AutofillMigrationDebugInfo& info);
virtual void ActivateDataType(
browser_sync::DataTypeController* data_type_controller,
@@ -395,6 +440,9 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
// so we don't need this hack anymore.
ProfileSyncService();
+ // Used by test classes that derive from ProfileSyncService.
+ virtual browser_sync::SyncBackendHost* GetBackendForTest();
+
// Helper to install and configure a data type manager.
void ConfigureDataTypeManager();
@@ -413,6 +461,10 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
// Test need to override this to create backends that allow setting up
// initial conditions, such as populating sync nodes.
+ //
+ // TODO(akalin): Figure out a better way to do this. Ideally, we'd
+ // construct the backend outside this class and pass it in to the
+ // contructor or Initialize().
virtual void CreateBackend();
const browser_sync::DataTypeController::TypeMap& data_type_controllers() {
@@ -450,13 +502,9 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
bool passphrase_migration_in_progress_;
private:
- friend class ProfileSyncServiceTest;
friend class ProfileSyncServicePasswordTest;
- friend class ProfileSyncServicePreferenceTest;
- friend class ProfileSyncServiceSessionTest;
+ friend class TestProfileSyncService;
FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState);
- FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest,
- UnrecoverableErrorSuspendsService);
// If |delete_sync_data_folder| is true, then this method will delete all
// previous "Sync Data" folders. (useful if the folder is partial/corrupt).
diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
index b4e8162..6f64059 100644
--- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
@@ -35,6 +35,7 @@
#include "chrome/browser/sync/profile_sync_test_util.h"
#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
#include "chrome/browser/sync/syncable/autofill_migration.h"
+#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/syncable/model_type.h"
#include "chrome/browser/sync/test_profile_sync_service.h"
@@ -64,12 +65,17 @@ using browser_sync::SyncerUtil;
using browser_sync::UnrecoverableErrorHandler;
using syncable::CREATE_NEW_UPDATE_ITEM;
using syncable::AUTOFILL;
+using syncable::BASE_VERSION;
+using syncable::CREATE;
using syncable::DirectoryChangeEvent;
using syncable::GET_BY_SERVER_TAG;
using syncable::INVALID;
+using syncable::MutableEntry;
+using syncable::OriginalEntries;
using syncable::SERVER_PARENT_ID;
using syncable::SERVER_SPECIFICS;
-using syncable::OriginalEntries;
+using syncable::SPECIFICS;
+using syncable::UNITTEST;
using syncable::WriterTag;
using syncable::WriteTransaction;
using testing::_;
@@ -314,8 +320,7 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest {
}
bool AddAutofillSyncNode(const AutofillEntry& entry) {
- sync_api::WriteTransaction trans(
- service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
sync_api::ReadNode autofill_root(&trans);
if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag))
return false;
@@ -331,8 +336,7 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest {
}
bool AddAutofillSyncNode(const AutoFillProfile& profile) {
- sync_api::WriteTransaction trans(
- service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
sync_api::ReadNode autofill_root(&trans);
if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag))
return false;
@@ -347,7 +351,7 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest {
bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries,
std::vector<AutoFillProfile>* profiles) {
- sync_api::ReadTransaction trans(service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(service_->GetUserShare());
sync_api::ReadNode autofill_root(&trans);
if (!autofill_root.InitByTagLookup(browser_sync::kAutofillTag))
return false;
@@ -384,7 +388,7 @@ class ProfileSyncServiceAutofillTest : public AbstractProfileSyncServiceTest {
bool GetAutofillProfilesFromSyncDBUnderProfileNode(
std::vector<AutoFillProfile>* profiles) {
- sync_api::ReadTransaction trans(service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(service_->GetUserShare());
sync_api::ReadNode autofill_root(&trans);
if (!autofill_root.InitByTagLookup(browser_sync::kAutofillProfileTag))
return false;
@@ -474,7 +478,7 @@ class AddAutofillTask : public Task {
static const bool kLoggingInfo = true;
class WriteTransactionTest: public WriteTransaction {
public:
- WriteTransactionTest(const ScopedDirLookup& directory,
+ WriteTransactionTest(const syncable::ScopedDirLookup& directory,
WriterTag writer, const char* source_file,
int line,
scoped_ptr<WaitableEvent> *wait_for_syncapi)
@@ -510,9 +514,9 @@ class FakeServerUpdater: public base::RefCountedThreadSafe<FakeServerUpdater> {
// This gets called in a modelsafeworker thread.
ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
- UserShare* user_share = service_->backend()->GetUserShareHandle();
- DirectoryManager* dir_manager = user_share->dir_manager.get();
- ScopedDirLookup dir(dir_manager, user_share->name);
+ sync_api::UserShare* user_share = service_->GetUserShare();
+ syncable::DirectoryManager* dir_manager = user_share->dir_manager.get();
+ syncable::ScopedDirLookup dir(dir_manager, user_share->name);
ASSERT_TRUE(dir.good());
// Create autofill protobuf
@@ -563,7 +567,7 @@ class FakeServerUpdater: public base::RefCountedThreadSafe<FakeServerUpdater> {
scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater *)this,
&FakeServerUpdater::Update));
std::vector<browser_sync::ModelSafeWorker*> workers;
- service_->backend()->GetWorkers(&workers);
+ service_->GetBackendForTest()->GetWorkers(&workers);
ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB));
if (!BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
@@ -578,7 +582,7 @@ class FakeServerUpdater: public base::RefCountedThreadSafe<FakeServerUpdater> {
scoped_ptr<Callback0::Type> c(NewCallback((FakeServerUpdater *)this,
&FakeServerUpdater::Update));
std::vector<browser_sync::ModelSafeWorker*> workers;
- service_->backend()->GetWorkers(&workers);
+ service_->GetBackendForTest()->GetWorkers(&workers);
ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB));
is_finished_.Reset();
diff --git a/chrome/browser/sync/profile_sync_service_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc
index 6f2cb90..4243c4c 100644
--- a/chrome/browser/sync/profile_sync_service_harness.cc
+++ b/chrome/browser/sync/profile_sync_service_harness.cc
@@ -447,7 +447,7 @@ bool ProfileSyncServiceHarness::IsSynced() {
snap->num_conflicting_updates == 0 && // We can decrypt everything.
ServiceIsPushingChanges() &&
GetStatus().notifications_enabled &&
- !service()->backend()->HasUnsyncedItems() &&
+ !service()->HasUnsyncedItems() &&
!snap->has_more_to_sync &&
snap->unsynced_count == 0);
}
@@ -480,8 +480,8 @@ bool ProfileSyncServiceHarness::MatchesOtherClient(
const SyncSessionSnapshot*
ProfileSyncServiceHarness::GetLastSessionSnapshot() const {
DCHECK(service_ != NULL) << "Sync service has not yet been set up.";
- if (service_->backend()) {
- return service_->backend()->GetLastSessionSnapshot();
+ if (service_->sync_initialized()) {
+ return service_->GetLastSessionSnapshot();
}
return NULL;
}
@@ -582,7 +582,7 @@ void ProfileSyncServiceHarness::LogClientInfo(std::string message) {
<< ", unsynced_count: " << snap->unsynced_count
<< ", num_conflicting_updates: " << snap->num_conflicting_updates
<< ", has_unsynced_items: "
- << service()->backend()->HasUnsyncedItems()
+ << service()->HasUnsyncedItems()
<< ", observed_passphrase_required: "
<< service()->observed_passphrase_required()
<< ", notifications_enabled: "
diff --git a/chrome/browser/sync/profile_sync_service_password_unittest.cc b/chrome/browser/sync/profile_sync_service_password_unittest.cc
index c0e0803..eca4b95 100644
--- a/chrome/browser/sync/profile_sync_service_password_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_password_unittest.cc
@@ -10,6 +10,7 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/password_manager/password_store.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/password_change_processor.h"
@@ -212,8 +213,7 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest {
}
void AddPasswordSyncNode(const PasswordForm& entry) {
- sync_api::WriteTransaction trans(
- service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
sync_api::ReadNode password_root(&trans);
ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag));
@@ -226,7 +226,7 @@ class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest {
}
void GetPasswordEntriesFromSyncDB(std::vector<PasswordForm>* entries) {
- sync_api::ReadTransaction trans(service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(service_->GetUserShare());
sync_api::ReadNode password_root(&trans);
ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag));
diff --git a/chrome/browser/sync/profile_sync_service_preference_unittest.cc b/chrome/browser/sync/profile_sync_service_preference_unittest.cc
index e1f3299..8c44e17a 100644
--- a/chrome/browser/sync/profile_sync_service_preference_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_preference_unittest.cc
@@ -95,8 +95,6 @@ class ProfileSyncServicePreferenceTest
return true;
}
- SyncBackendHost* backend() { return service_->backend_.get(); }
-
const Value& GetPreferenceValue(const std::string& name) {
const PrefService::Preference* preference =
prefs_->FindPreference(name.c_str());
@@ -105,7 +103,7 @@ class ProfileSyncServicePreferenceTest
// Caller gets ownership of the returned value.
const Value* GetSyncedValue(const std::string& name) {
- sync_api::ReadTransaction trans(service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(service_->GetUserShare());
sync_api::ReadNode node(&trans);
int64 node_id = model_associator_->GetSyncIdFromChromeId(name);
@@ -130,7 +128,7 @@ class ProfileSyncServicePreferenceTest
}
int64 SetSyncedValue(const std::string& name, const Value& value) {
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
sync_api::ReadNode root(&trans);
if (!root.InitByTagLookup(browser_sync::kPreferencesTag))
return sync_api::kInvalidId;
@@ -219,7 +217,7 @@ TEST_F(ProfileSyncServicePreferenceTest, WritePreferenceToNode) {
const PrefService::Preference* pref =
prefs_->FindPreference(prefs::kHomePage);
- sync_api::WriteTransaction trans(service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
sync_api::WriteNode node(&trans);
EXPECT_TRUE(node.InitByClientTagLookup(syncable::PREFERENCES,
prefs::kHomePage));
@@ -362,7 +360,7 @@ TEST_F(ProfileSyncServicePreferenceTest, UpdatedSyncNodeActionUpdate) {
record->action = SyncManager::ChangeRecord::ACTION_UPDATE;
record->id = node_id;
{
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
}
@@ -382,7 +380,7 @@ TEST_F(ProfileSyncServicePreferenceTest, UpdatedSyncNodeActionAdd) {
record->action = SyncManager::ChangeRecord::ACTION_ADD;
record->id = node_id;
{
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
}
@@ -404,7 +402,7 @@ TEST_F(ProfileSyncServicePreferenceTest, UpdatedSyncNodeUnknownPreference) {
record->action = SyncManager::ChangeRecord::ACTION_ADD;
record->id = node_id;
{
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
}
@@ -437,7 +435,7 @@ TEST_F(ProfileSyncServicePreferenceTest, ManagedPreferences) {
record->action = SyncManager::ChangeRecord::ACTION_UPDATE;
record->id = node_id;
{
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
}
EXPECT_TRUE(managed_value->Equals(
@@ -476,7 +474,7 @@ TEST_F(ProfileSyncServicePreferenceTest, DynamicManagedPreferences) {
record->action = SyncManager::ChangeRecord::ACTION_ADD;
record->id = node_id;
{
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
}
diff --git a/chrome/browser/sync/profile_sync_service_session_unittest.cc b/chrome/browser/sync/profile_sync_service_session_unittest.cc
index 3023d6b..fef7e14 100644
--- a/chrome/browser/sync/profile_sync_service_session_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_session_unittest.cc
@@ -123,8 +123,6 @@ class ProfileSyncServiceSessionTest
return true;
}
- SyncBackendHost* backend() { return sync_service_->backend(); }
-
// Path used in testing.
ScopedTempDir temp_dir_;
SessionServiceTestHelper helper_;
@@ -146,8 +144,10 @@ class CreateRootTask : public Task {
virtual ~CreateRootTask() {}
virtual void Run() {
- success_ = ProfileSyncServiceTestHelper::CreateRoot(syncable::SESSIONS,
- test_->sync_service(), test_->ids());
+ success_ = ProfileSyncServiceTestHelper::CreateRoot(
+ syncable::SESSIONS,
+ test_->sync_service()->GetUserShare(),
+ test_->ids());
}
bool success() { return success_; }
@@ -173,8 +173,7 @@ TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) {
ASSERT_NE(sync_api::kInvalidId, sync_id);
// Check that we can get the correct session specifics back from the node.
- sync_api::ReadTransaction trans(sync_service_->
- backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(sync_service_->GetUserShare());
sync_api::ReadNode node(&trans);
ASSERT_TRUE(node.InitByClientTagLookup(syncable::SESSIONS,
machine_tag));
@@ -320,7 +319,7 @@ TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionUpdate) {
record->id = node_id;
ASSERT_FALSE(notified_of_update_);
{
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
}
ASSERT_TRUE(notified_of_update_);
@@ -339,7 +338,7 @@ TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionAdd) {
record->id = node_id;
ASSERT_FALSE(notified_of_update_);
{
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
}
ASSERT_TRUE(notified_of_update_);
@@ -358,7 +357,7 @@ TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionDelete) {
record->id = node_id;
ASSERT_FALSE(notified_of_update_);
{
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(sync_service_->GetUserShare());
change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
}
ASSERT_TRUE(notified_of_update_);
diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
index 2ee601f..cdecc00 100644
--- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
@@ -192,8 +192,7 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
void AddTypedUrlSyncNode(const history::URLRow& url,
const history::VisitVector& visits) {
- sync_api::WriteTransaction trans(
- service_->backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
sync_api::ReadNode typed_url_root(&trans);
ASSERT_TRUE(typed_url_root.InitByTagLookup(browser_sync::kTypedUrlTag));
@@ -206,7 +205,7 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
}
void GetTypedUrlsFromSyncDB(std::vector<history::URLRow>* urls) {
- sync_api::ReadTransaction trans(service_->backend()->GetUserShareHandle());
+ sync_api::ReadTransaction trans(service_->GetUserShare());
sync_api::ReadNode typed_url_root(&trans);
if (!typed_url_root.InitByTagLookup(browser_sync::kTypedUrlTag))
return;
diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc
index 5c85c1d..15b93aa 100644
--- a/chrome/browser/sync/profile_sync_service_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_unittest.cc
@@ -52,18 +52,85 @@ using testing::Return;
using testing::WithArg;
using testing::Invoke;
+// TODO(akalin): Bookmark-specific tests should be moved into their
+// own file.
class TestBookmarkModelAssociator : public BookmarkModelAssociator {
public:
- TestBookmarkModelAssociator(TestProfileSyncService* service,
+ TestBookmarkModelAssociator(
+ TestProfileSyncService* service,
UnrecoverableErrorHandler* persist_ids_error_handler)
: BookmarkModelAssociator(service, persist_ids_error_handler),
- helper_(new TestModelAssociatorHelper(service->id_factory())) {
- }
+ id_factory_(service->id_factory()) {}
+
+ // TODO(akalin): This logic lazily creates any tagged node that is
+ // requested. A better way would be to have utility functions to
+ // create sync nodes from some bookmark structure and to use that.
virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) {
- return helper_->GetSyncIdForTaggedNode(this, tag, sync_id);
+ std::wstring tag_wide;
+ if (!UTF8ToWide(tag.c_str(), tag.length(), &tag_wide)) {
+ NOTREACHED() << "Unable to convert UTF8 to wide for string: " << tag;
+ return false;
+ }
+
+ bool root_exists = false;
+ syncable::ModelType type = model_type();
+ {
+ sync_api::WriteTransaction trans(sync_service()->GetUserShare());
+ sync_api::ReadNode uber_root(&trans);
+ uber_root.InitByRootLookup();
+
+ sync_api::ReadNode root(&trans);
+ root_exists = root.InitByTagLookup(
+ ProfileSyncServiceTestHelper::GetTagForType(type));
+ }
+
+ if (!root_exists) {
+ bool created = ProfileSyncServiceTestHelper::CreateRoot(
+ type,
+ sync_service()->GetUserShare(),
+ id_factory_);
+ if (!created)
+ return false;
+ }
+
+ sync_api::WriteTransaction trans(sync_service()->GetUserShare());
+ sync_api::ReadNode root(&trans);
+ EXPECT_TRUE(root.InitByTagLookup(
+ ProfileSyncServiceTestHelper::GetTagForType(type)));
+
+ // First, try to find a node with the title among the root's children.
+ // This will be the case if we are testing model persistence, and
+ // are reloading a sync repository created earlier in the test.
+ int64 last_child_id = sync_api::kInvalidId;
+ for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) {
+ sync_api::ReadNode child(&trans);
+ child.InitByIdLookup(id);
+ last_child_id = id;
+ if (tag_wide == child.GetTitle()) {
+ *sync_id = id;
+ return true;
+ }
+ id = child.GetSuccessorId();
+ }
+
+ sync_api::ReadNode predecessor_node(&trans);
+ sync_api::ReadNode* predecessor = NULL;
+ if (last_child_id != sync_api::kInvalidId) {
+ predecessor_node.InitByIdLookup(last_child_id);
+ predecessor = &predecessor_node;
+ }
+ sync_api::WriteNode node(&trans);
+ // Create new fake tagged nodes at the end of the ordering.
+ node.InitByCreation(type, root, predecessor);
+ node.SetIsFolder(true);
+ node.SetTitle(tag_wide);
+ node.SetExternalId(0);
+ *sync_id = node.GetId();
+ return true;
}
+
private:
- scoped_ptr<TestModelAssociatorHelper> helper_;
+ browser_sync::TestIdFactory* id_factory_;
};
// FakeServerChange constructs a list of sync_api::ChangeRecords while modifying
@@ -342,7 +409,7 @@ class ProfileSyncServiceTest : public testing::Test {
}
void ExpectSyncerNodeMatching(const BookmarkNode* bnode) {
- sync_api::ReadTransaction trans(service_->backend_->GetUserShareHandle());
+ sync_api::ReadTransaction trans(service_->GetUserShare());
ExpectSyncerNodeMatching(&trans, bnode);
}
@@ -420,7 +487,7 @@ class ProfileSyncServiceTest : public testing::Test {
}
void ExpectModelMatch() {
- sync_api::ReadTransaction trans(service_->backend_->GetUserShareHandle());
+ sync_api::ReadTransaction trans(service_->GetUserShare());
ExpectModelMatch(&trans);
}
@@ -433,8 +500,6 @@ class ProfileSyncServiceTest : public testing::Test {
model_->GetBookmarkBarNode()->id());
}
- SyncBackendHost* backend() { return service_->backend_.get(); }
-
// This serves as the "UI loop" on which the ProfileSyncService lives and
// operates. It is needed because the SyncBackend can post tasks back to
// the service, meaning it can't be null. It doesn't have to be running,
@@ -548,7 +613,7 @@ TEST_F(ProfileSyncServiceTest, ServerChangeProcessing) {
LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
StartSyncService();
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
FakeServerChange adds(&trans);
int64 f1 = adds.AddFolder(L"Server Folder B", bookmark_bar_id(), 0);
@@ -637,7 +702,7 @@ TEST_F(ProfileSyncServiceTest, ServerChangeRequiringFosterParent) {
LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
StartSyncService();
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
// Stress the immediate children of other_node because that's where
// ApplyModelChanges puts a temporary foster parent node.
@@ -686,7 +751,7 @@ TEST_F(ProfileSyncServiceTest, ServerChangeWithNonCanonicalURL) {
StartSyncService();
{
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
FakeServerChange adds(&trans);
std::string url("http://dev.chromium.org");
@@ -717,7 +782,7 @@ TEST_F(ProfileSyncServiceTest, DISABLED_ServerChangeWithInvalidURL) {
int child_count = 0;
{
- sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
FakeServerChange adds(&trans);
std::string url("x");
@@ -834,7 +899,7 @@ TEST_F(ProfileSyncServiceTest, UnrecoverableErrorSuspendsService) {
// updating the ProfileSyncService state. This should introduce
// inconsistency between the two models.
{
- sync_api::WriteTransaction trans(service_->backend_->GetUserShareHandle());
+ sync_api::WriteTransaction trans(service_->GetUserShare());
sync_api::WriteNode sync_node(&trans);
EXPECT_TRUE(associator()->InitSyncNodeFromChromeId(node->id(),
&sync_node));
@@ -1323,7 +1388,8 @@ TEST_F(ProfileSyncServiceTestWithData, RecoverAfterDeletingSyncDataDirectory) {
WriteTestDataToBookmarkModel();
// While the service is running.
- FilePath sync_data_directory = backend()->sync_data_folder_path();
+ FilePath sync_data_directory =
+ service_->GetBackendForTest()->sync_data_folder_path();
// Simulate a normal shutdown for the sync service (don't disable it for
// the user, which would reset the preferences and delete the sync data
@@ -1388,7 +1454,6 @@ TEST_F(ProfileSyncServiceTestWithData, TestStartupWithOldSyncData) {
// hasn't been completed.
}
- ASSERT_FALSE(service_->backend());
ASSERT_FALSE(service_->HasSyncSetupCompleted());
// Create some tokens in the token service; the service will startup when
diff --git a/chrome/browser/sync/profile_sync_test_util.h b/chrome/browser/sync/profile_sync_test_util.h
index 7a5249f..45f6046 100644
--- a/chrome/browser/sync/profile_sync_test_util.h
+++ b/chrome/browser/sync/profile_sync_test_util.h
@@ -27,6 +27,7 @@
#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/profile_sync_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
+#include "chrome/browser/sync/syncable/model_type.h"
#include "chrome/browser/sync/unrecoverable_error_handler.h"
#include "chrome/common/notification_details.h"
#include "chrome/common/notification_service.h"
@@ -46,85 +47,6 @@ ACTION(QuitUIMessageLoop) {
MessageLoop::current()->Quit();
}
-class TestModelAssociatorHelper {
- public:
- explicit TestModelAssociatorHelper(browser_sync::TestIdFactory* id_factory)
- : id_factory_(id_factory) {
- }
-
- template <class ModelAssociatorImpl>
- bool GetSyncIdForTaggedNode(ModelAssociatorImpl* associator,
- const std::string& tag, int64* sync_id) {
- std::wstring tag_wide;
- if (!UTF8ToWide(tag.c_str(), tag.length(), &tag_wide)) {
- NOTREACHED() << "Unable to convert UTF8 to wide for string: " << tag;
- return false;
- }
-
- browser_sync::SyncBackendHost::UserShareHandle share(
- associator->sync_service()->backend()->GetUserShareHandle());
- bool root_exists = false;
- ModelType type = ModelAssociatorImpl::model_type();
- {
- sync_api::WriteTransaction trans(share);
- sync_api::ReadNode uber_root(&trans);
- uber_root.InitByRootLookup();
-
- sync_api::ReadNode root(&trans);
- root_exists = root.InitByTagLookup(
- ProfileSyncServiceTestHelper::GetTagForType(type));
- }
-
- if (!root_exists) {
- bool created = ProfileSyncServiceTestHelper::CreateRoot(
- type,
- associator->sync_service(),
- id_factory_);
- if (!created)
- return false;
- }
-
- sync_api::WriteTransaction trans(share);
- sync_api::ReadNode root(&trans);
- EXPECT_TRUE(root.InitByTagLookup(
- ProfileSyncServiceTestHelper::GetTagForType(type)));
-
- // First, try to find a node with the title among the root's children.
- // This will be the case if we are testing model persistence, and
- // are reloading a sync repository created earlier in the test.
- int64 last_child_id = sync_api::kInvalidId;
- for (int64 id = root.GetFirstChildId(); id != sync_api::kInvalidId; /***/) {
- sync_api::ReadNode child(&trans);
- child.InitByIdLookup(id);
- last_child_id = id;
- if (tag_wide == child.GetTitle()) {
- *sync_id = id;
- return true;
- }
- id = child.GetSuccessorId();
- }
-
- sync_api::ReadNode predecessor_node(&trans);
- sync_api::ReadNode* predecessor = NULL;
- if (last_child_id != sync_api::kInvalidId) {
- predecessor_node.InitByIdLookup(last_child_id);
- predecessor = &predecessor_node;
- }
- sync_api::WriteNode node(&trans);
- // Create new fake tagged nodes at the end of the ordering.
- node.InitByCreation(ModelAssociatorImpl::model_type(), root, predecessor);
- node.SetIsFolder(true);
- node.SetTitle(tag_wide);
- node.SetExternalId(0);
- *sync_id = node.GetId();
- return true;
- }
-
- ~TestModelAssociatorHelper() {}
- private:
- browser_sync::TestIdFactory* id_factory_;
-};
-
class ProfileSyncServiceObserverMock : public ProfileSyncServiceObserver {
public:
MOCK_METHOD0(OnStateChanged, void());
diff --git a/chrome/browser/sync/sync_ui_util.cc b/chrome/browser/sync/sync_ui_util.cc
index e1ac70f..f23fe75 100644
--- a/chrome/browser/sync/sync_ui_util.cc
+++ b/chrome/browser/sync/sync_ui_util.cc
@@ -406,13 +406,9 @@ void ConstructAboutInformation(ProfileSyncService* service,
strings->SetString("unrecoverable_error_location", location_str);
} else if (!service->sync_initialized()) {
strings->SetString("summary", "Sync not yet initialized");
- } else if (service->backend() == NULL) {
- strings->SetString("summary",
- "Unrecoverable error detected. Backend is null when it shouldnt be");
- NOTREACHED();
} else {
browser_sync::ModelSafeRoutingInfo routes;
- service->backend()->GetModelSafeRoutingInfo(&routes);
+ service->GetModelSafeRoutingInfo(&routes);
ListValue* routing_info = new ListValue();
strings->Set("routing_info", routing_info);
browser_sync::ModelSafeRoutingInfo::const_iterator it = routes.begin();
@@ -425,10 +421,10 @@ void ConstructAboutInformation(ProfileSyncService* service,
sync_ui_util::AddBoolSyncDetail(details,
"Autofill Migrated",
- service->backend()->GetAutofillMigrationState() ==
+ service->GetAutofillMigrationState() ==
syncable::MIGRATED);
syncable::AutofillMigrationDebugInfo info =
- service->backend()->GetAutofillMigrationDebugInfo();
+ service->GetAutofillMigrationDebugInfo();
sync_ui_util::AddIntSyncDetail(details,
"Bookmarks created during migration",
diff --git a/chrome/browser/sync/test_profile_sync_service.cc b/chrome/browser/sync/test_profile_sync_service.cc
index bab5d7d..9886dd1 100644
--- a/chrome/browser/sync/test_profile_sync_service.cc
+++ b/chrome/browser/sync/test_profile_sync_service.cc
@@ -5,22 +5,42 @@
#include "chrome/browser/sync/test_profile_sync_service.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
+#include "chrome/browser/sync/engine/syncapi.h"
+#include "chrome/browser/sync/glue/data_type_controller.h"
+#include "chrome/browser/sync/glue/sync_backend_host.h"
+#include "chrome/browser/sync/profile_sync_factory.h"
+#include "chrome/browser/sync/sessions/session_state.h"
+#include "chrome/browser/sync/syncable/directory_manager.h"
+#include "chrome/browser/sync/syncable/syncable.h"
+#include "chrome/test/sync/test_http_bridge_factory.h"
+
+using browser_sync::ModelSafeRoutingInfo;
+using browser_sync::sessions::ErrorCounters;
+using browser_sync::sessions::SyncerStatus;
+using browser_sync::sessions::SyncSessionSnapshot;
+using syncable::DirectoryManager;
+using syncable::ModelType;
+using syncable::ScopedDirLookup;
+using sync_api::UserShare;
+
+ACTION_P(CallOnPaused, core) {
+ core->OnPaused();
+};
+
+ACTION_P(CallOnResumed, core) {
+ core->OnResumed();
+}
namespace browser_sync {
SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest(
- TestProfileSyncService* service,
Profile* profile,
- Task* initial_condition_setup_task,
int num_expected_resumes,
int num_expected_pauses,
bool set_initial_sync_ended_on_init,
bool synchronous_init)
- : browser_sync::SyncBackendHost(service, profile),
- initial_condition_setup_task_(initial_condition_setup_task),
- set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init),
- synchronous_init_(synchronous_init),
- test_service_(service) {
+ : browser_sync::SyncBackendHost(profile),
+ synchronous_init_(synchronous_init) {
// By default, the RequestPause and RequestResume methods will
// send the confirmation notification and return true.
ON_CALL(*this, RequestPause()).
@@ -40,20 +60,129 @@ SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest(
RequestNudge()).Times(set_initial_sync_ended_on_init ? 0 : 1);
}
-void
-SyncBackendHostForProfileSyncTest::
- HandleInitializationCompletedOnFrontendLoop() {
- set_syncapi_initialized(); // Need to do this asap so task below works.
+void SyncBackendHostForProfileSyncTest::ConfigureDataTypes(
+ const DataTypeController::TypeMap& data_type_controllers,
+ const syncable::ModelTypeSet& types,
+ CancelableTask* ready_task) {
+ SetAutofillMigrationState(syncable::MIGRATED);
+ SyncBackendHost::ConfigureDataTypes(
+ data_type_controllers, types, ready_task);
+}
+
+void SyncBackendHostForProfileSyncTest::
+ SimulateSyncCycleCompletedInitialSyncEnded() {
+ syncable::ModelTypeBitSet sync_ended;
+ ModelSafeRoutingInfo enabled_types;
+ GetModelSafeRoutingInfo(&enabled_types);
+ std::string download_progress_markers[syncable::MODEL_TYPE_COUNT];
+ for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin();
+ i != enabled_types.end(); ++i) {
+ sync_ended.set(i->first);
+ }
+ core_->HandleSyncCycleCompletedOnFrontendLoop(new SyncSessionSnapshot(
+ SyncerStatus(), ErrorCounters(), 0, false,
+ sync_ended, download_progress_markers, false, false, 0, 0, false));
+}
+
+sync_api::HttpPostProviderFactory*
+ SyncBackendHostForProfileSyncTest::MakeHttpBridgeFactory(
+ URLRequestContextGetter* getter) {
+ return new browser_sync::TestHttpBridgeFactory;
+}
+
+void SyncBackendHostForProfileSyncTest::InitCore(
+ const Core::DoInitializeOptions& options) {
+ std::wstring user = L"testuser";
+ core_loop()->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(core_.get(),
+ &SyncBackendHost::Core::DoInitializeForTest,
+ user,
+ options.http_bridge_factory,
+ options.delete_sync_data_folder));
+
+ // TODO(akalin): Figure out a better way to do this.
+ if (synchronous_init_) {
+ // The SyncBackend posts a task to the current loop when
+ // initialization completes.
+ MessageLoop::current()->Run();
+ }
+}
+
+void SyncBackendHostForProfileSyncTest::
+ SetDefaultExpectationsForWorkerCreation(ProfileMock* profile) {
+ EXPECT_CALL(*profile, GetPasswordStore(testing::_)).
+ WillOnce(testing::Return((PasswordStore*)NULL));
+}
+
+void SyncBackendHostForProfileSyncTest::SetHistoryServiceExpectations(
+ ProfileMock* profile) {
+ EXPECT_CALL(*profile, GetHistoryService(testing::_)).
+ WillOnce(testing::Return((HistoryService*)NULL));
+}
+
+} // namespace browser_sync
+
+browser_sync::TestIdFactory* TestProfileSyncService::id_factory() {
+ return &id_factory_;
+}
+
+browser_sync::SyncBackendHostForProfileSyncTest*
+ TestProfileSyncService::GetBackendForTest() {
+ return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>(
+ ProfileSyncService::GetBackendForTest());
+}
+
+TestProfileSyncService::TestProfileSyncService(
+ ProfileSyncFactory* factory,
+ Profile* profile,
+ const std::string& test_user,
+ bool synchronous_backend_initialization,
+ Task* initial_condition_setup_task)
+ : ProfileSyncService(factory, profile, test_user),
+ synchronous_backend_initialization_(
+ synchronous_backend_initialization),
+ synchronous_sync_configuration_(false),
+ num_expected_resumes_(1),
+ num_expected_pauses_(1),
+ initial_condition_setup_task_(initial_condition_setup_task),
+ set_initial_sync_ended_on_init_(true) {
+ RegisterPreferences();
+ SetSyncSetupCompleted();
+}
+
+TestProfileSyncService::~TestProfileSyncService() {}
+
+void TestProfileSyncService::SetInitialSyncEndedForEnabledTypes() {
+ UserShare* user_share = GetUserShare();
+ DirectoryManager* dir_manager = user_share->dir_manager.get();
+
+ ScopedDirLookup dir(dir_manager, user_share->name);
+ if (!dir.good())
+ FAIL();
+
+ ModelSafeRoutingInfo enabled_types;
+ backend_->GetModelSafeRoutingInfo(&enabled_types);
+ for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin();
+ i != enabled_types.end(); ++i) {
+ dir->set_initial_sync_ended_for_type(i->first, true);
+ }
+}
+
+void TestProfileSyncService::OnBackendInitialized() {
+ // Set this so below code can access GetUserShare().
+ backend_initialized_ = true;
// Set up any nodes the test wants around before model association.
if (initial_condition_setup_task_) {
initial_condition_setup_task_->Run();
+ initial_condition_setup_task_ = NULL;
}
// Pretend we downloaded initial updates and set initial sync ended bits
// if we were asked to.
if (set_initial_sync_ended_on_init_) {
- UserShare* user_share = core_->syncapi()->GetUserShare();
+ UserShare* user_share = GetUserShare();
DirectoryManager* dir_manager = user_share->dir_manager.get();
ScopedDirLookup dir(dir_manager, user_share->name);
@@ -62,22 +191,52 @@ SyncBackendHostForProfileSyncTest::
if (!dir->initial_sync_ended_for_type(syncable::NIGORI)) {
ProfileSyncServiceTestHelper::CreateRoot(
- syncable::NIGORI, test_service_, test_service_->id_factory());
+ syncable::NIGORI, GetUserShare(),
+ id_factory());
}
SetInitialSyncEndedForEnabledTypes();
}
- SyncBackendHost::HandleInitializationCompletedOnFrontendLoop();
+ ProfileSyncService::OnBackendInitialized();
+
+ // TODO(akalin): Figure out a better way to do this.
+ if (synchronous_backend_initialization_) {
+ MessageLoop::current()->Quit();
+ }
}
-} // namespace browser_sync
+void TestProfileSyncService::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ ProfileSyncService::Observe(type, source, details);
+ if (type == NotificationType::SYNC_CONFIGURE_DONE &&
+ !synchronous_sync_configuration_) {
+ MessageLoop::current()->Quit();
+ }
+}
+
+void TestProfileSyncService::set_num_expected_resumes(int times) {
+ num_expected_resumes_ = times;
+}
+void TestProfileSyncService::set_num_expected_pauses(int num) {
+ num_expected_pauses_ = num;
+}
+void TestProfileSyncService::dont_set_initial_sync_ended_on_init() {
+ set_initial_sync_ended_on_init_ = false;
+}
+void TestProfileSyncService::set_synchronous_sync_configuration() {
+ synchronous_sync_configuration_ = true;
+}
void TestProfileSyncService::CreateBackend() {
backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest(
- this, profile(),
- initial_condition_setup_task_.release(),
+ profile(),
num_expected_resumes_, num_expected_pauses_,
set_initial_sync_ended_on_init_,
synchronous_backend_initialization_));
}
+
+std::string TestProfileSyncService::GetLsidForAuthBootstraping() {
+ return "foo";
+}
diff --git a/chrome/browser/sync/test_profile_sync_service.h b/chrome/browser/sync/test_profile_sync_service.h
index b1d6ef4..452b1ed 100644
--- a/chrome/browser/sync/test_profile_sync_service.h
+++ b/chrome/browser/sync/test_profile_sync_service.h
@@ -8,41 +8,16 @@
#include <string>
-#include "base/message_loop.h"
-#include "chrome/browser/sync/engine/syncapi.h"
-#include "chrome/browser/sync/profile_sync_factory.h"
-#include "chrome/browser/sync/profile_sync_service.h"
-#include "chrome/browser/sync/glue/data_type_controller.h"
#include "chrome/browser/sync/glue/data_type_manager_impl.h"
-#include "chrome/browser/sync/glue/sync_backend_host.h"
-#include "chrome/browser/sync/sessions/session_state.h"
-#include "chrome/browser/sync/syncable/directory_manager.h"
-#include "chrome/browser/sync/syncable/syncable.h"
+#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/test/profile_mock.h"
-#include "chrome/test/sync/test_http_bridge_factory.h"
#include "chrome/test/sync/engine/test_id_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
class Profile;
+class Task;
class TestProfileSyncService;
-using browser_sync::ModelSafeRoutingInfo;
-using browser_sync::sessions::ErrorCounters;
-using browser_sync::sessions::SyncerStatus;
-using browser_sync::sessions::SyncSessionSnapshot;
-using sync_api::UserShare;
-using syncable::DirectoryManager;
-using syncable::ModelType;
-using syncable::ScopedDirLookup;
-
-ACTION_P(CallOnPaused, core) {
- core->OnPaused();
-};
-
-ACTION_P(CallOnResumed, core) {
- core->OnResumed();
-}
-
ACTION(ReturnNewDataTypeManager) {
return new browser_sync::DataTypeManagerImpl(arg0, arg1);
}
@@ -55,17 +30,10 @@ namespace browser_sync {
// download.
class SyncBackendHostForProfileSyncTest : public SyncBackendHost {
public:
- // |initial_condition_setup_task| can be used to populate nodes before the
- // OnBackendInitialized callback fires.
- // |set_initial_sync_ended_on_init| determines whether we pretend that a full
- // initial download has occurred and set bits for enabled data types. If
- // this is false, configuring data types will require a syncer nudge.
// |synchronous_init| causes initialization to block until the syncapi has
// completed setting itself up and called us back.
SyncBackendHostForProfileSyncTest(
- TestProfileSyncService* service,
Profile* profile,
- Task* initial_condition_setup_task,
int num_expected_resumes,
int num_expected_pauses,
bool set_initial_sync_ended_on_init,
@@ -75,141 +43,64 @@ class SyncBackendHostForProfileSyncTest : public SyncBackendHost {
MOCK_METHOD0(RequestResume, bool());
MOCK_METHOD0(RequestNudge, void());
- void SetInitialSyncEndedForEnabledTypes() {
- UserShare* user_share = core_->syncapi()->GetUserShare();
- DirectoryManager* dir_manager = user_share->dir_manager.get();
-
- ScopedDirLookup dir(dir_manager, user_share->name);
- if (!dir.good())
- FAIL();
-
- ModelSafeRoutingInfo enabled_types;
- GetModelSafeRoutingInfo(&enabled_types);
- for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin();
- i != enabled_types.end(); ++i) {
- dir->set_initial_sync_ended_for_type(i->first, true);
- }
- }
-
virtual void ConfigureDataTypes(
const DataTypeController::TypeMap& data_type_controllers,
const syncable::ModelTypeSet& types,
- CancelableTask* ready_task) {
- SetAutofillMigrationState(syncable::MIGRATED);
- SyncBackendHost::ConfigureDataTypes(
- data_type_controllers, types, ready_task);
- }
+ CancelableTask* ready_task);
// Called when a nudge comes in.
- void SimulateSyncCycleCompletedInitialSyncEnded() {
- syncable::ModelTypeBitSet sync_ended;
- ModelSafeRoutingInfo enabled_types;
- GetModelSafeRoutingInfo(&enabled_types);
- std::string download_progress_markers[syncable::MODEL_TYPE_COUNT];
- for (ModelSafeRoutingInfo::const_iterator i = enabled_types.begin();
- i != enabled_types.end(); ++i) {
- sync_ended.set(i->first);
- }
- core_->HandleSyncCycleCompletedOnFrontendLoop(new SyncSessionSnapshot(
- SyncerStatus(), ErrorCounters(), 0, false,
- sync_ended, download_progress_markers, false, false, 0, 0, false));
- }
-
- virtual void HandleInitializationCompletedOnFrontendLoop();
+ void SimulateSyncCycleCompletedInitialSyncEnded();
virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory(
- URLRequestContextGetter* getter) {
- return new browser_sync::TestHttpBridgeFactory;
- }
-
- virtual void InitCore(const Core::DoInitializeOptions& options) {
- std::wstring user = L"testuser";
- core_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(core_.get(),
- &SyncBackendHost::Core::DoInitializeForTest,
- user,
- options.http_bridge_factory,
- options.delete_sync_data_folder));
-
- // TODO(akalin): Figure out a better way to do this.
- if (synchronous_init_) {
- // The SyncBackend posts a task to the current loop when
- // initialization completes.
- MessageLoop::current()->Run();
- }
- }
-
- static void SetDefaultExpectationsForWorkerCreation(ProfileMock* profile) {
- EXPECT_CALL(*profile, GetPasswordStore(testing::_)).
- WillOnce(testing::Return((PasswordStore*)NULL));
- }
-
- static void SetHistoryServiceExpectations(ProfileMock* profile) {
- EXPECT_CALL(*profile, GetHistoryService(testing::_)).
- WillOnce(testing::Return((HistoryService*)NULL));
- }
+ URLRequestContextGetter* getter);
+
+ virtual void InitCore(const Core::DoInitializeOptions& options);
+
+ static void SetDefaultExpectationsForWorkerCreation(ProfileMock* profile);
+
+ static void SetHistoryServiceExpectations(ProfileMock* profile);
private:
- Task* initial_condition_setup_task_;
- bool set_initial_sync_ended_on_init_;
bool synchronous_init_;
- TestProfileSyncService* test_service_;
};
} // namespace browser_sync
class TestProfileSyncService : public ProfileSyncService {
public:
+ // |initial_condition_setup_task| can be used to populate nodes
+ // before the OnBackendInitialized callback fires.
TestProfileSyncService(ProfileSyncFactory* factory,
Profile* profile,
const std::string& test_user,
bool synchronous_backend_initialization,
- Task* initial_condition_setup_task)
- : ProfileSyncService(factory, profile, test_user),
- synchronous_backend_initialization_(
- synchronous_backend_initialization),
- synchronous_sync_configuration_(false),
- num_expected_resumes_(1),
- num_expected_pauses_(1),
- initial_condition_setup_task_(initial_condition_setup_task),
- set_initial_sync_ended_on_init_(true) {
- RegisterPreferences();
- SetSyncSetupCompleted();
- }
- virtual ~TestProfileSyncService() { }
-
- virtual void OnBackendInitialized() {
- ProfileSyncService::OnBackendInitialized();
- // TODO(akalin): Figure out a better way to do this.
- if (synchronous_backend_initialization_) {
- MessageLoop::current()->Quit();
- }
- }
+ Task* initial_condition_setup_task);
+
+ virtual ~TestProfileSyncService();
+
+ void SetInitialSyncEndedForEnabledTypes();
+
+ virtual void OnBackendInitialized();
virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- ProfileSyncService::Observe(type, source, details);
- if (type == NotificationType::SYNC_CONFIGURE_DONE &&
- !synchronous_sync_configuration_) {
- MessageLoop::current()->Quit();
- }
- }
-
- void set_num_expected_resumes(int times) {
- num_expected_resumes_ = times;
- }
- void set_num_expected_pauses(int num) {
- num_expected_pauses_ = num;
- }
- void dont_set_initial_sync_ended_on_init() {
- set_initial_sync_ended_on_init_ = false;
- }
- void set_synchronous_sync_configuration() {
- synchronous_sync_configuration_ = true;
- }
-
- browser_sync::TestIdFactory* id_factory() { return &id_factory_; }
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ void set_num_expected_resumes(int times);
+ void set_num_expected_pauses(int num);
+
+ // If this is called, configuring data types will require a syncer
+ // nudge.
+ void dont_set_initial_sync_ended_on_init();
+ void set_synchronous_sync_configuration();
+
+ browser_sync::TestIdFactory* id_factory();
+
+ // Override of ProfileSyncService::GetBackendForTest() with a more
+ // specific return type (since C++ supports covariant return types)
+ // that is made public.
+ virtual browser_sync::SyncBackendHostForProfileSyncTest*
+ GetBackendForTest();
protected:
virtual void CreateBackend();
@@ -217,9 +108,9 @@ class TestProfileSyncService : public ProfileSyncService {
private:
// When testing under ChromiumOS, this method must not return an empty
// value value in order for the profile sync service to start.
- virtual std::string GetLsidForAuthBootstraping() {
- return "foo";
- }
+ virtual std::string GetLsidForAuthBootstraping();
+
+ browser_sync::TestIdFactory id_factory_;
bool synchronous_backend_initialization_;
@@ -230,9 +121,8 @@ class TestProfileSyncService : public ProfileSyncService {
int num_expected_resumes_;
int num_expected_pauses_;
- scoped_ptr<Task> initial_condition_setup_task_;
+ Task* initial_condition_setup_task_;
bool set_initial_sync_ended_on_init_;
- browser_sync::TestIdFactory id_factory_;
};
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index f8cc5d9..f0c35b3 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1374,6 +1374,7 @@
'browser/ssl/ssl_host_state_unittest.cc',
'browser/status_icons/status_icon_unittest.cc',
'browser/status_icons/status_tray_unittest.cc',
+ 'browser/sync/abstract_profile_sync_service_test.cc',
'browser/sync/abstract_profile_sync_service_test.h',
'browser/sync/glue/autofill_data_type_controller_unittest.cc',
'browser/sync/glue/autofill_model_associator_unittest.cc',