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

Unified Diff: chrome/browser/sync/engine/syncer_thread.cc

Issue 6182004: [SYNC] Refactor SyncSourceInfo and add support in chrome invalidation client ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: vector->map + comments Created 9 years, 11 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/engine/syncer_thread.cc
===================================================================
--- chrome/browser/sync/engine/syncer_thread.cc (revision 71618)
+++ chrome/browser/sync/engine/syncer_thread.cc (working copy)
@@ -7,6 +7,8 @@
#include <algorithm>
#include <map>
#include <queue>
+#include <string>
+#include <vector>
#include "base/rand_util.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
@@ -54,6 +56,19 @@
const int SyncerThread::kMaxBackoffSeconds = 60 * 60 * 4; // 4 hours.
+void SyncerThread::NudgeSyncerWithPayloads(
+ int milliseconds_from_now,
+ NudgeSource source,
+ const std::map<syncable::ModelType, std::string>& payloads) {
+ base::AutoLock lock(lock_);
+ if (vault_.syncer_ == NULL) {
+ return;
+ }
+
+ syncable::ModelTypeBitSet model_types; // All false by default.
+ NudgeSyncImpl(milliseconds_from_now, source, model_types, payloads);
+}
+
void SyncerThread::NudgeSyncerWithDataTypes(
int milliseconds_from_now,
NudgeSource source,
@@ -63,7 +78,8 @@
return;
}
- NudgeSyncImpl(milliseconds_from_now, source, model_types);
+ std::map<syncable::ModelType, std::string> empty_payload;
+ NudgeSyncImpl(milliseconds_from_now, source, model_types, empty_payload);
}
void SyncerThread::NudgeSyncer(
@@ -74,8 +90,10 @@
return;
}
- syncable::ModelTypeBitSet model_types; // All false by default.
- NudgeSyncImpl(milliseconds_from_now, source, model_types);
+ syncable::ModelTypeBitSet model_types;
+ model_types.set(); // The default nudge acts on all datatypes.
+ std::map<syncable::ModelType, std::string> empty_payload;
+ NudgeSyncImpl(milliseconds_from_now, source, model_types, empty_payload);
}
SyncerThread::SyncerThread(sessions::SyncSessionContext* context)
@@ -342,12 +360,14 @@
// Update timing information for how often these datatypes are triggering
// nudges.
base::TimeTicks now = TimeTicks::Now();
- for (size_t i = syncable::FIRST_REAL_MODEL_TYPE;
- i < session->source().second.size();
- ++i) {
- if (session->source().second[i]) {
- syncable::PostTimeToTypeHistogram(syncable::ModelType(i),
- now - last_sync_time);
+ if (!last_sync_time.is_null()) {
+ for (size_t i = syncable::FIRST_REAL_MODEL_TYPE;
+ i < session->source().types.size();
+ ++i) {
+ if (session->source().types[i]) {
+ syncable::PostTimeToTypeHistogram(syncable::ModelType(i),
+ now - last_sync_time);
+ }
}
}
@@ -575,6 +595,7 @@
bool nudged = false;
NudgeSource nudge_source = kUnknown;
syncable::ModelTypeBitSet model_types;
+ std::map<syncable::ModelType, std::string> payloads;
// Has the previous sync cycle completed?
if (continue_sync_cycle)
nudge_source = kContinuation;
@@ -584,12 +605,14 @@
if (!was_throttled) {
nudge_source = vault_.pending_nudge_source_;
model_types = vault_.pending_nudge_types_;
+ payloads = vault_.datatype_payloads_;
nudged = true;
}
VLOG(1) << "Clearing pending nudge from " << vault_.pending_nudge_source_
<< " at tick " << vault_.pending_nudge_time_.ToInternalValue();
vault_.pending_nudge_source_ = kUnknown;
vault_.pending_nudge_types_.reset();
+ vault_.datatype_payloads_.clear();
vault_.pending_nudge_time_ = base::TimeTicks();
}
@@ -599,11 +622,12 @@
// from syncer having more work to do. This will be handled properly with
// the message loop based syncer thread, bug 26339.
return MakeSyncSourceInfo(nudged || nudge_source == kContinuation,
- nudge_source, model_types, initial_sync);
+ nudge_source, model_types, payloads, initial_sync);
}
SyncSourceInfo SyncerThread::MakeSyncSourceInfo(bool nudged,
NudgeSource nudge_source, const syncable::ModelTypeBitSet& nudge_types,
+ const std::map<syncable::ModelType, std::string>& payloads,
bool* initial_sync) {
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source =
sync_pb::GetUpdatesCallerInfo::UNKNOWN;
@@ -632,7 +656,22 @@
break;
}
}
- return SyncSourceInfo(updates_source, nudge_types);
+
+ syncable::ModelTypeBitSet sync_source_types;
+ if (nudge_types.none()) {
+ // No datatypes requested. This must be a poll so set all enabled datatypes.
+ DCHECK(payloads.empty()); // There should be no payloads
+ ModelSafeRoutingInfo routes;
+ session_context_->registrar()->GetModelSafeRoutingInfo(&routes);
+ for (ModelSafeRoutingInfo::const_iterator i = routes.begin();
+ i != routes.end(); ++i) {
+ sync_source_types.set(i->first);
+ }
+ } else {
+ sync_source_types = nudge_types;
+ }
+
+ return SyncSourceInfo(updates_source, sync_source_types, payloads);
}
void SyncerThread::CreateSyncer(const std::string& dirname) {
@@ -735,8 +774,8 @@
// Called with mutex_ already locked.
void SyncerThread::NudgeSyncImpl(int milliseconds_from_now,
- NudgeSource source,
- const syncable::ModelTypeBitSet& model_types) {
+ NudgeSource source, const syncable::ModelTypeBitSet& model_types,
+ const std::map<syncable::ModelType, std::string>& payloads) {
// TODO(sync): Add the option to reset the backoff state machine.
// This is needed so nudges that are a result of the user's desire
// to download updates for a new data type can be satisfied quickly.
@@ -753,6 +792,19 @@
// if pending_source is kLocal and |source| is kClearPrivateData).
vault_.pending_nudge_types_ |= model_types;
+ // Any datatype that does actually have a payload signifies that we are
+ // requesting that datatype (and hence the corresponding
+ // |pending_nudge_types_| slot should be set).
+ for (std::map<syncable::ModelType, std::string>::const_iterator i =
+ payloads.begin();
+ i != payloads.end();
+ ++i) {
+ // This datatype has a payload we should hold on to.
+ // Overwrite old payloads as we only need the most recent one.
+ vault_.pending_nudge_types_.set(i->first);
+ vault_.datatype_payloads_[i->first] = i->second;
+ }
+
const TimeTicks nudge_time = TimeTicks::Now() +
TimeDelta::FromMilliseconds(milliseconds_from_now);
if (nudge_time <= vault_.pending_nudge_time_) {

Powered by Google App Engine
This is Rietveld 408576698