Skip to content

Commit

Permalink
[Sync] Convert syncable/ directory to ModelEnumSet
Browse files Browse the repository at this point in the history
First in a series of patches to replace ModelType{Bit,}Set with
ModelEnumSet (which will then be renamed to ModelTypeSet).

BUG=79970
TEST=


Review URL: http://codereview.chromium.org/8772074

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113286 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
akalin@chromium.org committed Dec 6, 2011
1 parent 86066c2 commit 539c0e7
Show file tree
Hide file tree
Showing 59 changed files with 615 additions and 530 deletions.
11 changes: 4 additions & 7 deletions chrome/browser/sync/engine/apply_updates_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,10 @@ void ApplyUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) {
// some subset of the currently synced datatypes.
const sessions::StatusController& status(session->status_controller());
if (status.ServerSaysNothingMoreToDownload()) {
for (int i = syncable::FIRST_REAL_MODEL_TYPE;
i < syncable::MODEL_TYPE_COUNT; ++i) {
syncable::ModelType model_type = syncable::ModelTypeFromInt(i);
if (status.updates_request_types()[i]) {
// This gets persisted to the directory's backing store.
dir->set_initial_sync_ended_for_type(model_type, true);
}
for (syncable::ModelEnumSet::Iterator it =
status.updates_request_types().First(); it.Good(); it.Inc()) {
// This gets persisted to the directory's backing store.
dir->set_initial_sync_ended_for_type(it.Get(), true);
}
}
}
Expand Down
45 changes: 16 additions & 29 deletions chrome/browser/sync/engine/cleanup_disabled_types_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,8 @@ CleanupDisabledTypesCommand::CleanupDisabledTypesCommand() {}
CleanupDisabledTypesCommand::~CleanupDisabledTypesCommand() {}

void CleanupDisabledTypesCommand::ExecuteImpl(sessions::SyncSession* session) {
using syncable::ModelTypeSet;
using syncable::ModelTypeSetToString;

const ModelTypeSet& all_types = syncable::GetAllRealModelTypes();
const ModelTypeSet& enabled_types =
GetRoutingInfoTypes(session->routing_info());

// Initially set |to_cleanup| to |all_types| \setminus |enabled_types|.
ModelTypeSet to_cleanup;
std::set_difference(all_types.begin(), all_types.end(),
enabled_types.begin(), enabled_types.end(),
std::inserter(to_cleanup, to_cleanup.end()));

DVLOG(1) << "all_types = " << ModelTypeSetToString(all_types)
<< ", enabled_types = " << ModelTypeSetToString(enabled_types)
<< ", to_cleanup = " << ModelTypeSetToString(to_cleanup);
using syncable::ModelEnumSet;
using syncable::ModelEnumSetToString;

// Because a full directory purge is slow, we avoid purging
// undesired types unless we have reason to believe they were
Expand All @@ -53,27 +39,28 @@ void CleanupDisabledTypesCommand::ExecuteImpl(sessions::SyncSession* session) {
// | (failure, browser restart
// | before another sync session,..)

const ModelTypeSet& previous_enabled_types =
const ModelEnumSet enabled_types =
GetRoutingInfoTypes(session->routing_info());

const ModelEnumSet previous_enabled_types =
GetRoutingInfoTypes(
session->context()->previous_session_routing_info());

ModelEnumSet to_cleanup = Difference(ModelEnumSet::All(), enabled_types);

// If |previous_enabled_types| is non-empty (i.e., not the first
// sync session), set |to_cleanup| to its intersection with
// |previous_enabled_types|.
if (!previous_enabled_types.empty()) {
using std::swap;
ModelTypeSet temp;
std::set_intersection(
to_cleanup.begin(), to_cleanup.end(),
previous_enabled_types.begin(), previous_enabled_types.end(),
std::inserter(temp, temp.end()));
swap(to_cleanup, temp);
if (!previous_enabled_types.Empty()) {
to_cleanup.RetainAll(previous_enabled_types);
}

DVLOG(1) << "previous_enabled_types = "
<< ModelTypeSetToString(previous_enabled_types)
<< ", to_cleanup = " << ModelTypeSetToString(to_cleanup);
DVLOG(1) << "enabled_types = " << ModelEnumSetToString(enabled_types)
<< ", previous_enabled_types = "
<< ModelEnumSetToString(previous_enabled_types)
<< ", to_cleanup = " << ModelEnumSetToString(to_cleanup);

if (to_cleanup.empty())
if (to_cleanup.Empty())
return;

syncable::ScopedDirLookup dir(session->context()->directory_manager(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -8,22 +8,23 @@

#include "chrome/browser/sync/engine/syncer_end_command.h"
#include "chrome/browser/sync/sessions/sync_session.h"
#include "chrome/browser/sync/syncable/model_type_test_util.h"
#include "chrome/browser/sync/test/engine/syncer_command_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gmock/include/gmock/gmock.h"

using testing::_;

namespace browser_sync {

namespace {

using syncable::HasModelTypes;
using syncable::ModelEnumSet;
using testing::_;

class CleanupDisabledTypesCommandTest : public MockDirectorySyncerCommandTest {
public:
CleanupDisabledTypesCommandTest() {
for (int i = syncable::FIRST_REAL_MODEL_TYPE;
i < syncable::MODEL_TYPE_COUNT; i++) {
all_types_.insert(syncable::ModelTypeFromInt(i));
}
}
CleanupDisabledTypesCommandTest() {}

virtual void SetUp() {
mutable_routing_info()->clear();
(*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_PASSIVE;
Expand All @@ -34,19 +35,15 @@ class CleanupDisabledTypesCommandTest : public MockDirectorySyncerCommandTest {
virtual bool IsSyncingCurrentlySilenced() {
return false;
}

const syncable::ModelTypeSet& all_types() { return all_types_; }

private:
syncable::ModelTypeSet all_types_;
};

// TODO(tim): Add syncer test to verify previous routing info is set.
TEST_F(CleanupDisabledTypesCommandTest, NoPreviousRoutingInfo) {
CleanupDisabledTypesCommand command;
syncable::ModelTypeSet expected(all_types());
expected.erase(syncable::BOOKMARKS);
EXPECT_CALL(*mock_directory(), PurgeEntriesWithTypeIn(expected));
ModelEnumSet expected = ModelEnumSet::All();
expected.Remove(syncable::BOOKMARKS);
EXPECT_CALL(*mock_directory(),
PurgeEntriesWithTypeIn(HasModelTypes(expected)));
command.ExecuteImpl(session());
}

Expand All @@ -65,9 +62,6 @@ TEST_F(CleanupDisabledTypesCommandTest, NoPurge) {

TEST_F(CleanupDisabledTypesCommandTest, TypeDisabled) {
CleanupDisabledTypesCommand command;
syncable::ModelTypeSet expected;
expected.insert(syncable::PASSWORDS);
expected.insert(syncable::PREFERENCES);

(*mutable_routing_info())[syncable::AUTOFILL] = GROUP_PASSIVE;
(*mutable_routing_info())[syncable::THEMES] = GROUP_PASSIVE;
Expand All @@ -78,9 +72,12 @@ TEST_F(CleanupDisabledTypesCommandTest, TypeDisabled) {
prev[syncable::PREFERENCES] = GROUP_PASSIVE;
session()->context()->set_previous_session_routing_info(prev);

EXPECT_CALL(*mock_directory(), PurgeEntriesWithTypeIn(expected));
const ModelEnumSet expected(syncable::PASSWORDS, syncable::PREFERENCES);
EXPECT_CALL(*mock_directory(),
PurgeEntriesWithTypeIn(HasModelTypes(expected)));
command.ExecuteImpl(session());
}

} // namespace browser_sync
} // namespace

} // namespace browser_sync
22 changes: 12 additions & 10 deletions chrome/browser/sync/engine/download_updates_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ using sessions::SyncSession;
using std::string;
using syncable::FIRST_REAL_MODEL_TYPE;
using syncable::MODEL_TYPE_COUNT;
using syncable::ModelEnumSet;
using syncable::ModelEnumSetToString;

DownloadUpdatesCommand::DownloadUpdatesCommand() {}
DownloadUpdatesCommand::~DownloadUpdatesCommand() {}
Expand All @@ -50,28 +52,28 @@ void DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) {
}

// Request updates for all enabled types.
syncable::ModelTypeBitSet enabled_types;
const ModelEnumSet enabled_types =
GetRoutingInfoTypes(session->routing_info());
DVLOG(1) << "Getting updates for types "
<< ModelEnumSetToString(enabled_types);
DCHECK(!enabled_types.Empty());

const syncable::ModelTypePayloadMap& type_payload_map =
session->source().types;
for (ModelSafeRoutingInfo::const_iterator i = session->routing_info().begin();
i != session->routing_info().end(); ++i) {
syncable::ModelType model_type = syncable::ModelTypeFromInt(i->first);
enabled_types[i->first] = true;
for (ModelEnumSet::Iterator it = enabled_types.First();
it.Good(); it.Inc()) {
sync_pb::DataTypeProgressMarker* progress_marker =
get_updates->add_from_progress_marker();
dir->GetDownloadProgress(model_type, progress_marker);
dir->GetDownloadProgress(it.Get(), progress_marker);

// Set notification hint if present.
syncable::ModelTypePayloadMap::const_iterator type_payload =
type_payload_map.find(i->first);
type_payload_map.find(it.Get());
if (type_payload != type_payload_map.end()) {
progress_marker->set_notification_hint(type_payload->second);
}
}

DVLOG(1) << "Getting updates for types " << enabled_types.to_string();
DCHECK(enabled_types.any());

// We want folders for our associated types, always. If we were to set
// this to false, the server would send just the non-container items
// (e.g. Bookmark URLs but not their containing folders).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DownloadUpdatesCommandTest : public SyncerCommandTest {
TEST_F(DownloadUpdatesCommandTest, ExecuteNoPayloads) {
ConfigureMockServerConnection();
mock_server()->ExpectGetUpdatesRequestTypes(
ModelTypeBitSetFromSet(GetRoutingInfoTypes(routing_info())));
GetRoutingInfoTypes(routing_info()));
command_.ExecuteImpl(session());
}

Expand All @@ -56,7 +56,7 @@ TEST_F(DownloadUpdatesCommandTest, ExecuteWithPayloads) {
source.types[syncable::BOOKMARKS] = "bookmark_payload";
source.types[syncable::PREFERENCES] = "preferences_payload";
mock_server()->ExpectGetUpdatesRequestTypes(
ModelTypeBitSetFromSet(GetRoutingInfoTypes(routing_info())));
GetRoutingInfoTypes(routing_info()));
mock_server()->ExpectGetUpdatesRequestPayloads(source.types);
command_.ExecuteImpl(session(source));
}
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/sync/engine/model_safe_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ std::string ModelSafeRoutingInfoToString(
return json;
}

syncable::ModelTypeSet GetRoutingInfoTypes(
syncable::ModelEnumSet GetRoutingInfoTypes(
const ModelSafeRoutingInfo& routing_info) {
syncable::ModelTypeSet types;
syncable::ModelEnumSet types;
for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin();
it != routing_info.end(); ++it) {
types.insert(it->first);
types.Put(it->first);
}
return types;
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/sync/engine/model_safe_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ base::DictionaryValue* ModelSafeRoutingInfoToValue(
std::string ModelSafeRoutingInfoToString(
const ModelSafeRoutingInfo& routing_info);

syncable::ModelTypeSet GetRoutingInfoTypes(
syncable::ModelEnumSet GetRoutingInfoTypes(
const ModelSafeRoutingInfo& routing_info);

ModelSafeGroup GetGroupForModelType(const syncable::ModelType type,
Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/sync/engine/model_safe_worker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ TEST_F(ModelSafeWorkerTest, GetRoutingInfoTypes) {
routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE;
routing_info[syncable::NIGORI] = GROUP_UI;
routing_info[syncable::PREFERENCES] = GROUP_DB;
syncable::ModelTypeSet expected_types;
expected_types.insert(syncable::BOOKMARKS);
expected_types.insert(syncable::NIGORI);
expected_types.insert(syncable::PREFERENCES);
EXPECT_EQ(expected_types, GetRoutingInfoTypes(routing_info));
const syncable::ModelEnumSet expected_types(
syncable::BOOKMARKS,
syncable::NIGORI,
syncable::PREFERENCES);
EXPECT_TRUE(GetRoutingInfoTypes(routing_info).Equals(expected_types));
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/sync/engine/store_timestamps_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void StoreTimestampsCommand::ExecuteImpl(sessions::SyncSession* session) {
DVLOG_IF(1, forward_progress_types.any())
<< "Get Updates got new progress marker for types: "
<< forward_progress_types.to_string() << " out of possible: "
<< status->updates_request_types().to_string();
<< syncable::ModelEnumSetToString(status->updates_request_types());
}
if (updates.has_changes_remaining()) {
int64 changes_left = updates.changes_remaining();
Expand Down
31 changes: 15 additions & 16 deletions chrome/browser/sync/engine/sync_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,16 @@ void SyncScheduler::ScheduleCleanupDisabledTypes() {

void SyncScheduler::ScheduleNudge(
const TimeDelta& delay,
NudgeSource source, const ModelTypeBitSet& types,
NudgeSource source, syncable::ModelEnumSet types,
const tracked_objects::Location& nudge_location) {
DCHECK_EQ(MessageLoop::current(), sync_loop_);
SDVLOG_LOC(nudge_location, 2)
<< "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, "
<< "source " << GetNudgeSourceString(source) << ", "
<< "types " << syncable::ModelTypeBitSetToString(types);
<< "types " << syncable::ModelEnumSetToString(types);

ModelTypePayloadMap types_with_payloads =
syncable::ModelTypePayloadMapFromBitSet(types, std::string());
syncable::ModelTypePayloadMapFromEnumSet(types, std::string());
PostTask(nudge_location, "ScheduleNudgeImpl",
base::Bind(&SyncScheduler::ScheduleNudgeImpl,
weak_ptr_factory_.GetWeakPtr(),
Expand Down Expand Up @@ -562,7 +562,7 @@ void SyncScheduler::ScheduleNudgeImpl(

// Helper to extract the routing info and workers corresponding to types in
// |types| from |registrar|.
void GetModelSafeParamsForTypes(const ModelTypeBitSet& types,
void GetModelSafeParamsForTypes(syncable::ModelEnumSet types,
ModelSafeWorkerRegistrar* registrar, ModelSafeRoutingInfo* routes,
std::vector<ModelSafeWorker*>* workers) {
ModelSafeRoutingInfo r_tmp;
Expand All @@ -573,19 +573,18 @@ void GetModelSafeParamsForTypes(const ModelTypeBitSet& types,
bool passive_group_added = false;

typedef std::vector<ModelSafeWorker*>::const_iterator iter;
for (size_t i = syncable::FIRST_REAL_MODEL_TYPE; i < types.size(); ++i) {
if (!types.test(i))
continue;
syncable::ModelType t = syncable::ModelTypeFromInt(i);
for (syncable::ModelEnumSet::Iterator it = types.First();
it.Good(); it.Inc()) {
const syncable::ModelType t = it.Get();
DCHECK_EQ(1U, r_tmp.count(t));
(*routes)[t] = r_tmp[t];
iter it = std::find_if(w_tmp.begin(), w_tmp.end(),
ModelSafeWorkerGroupIs(r_tmp[t]));
if (it != w_tmp.end()) {
iter it2 = std::find_if(workers->begin(), workers->end(),
ModelSafeWorkerGroupIs(r_tmp[t]));
if (it2 == workers->end())
workers->push_back(*it);
iter w_tmp_it = std::find_if(w_tmp.begin(), w_tmp.end(),
ModelSafeWorkerGroupIs(r_tmp[t]));
if (w_tmp_it != w_tmp.end()) {
iter workers_it = std::find_if(workers->begin(), workers->end(),
ModelSafeWorkerGroupIs(r_tmp[t]));
if (workers_it == workers->end())
workers->push_back(*w_tmp_it);

if (r_tmp[t] == GROUP_PASSIVE)
passive_group_added = true;
Expand All @@ -606,7 +605,7 @@ void GetModelSafeParamsForTypes(const ModelTypeBitSet& types,
}

void SyncScheduler::ScheduleConfig(
const ModelTypeBitSet& types,
syncable::ModelEnumSet types,
GetUpdatesCallerInfo::GetUpdatesSource source) {
DCHECK_EQ(MessageLoop::current(), sync_loop_);
DCHECK(IsConfigRelatedUpdateSourceValue(source));
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/sync/engine/sync_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SyncScheduler : public sessions::SyncSession::Delegate,

// The meat and potatoes.
void ScheduleNudge(const base::TimeDelta& delay, NudgeSource source,
const syncable::ModelTypeBitSet& types,
syncable::ModelEnumSet types,
const tracked_objects::Location& nudge_location);
void ScheduleNudgeWithPayloads(
const base::TimeDelta& delay, NudgeSource source,
Expand All @@ -89,7 +89,7 @@ class SyncScheduler : public sessions::SyncSession::Delegate,
// Note: The source argument of this function must come from the subset of
// GetUpdatesCallerInfo values related to configurations.
void ScheduleConfig(
const syncable::ModelTypeBitSet& types,
syncable::ModelEnumSet types,
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);

void ScheduleClearUserData();
Expand Down
Loading

0 comments on commit 539c0e7

Please sign in to comment.