Chromium Code Reviews| Index: chrome/browser/sync/engine/syncer_thread.cc |
| =================================================================== |
| --- chrome/browser/sync/engine/syncer_thread.cc (revision 71061) |
| +++ 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::vector<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::vector<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::vector<std::string> empty_payload; // No payloads. |
| + 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::vector<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,12 +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, |
| - bool* initial_sync) { |
| + const std::vector<std::string>& payloads, bool* initial_sync) { |
| sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source = |
| sync_pb::GetUpdatesCallerInfo::UNKNOWN; |
| if (*initial_sync) { |
| @@ -632,7 +655,23 @@ |
| 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) { |
| @@ -736,7 +775,8 @@ |
| // Called with mutex_ already locked. |
| void SyncerThread::NudgeSyncImpl(int milliseconds_from_now, |
| NudgeSource source, |
| - const syncable::ModelTypeBitSet& model_types) { |
| + const syncable::ModelTypeBitSet& model_types, |
| + const std::vector<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 +793,21 @@ |
| // if pending_source is kLocal and |source| is kClearPrivateData). |
| vault_.pending_nudge_types_ |= model_types; |
| + // Any nudge results in the payloads vector at least having an empty string |
| + // for each datatype. 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). |
| + vault_.datatype_payloads_.resize(syncable::MODEL_TYPE_COUNT); |
| + for (size_t i = syncable::FIRST_REAL_MODEL_TYPE; |
| + i < payloads.size(); |
| + ++i) { |
| + if (!payloads[i].empty()) { |
| + // This datatype has a payload we should hold on to. |
| + vault_.pending_nudge_types_.set(i); |
| + vault_.datatype_payloads_[i] = payloads[i]; // Overwrite old payloads. |
|
akalin
2011/01/12 09:55:19
why can we get away with overwriting? Don't we ne
Nicolas Zea
2011/01/13 19:17:30
We merge across datatypes, but if we receive a pay
akalin
2011/01/13 19:47:41
Okay, if that's the case, maybe expand the comment
Nicolas Zea
2011/01/18 06:07:23
Done.
|
| + } |
| + } |
| + |
| const TimeTicks nudge_time = TimeTicks::Now() + |
| TimeDelta::FromMilliseconds(milliseconds_from_now); |
| if (nudge_time <= vault_.pending_nudge_time_) { |