Index: chrome/browser/sync/sessions/sync_session.cc |
diff --git a/chrome/browser/sync/sessions/sync_session.cc b/chrome/browser/sync/sessions/sync_session.cc |
index f399d7d7904ed1fee8a5425a8641cfaaab04675e..f749e33c0ef24f00fec3432556b4039b01801e3e 100644 |
--- a/chrome/browser/sync/sessions/sync_session.cc |
+++ b/chrome/browser/sync/sessions/sync_session.cc |
@@ -6,12 +6,48 @@ |
#include <algorithm> |
+#include "base/logging.h" |
#include "chrome/browser/sync/syncable/directory_manager.h" |
#include "chrome/browser/sync/syncable/model_type.h" |
namespace browser_sync { |
namespace sessions { |
+namespace { |
+ |
+std::set<ModelSafeGroup> ComputeEnabledGroups( |
+ const ModelSafeRoutingInfo& routing_info, |
+ const std::vector<ModelSafeWorker*>& workers) { |
+ std::set<ModelSafeGroup> enabled_groups; |
+ // Project the list of enabled types (i.e., types in the routing |
+ // info) to a list of enabled groups. |
+ for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); |
+ it != routing_info.end(); ++it) { |
+ enabled_groups.insert(it->second); |
+ } |
+ // GROUP_PASSIVE is always enabled, since that's the group that |
+ // top-level folders map to. |
+ enabled_groups.insert(GROUP_PASSIVE); |
+ if (logging::DEBUG_MODE) { |
tim (not reviewing)
2011/11/29 00:01:59
I haven't seen this get used before... is this jus
akalin
2011/11/30 01:33:03
Yeah pretty much. Although I should have used DCH
|
+ // We sometimes create dummy SyncSession objects (see |
+ // SyncScheduler::InitialSnapshot) so don't check in that case. |
+ if (!routing_info.empty() || !workers.empty()) { |
+ std::set<ModelSafeGroup> groups_with_workers; |
+ for (std::vector<ModelSafeWorker*>::const_iterator it = workers.begin(); |
+ it != workers.end(); ++it) { |
+ groups_with_workers.insert((*it)->GetModelSafeGroup()); |
+ } |
+ // All enabled groups should have a corresponding worker. |
+ DCHECK(std::includes( |
+ groups_with_workers.begin(), groups_with_workers.end(), |
+ enabled_groups.begin(), enabled_groups.end())); |
+ } |
+ } |
+ return enabled_groups; |
+} |
+ |
+} // namesepace |
+ |
SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, |
const SyncSourceInfo& source, |
const ModelSafeRoutingInfo& routing_info, |
@@ -21,7 +57,8 @@ SyncSession::SyncSession(SyncSessionContext* context, Delegate* delegate, |
write_transaction_(NULL), |
delegate_(delegate), |
workers_(workers), |
- routing_info_(routing_info) { |
+ routing_info_(routing_info), |
+ enabled_groups_(ComputeEnabledGroups(routing_info_, workers_)) { |
status_controller_.reset(new StatusController(routing_info_)); |
std::sort(workers_.begin(), workers_.end()); |
} |
@@ -53,15 +90,18 @@ void SyncSession::Coalesce(const SyncSession& session) { |
++it) { |
routing_info_[it->first] = it->second; |
} |
+ |
+ // Now update enabled groups. |
+ enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_); |
} |
-void SyncSession::RebaseRoutingInfoWithLatest(SyncSession* session) { |
+void SyncSession::RebaseRoutingInfoWithLatest(const SyncSession& session) { |
ModelSafeRoutingInfo temp_routing_info; |
// Take the intersecion and also set the routing info(it->second) from the |
// passed in session. |
for (ModelSafeRoutingInfo::const_iterator it = |
- session->routing_info_.begin(); it != session->routing_info_.end(); |
+ session.routing_info_.begin(); it != session.routing_info_.end(); |
++it) { |
if (routing_info_.find(it->first) != routing_info_.end()) { |
temp_routing_info[it->first] = it->second; |
@@ -72,14 +112,17 @@ void SyncSession::RebaseRoutingInfoWithLatest(SyncSession* session) { |
routing_info_.swap(temp_routing_info); |
// Now update the payload map. |
- PurgeStalePayload(&source_.types, session->routing_info_); |
+ PurgeStalePayload(&source_.types, session.routing_info_); |
// Now update the workers. |
std::vector<ModelSafeWorker*> temp; |
std::set_intersection(workers_.begin(), workers_.end(), |
- session->workers_.begin(), session->workers_.end(), |
+ session.workers_.begin(), session.workers_.end(), |
std::back_inserter(temp)); |
workers_.swap(temp); |
+ |
+ // Now update enabled groups. |
+ enabled_groups_ = ComputeEnabledGroups(routing_info_, workers_); |
} |
void SyncSession::ResetTransientState() { |
@@ -141,7 +184,27 @@ bool SyncSession::HasMoreToSync() const { |
status->conflicts_resolved(); |
// Or, we have conflicting updates, but we're making progress on |
// resolving them... |
+} |
+ |
+const std::set<ModelSafeGroup>& SyncSession::GetEnabledGroups() const { |
+ return enabled_groups_; |
+} |
+ |
+std::set<ModelSafeGroup> SyncSession::GetEnabledGroupsWithConflicts() const { |
+ const std::set<ModelSafeGroup>& enabled_groups = GetEnabledGroups(); |
+ std::set<ModelSafeGroup> enabled_groups_with_conflicts; |
+ for (std::set<ModelSafeGroup>::const_iterator it = |
+ enabled_groups.begin(); it != enabled_groups.end(); ++it) { |
+ const sessions::ConflictProgress* conflict_progress = |
+ status_controller_->GetUnrestrictedConflictProgress(*it); |
+ if (conflict_progress && |
+ (conflict_progress->ConflictingItemsBegin() != |
+ conflict_progress->ConflictingItemsEnd())) { |
+ enabled_groups_with_conflicts.insert(*it); |
+ } |
} |
+ return enabled_groups_with_conflicts; |
+} |
} // namespace sessions |
} // namespace browser_sync |