#include "chrome/browser/sync/glue/synced_device_tracker.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
+#include "sync/internal_api/public/events/protocol_event.h"
#include "sync/internal_api/public/http_post_provider_factory.h"
#include "sync/internal_api/public/internal_components_factory.h"
+#include "sync/internal_api/public/sessions/commit_counters.h"
+#include "sync/internal_api/public/sessions/status_counters.h"
#include "sync/internal_api/public/sessions/sync_session_snapshot.h"
+#include "sync/internal_api/public/sessions/update_counters.h"
+#include "sync/internal_api/public/sync_core_proxy.h"
#include "sync/internal_api/public/sync_manager.h"
#include "sync/internal_api/public/sync_manager_factory.h"
sync_loop_(NULL),
registrar_(NULL),
has_sync_setup_completed_(has_sync_setup_completed),
+ forward_protocol_events_(false),
weak_ptr_factory_(this) {
DCHECK(backend.get());
}
type);
}
-void SyncBackendHostCore::OnStopSyncingPermanently() {
- if (!sync_loop_)
- return;
- DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
- host_.Call(
- FROM_HERE,
- &SyncBackendHostImpl::HandleStopSyncingPermanentlyOnFrontendLoop);
-}
-
void SyncBackendHostCore::OnEncryptedTypesChanged(
syncer::ModelTypeSet encrypted_types,
bool encrypt_everything) {
type, passphrase_time);
}
+void SyncBackendHostCore::OnCommitCountersUpdated(
+ syncer::ModelType type,
+ const syncer::CommitCounters& counters) {
+ host_.Call(
+ FROM_HERE,
+ &SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop,
+ type, counters);
+}
+
+void SyncBackendHostCore::OnUpdateCountersUpdated(
+ syncer::ModelType type,
+ const syncer::UpdateCounters& counters) {
+ host_.Call(
+ FROM_HERE,
+ &SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop,
+ type, counters);
+}
+
+void SyncBackendHostCore::OnStatusCountersUpdated(
+ syncer::ModelType type,
+ const syncer::StatusCounters& counters) {
+ host_.Call(
+ FROM_HERE,
+ &SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop,
+ type, counters);
+}
+
void SyncBackendHostCore::OnActionableError(
const syncer::SyncProtocolError& sync_error) {
if (!sync_loop_)
sync_error);
}
+void SyncBackendHostCore::OnMigrationRequested(syncer::ModelTypeSet types) {
+ DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
+ host_.Call(
+ FROM_HERE,
+ &SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop,
+ types);
+}
+
+void SyncBackendHostCore::OnProtocolEvent(
+ const syncer::ProtocolEvent& event) {
+ // TODO(rlarocque): Find a way to pass event_clone as a scoped_ptr.
+ if (forward_protocol_events_) {
+ scoped_ptr<syncer::ProtocolEvent> event_clone(event.Clone());
+ host_.Call(
+ FROM_HERE,
+ &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop,
+ event_clone.release());
+ }
+}
+
void SyncBackendHostCore::DoOnInvalidatorStateChange(
syncer::InvalidatorState state) {
DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
}
void SyncBackendHostCore::DoFinishInitialProcessControlTypes() {
+ DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
+
registrar_->ActivateDataType(syncer::DEVICE_INFO,
syncer::GROUP_PASSIVE,
synced_device_tracker_.get(),
FROM_HERE,
&SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop,
js_backend_,
- debug_info_listener_);
+ debug_info_listener_,
+ sync_manager_->GetSyncCoreProxy());
js_backend_.Reset();
debug_info_listener_.Reset();
DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
if (sync_manager_) {
save_changes_timer_.reset();
+ DisableDirectoryTypeDebugInfoForwarding();
sync_manager_->RemoveObserver(this);
sync_manager_->ShutdownOnSyncThread();
sync_manager_.reset();
retry_callback);
}
+void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() {
+ DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
+ forward_protocol_events_ = true;
+
+ if (sync_manager_) {
+ // Grab our own copy of the buffered events.
+ // The buffer is not modified by this operation.
+ std::vector<syncer::ProtocolEvent*> buffered_events;
+ sync_manager_->GetBufferedProtocolEvents().release(&buffered_events);
+
+ // Send them all over the fence to the host.
+ for (std::vector<syncer::ProtocolEvent*>::iterator it =
+ buffered_events.begin(); it != buffered_events.end(); ++it) {
+ // TODO(rlarocque): Make it explicit that host_ takes ownership.
+ host_.Call(
+ FROM_HERE,
+ &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop,
+ *it);
+ }
+ }
+}
+
+void SyncBackendHostCore::DisableProtocolEventForwarding() {
+ forward_protocol_events_ = false;
+}
+
+void SyncBackendHostCore::EnableDirectoryTypeDebugInfoForwarding() {
+ DCHECK(sync_manager_);
+ if (!sync_manager_->HasDirectoryTypeDebugInfoObserver(this))
+ sync_manager_->RegisterDirectoryTypeDebugInfoObserver(this);
+ sync_manager_->RequestEmitDebugInfo();
+}
+
+void SyncBackendHostCore::DisableDirectoryTypeDebugInfoForwarding() {
+ DCHECK(sync_manager_);
+ if (sync_manager_->HasDirectoryTypeDebugInfoObserver(this))
+ sync_manager_->UnregisterDirectoryTypeDebugInfoObserver(this);
+}
+
void SyncBackendHostCore::DeleteSyncDataFolder() {
DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
if (base::DirectoryExists(sync_data_folder_path_)) {
}
}
+void SyncBackendHostCore::GetAllNodesForTypes(
+ syncer::ModelTypeSet types,
+ scoped_refptr<base::SequencedTaskRunner> task_runner,
+ base::Callback<void(const std::vector<syncer::ModelType>& type,
+ ScopedVector<base::ListValue>)> callback) {
+ std::vector<syncer::ModelType> types_vector;
+ ScopedVector<base::ListValue> node_lists;
+
+ syncer::ModelSafeRoutingInfo routes;
+ registrar_->GetModelSafeRoutingInfo(&routes);
+ syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routes);
+
+ for (syncer::ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) {
+ types_vector.push_back(it.Get());
+ if (!enabled_types.Has(it.Get())) {
+ node_lists.push_back(new base::ListValue());
+ } else {
+ node_lists.push_back(
+ sync_manager_->GetAllNodesForType(it.Get()).release());
+ }
+ }
+
+ task_runner->PostTask(
+ FROM_HERE,
+ base::Bind(callback, types_vector, base::Passed(&node_lists)));
+}
+
void SyncBackendHostCore::StartSavingChanges() {
// We may already be shut down.
if (!sync_loop_)