summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/glue
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-12 03:04:13 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-12 03:04:13 +0000
commite3b0ee5f1dc1647f3f00439c9a7f9bb7e97345dd (patch)
tree1a3d69ff713b154f619f2115aab7284bbe6cac5e /chrome/browser/sync/glue
parent8c9add0068743ba549a235e4748e686d8622f3b3 (diff)
downloadchromium_src-e3b0ee5f1dc1647f3f00439c9a7f9bb7e97345dd.zip
chromium_src-e3b0ee5f1dc1647f3f00439c9a7f9bb7e97345dd.tar.gz
chromium_src-e3b0ee5f1dc1647f3f00439c9a7f9bb7e97345dd.tar.bz2
[Sync] Persist invalidation versions to preferences
Define InvalidationVersionTracker interface and make SyncPrefs inherit from it. Pass down SyncPrefs (as InvalidationVersionTracker) all the way down to ChromeInvalidationClient and call it when there is a new max invalidation version. Pass SyncBackendHost a WeakPtr instead of a raw pointer to SyncPrefs. Made sync_listen_notifications work again. BUG=85286 TEST= Review URL: http://codereview.chromium.org/8188006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104983 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/glue')
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.cc23
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.h10
-rw-r--r--chrome/browser/sync/glue/sync_backend_host_unittest.cc3
3 files changed, 22 insertions, 14 deletions
diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc
index 1a322cb..4e6c7c4 100644
--- a/chrome/browser/sync/glue/sync_backend_host.cc
+++ b/chrome/browser/sync/glue/sync_backend_host.cc
@@ -58,7 +58,7 @@ using sync_api::SyncCredentials;
SyncBackendHost::SyncBackendHost(const std::string& name,
Profile* profile,
- SyncPrefs* sync_prefs)
+ const base::WeakPtr<SyncPrefs>& sync_prefs)
: core_(new Core(name, ALLOW_THIS_IN_INITIALIZER_LIST(this))),
initialization_state_(NOT_ATTEMPTED),
sync_thread_("Chrome_SyncThread"),
@@ -66,14 +66,15 @@ SyncBackendHost::SyncBackendHost(const std::string& name,
profile_(profile),
sync_prefs_(sync_prefs),
name_(name),
- sync_notifier_factory_(webkit_glue::GetUserAgent(GURL()),
- profile_->GetRequestContext(),
- *CommandLine::ForCurrentProcess()),
+ sync_notifier_factory_(
+ webkit_glue::GetUserAgent(GURL()),
+ profile_->GetRequestContext(),
+ sync_prefs,
+ *CommandLine::ForCurrentProcess()),
frontend_(NULL),
sync_data_folder_path_(
profile_->GetPath().Append(kSyncDataFolderName)),
last_auth_error_(AuthError::None()) {
- CHECK(sync_prefs_);
}
SyncBackendHost::SyncBackendHost()
@@ -81,11 +82,12 @@ SyncBackendHost::SyncBackendHost()
sync_thread_("Chrome_SyncThread"),
frontend_loop_(MessageLoop::current()),
profile_(NULL),
- sync_prefs_(NULL),
name_("Unknown"),
- sync_notifier_factory_(webkit_glue::GetUserAgent(GURL()),
- NULL,
- *CommandLine::ForCurrentProcess()),
+ sync_notifier_factory_(
+ webkit_glue::GetUserAgent(GURL()),
+ NULL,
+ base::WeakPtr<sync_notifier::InvalidationVersionTracker>(),
+ *CommandLine::ForCurrentProcess()),
frontend_(NULL),
last_auth_error_(AuthError::None()) {
}
@@ -109,6 +111,7 @@ void SyncBackendHost::Initialize(
DCHECK(frontend);
syncable::ModelTypeSet initial_types_with_nigori(initial_types);
+ CHECK(sync_prefs_.get());
if (sync_prefs_->HasSyncSetupCompleted()) {
initial_types_with_nigori.insert(syncable::NIGORI);
}
@@ -884,6 +887,7 @@ void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(
// If setup has completed, start off in DOWNLOADING_NIGORI so that
// we start off by refreshing encryption.
+ CHECK(sync_prefs_.get());
if (sync_prefs_->HasSyncSetupCompleted() &&
initialization_state_ < DOWNLOADING_NIGORI) {
initialization_state_ = DOWNLOADING_NIGORI;
@@ -994,6 +998,7 @@ sync_api::HttpPostProviderFactory* SyncBackendHost::MakeHttpBridgeFactory(
void SyncBackendHost::PersistEncryptionBootstrapToken(
const std::string& token) {
+ CHECK(sync_prefs_.get());
sync_prefs_->SetEncryptionBootstrapToken(token);
}
diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h
index f92c7d4..0fba6ca 100644
--- a/chrome/browser/sync/glue/sync_backend_host.h
+++ b/chrome/browser/sync/glue/sync_backend_host.h
@@ -15,6 +15,7 @@
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
#include "base/timer.h"
#include "chrome/browser/sync/engine/model_safe_worker.h"
@@ -122,10 +123,11 @@ class SyncBackendHost {
// 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). Does not take
- // ownership of |sync_prefs|.
+ // the same thread it used to call the constructor). Must outlive
+ // |sync_prefs|.
SyncBackendHost(const std::string& name,
- Profile* profile, SyncPrefs* sync_prefs);
+ Profile* profile,
+ const base::WeakPtr<SyncPrefs>& sync_prefs);
// For testing.
// TODO(skrul): Extract an interface so this is not needed.
SyncBackendHost();
@@ -552,7 +554,7 @@ class SyncBackendHost {
Profile* const profile_;
- SyncPrefs* const sync_prefs_;
+ const base::WeakPtr<SyncPrefs> sync_prefs_;
// Name used for debugging (set from profile_->GetDebugName()).
const std::string name_;
diff --git a/chrome/browser/sync/glue/sync_backend_host_unittest.cc b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
index dac72d5..57822ed 100644
--- a/chrome/browser/sync/glue/sync_backend_host_unittest.cc
+++ b/chrome/browser/sync/glue/sync_backend_host_unittest.cc
@@ -85,7 +85,8 @@ TEST_F(SyncBackendHostTest, InitShutdown) {
profile.CreateRequestContext();
SyncPrefs sync_prefs(profile.GetPrefs());
- SyncBackendHost backend(profile.GetDebugName(), &profile, &sync_prefs);
+ SyncBackendHost backend(profile.GetDebugName(),
+ &profile, sync_prefs.AsWeakPtr());
MockSyncFrontend mock_frontend;
sync_api::SyncCredentials credentials;