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

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: payloads/nudge type merge 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>
akalin 2011/01/21 19:50:09 no need for this anymore
Nicolas Zea 2011/01/21 21:57:44 There is still use of vector for the model type wo
#include "base/rand_util.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
@@ -54,6 +56,18 @@
const int SyncerThread::kMaxBackoffSeconds = 60 * 60 * 4; // 4 hours.
+void SyncerThread::NudgeSyncerWithPayloads(
+ int milliseconds_from_now,
+ NudgeSource source,
+ const SyncSourceInfo::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,16 @@
return;
}
- NudgeSyncImpl(milliseconds_from_now, source, model_types);
+ SyncSourceInfo::ModelTypeMap model_types_with_payloads;
akalin 2011/01/21 19:50:09 Could use utility function here, too
Nicolas Zea 2011/01/21 21:57:44 Done.
+ for (size_t i = syncable::FIRST_REAL_MODEL_TYPE;
+ i < syncable::MODEL_TYPE_COUNT;
+ ++i) {
+ if (model_types[i]) {
+ model_types_with_payloads[syncable::ModelTypeFromInt(i)] =
+ std::string("");
akalin 2011/01/21 19:50:09 can be just std::string()
Nicolas Zea 2011/01/21 21:57:44 Done.
+ }
+ }
+ NudgeSyncImpl(milliseconds_from_now, source, model_types_with_payloads);
}
void SyncerThread::NudgeSyncer(
@@ -74,8 +97,15 @@
return;
}
- syncable::ModelTypeBitSet model_types; // All false by default.
- NudgeSyncImpl(milliseconds_from_now, source, model_types);
+ // Set all enabled datatypes.
+ SyncSourceInfo::ModelTypeMap model_types_with_payloads;
+ ModelSafeRoutingInfo routes;
+ session_context_->registrar()->GetModelSafeRoutingInfo(&routes);
+ for (ModelSafeRoutingInfo::const_iterator i = routes.begin();
akalin 2011/01/21 19:50:09 Room for another util. function to go from ModelSa
Nicolas Zea 2011/01/21 21:57:44 Done.
+ i != routes.end(); ++i) {
+ model_types_with_payloads[i->first] = std::string("");
+ }
+ NudgeSyncImpl(milliseconds_from_now, source, model_types_with_payloads);
}
SyncerThread::SyncerThread(sessions::SyncSessionContext* context)
@@ -342,11 +372,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()) {
+ SyncSourceInfo::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 +605,7 @@
bool* was_nudged) {
bool nudged = false;
NudgeSource nudge_source = kUnknown;
- syncable::ModelTypeBitSet model_types;
+ SyncSourceInfo::ModelTypeMap model_types;
// Has the previous sync cycle completed?
if (continue_sync_cycle)
nudge_source = kContinuation;
@@ -589,7 +620,7 @@
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();
}
@@ -603,7 +634,8 @@
}
SyncSourceInfo SyncerThread::MakeSyncSourceInfo(bool nudged,
- NudgeSource nudge_source, const syncable::ModelTypeBitSet& nudge_types,
+ NudgeSource nudge_source,
+ const SyncSourceInfo::ModelTypeMap& nudge_types,
bool* initial_sync) {
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source =
sync_pb::GetUpdatesCallerInfo::UNKNOWN;
@@ -632,7 +664,21 @@
break;
}
}
- return SyncSourceInfo(updates_source, nudge_types);
+
+ SyncSourceInfo::ModelTypeMap sync_source_types;
+ if (nudge_types.empty()) {
+ // No datatypes requested. This must be a poll so set all enabled datatypes.
+ ModelSafeRoutingInfo routes;
+ session_context_->registrar()->GetModelSafeRoutingInfo(&routes);
+ for (ModelSafeRoutingInfo::const_iterator i = routes.begin();
+ i != routes.end(); ++i) {
+ sync_source_types[i->first] = std::string("");
+ }
+ } else {
+ sync_source_types = nudge_types;
+ }
+
+ return SyncSourceInfo(updates_source, sync_source_types);
}
void SyncerThread::CreateSyncer(const std::string& dirname) {
@@ -734,9 +780,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 SyncSourceInfo::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 +794,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 (SyncSourceInfo::ModelTypeMap::const_iterator i =
+ 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);

Powered by Google App Engine
This is Rietveld 408576698