summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.cc11
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.h13
-rw-r--r--chrome/browser/sync/glue/sync_backend_host_unittest.cc5
-rw-r--r--chrome/browser/sync/invalidations/invalidator_storage.cc136
-rw-r--r--chrome/browser/sync/invalidations/invalidator_storage.h75
-rw-r--r--chrome/browser/sync/invalidations/invalidator_storage_unittest.cc129
-rw-r--r--chrome/browser/sync/profile_sync_service.cc5
-rw-r--r--chrome/browser/sync/profile_sync_service.h4
-rw-r--r--chrome/browser/sync/sync_prefs.cc75
-rw-r--r--chrome/browser/sync/sync_prefs.h7
-rw-r--r--chrome/browser/sync/sync_prefs_unittest.cc32
-rw-r--r--chrome/browser/sync/test_profile_sync_service.cc4
-rw-r--r--chrome/browser/sync/test_profile_sync_service.h3
13 files changed, 377 insertions, 122 deletions
diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc
index 28c73dc..ebf3cbc 100644
--- a/chrome/browser/sync/glue/sync_backend_host.cc
+++ b/chrome/browser/sync/glue/sync_backend_host.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/sync/glue/chrome_encryptor.h"
#include "chrome/browser/sync/glue/http_bridge.h"
#include "chrome/browser/sync/glue/sync_backend_registrar.h"
+#include "chrome/browser/sync/invalidations/invalidator_storage.h"
#include "chrome/browser/sync/sync_prefs.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
@@ -279,9 +280,11 @@ notifier::NotifierOptions ParseNotifierOptions(
} // namespace
-SyncBackendHost::SyncBackendHost(const std::string& name,
- Profile* profile,
- const base::WeakPtr<SyncPrefs>& sync_prefs)
+SyncBackendHost::SyncBackendHost(
+ const std::string& name,
+ Profile* profile,
+ const base::WeakPtr<SyncPrefs>& sync_prefs,
+ const base::WeakPtr<InvalidatorStorage>& invalidator_storage)
: weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
sync_thread_("Chrome_SyncThread"),
frontend_loop_(MessageLoop::current()),
@@ -296,7 +299,7 @@ SyncBackendHost::SyncBackendHost(const std::string& name,
ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
profile_->GetRequestContext()),
content::GetUserAgent(GURL()),
- sync_prefs),
+ invalidator_storage),
frontend_(NULL) {
}
diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h
index ed59e3a..468cb75 100644
--- a/chrome/browser/sync/glue/sync_backend_host.h
+++ b/chrome/browser/sync/glue/sync_backend_host.h
@@ -39,6 +39,7 @@ namespace browser_sync {
class ChangeProcessor;
struct Experiments;
+class InvalidatorStorage;
class JsBackend;
class JsEventHandler;
class SyncBackendRegistrar;
@@ -148,10 +149,14 @@ class SyncBackendHost : public BackendDataTypeConfigurer {
// 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). Must outlive
- // |sync_prefs|.
- SyncBackendHost(const std::string& name,
- Profile* profile,
- const base::WeakPtr<SyncPrefs>& sync_prefs);
+ // |sync_prefs| and |invalidator_storage|.
+ SyncBackendHost(
+ const std::string& name,
+ Profile* profile,
+ const base::WeakPtr<SyncPrefs>& sync_prefs,
+ // TODO(tim): Temporary, remove when bug 124137 finished.
+ const base::WeakPtr<InvalidatorStorage>& invalidator_storage);
+
// For testing.
// TODO(skrul): Extract an interface so this is not needed.
explicit SyncBackendHost(Profile* profile);
diff --git a/chrome/browser/sync/glue/sync_backend_host_unittest.cc b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
index 097ba04..cde6568 100644
--- a/chrome/browser/sync/glue/sync_backend_host_unittest.cc
+++ b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
@@ -8,6 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
+#include "chrome/browser/sync/invalidations/invalidator_storage.h"
#include "chrome/browser/sync/sync_prefs.h"
#include "chrome/test/base/testing_profile.h"
#include "content/test/test_browser_thread.h"
@@ -93,8 +94,10 @@ TEST_F(SyncBackendHostTest, InitShutdown) {
profile.CreateRequestContext();
SyncPrefs sync_prefs(profile.GetPrefs());
+ InvalidatorStorage invalidator_storage(profile.GetPrefs());
SyncBackendHost backend(profile.GetDebugName(),
- &profile, sync_prefs.AsWeakPtr());
+ &profile, sync_prefs.AsWeakPtr(),
+ invalidator_storage.AsWeakPtr());
MockSyncFrontend mock_frontend;
sync_api::SyncCredentials credentials;
diff --git a/chrome/browser/sync/invalidations/invalidator_storage.cc b/chrome/browser/sync/invalidations/invalidator_storage.cc
new file mode 100644
index 0000000..e2eb055
--- /dev/null
+++ b/chrome/browser/sync/invalidations/invalidator_storage.cc
@@ -0,0 +1,136 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/invalidations/invalidator_storage.h"
+
+#include "base/logging.h"
+#include "base/string_number_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/common/pref_names.h"
+
+using sync_notifier::InvalidationVersionMap;
+
+namespace browser_sync {
+
+InvalidatorStorage::InvalidatorStorage(PrefService* pref_service)
+ : pref_service_(pref_service) {
+ // TODO(tim): Create a Mock instead of maintaining the if(!pref_service_) case
+ // throughout this file. This is a problem now due to lack of injection at
+ // ProfileSyncService. Bug 130176.
+ if (pref_service_) {
+ pref_service_->RegisterDictionaryPref(prefs::kSyncMaxInvalidationVersions,
+ PrefService::UNSYNCABLE_PREF);
+ pref_service_->RegisterStringPref(prefs::kInvalidatorInvalidationState,
+ std::string(),
+ PrefService::UNSYNCABLE_PREF);
+ }
+}
+
+InvalidatorStorage::~InvalidatorStorage() {
+}
+
+InvalidationVersionMap InvalidatorStorage::GetAllMaxVersions() const {
+ DCHECK(non_thread_safe_.CalledOnValidThread());
+ if (!pref_service_) {
+ return InvalidationVersionMap();
+ }
+
+ const base::DictionaryValue* max_versions_dict =
+ pref_service_->GetDictionary(prefs::kSyncMaxInvalidationVersions);
+ CHECK(max_versions_dict);
+ InvalidationVersionMap max_versions;
+ DeserializeMap(max_versions_dict, &max_versions);
+ return max_versions;
+}
+
+void InvalidatorStorage::SetMaxVersion(syncable::ModelType model_type,
+ int64 max_version) {
+ DCHECK(non_thread_safe_.CalledOnValidThread());
+ DCHECK(syncable::IsRealDataType(model_type));
+ CHECK(pref_service_);
+ InvalidationVersionMap max_versions =
+ GetAllMaxVersions();
+ InvalidationVersionMap::iterator it =
+ max_versions.find(model_type);
+ if ((it != max_versions.end()) && (max_version <= it->second)) {
+ NOTREACHED();
+ return;
+ }
+ max_versions[model_type] = max_version;
+
+ base::DictionaryValue max_versions_dict;
+ SerializeMap(max_versions, &max_versions_dict);
+ pref_service_->Set(prefs::kSyncMaxInvalidationVersions, max_versions_dict);
+}
+
+// static
+void InvalidatorStorage::DeserializeMap(
+ const base::DictionaryValue* max_versions_dict,
+ InvalidationVersionMap* map) {
+ map->clear();
+ // Convert from a string -> string DictionaryValue to a
+ // ModelType -> int64 map
+ // .
+ for (base::DictionaryValue::key_iterator it =
+ max_versions_dict->begin_keys();
+ it != max_versions_dict->end_keys(); ++it) {
+ int model_type_int = 0;
+ if (!base::StringToInt(*it, &model_type_int)) {
+ LOG(WARNING) << "Invalid model type key: " << *it;
+ continue;
+ }
+ if ((model_type_int < syncable::FIRST_REAL_MODEL_TYPE) ||
+ (model_type_int >= syncable::MODEL_TYPE_COUNT)) {
+ LOG(WARNING) << "Out-of-range model type key: " << model_type_int;
+ continue;
+ }
+ const syncable::ModelType model_type =
+ syncable::ModelTypeFromInt(model_type_int);
+ std::string max_version_str;
+ CHECK(max_versions_dict->GetString(*it, &max_version_str));
+ int64 max_version = 0;
+ if (!base::StringToInt64(max_version_str, &max_version)) {
+ LOG(WARNING) << "Invalid max invalidation version for "
+ << syncable::ModelTypeToString(model_type) << ": "
+ << max_version_str;
+ continue;
+ }
+ (*map)[model_type] = max_version;
+ }
+}
+
+// static
+void InvalidatorStorage::SerializeMap(
+ const InvalidationVersionMap& map, base::DictionaryValue* to_dict) {
+ // Convert from a ModelType -> int64 map to a string -> string
+ // DictionaryValue.
+ for (InvalidationVersionMap::const_iterator it = map.begin();
+ it != map.end(); ++it) {
+ to_dict->SetString(
+ base::IntToString(it->first),
+ base::Int64ToString(it->second));
+ }
+}
+
+std::string InvalidatorStorage::GetInvalidationState() const {
+ DLOG(WARNING) << "TODO(tim): Wire this up. Bug 124140.";
+ return pref_service_ ?
+ pref_service_->GetString(prefs::kInvalidatorInvalidationState) : "";
+}
+
+void InvalidatorStorage::SetInvalidationState(const std::string& state) {
+ DLOG(WARNING) << "TODO(tim): Wire this up. Bug 124140.";
+ DCHECK(non_thread_safe_.CalledOnValidThread());
+ pref_service_->SetString(prefs::kInvalidatorInvalidationState,
+ state);
+}
+
+void InvalidatorStorage::Clear() {
+ DCHECK(non_thread_safe_.CalledOnValidThread());
+ pref_service_->ClearPref(prefs::kInvalidatorInvalidationState);
+ pref_service_->ClearPref(prefs::kSyncMaxInvalidationVersions);
+}
+
+} // namespace browser_sync
diff --git a/chrome/browser/sync/invalidations/invalidator_storage.h b/chrome/browser/sync/invalidations/invalidator_storage.h
new file mode 100644
index 0000000..ab5ceca
--- /dev/null
+++ b/chrome/browser/sync/invalidations/invalidator_storage.h
@@ -0,0 +1,75 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Wraps PrefService in an InvalidationStateTracker to allow SyncNotifiers
+// to use PrefService as persistence for invalidation state. It is not thread
+// safe, and lives on the UI thread.
+
+#ifndef CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_
+#define CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_
+
+#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/non_thread_safe.h"
+#include "sync/notifier/invalidation_state_tracker.h"
+#include "sync/syncable/model_type.h"
+
+class PrefService;
+
+namespace base {
+ class DictionaryValue;
+}
+
+namespace browser_sync {
+
+// TODO(tim): Bug 124137. We may want to move this outside of sync/ into a
+// browser/invalidations directory, or re-organize to have a browser
+// subdirectory that contains signin/ sync/ invalidations/ and other cloud
+// services. For now this is still tied to sync while we refactor, so minimize
+// churn and keep it here.
+class InvalidatorStorage : public base::SupportsWeakPtr<InvalidatorStorage>,
+ public sync_notifier::InvalidationStateTracker {
+ public:
+ // |pref_service| may be NULL (for unit tests), but in that case no setter
+ // methods should be called. Does not own |pref_service|.
+ explicit InvalidatorStorage(PrefService* pref_service);
+ virtual ~InvalidatorStorage();
+
+ // Erases invalidation versions and state stored on disk.
+ void Clear();
+
+ // InvalidationStateTracker implementation.
+ virtual sync_notifier::InvalidationVersionMap GetAllMaxVersions() const
+ OVERRIDE;
+ virtual void SetMaxVersion(syncable::ModelType model_type,
+ int64 max_version) OVERRIDE;
+ // TODO(tim): These are not yet used. Bug 124140.
+ virtual void SetInvalidationState(const std::string& state) OVERRIDE;
+ virtual std::string GetInvalidationState() const OVERRIDE;
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, SerializeEmptyMap);
+ FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeOutOfRange);
+ FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeInvalidFormat);
+ FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeEmptyDictionary);
+ FRIEND_TEST_ALL_PREFIXES(InvalidatorStorageTest, DeserializeBasic);
+
+ base::NonThreadSafe non_thread_safe_;
+
+ // Helpers to convert between InvalidationVersionMap <--> DictionaryValue.
+ static void DeserializeMap(const base::DictionaryValue* max_versions_dict,
+ sync_notifier::InvalidationVersionMap* map);
+ static void SerializeMap(const sync_notifier::InvalidationVersionMap& map,
+ base::DictionaryValue* to_dict);
+
+ // May be NULL.
+ PrefService* const pref_service_;
+
+ DISALLOW_COPY_AND_ASSIGN(InvalidatorStorage);
+};
+
+} // namespace browser_sync
+
+#endif // CHROME_BROWSER_SYNC_INVALIDATIONS_INVALIDATOR_STORAGE_H_
diff --git a/chrome/browser/sync/invalidations/invalidator_storage_unittest.cc b/chrome/browser/sync/invalidations/invalidator_storage_unittest.cc
new file mode 100644
index 0000000..765f332
--- /dev/null
+++ b/chrome/browser/sync/invalidations/invalidator_storage_unittest.cc
@@ -0,0 +1,129 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+#include "chrome/browser/sync/invalidations/invalidator_storage.h"
+
+#include "base/message_loop.h"
+#include "base/string_number_conversions.h"
+#include "chrome/test/base/testing_pref_service.h"
+#include "sync/syncable/model_type.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using sync_notifier::InvalidationVersionMap;
+
+namespace browser_sync {
+
+class InvalidatorStorageTest : public testing::Test {
+ protected:
+ TestingPrefService pref_service_;
+
+ private:
+ MessageLoop loop_;
+};
+
+TEST_F(InvalidatorStorageTest, MaxInvalidationVersions) {
+ InvalidatorStorage storage(&pref_service_);
+
+ InvalidationVersionMap expected_max_versions;
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+
+ expected_max_versions[syncable::BOOKMARKS] = 2;
+ storage.SetMaxVersion(syncable::BOOKMARKS, 2);
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+
+ expected_max_versions[syncable::PREFERENCES] = 5;
+ storage.SetMaxVersion(syncable::PREFERENCES, 5);
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+
+ expected_max_versions[syncable::APP_NOTIFICATIONS] = 3;
+ storage.SetMaxVersion(syncable::APP_NOTIFICATIONS, 3);
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+
+ expected_max_versions[syncable::APP_NOTIFICATIONS] = 4;
+ storage.SetMaxVersion(syncable::APP_NOTIFICATIONS, 4);
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+}
+
+TEST_F(InvalidatorStorageTest, Clear) {
+ InvalidatorStorage storage(&pref_service_);
+ EXPECT_TRUE(storage.GetAllMaxVersions().empty());
+ EXPECT_TRUE(storage.GetInvalidationState().empty());
+
+ storage.SetInvalidationState("test");
+ EXPECT_EQ("test", storage.GetInvalidationState());
+ {
+ InvalidationVersionMap expected_max_versions;
+ expected_max_versions[syncable::APP_NOTIFICATIONS] = 3;
+ storage.SetMaxVersion(syncable::APP_NOTIFICATIONS, 3);
+ EXPECT_EQ(expected_max_versions, storage.GetAllMaxVersions());
+ }
+
+ storage.Clear();
+
+ EXPECT_TRUE(storage.GetAllMaxVersions().empty());
+ EXPECT_TRUE(storage.GetInvalidationState().empty());
+}
+
+TEST_F(InvalidatorStorageTest, SerializeEmptyMap) {
+ InvalidationVersionMap empty_map;
+ base::DictionaryValue dict;
+ InvalidatorStorage::SerializeMap(empty_map, &dict);
+ EXPECT_TRUE(dict.empty());
+}
+
+TEST_F(InvalidatorStorageTest, DeserializeOutOfRange) {
+ InvalidationVersionMap map;
+ base::DictionaryValue dict_with_out_of_range_type;
+
+ dict_with_out_of_range_type.SetString(
+ base::IntToString(syncable::TOP_LEVEL_FOLDER), "100");
+ dict_with_out_of_range_type.SetString(
+ base::IntToString(syncable::BOOKMARKS), "5");
+
+ InvalidatorStorage::DeserializeMap(&dict_with_out_of_range_type, &map);
+
+ EXPECT_EQ(1U, map.size());
+ EXPECT_EQ(5, map[syncable::BOOKMARKS]);
+}
+
+TEST_F(InvalidatorStorageTest, DeserializeInvalidFormat) {
+ InvalidationVersionMap map;
+ base::DictionaryValue dict_with_invalid_format;
+
+ dict_with_invalid_format.SetString("whoops", "5");
+ dict_with_invalid_format.SetString("ohnoes", "whoops");
+ dict_with_invalid_format.SetString(
+ base::IntToString(syncable::BOOKMARKS), "ohnoes");
+ dict_with_invalid_format.SetString(
+ base::IntToString(syncable::AUTOFILL), "10");
+
+ InvalidatorStorage::DeserializeMap(&dict_with_invalid_format, &map);
+
+ EXPECT_EQ(1U, map.size());
+ EXPECT_EQ(10, map[syncable::AUTOFILL]);
+}
+
+TEST_F(InvalidatorStorageTest, DeserializeEmptyDictionary) {
+ InvalidationVersionMap map;
+ base::DictionaryValue dict;
+ InvalidatorStorage::DeserializeMap(&dict, &map);
+ EXPECT_TRUE(map.empty());
+}
+
+TEST_F(InvalidatorStorageTest, DeserializeBasic) {
+ InvalidationVersionMap map;
+ base::DictionaryValue dict;
+
+ dict.SetString(base::IntToString(syncable::AUTOFILL), "10");
+ dict.SetString(base::IntToString(syncable::BOOKMARKS), "15");
+
+ InvalidatorStorage::DeserializeMap(&dict, &map);
+ EXPECT_EQ(2U, map.size());
+ EXPECT_EQ(10, map[syncable::AUTOFILL]);
+ EXPECT_EQ(15, map[syncable::BOOKMARKS]);
+}
+
+} // namespace browser_sync
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index d9f6e4e..7ad7373 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -117,6 +117,7 @@ ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory,
profile_(profile),
// |profile| may be NULL in unit tests.
sync_prefs_(profile_ ? profile_->GetPrefs() : NULL),
+ invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL),
sync_service_url_(kDevServerUrl),
backend_initialized_(false),
is_auth_in_progress_(false),
@@ -362,7 +363,8 @@ void ProfileSyncService::InitializeBackend(bool delete_stale_data) {
void ProfileSyncService::CreateBackend() {
backend_.reset(
new SyncBackendHost(profile_->GetDebugName(),
- profile_, sync_prefs_.AsWeakPtr()));
+ profile_, sync_prefs_.AsWeakPtr(),
+ invalidator_storage_.AsWeakPtr()));
}
bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
@@ -525,6 +527,7 @@ void ProfileSyncService::DisableForUser() {
// Clear prefs (including SyncSetupHasCompleted) before shutting down so
// PSS clients don't think we're set up while we're shutting down.
sync_prefs_.ClearPreferences();
+ invalidator_storage_.Clear();
ClearUnrecoverableError();
ShutdownImpl(true);
diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h
index 362ed37..ea1d0679 100644
--- a/chrome/browser/sync/profile_sync_service.h
+++ b/chrome/browser/sync/profile_sync_service.h
@@ -25,6 +25,7 @@
#include "chrome/browser/sync/glue/data_type_controller.h"
#include "chrome/browser/sync/glue/data_type_manager.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
+#include "chrome/browser/sync/invalidations/invalidator_storage.h"
#include "chrome/browser/sync/profile_sync_service_observer.h"
#include "chrome/browser/sync/sync_prefs.h"
#include "chrome/common/net/gaia/google_service_auth_error.h"
@@ -640,6 +641,9 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
// preferences.
browser_sync::SyncPrefs sync_prefs_;
+ // TODO(tim): Move this to InvalidationService, once it exists. Bug 124137.
+ browser_sync::InvalidatorStorage invalidator_storage_;
+
// TODO(ncarter): Put this in a profile, once there is UI for it.
// This specifies where to find the sync server.
GURL sync_service_url_;
diff --git a/chrome/browser/sync/sync_prefs.cc b/chrome/browser/sync/sync_prefs.cc
index 1ba1c9a..4239208 100644
--- a/chrome/browser/sync/sync_prefs.cc
+++ b/chrome/browser/sync/sync_prefs.cc
@@ -21,6 +21,9 @@ SyncPrefObserver::~SyncPrefObserver() {}
SyncPrefs::SyncPrefs(PrefService* pref_service)
: pref_service_(pref_service) {
RegisterPrefGroups();
+ // TODO(tim): Create a Mock instead of maintaining the if(!pref_service_) case
+ // throughout this file. This is a problem now due to lack of injection at
+ // ProfileSyncService. Bug 130176.
if (pref_service_) {
RegisterPreferences();
// Watch the preference that indicates sync is managed so we can take
@@ -52,8 +55,6 @@ void SyncPrefs::ClearPreferences() {
// TODO(nick): The current behavior does not clear
// e.g. prefs::kSyncBookmarks. Is that really what we want?
-
- pref_service_->ClearPref(prefs::kSyncMaxInvalidationVersions);
}
bool SyncPrefs::HasSyncSetupCompleted() const {
@@ -189,73 +190,6 @@ void SyncPrefs::SetSpareBootstrapToken(const std::string& token) {
}
#endif
-sync_notifier::InvalidationVersionMap SyncPrefs::GetAllMaxVersions() const {
- DCHECK(non_thread_safe_.CalledOnValidThread());
- if (!pref_service_) {
- return sync_notifier::InvalidationVersionMap();
- }
- // Complicated gross code to convert from a string -> string
- // DictionaryValue to a ModelType -> int64 map.
- const base::DictionaryValue* max_versions_dict =
- pref_service_->GetDictionary(prefs::kSyncMaxInvalidationVersions);
- CHECK(max_versions_dict);
- sync_notifier::InvalidationVersionMap max_versions;
- for (base::DictionaryValue::key_iterator it =
- max_versions_dict->begin_keys();
- it != max_versions_dict->end_keys(); ++it) {
- int model_type_int = 0;
- if (!base::StringToInt(*it, &model_type_int)) {
- LOG(WARNING) << "Invalid model type key: " << *it;
- continue;
- }
- if ((model_type_int < syncable::FIRST_REAL_MODEL_TYPE) ||
- (model_type_int >= syncable::MODEL_TYPE_COUNT)) {
- LOG(WARNING) << "Out-of-range model type key: " << model_type_int;
- continue;
- }
- const syncable::ModelType model_type =
- syncable::ModelTypeFromInt(model_type_int);
- std::string max_version_str;
- CHECK(max_versions_dict->GetString(*it, &max_version_str));
- int64 max_version = 0;
- if (!base::StringToInt64(max_version_str, &max_version)) {
- LOG(WARNING) << "Invalid max invalidation version for "
- << syncable::ModelTypeToString(model_type) << ": "
- << max_version_str;
- continue;
- }
- max_versions[model_type] = max_version;
- }
- return max_versions;
-}
-
-void SyncPrefs::SetMaxVersion(syncable::ModelType model_type,
- int64 max_version) {
- DCHECK(non_thread_safe_.CalledOnValidThread());
- DCHECK(syncable::IsRealDataType(model_type));
- CHECK(pref_service_);
- sync_notifier::InvalidationVersionMap max_versions =
- GetAllMaxVersions();
- sync_notifier::InvalidationVersionMap::iterator it =
- max_versions.find(model_type);
- if ((it != max_versions.end()) && (max_version <= it->second)) {
- NOTREACHED();
- return;
- }
- max_versions[model_type] = max_version;
-
- // Gross code to convert from a ModelType -> int64 map to a string
- // -> string DictionaryValue.
- base::DictionaryValue max_versions_dict;
- for (sync_notifier::InvalidationVersionMap::const_iterator it =
- max_versions.begin();
- it != max_versions.end(); ++it) {
- max_versions_dict.SetString(
- base::IntToString(it->first),
- base::Int64ToString(it->second));
- }
- pref_service_->Set(prefs::kSyncMaxInvalidationVersions, max_versions_dict);
-}
void SyncPrefs::AcknowledgeSyncedTypes(
syncable::ModelTypeSet types) {
@@ -435,9 +369,6 @@ void SyncPrefs::RegisterPreferences() {
pref_service_->RegisterListPref(prefs::kSyncAcknowledgedSyncTypes,
syncable::ModelTypeSetToValue(model_set),
PrefService::UNSYNCABLE_PREF);
-
- pref_service_->RegisterDictionaryPref(prefs::kSyncMaxInvalidationVersions,
- PrefService::UNSYNCABLE_PREF);
}
void SyncPrefs::RegisterDataTypePreferredPref(syncable::ModelType type,
diff --git a/chrome/browser/sync/sync_prefs.h b/chrome/browser/sync/sync_prefs.h
index d2cc6ad..31d1d183 100644
--- a/chrome/browser/sync/sync_prefs.h
+++ b/chrome/browser/sync/sync_prefs.h
@@ -45,7 +45,6 @@ class SyncPrefObserver {
// sync_setup_wizard_unittest.cc
// two_client_preferences_sync_test.cc
class SyncPrefs : public base::SupportsWeakPtr<SyncPrefs>,
- public sync_notifier::InvalidationStateTracker,
public content::NotificationObserver {
public:
// |pref_service| may be NULL (for unit tests), but in that case no
@@ -106,12 +105,6 @@ class SyncPrefs : public base::SupportsWeakPtr<SyncPrefs>,
void SetSpareBootstrapToken(const std::string& token);
#endif
- // InvalidationStateTracker implementation.
- virtual sync_notifier::InvalidationVersionMap
- GetAllMaxVersions() const OVERRIDE;
- virtual void SetMaxVersion(syncable::ModelType model_type,
- int64 max_version) OVERRIDE;
-
// Merges the given set of types with the set of acknowledged types.
void AcknowledgeSyncedTypes(syncable::ModelTypeSet types);
diff --git a/chrome/browser/sync/sync_prefs_unittest.cc b/chrome/browser/sync/sync_prefs_unittest.cc
index a52432e..351d681 100644
--- a/chrome/browser/sync/sync_prefs_unittest.cc
+++ b/chrome/browser/sync/sync_prefs_unittest.cc
@@ -125,29 +125,6 @@ TEST_F(SyncPrefsTest, PreferredTypesNotKeepEverythingSynced) {
}
}
-TEST_F(SyncPrefsTest, MaxInvalidationVersions) {
- SyncPrefs sync_prefs(&pref_service_);
-
- sync_notifier::InvalidationVersionMap expected_max_versions;
- EXPECT_EQ(expected_max_versions, sync_prefs.GetAllMaxVersions());
-
- expected_max_versions[syncable::BOOKMARKS] = 2;
- sync_prefs.SetMaxVersion(syncable::BOOKMARKS, 2);
- EXPECT_EQ(expected_max_versions, sync_prefs.GetAllMaxVersions());
-
- expected_max_versions[syncable::PREFERENCES] = 5;
- sync_prefs.SetMaxVersion(syncable::PREFERENCES, 5);
- EXPECT_EQ(expected_max_versions, sync_prefs.GetAllMaxVersions());
-
- expected_max_versions[syncable::APP_NOTIFICATIONS] = 3;
- sync_prefs.SetMaxVersion(syncable::APP_NOTIFICATIONS, 3);
- EXPECT_EQ(expected_max_versions, sync_prefs.GetAllMaxVersions());
-
- expected_max_versions[syncable::APP_NOTIFICATIONS] = 4;
- sync_prefs.SetMaxVersion(syncable::APP_NOTIFICATIONS, 4);
- EXPECT_EQ(expected_max_versions, sync_prefs.GetAllMaxVersions());
-}
-
class MockSyncPrefObserver : public SyncPrefObserver {
public:
MOCK_METHOD1(OnSyncManagedPrefChange, void(bool));
@@ -195,7 +172,6 @@ TEST_F(SyncPrefsTest, ClearPreferences) {
EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted());
EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime());
EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
- EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty());
sync_prefs.SetSyncSetupCompleted();
sync_prefs.SetLastSyncedTime(base::Time::Now());
@@ -204,19 +180,12 @@ TEST_F(SyncPrefsTest, ClearPreferences) {
EXPECT_TRUE(sync_prefs.HasSyncSetupCompleted());
EXPECT_NE(base::Time(), sync_prefs.GetLastSyncedTime());
EXPECT_EQ("token", sync_prefs.GetEncryptionBootstrapToken());
- {
- sync_notifier::InvalidationVersionMap expected_max_versions;
- expected_max_versions[syncable::APP_NOTIFICATIONS] = 3;
- sync_prefs.SetMaxVersion(syncable::APP_NOTIFICATIONS, 3);
- EXPECT_EQ(expected_max_versions, sync_prefs.GetAllMaxVersions());
- }
sync_prefs.ClearPreferences();
EXPECT_FALSE(sync_prefs.HasSyncSetupCompleted());
EXPECT_EQ(base::Time(), sync_prefs.GetLastSyncedTime());
EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
- EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty());
}
TEST_F(SyncPrefsTest, NullPrefService) {
@@ -230,7 +199,6 @@ TEST_F(SyncPrefsTest, NullPrefService) {
EXPECT_TRUE(sync_prefs.GetPreferredDataTypes(non_passive_types).Empty());
EXPECT_FALSE(sync_prefs.IsManaged());
EXPECT_TRUE(sync_prefs.GetEncryptionBootstrapToken().empty());
- EXPECT_TRUE(sync_prefs.GetAllMaxVersions().empty());
}
} // namespace
diff --git a/chrome/browser/sync/test_profile_sync_service.cc b/chrome/browser/sync/test_profile_sync_service.cc
index d99fdbc..60c881b 100644
--- a/chrome/browser/sync/test_profile_sync_service.cc
+++ b/chrome/browser/sync/test_profile_sync_service.cc
@@ -31,12 +31,13 @@ namespace browser_sync {
SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest(
Profile* profile,
const base::WeakPtr<SyncPrefs>& sync_prefs,
+ const base::WeakPtr<InvalidatorStorage>& invalidator_storage,
bool set_initial_sync_ended_on_init,
bool synchronous_init,
bool fail_initial_download,
bool use_real_database)
: browser_sync::SyncBackendHost(
- profile->GetDebugName(), profile, sync_prefs),
+ profile->GetDebugName(), profile, sync_prefs, invalidator_storage),
synchronous_init_(synchronous_init),
fail_initial_download_(fail_initial_download),
use_real_database_(use_real_database) {}
@@ -225,6 +226,7 @@ void TestProfileSyncService::CreateBackend() {
backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest(
profile(),
sync_prefs_.AsWeakPtr(),
+ invalidator_storage_.AsWeakPtr(),
set_initial_sync_ended_on_init_,
synchronous_backend_initialization_,
fail_initial_download_,
diff --git a/chrome/browser/sync/test_profile_sync_service.h b/chrome/browser/sync/test_profile_sync_service.h
index 6869486..1227e5f 100644
--- a/chrome/browser/sync/test_profile_sync_service.h
+++ b/chrome/browser/sync/test_profile_sync_service.h
@@ -12,7 +12,9 @@
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/sync/glue/data_type_manager_impl.h"
+#include "chrome/browser/sync/invalidations/invalidator_storage.h"
#include "chrome/browser/sync/profile_sync_service.h"
+#include "chrome/browser/sync/sync_prefs.h"
#include "chrome/test/base/profile_mock.h"
#include "sync/test/engine/test_id_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -34,6 +36,7 @@ class SyncBackendHostForProfileSyncTest : public SyncBackendHost {
SyncBackendHostForProfileSyncTest(
Profile* profile,
const base::WeakPtr<SyncPrefs>& sync_prefs,
+ const base::WeakPtr<InvalidatorStorage>& invalidator_storage,
bool set_initial_sync_ended_on_init,
bool synchronous_init,
bool fail_initial_download,