Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1644)

Unified Diff: chrome/browser/sync/glue/sync_backend_host.cc

Issue 10805002: [Sync] Enable adding notifier observers from ProfileSyncService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typos Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/glue/sync_backend_host.cc
diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc
index 295bb8c5f7ea6b4d89007e75e9ce6f0fe54bda97..49f2464d20d130fdf6246f8ec157b0c57519caef 100644
--- a/chrome/browser/sync/glue/sync_backend_host.cc
+++ b/chrome/browser/sync/glue/sync_backend_host.cc
@@ -43,8 +43,8 @@
#include "net/url_request/url_request_context_getter.h"
#include "sync/internal_api/public/base_transaction.h"
#include "sync/internal_api/public/engine/model_safe_worker.h"
-#include "sync/internal_api/public/internal_components_factory_impl.h"
#include "sync/internal_api/public/http_bridge.h"
+#include "sync/internal_api/public/internal_components_factory_impl.h"
#include "sync/internal_api/public/read_transaction.h"
#include "sync/internal_api/public/sync_manager_factory.h"
#include "sync/internal_api/public/util/experiments.h"
@@ -78,7 +78,8 @@ using syncer::SyncCredentials;
class SyncBackendHost::Core
: public base::RefCountedThreadSafe<SyncBackendHost::Core>,
- public syncer::SyncManager::Observer {
+ public syncer::SyncManager::Observer,
+ public syncer::SyncNotifierObserver {
public:
Core(const std::string& name,
const FilePath& sync_data_folder_path,
@@ -110,6 +111,14 @@ class SyncBackendHost::Core
virtual void OnActionableError(
const syncer::SyncProtocolError& sync_error) OVERRIDE;
+ // syncer::SyncNotifierObserver implementation.
+ virtual void OnNotificationsEnabled() OVERRIDE;
+ virtual void OnNotificationsDisabled(
+ syncer::NotificationsDisabledReason reason) OVERRIDE;
+ virtual void OnIncomingNotification(
+ const syncer::ObjectIdPayloadMap& id_payloads,
+ syncer::IncomingNotificationSource source) OVERRIDE;
+
// Note:
//
// The Do* methods are the various entry points from our
@@ -125,6 +134,10 @@ class SyncBackendHost::Core
// SyncBackendHost::UpdateCredentials
void DoUpdateCredentials(const syncer::SyncCredentials& credentials);
+ // Called to update the given registered ids on behalf of
+ // SyncBackendHost::UpdateRegisteredIds
+ void DoUpdateRegisteredIds(const syncer::ObjectIdSet& ids);
+
// Called to tell the syncapi to start syncing (generally after
// initialization and authentication).
void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info);
@@ -422,6 +435,14 @@ void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) {
credentials));
}
+void SyncBackendHost::UpdateRegisteredIds(const syncer::ObjectIdSet& ids) {
+ DCHECK_EQ(MessageLoop::current(), frontend_loop_);
+ DCHECK(sync_thread_.IsRunning());
+ sync_thread_.message_loop()->PostTask(FROM_HERE,
+ base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredIds,
+ core_.get(), ids));
+}
+
void SyncBackendHost::StartSyncingWithServer() {
SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called.";
@@ -950,6 +971,35 @@ void SyncBackendHost::Core::OnActionableError(
sync_error);
}
+void SyncBackendHost::Core::OnNotificationsEnabled() {
+ if (!sync_loop_)
+ return;
+ DCHECK_EQ(MessageLoop::current(), sync_loop_);
+ host_.Call(FROM_HERE,
+ &SyncBackendHost::HandleNotificationsEnabledOnFrontendLoop);
+}
+
+void SyncBackendHost::Core::OnNotificationsDisabled(
+ syncer::NotificationsDisabledReason reason) {
+ if (!sync_loop_)
+ return;
+ DCHECK_EQ(MessageLoop::current(), sync_loop_);
+ host_.Call(FROM_HERE,
+ &SyncBackendHost::HandleNotificationsDisabledOnFrontendLoop,
+ reason);
+}
+
+void SyncBackendHost::Core::OnIncomingNotification(
+ const syncer::ObjectIdPayloadMap& id_payloads,
+ syncer::IncomingNotificationSource source) {
+ if (!sync_loop_)
+ return;
+ DCHECK_EQ(MessageLoop::current(), sync_loop_);
+ host_.Call(FROM_HERE,
+ &SyncBackendHost::HandleIncomingNotificationOnFrontendLoop,
+ id_payloads, source);
+}
+
void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) {
DCHECK(!sync_loop_);
sync_loop_ = options.sync_loop;
@@ -1017,6 +1067,12 @@ void SyncBackendHost::Core::DoUpdateCredentials(
sync_manager_->UpdateCredentials(credentials);
}
+void SyncBackendHost::Core::DoUpdateRegisteredIds(
+ const syncer::ObjectIdSet& ids) {
+ DCHECK_EQ(MessageLoop::current(), sync_loop_);
+ sync_manager_->UpdateRegisteredIds(this, ids);
+}
+
void SyncBackendHost::Core::DoStartSyncing(
const syncer::ModelSafeRoutingInfo& routing_info) {
DCHECK_EQ(MessageLoop::current(), sync_loop_);
@@ -1061,6 +1117,7 @@ void SyncBackendHost::Core::DoShutdown(bool sync_disabled) {
return;
save_changes_timer_.reset();
+ sync_manager_->UpdateRegisteredIds(this, syncer::ObjectIdSet());
sync_manager_->ShutdownOnSyncThread();
sync_manager_->RemoveObserver(this);
sync_manager_.reset();
@@ -1272,6 +1329,30 @@ void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop(
frontend_->OnActionableError(sync_error);
}
+void SyncBackendHost::HandleNotificationsEnabledOnFrontendLoop() {
+ if (!frontend_)
+ return;
+ DCHECK_EQ(MessageLoop::current(), frontend_loop_);
+ frontend_->OnNotificationsEnabled();
+}
+
+void SyncBackendHost::HandleNotificationsDisabledOnFrontendLoop(
+ syncer::NotificationsDisabledReason reason) {
+ if (!frontend_)
+ return;
+ DCHECK_EQ(MessageLoop::current(), frontend_loop_);
+ frontend_->OnNotificationsDisabled(reason);
+}
+
+void SyncBackendHost::HandleIncomingNotificationOnFrontendLoop(
+ const syncer::ObjectIdPayloadMap& id_payloads,
+ syncer::IncomingNotificationSource source) {
+ if (!frontend_)
+ return;
+ DCHECK_EQ(MessageLoop::current(), frontend_loop_);
+ frontend_->OnIncomingNotification(id_payloads, source);
+}
+
bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys(
const std::string& passphrase) const {
DCHECK(cached_pending_keys_.has_blob());

Powered by Google App Engine
This is Rietveld 408576698