summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-30 02:34:48 +0000
committertim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-30 02:34:48 +0000
commit7800d79ee9ecdfcca77ba895b7679c8f1fb85ee4 (patch)
treee56bacac84e7ab2ce10ff5b5adcff85859fdbb38
parent2404a282786943958a5fce4cd111dfa538ae0a33 (diff)
downloadchromium_src-7800d79ee9ecdfcca77ba895b7679c8f1fb85ee4.zip
chromium_src-7800d79ee9ecdfcca77ba895b7679c8f1fb85ee4.tar.gz
chromium_src-7800d79ee9ecdfcca77ba895b7679c8f1fb85ee4.tar.bz2
sync: move invalidation version prefs out of SyncPrefs into InvalidatorStorage.
De-coupling so we don't add more sync < > invalidations deps while adding support for storing opaque notification state in InvalidationStateTracker. Added get/setters to InvalidationStateTracker and impl (InvalidatorStorage), but it's not wired up for use yet. Next step is to add migration code to move state from syncable::Directory to InvalidationStateTracker. Comment in invalidator_storage.h explains motivations for not moving out of sync. This patch creates the c/b/s/invalidations directory, which we can move non-profile-sync-specific chrome invalidations code to (such as BridgedSyncNotifier, and the android related part of ChromeSyncNotificationsBridge). BUG=124140 TEST=InvalidatorStorageTest, should be no functional changes Review URL: https://chromiumcodereview.appspot.com/10451058 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139464 0039d316-1c4b-4281-b951-d872f2087c98
-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
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/common/pref_names.h2
-rw-r--r--sync/notifier/chrome_invalidation_client_unittest.cc2
-rw-r--r--sync/notifier/invalidation_state_tracker.h6
-rw-r--r--sync/notifier/non_blocking_invalidation_notifier.cc4
-rw-r--r--sync/notifier/non_blocking_invalidation_notifier.h1
-rw-r--r--sync/tools/sync_listen_notifications.cc8
22 files changed, 405 insertions, 123 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,
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 588111e..1950a9949 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2168,6 +2168,8 @@
'browser/sync/glue/ui_data_type_controller.h',
'browser/sync/glue/ui_model_worker.cc',
'browser/sync/glue/ui_model_worker.h',
+ 'browser/sync/invalidations/invalidator_storage.cc',
+ 'browser/sync/invalidations/invalidator_storage.h',
'browser/sync/backend_migrator.cc',
'browser/sync/backend_migrator.h',
'browser/sync/backend_unrecoverable_error_handler.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 15782e6..c866587 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1547,6 +1547,7 @@
'browser/sync/glue/typed_url_model_associator_unittest.cc',
'browser/sync/glue/ui_data_type_controller_unittest.cc',
'browser/sync/glue/ui_model_worker_unittest.cc',
+ 'browser/sync/invalidations/invalidator_storage_unittest.cc',
'browser/sync/profile_sync_components_factory_impl_unittest.cc',
'browser/sync/profile_sync_components_factory_mock.cc',
'browser/sync/profile_sync_components_factory_mock.h',
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index b377f92..d4e05ea 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -1553,6 +1553,9 @@ const char kSyncMaxInvalidationVersions[] = "sync.max_invalidation_versions";
// disable/enable events.
const char kSyncSessionsGUID[] = "sync.session_sync_guid";
+// Opaque state from the invalidation subsystem that is persisted via prefs.
+const char kInvalidatorInvalidationState[] = "invalidator.invalidation_state";
+
// A string that can be used to restore sync encryption infrastructure on
// startup so that the user doesn't need to provide credentials on each start.
const char kSyncEncryptionBootstrapToken[] =
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index db8ef20..4037455 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -576,6 +576,8 @@ extern const char kSyncAcknowledgedSyncTypes[];
extern const char kSyncMaxInvalidationVersions[];
extern const char kSyncSessionsGUID[];
+extern const char kInvalidatorInvalidationState[];
+
extern const char kSyncPromoStartupCount[];
extern const char kSyncPromoViewCount[];
extern const char kSyncPromoUserSkipped[];
diff --git a/sync/notifier/chrome_invalidation_client_unittest.cc b/sync/notifier/chrome_invalidation_client_unittest.cc
index 225eab6..2892491 100644
--- a/sync/notifier/chrome_invalidation_client_unittest.cc
+++ b/sync/notifier/chrome_invalidation_client_unittest.cc
@@ -52,6 +52,8 @@ class MockInvalidationStateTracker
public:
MOCK_CONST_METHOD0(GetAllMaxVersions, InvalidationVersionMap());
MOCK_METHOD2(SetMaxVersion, void(syncable::ModelType, int64));
+ MOCK_CONST_METHOD0(GetInvalidationState, std::string());
+ MOCK_METHOD1(SetInvalidationState, void(const std::string&));
};
class MockStateWriter : public StateWriter {
diff --git a/sync/notifier/invalidation_state_tracker.h b/sync/notifier/invalidation_state_tracker.h
index dc8ef26..12568e6 100644
--- a/sync/notifier/invalidation_state_tracker.h
+++ b/sync/notifier/invalidation_state_tracker.h
@@ -28,6 +28,12 @@ class InvalidationStateTracker {
virtual void SetMaxVersion(syncable::ModelType model_type,
int64 max_version) = 0;
+ // Used by InvalidationClient for persistence. |state| is opaque data we can
+ // present back to the client (e.g. after a restart) for it to bootstrap
+ // itself.
+ virtual void SetInvalidationState(const std::string& state) = 0;
+ virtual std::string GetInvalidationState() const = 0;
+
protected:
virtual ~InvalidationStateTracker() {}
};
diff --git a/sync/notifier/non_blocking_invalidation_notifier.cc b/sync/notifier/non_blocking_invalidation_notifier.cc
index b6436a1..8830a23 100644
--- a/sync/notifier/non_blocking_invalidation_notifier.cc
+++ b/sync/notifier/non_blocking_invalidation_notifier.cc
@@ -14,6 +14,7 @@ namespace sync_notifier {
class NonBlockingInvalidationNotifier::Core
: public base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>,
+ // SyncNotifierObserver to observe the InvalidationNotifier we create.
public SyncNotifierObserver {
public:
// Called on parent thread. |delegate_observer| should be
@@ -35,7 +36,8 @@ class NonBlockingInvalidationNotifier::Core
void UpdateCredentials(const std::string& email, const std::string& token);
void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types);
- // SyncNotifierObserver implementation (all called on I/O thread).
+ // SyncNotifierObserver implementation (all called on I/O thread by
+ // InvalidationNotifier).
virtual void OnIncomingNotification(
const syncable::ModelTypePayloadMap& type_payloads,
IncomingNotificationSource source);
diff --git a/sync/notifier/non_blocking_invalidation_notifier.h b/sync/notifier/non_blocking_invalidation_notifier.h
index 1189403..58002f4 100644
--- a/sync/notifier/non_blocking_invalidation_notifier.h
+++ b/sync/notifier/non_blocking_invalidation_notifier.h
@@ -30,6 +30,7 @@ namespace sync_notifier {
class NonBlockingInvalidationNotifier
: public SyncNotifier,
+ // SyncNotifierObserver to "observe" our Core via WeakHandle.
public SyncNotifierObserver {
public:
// |invalidation_state_tracker| must be initialized.
diff --git a/sync/tools/sync_listen_notifications.cc b/sync/tools/sync_listen_notifications.cc
index 41ed284..9e8948b 100644
--- a/sync/tools/sync_listen_notifications.cc
+++ b/sync/tools/sync_listen_notifications.cc
@@ -85,6 +85,14 @@ class NullInvalidationStateTracker
<< syncable::ModelTypeToString(model_type) << " to "
<< max_invalidation_version;
}
+
+ virtual std::string GetInvalidationState() const OVERRIDE {
+ return std::string();
+ }
+
+ virtual void SetInvalidationState(const std::string& state) OVERRIDE {
+ LOG(INFO) << "Setting invalidation state to: " << state;
+ }
};
const char kEmailSwitch[] = "email";