#include "sync/js/js_reply_handler.h"
#include "sync/notifier/invalidation_util.h"
#include "sync/notifier/invalidator.h"
+#include "sync/notifier/object_id_invalidation_map.h"
#include "sync/protocol/proto_value_conversions.h"
#include "sync/protocol/sync.pb.h"
#include "sync/syncable/directory.h"
"getNotificationInfo",
&SyncManagerImpl::GetNotificationInfo);
BindJsMessageHandler(
- "getRootNodeDetails",
- &SyncManagerImpl::GetRootNodeDetails);
- BindJsMessageHandler(
- "getNodeSummariesById",
- &SyncManagerImpl::GetNodeSummariesById);
- BindJsMessageHandler(
- "getNodeDetailsById",
- &SyncManagerImpl::GetNodeDetailsById);
- BindJsMessageHandler(
"getAllNodes",
&SyncManagerImpl::GetAllNodes);
BindJsMessageHandler(
- "getChildNodeIds",
- &SyncManagerImpl::GetChildNodeIds);
- BindJsMessageHandler(
"getClientServerTraffic",
&SyncManagerImpl::GetClientServerTraffic);
}
ConfigurationParams params(GetSourceFromReason(reason),
to_download,
new_routing_info,
- ready_task);
+ ready_task,
+ retry_task);
scheduler_->Start(SyncScheduler::CONFIGURATION_MODE);
- if (!scheduler_->ScheduleConfiguration(params))
- retry_task.Run();
+ scheduler_->ScheduleConfiguration(params);
}
void SyncManagerImpl::Init(
int port,
bool use_ssl,
scoped_ptr<HttpPostProviderFactory> post_factory,
- const std::vector<ModelSafeWorker*>& workers,
+ const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
ExtensionsActivity* extensions_activity,
SyncManager::ChangeDelegate* change_delegate,
const SyncCredentials& credentials,
std::string sync_id = directory()->cache_guid();
+ DVLOG(1) << "Setting sync client ID: " << sync_id;
allstatus_.SetSyncId(sync_id);
+ DVLOG(1) << "Setting invalidator client ID: " << invalidator_client_id;
allstatus_.SetInvalidatorClientId(invalidator_client_id);
- DVLOG(1) << "Setting sync client ID: " << sync_id;
- DVLOG(1) << "Setting invalidator client ID: " << invalidator_client_id;
+ model_type_registry_.reset(new ModelTypeRegistry(workers, directory()));
// Build a SyncSessionContext and store the worker in it.
DVLOG(1) << "Sync is bringing up SyncSessionContext.";
session_context_ = internal_components_factory->BuildContext(
connection_manager_.get(),
directory(),
- workers,
extensions_activity,
listeners,
&debug_info_event_listener_,
&traffic_recorder_,
+ model_type_registry_.get(),
invalidator_client_id).Pass();
session_context_->set_account_name(credentials.email);
scheduler_ = internal_components_factory->BuildScheduler(
// appropriately set and that it's only modified when switching to normal
// mode.
DCHECK(thread_checker_.CalledOnValidThread());
- session_context_->set_routing_info(routing_info);
+ session_context_->SetRoutingInfo(routing_info);
scheduler_->Start(SyncScheduler::NORMAL_MODE);
}
scheduler_.reset();
session_context_.reset();
+ model_type_registry_.reset();
if (sync_encryption_handler_) {
sync_encryption_handler_->RemoveObserver(&debug_info_event_listener_);
nudge_location);
}
-void SyncManagerImpl::OnSyncEngineEvent(const SyncEngineEvent& event) {
+void SyncManagerImpl::OnSyncCycleEvent(const SyncCycleEvent& event) {
DCHECK(thread_checker_.CalledOnValidThread());
// Only send an event if this is due to a cycle ending and this cycle
// concludes a canonical "sync" process; that is, based on what is known
//
// Notifications are sent at the end of every sync cycle, regardless of
// whether we should sync again.
- if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) {
+ if (event.what_happened == SyncCycleEvent::SYNC_CYCLE_ENDED) {
if (!initialized_) {
- LOG(INFO) << "OnSyncCycleCompleted not sent because sync api is not "
- << "initialized";
+ DVLOG(1) << "OnSyncCycleCompleted not sent because sync api is not "
+ << "initialized";
return;
}
FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
OnSyncCycleCompleted(event.snapshot));
}
+}
- if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) {
- FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
- OnStopSyncingPermanently());
- return;
- }
+void SyncManagerImpl::OnActionableError(const SyncProtocolError& error) {
+ FOR_EACH_OBSERVER(
+ SyncManager::Observer, observers_,
+ OnActionableError(error));
+}
- if (event.what_happened == SyncEngineEvent::ACTIONABLE_ERROR) {
- FOR_EACH_OBSERVER(
- SyncManager::Observer, observers_,
- OnActionableError(
- event.snapshot.model_neutral_state().sync_protocol_error));
- return;
- }
+void SyncManagerImpl::OnRetryTimeChanged(base::Time) {}
+
+void SyncManagerImpl::OnThrottledTypesChanged(ModelTypeSet) {}
+
+void SyncManagerImpl::OnMigrationRequested(ModelTypeSet types) {
+ FOR_EACH_OBSERVER(
+ SyncManager::Observer, observers_,
+ OnMigrationRequested(types));
}
void SyncManagerImpl::SetJsEventHandler(
return JsArgList(&return_args);
}
-JsArgList SyncManagerImpl::GetRootNodeDetails(
- const JsArgList& args) {
- ReadTransaction trans(FROM_HERE, GetUserShare());
- ReadNode root(&trans);
- root.InitByRootLookup();
- base::ListValue return_args;
- return_args.Append(root.GetDetailsAsValue());
- return JsArgList(&return_args);
-}
-
JsArgList SyncManagerImpl::GetClientServerTraffic(
const JsArgList& args) {
base::ListValue return_args;
return JsArgList(&return_args);
}
-namespace {
-
-int64 GetId(const base::ListValue& ids, int i) {
- std::string id_str;
- if (!ids.GetString(i, &id_str)) {
- return kInvalidId;
- }
- int64 id = kInvalidId;
- if (!base::StringToInt64(id_str, &id)) {
- return kInvalidId;
- }
- return id;
-}
-
-JsArgList GetNodeInfoById(
- const JsArgList& args,
- UserShare* user_share,
- base::DictionaryValue* (BaseNode::*info_getter)() const) {
- CHECK(info_getter);
- base::ListValue return_args;
- base::ListValue* node_summaries = new base::ListValue();
- return_args.Append(node_summaries);
- const base::ListValue* id_list = NULL;
- ReadTransaction trans(FROM_HERE, user_share);
- if (args.Get().GetList(0, &id_list)) {
- CHECK(id_list);
- for (size_t i = 0; i < id_list->GetSize(); ++i) {
- int64 id = GetId(*id_list, i);
- if (id == kInvalidId) {
- continue;
- }
- ReadNode node(&trans);
- if (node.InitByIdLookup(id) != BaseNode::INIT_OK) {
- continue;
- }
- node_summaries->Append((node.*info_getter)());
- }
- }
- return JsArgList(&return_args);
-}
-
-} // namespace
-
-JsArgList SyncManagerImpl::GetNodeSummariesById(const JsArgList& args) {
- return GetNodeInfoById(args, GetUserShare(), &BaseNode::GetSummaryAsValue);
-}
-
-JsArgList SyncManagerImpl::GetNodeDetailsById(const JsArgList& args) {
- return GetNodeInfoById(args, GetUserShare(), &BaseNode::GetDetailsAsValue);
-}
-
JsArgList SyncManagerImpl::GetAllNodes(const JsArgList& args) {
- base::ListValue return_args;
- base::ListValue* result = new base::ListValue();
- return_args.Append(result);
-
ReadTransaction trans(FROM_HERE, GetUserShare());
- std::vector<const syncable::EntryKernel*> entry_kernels;
- trans.GetDirectory()->GetAllEntryKernels(trans.GetWrappedTrans(),
- &entry_kernels);
-
- for (std::vector<const syncable::EntryKernel*>::const_iterator it =
- entry_kernels.begin(); it != entry_kernels.end(); ++it) {
- result->Append((*it)->ToValue(trans.GetCryptographer()));
- }
-
- return JsArgList(&return_args);
-}
-
-JsArgList SyncManagerImpl::GetChildNodeIds(const JsArgList& args) {
base::ListValue return_args;
- base::ListValue* child_ids = new base::ListValue();
- return_args.Append(child_ids);
- int64 id = GetId(args.Get(), 0);
- if (id != kInvalidId) {
- ReadTransaction trans(FROM_HERE, GetUserShare());
- syncable::Directory::Metahandles child_handles;
- trans.GetDirectory()->GetChildHandlesByHandle(trans.GetWrappedTrans(),
- id, &child_handles);
- for (syncable::Directory::Metahandles::const_iterator it =
- child_handles.begin(); it != child_handles.end(); ++it) {
- child_ids->Append(new base::StringValue(base::Int64ToString(*it)));
- }
- }
+ scoped_ptr<base::ListValue> nodes(
+ trans.GetDirectory()->GetAllNodeDetails(trans.GetWrappedTrans()));
+ return_args.Append(nodes.release());
return JsArgList(&return_args);
}
}
bool found_experiment = false;
- ReadNode autofill_culling_node(&trans);
- if (autofill_culling_node.InitByClientTagLookup(
- syncer::EXPERIMENTS,
- syncer::kAutofillCullingTag) == BaseNode::INIT_OK &&
- autofill_culling_node.GetExperimentsSpecifics().
- autofill_culling().enabled()) {
- experiments->autofill_culling = true;
- found_experiment = true;
- }
-
ReadNode favicon_sync_node(&trans);
if (favicon_sync_node.InitByClientTagLookup(
syncer::EXPERIMENTS,
// know about this.
}
+ ReadNode gcm_channel_node(&trans);
+ if (gcm_channel_node.InitByClientTagLookup(
+ syncer::EXPERIMENTS,
+ syncer::kGCMChannelTag) == BaseNode::INIT_OK &&
+ gcm_channel_node.GetExperimentsSpecifics().gcm_channel().has_enabled()) {
+ experiments->gcm_channel_state =
+ (gcm_channel_node.GetExperimentsSpecifics().gcm_channel().enabled() ?
+ syncer::Experiments::ENABLED : syncer::Experiments::SUPPRESSED);
+ found_experiment = true;
+ }
+
+ ReadNode enhanced_bookmarks_node(&trans);
+ if (enhanced_bookmarks_node.InitByClientTagLookup(
+ syncer::EXPERIMENTS, syncer::kEnhancedBookmarksTag) ==
+ BaseNode::INIT_OK &&
+ enhanced_bookmarks_node.GetExperimentsSpecifics()
+ .has_enhanced_bookmarks()) {
+ const sync_pb::EnhancedBookmarksFlags& enhanced_bookmarks =
+ enhanced_bookmarks_node.GetExperimentsSpecifics().enhanced_bookmarks();
+ if (enhanced_bookmarks.has_enabled())
+ experiments->enhanced_bookmarks_enabled = enhanced_bookmarks.enabled();
+ if (enhanced_bookmarks.has_extension_id()) {
+ experiments->enhanced_bookmarks_ext_id =
+ enhanced_bookmarks.extension_id();
+ }
+ found_experiment = true;
+ }
+
return found_experiment;
}