Chromium Code Reviews| 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) |
| @@ -5,8 +5,9 @@ |
| #include "chrome/browser/sync/engine/syncer_thread.h" |
| #include <algorithm> |
| -#include <map> |
| #include <queue> |
| +#include <string> |
| +#include <vector> |
| #include "base/rand_util.h" |
| #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| @@ -31,6 +32,7 @@ |
| namespace browser_sync { |
| +using sessions::ModelTypeMap; |
| using sessions::SyncSession; |
| using sessions::SyncSessionSnapshot; |
| using sessions::SyncSourceInfo; |
| @@ -54,6 +56,18 @@ |
| const int SyncerThread::kMaxBackoffSeconds = 60 * 60 * 4; // 4 hours. |
| +void SyncerThread::NudgeSyncerWithPayloads( |
| + int milliseconds_from_now, |
| + NudgeSource source, |
| + const ModelTypeMap& model_types_with_payloads) { |
| + base::AutoLock lock(lock_); |
| + if (vault_.syncer_ == NULL) { |
| + return; |
| + } |
| + |
| + NudgeSyncImpl(milliseconds_from_now, source, model_types_with_payloads); |
| +} |
| + |
| void SyncerThread::NudgeSyncerWithDataTypes( |
| int milliseconds_from_now, |
| NudgeSource source, |
| @@ -63,7 +77,11 @@ |
| return; |
| } |
| - NudgeSyncImpl(milliseconds_from_now, source, model_types); |
| + ModelTypeMap model_types_with_payloads; |
| + sessions::BuildModelTypeMapFromModelTypeBitSet(model_types, |
| + std::string(), |
| + &model_types_with_payloads); |
| + NudgeSyncImpl(milliseconds_from_now, source, model_types_with_payloads); |
| } |
| void SyncerThread::NudgeSyncer( |
| @@ -74,8 +92,15 @@ |
| return; |
| } |
| - syncable::ModelTypeBitSet model_types; // All false by default. |
| - NudgeSyncImpl(milliseconds_from_now, source, model_types); |
| + // Set all enabled datatypes. |
| + ModelTypeMap model_types_with_payloads; |
| + ModelSafeRoutingInfo routes; |
| + session_context_->registrar()->GetModelSafeRoutingInfo(&routes); |
| + sessions::BuildModelTypeMapFromModelSafeRoutingInfo( |
| + routes, |
| + std::string(), |
| + &model_types_with_payloads); |
| + NudgeSyncImpl(milliseconds_from_now, source, model_types_with_payloads); |
| } |
| SyncerThread::SyncerThread(sessions::SyncSessionContext* context) |
| @@ -342,11 +367,12 @@ |
| // 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), |
| + if (!last_sync_time.is_null()) { |
| + ModelTypeMap::const_iterator iter; |
| + for (iter = session->source().types.begin(); |
| + iter != session->source().types.end(); |
| + ++iter) { |
| + syncable::PostTimeToTypeHistogram(iter->first, |
| now - last_sync_time); |
| } |
| } |
| @@ -574,7 +600,7 @@ |
| bool* was_nudged) { |
| bool nudged = false; |
| NudgeSource nudge_source = kUnknown; |
| - syncable::ModelTypeBitSet model_types; |
| + ModelTypeMap model_types_with_payloads; |
| // Has the previous sync cycle completed? |
| if (continue_sync_cycle) |
| nudge_source = kContinuation; |
| @@ -583,13 +609,13 @@ |
| if (!vault_.pending_nudge_time_.is_null()) { |
| if (!was_throttled) { |
| nudge_source = vault_.pending_nudge_source_; |
| - model_types = vault_.pending_nudge_types_; |
| + model_types_with_payloads = vault_.pending_nudge_types_; |
| 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_.pending_nudge_types_.clear(); |
| vault_.pending_nudge_time_ = base::TimeTicks(); |
| } |
| @@ -599,11 +625,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_with_payloads, initial_sync); |
| } |
| SyncSourceInfo SyncerThread::MakeSyncSourceInfo(bool nudged, |
| - NudgeSource nudge_source, const syncable::ModelTypeBitSet& nudge_types, |
| + NudgeSource nudge_source, |
| + const ModelTypeMap& model_types_with_payloads, |
| bool* initial_sync) { |
| sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source = |
| sync_pb::GetUpdatesCallerInfo::UNKNOWN; |
| @@ -632,7 +659,20 @@ |
| break; |
| } |
| } |
| - return SyncSourceInfo(updates_source, nudge_types); |
| + |
| + ModelTypeMap sync_source_types; |
| + if (model_types_with_payloads.empty()) { |
| + // No datatypes requested. This must be a poll so set all enabled datatypes. |
| + ModelSafeRoutingInfo routes; |
| + session_context_->registrar()->GetModelSafeRoutingInfo(&routes); |
| + sessions::BuildModelTypeMapFromModelSafeRoutingInfo(routes, |
| + std::string(), |
| + &sync_source_types); |
| + } else { |
| + sync_source_types = model_types_with_payloads; |
| + } |
| + |
| + return SyncSourceInfo(updates_source, sync_source_types); |
| } |
| void SyncerThread::CreateSyncer(const std::string& dirname) { |
| @@ -734,9 +774,10 @@ |
| } |
| // Called with mutex_ already locked. |
| -void SyncerThread::NudgeSyncImpl(int milliseconds_from_now, |
| - NudgeSource source, |
| - const syncable::ModelTypeBitSet& model_types) { |
| +void SyncerThread::NudgeSyncImpl( |
| + int milliseconds_from_now, |
| + NudgeSource source, |
| + const ModelTypeMap& model_types_with_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. |
| @@ -747,11 +788,22 @@ |
| return; |
| } |
| - // Union the current bitset with any from nudges that may have already |
| + // Union the current ModelTypeMap with any from nudges that may have already |
| // posted (coalesce the nudge datatype information). |
| // TODO(tim): It seems weird to do this if the sources don't match up (e.g. |
| // if pending_source is kLocal and |source| is kClearPrivateData). |
| - vault_.pending_nudge_types_ |= model_types; |
| + for (ModelTypeMap::const_iterator i = |
|
akalin
2011/01/24 22:17:29
I think this logic is tricky enough that it should
Nicolas Zea
2011/01/25 00:29:14
Done.
|
| + model_types_with_payloads.begin(); |
| + i != model_types_with_payloads.end(); |
| + ++i) { |
| + if (vault_.pending_nudge_types_.count(i->first) == 0) { |
| + // If this datatype isn't already in our map, add it. |
| + vault_.pending_nudge_types_[i->first] = i->second; |
| + } else if (i->second.length() > 0) { |
| + // If it is, we only overwrite the payload if the new one is non-empty. |
| + vault_.pending_nudge_types_[i->first] = i->second; |
| + } |
| + } |
| const TimeTicks nudge_time = TimeTicks::Now() + |
| TimeDelta::FromMilliseconds(milliseconds_from_now); |