summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-22 21:52:44 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-22 21:52:44 +0000
commitab44ef0ed3524ac26a5486d0e071c689f98d7087 (patch)
treeeb8f189e05e1d3087822785127399e5961fe4a3a /chrome/browser
parent3dec196bbf9945f96ab4a30802f238cda8518087 (diff)
downloadchromium_src-ab44ef0ed3524ac26a5486d0e071c689f98d7087.zip
chromium_src-ab44ef0ed3524ac26a5486d0e071c689f98d7087.tar.gz
chromium_src-ab44ef0ed3524ac26a5486d0e071c689f98d7087.tar.bz2
[Sync] Move TypePayloadMap into its own file
Also rename it to ModelTypePayloadMap. BUG=None TEST= Review URL: http://codereview.chromium.org/6718024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79046 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/sync/engine/download_updates_command.cc9
-rw-r--r--chrome/browser/sync/engine/syncapi.cc11
-rw-r--r--chrome/browser/sync/engine/syncer_thread.cc32
-rw-r--r--chrome/browser/sync/engine/syncer_thread.h11
-rw-r--r--chrome/browser/sync/engine/syncer_thread2.cc18
-rw-r--r--chrome/browser/sync/engine/syncer_thread2.h10
-rw-r--r--chrome/browser/sync/engine/syncer_thread2_unittest.cc32
-rw-r--r--chrome/browser/sync/engine/syncer_thread_adapter.cc4
-rw-r--r--chrome/browser/sync/engine/syncer_thread_adapter.h8
-rw-r--r--chrome/browser/sync/engine/syncer_thread_unittest.cc16
-rw-r--r--chrome/browser/sync/engine/syncer_unittest.cc6
-rw-r--r--chrome/browser/sync/notifier/invalidation_notifier.cc4
-rw-r--r--chrome/browser/sync/notifier/p2p_notifier.cc6
-rw-r--r--chrome/browser/sync/notifier/sync_notifier_observer.h4
-rw-r--r--chrome/browser/sync/sessions/session_state.cc57
-rw-r--r--chrome/browser/sync/sessions/session_state.h33
-rw-r--r--chrome/browser/sync/sessions/session_state_unittest.cc16
-rw-r--r--chrome/browser/sync/sessions/sync_session_unittest.cc31
-rw-r--r--chrome/browser/sync/syncable/model_type_payload_map.cc61
-rw-r--r--chrome/browser/sync/syncable/model_type_payload_map.h50
-rw-r--r--chrome/browser/sync/syncable/model_type_payload_map_unittest.cc38
-rw-r--r--chrome/browser/sync/tools/sync_listen_notifications.cc19
22 files changed, 280 insertions, 196 deletions
diff --git a/chrome/browser/sync/engine/download_updates_command.cc b/chrome/browser/sync/engine/download_updates_command.cc
index ba6cb75..e05da4e 100644
--- a/chrome/browser/sync/engine/download_updates_command.cc
+++ b/chrome/browser/sync/engine/download_updates_command.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 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.
@@ -9,8 +9,8 @@
#include "chrome/browser/sync/engine/syncer.h"
#include "chrome/browser/sync/engine/syncer_proto_util.h"
#include "chrome/browser/sync/engine/syncproto.h"
-#include "chrome/browser/sync/sessions/sync_session.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
using syncable::ScopedDirLookup;
@@ -43,7 +43,8 @@ void DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) {
// Request updates for all enabled types.
syncable::ModelTypeBitSet enabled_types;
- const sessions::TypePayloadMap& type_payload_map = session->source().types;
+ 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);
@@ -53,7 +54,7 @@ void DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) {
dir->GetDownloadProgress(model_type, progress_marker);
// Set notification hint if present.
- sessions::TypePayloadMap::const_iterator type_payload =
+ syncable::ModelTypePayloadMap::const_iterator type_payload =
type_payload_map.find(i->first);
if (type_payload != type_payload_map.end()) {
progress_marker->set_notification_hint(type_payload->second);
diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/engine/syncapi.cc
index 185c116..93fe728 100644
--- a/chrome/browser/sync/engine/syncapi.cc
+++ b/chrome/browser/sync/engine/syncapi.cc
@@ -55,6 +55,7 @@
#include "chrome/browser/sync/sessions/sync_session_context.h"
#include "chrome/browser/sync/syncable/autofill_migration.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
#include "chrome/browser/sync/syncable/nigori_util.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/browser/sync/util/crypto_helpers.h"
@@ -1194,7 +1195,7 @@ class SyncManager::SyncInternal
bool notifications_enabled);
virtual void OnIncomingNotification(
- const browser_sync::sessions::TypePayloadMap& type_payloads);
+ const syncable::ModelTypePayloadMap& type_payloads);
virtual void StoreState(const std::string& cookie);
@@ -2564,7 +2565,7 @@ void SyncManager::SyncInternal::OnNotificationStateChange(
}
void SyncManager::SyncInternal::OnIncomingNotification(
- const browser_sync::sessions::TypePayloadMap& type_payloads) {
+ const syncable::ModelTypePayloadMap& type_payloads) {
if (!type_payloads.empty()) {
if (syncer_thread()) {
syncer_thread()->NudgeSyncerWithPayloads(
@@ -2581,7 +2582,7 @@ void SyncManager::SyncInternal::OnIncomingNotification(
ListValue args;
ListValue* changed_types = new ListValue();
args.Append(changed_types);
- for (browser_sync::sessions::TypePayloadMap::const_iterator
+ for (syncable::ModelTypePayloadMap::const_iterator
it = type_payloads.begin();
it != type_payloads.end(); ++it) {
const std::string& model_type_str =
@@ -2676,8 +2677,8 @@ void SyncManager::TriggerOnNotificationStateChangeForTest(
void SyncManager::TriggerOnIncomingNotificationForTest(
const syncable::ModelTypeBitSet& model_types) {
- browser_sync::sessions::TypePayloadMap model_types_with_payloads =
- browser_sync::sessions::MakeTypePayloadMapFromBitSet(model_types,
+ syncable::ModelTypePayloadMap model_types_with_payloads =
+ syncable::ModelTypePayloadMapFromBitSet(model_types,
std::string());
data_->OnIncomingNotification(model_types_with_payloads);
diff --git a/chrome/browser/sync/engine/syncer_thread.cc b/chrome/browser/sync/engine/syncer_thread.cc
index 8ad82e5..5851c45 100644
--- a/chrome/browser/sync/engine/syncer_thread.cc
+++ b/chrome/browser/sync/engine/syncer_thread.cc
@@ -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.
@@ -34,7 +34,7 @@ namespace browser_sync {
using sessions::SyncSession;
using sessions::SyncSessionSnapshot;
using sessions::SyncSourceInfo;
-using sessions::TypePayloadMap;
+using syncable::ModelTypePayloadMap;
// We use high values here to ensure that failure to receive poll updates from
// the server doesn't result in rapid-fire polling from the client due to low
@@ -68,7 +68,7 @@ SyncerThread::ProtectedFields::~ProtectedFields() {}
void SyncerThread::NudgeSyncerWithPayloads(
int milliseconds_from_now,
NudgeSource source,
- const TypePayloadMap& model_types_with_payloads) {
+ const ModelTypePayloadMap& model_types_with_payloads) {
base::AutoLock lock(lock_);
if (vault_.syncer_ == NULL) {
return;
@@ -86,8 +86,8 @@ void SyncerThread::NudgeSyncerWithDataTypes(
return;
}
- TypePayloadMap model_types_with_payloads =
- sessions::MakeTypePayloadMapFromBitSet(model_types, std::string());
+ ModelTypePayloadMap model_types_with_payloads =
+ syncable::ModelTypePayloadMapFromBitSet(model_types, std::string());
NudgeSyncImpl(milliseconds_from_now, source, model_types_with_payloads);
}
@@ -102,8 +102,8 @@ void SyncerThread::NudgeSyncer(
// Set all enabled datatypes.
ModelSafeRoutingInfo routes;
session_context_->registrar()->GetModelSafeRoutingInfo(&routes);
- TypePayloadMap model_types_with_payloads =
- sessions::MakeTypePayloadMapFromRoutingInfo(routes, std::string());
+ ModelTypePayloadMap model_types_with_payloads =
+ syncable::ModelTypePayloadMapFromRoutingInfo(routes, std::string());
NudgeSyncImpl(milliseconds_from_now, source, model_types_with_payloads);
}
@@ -372,7 +372,7 @@ void SyncerThread::ThreadMainLoop() {
// nudges.
base::TimeTicks now = TimeTicks::Now();
if (!last_sync_time.is_null()) {
- TypePayloadMap::const_iterator iter;
+ ModelTypePayloadMap::const_iterator iter;
for (iter = session->source().types.begin();
iter != session->source().types.end();
++iter) {
@@ -604,7 +604,7 @@ SyncSourceInfo SyncerThread::GetAndResetNudgeSource(bool was_throttled,
bool* was_nudged) {
bool nudged = false;
NudgeSource nudge_source = kUnknown;
- TypePayloadMap model_types_with_payloads;
+ ModelTypePayloadMap model_types_with_payloads;
// Has the previous sync cycle completed?
if (continue_sync_cycle)
nudge_source = kContinuation;
@@ -634,7 +634,7 @@ SyncSourceInfo SyncerThread::GetAndResetNudgeSource(bool was_throttled,
SyncSourceInfo SyncerThread::MakeSyncSourceInfo(bool nudged,
NudgeSource nudge_source,
- const TypePayloadMap& model_types_with_payloads,
+ const ModelTypePayloadMap& model_types_with_payloads,
bool* initial_sync) {
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source =
sync_pb::GetUpdatesCallerInfo::UNKNOWN;
@@ -664,12 +664,12 @@ SyncSourceInfo SyncerThread::MakeSyncSourceInfo(bool nudged,
}
}
- TypePayloadMap sync_source_types;
+ ModelTypePayloadMap 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);
- sync_source_types = sessions::MakeTypePayloadMapFromRoutingInfo(routes,
+ sync_source_types = syncable::ModelTypePayloadMapFromRoutingInfo(routes,
std::string());
} else {
sync_source_types = model_types_with_payloads;
@@ -779,7 +779,7 @@ int SyncerThread::CalculateSyncWaitTime(int last_interval, int user_idle_ms) {
void SyncerThread::NudgeSyncImpl(
int milliseconds_from_now,
NudgeSource source,
- const TypePayloadMap& model_types_with_payloads) {
+ const ModelTypePayloadMap& 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.
@@ -790,11 +790,11 @@ void SyncerThread::NudgeSyncImpl(
return;
}
- // Union the current TypePayloadMap with any from nudges that may have already
- // posted (coalesce the nudge datatype information).
+ // Union the current ModelTypePayloadMap 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).
- sessions::CoalescePayloads(&vault_.pending_nudge_types_,
+ syncable::CoalescePayloads(&vault_.pending_nudge_types_,
model_types_with_payloads);
const TimeTicks nudge_time = TimeTicks::Now() +
diff --git a/chrome/browser/sync/engine/syncer_thread.h b/chrome/browser/sync/engine/syncer_thread.h
index b8bf724..e25e33a 100644
--- a/chrome/browser/sync/engine/syncer_thread.h
+++ b/chrome/browser/sync/engine/syncer_thread.h
@@ -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.
//
@@ -24,6 +24,7 @@
#include "chrome/browser/sync/engine/syncer_types.h"
#include "chrome/browser/sync/sessions/sync_session.h"
#include "chrome/browser/sync/syncable/model_type.h"
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
#include "chrome/common/deprecated/event_sys-inl.h"
#if defined(OS_LINUX)
@@ -149,7 +150,7 @@ class SyncerThread : public base::RefCountedThreadSafe<SyncerThread>,
virtual void NudgeSyncerWithPayloads(
int milliseconds_from_now,
NudgeSource source,
- const sessions::TypePayloadMap& model_types_with_payloads);
+ const syncable::ModelTypePayloadMap& model_types_with_payloads);
void SetNotificationsEnabled(bool notifications_enabled);
@@ -209,7 +210,7 @@ class SyncerThread : public base::RefCountedThreadSafe<SyncerThread>,
// payload overwrites old ones). These payloads are used by the download
// updates command and can contain datatype specific information the server
// might use.
- sessions::TypePayloadMap pending_nudge_types_;
+ syncable::ModelTypePayloadMap pending_nudge_types_;
// null iff there is no pending nudge.
base::TimeTicks pending_nudge_time_;
@@ -290,7 +291,7 @@ class SyncerThread : public base::RefCountedThreadSafe<SyncerThread>,
sessions::SyncSourceInfo MakeSyncSourceInfo(
bool nudged,
NudgeSource nudge_source,
- const sessions::TypePayloadMap& model_types_with_payloads,
+ const syncable::ModelTypePayloadMap& model_types_with_payloads,
bool* initial_sync);
int UserIdleTime();
@@ -337,7 +338,7 @@ class SyncerThread : public base::RefCountedThreadSafe<SyncerThread>,
void NudgeSyncImpl(
int milliseconds_from_now,
NudgeSource source,
- const sessions::TypePayloadMap& model_types_with_payloads);
+ const syncable::ModelTypePayloadMap& model_types_with_payloads);
#if defined(OS_LINUX)
// On Linux, we need this information in order to query idle time.
diff --git a/chrome/browser/sync/engine/syncer_thread2.cc b/chrome/browser/sync/engine/syncer_thread2.cc
index ef46360..220f5d4 100644
--- a/chrome/browser/sync/engine/syncer_thread2.cc
+++ b/chrome/browser/sync/engine/syncer_thread2.cc
@@ -17,7 +17,7 @@ namespace browser_sync {
using sessions::SyncSession;
using sessions::SyncSessionSnapshot;
using sessions::SyncSourceInfo;
-using sessions::TypePayloadMap;
+using syncable::ModelTypePayloadMap;
using syncable::ModelTypeBitSet;
using sync_pb::GetUpdatesCallerInfo;
@@ -190,15 +190,15 @@ void SyncerThread::ScheduleNudge(const TimeDelta& delay,
return;
}
- TypePayloadMap types_with_payloads =
- sessions::MakeTypePayloadMapFromBitSet(types, std::string());
+ ModelTypePayloadMap types_with_payloads =
+ syncable::ModelTypePayloadMapFromBitSet(types, std::string());
thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
this, &SyncerThread::ScheduleNudgeImpl, delay, source,
types_with_payloads));
}
void SyncerThread::ScheduleNudgeWithPayloads(const TimeDelta& delay,
- NudgeSource source, const TypePayloadMap& types_with_payloads) {
+ NudgeSource source, const ModelTypePayloadMap& types_with_payloads) {
if (!thread_.IsRunning()) {
NOTREACHED();
return;
@@ -218,7 +218,7 @@ void SyncerThread::ScheduleClearUserDataImpl() {
}
void SyncerThread::ScheduleNudgeImpl(const TimeDelta& delay,
- NudgeSource source, const TypePayloadMap& types_with_payloads) {
+ NudgeSource source, const ModelTypePayloadMap& types_with_payloads) {
DCHECK_EQ(MessageLoop::current(), thread_.message_loop());
TimeTicks rough_start = TimeTicks::Now() + delay;
@@ -308,7 +308,7 @@ void SyncerThread::ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info,
// TODO(tim): config-specific GetUpdatesCallerInfo value?
SyncSession* session = new SyncSession(session_context_.get(), this,
SyncSourceInfo(GetUpdatesCallerInfo::FIRST_UPDATE,
- sessions::MakeTypePayloadMapFromRoutingInfo(
+ syncable::ModelTypePayloadMapFromRoutingInfo(
routing_info, std::string())),
routing_info, workers);
ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), CONFIGURATION, session);
@@ -382,7 +382,7 @@ void SyncerThread::FinishSyncSessionJob(const SyncSessionJob& job) {
// Update timing information for how often datatypes are triggering nudges.
base::TimeTicks now = TimeTicks::Now();
if (!last_sync_session_end_time_.is_null()) {
- TypePayloadMap::const_iterator iter;
+ ModelTypePayloadMap::const_iterator iter;
for (iter = job.session->source().types.begin();
iter != job.session->source().types.end();
++iter) {
@@ -525,8 +525,8 @@ void SyncerThread::PollTimerCallback() {
std::vector<ModelSafeWorker*> w;
session_context_->registrar()->GetModelSafeRoutingInfo(&r);
session_context_->registrar()->GetWorkers(&w);
- TypePayloadMap types_with_payloads =
- sessions::MakeTypePayloadMapFromRoutingInfo(r, std::string());
+ ModelTypePayloadMap types_with_payloads =
+ syncable::ModelTypePayloadMapFromRoutingInfo(r, std::string());
SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads);
SyncSession* s = new SyncSession(session_context_.get(), this, info, r, w);
ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), POLL, s);
diff --git a/chrome/browser/sync/engine/syncer_thread2.h b/chrome/browser/sync/engine/syncer_thread2.h
index 89e0c96..378b9aa 100644
--- a/chrome/browser/sync/engine/syncer_thread2.h
+++ b/chrome/browser/sync/engine/syncer_thread2.h
@@ -17,6 +17,7 @@
#include "chrome/browser/sync/engine/nudge_source.h"
#include "chrome/browser/sync/engine/polling_constants.h"
#include "chrome/browser/sync/engine/syncer.h"
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
#include "chrome/browser/sync/sessions/sync_session.h"
#include "chrome/browser/sync/sessions/sync_session_context.h"
@@ -62,7 +63,7 @@ class SyncerThread : public sessions::SyncSession::Delegate {
const syncable::ModelTypeBitSet& types);
void ScheduleNudgeWithPayloads(
const base::TimeDelta& delay, NudgeSource source,
- const sessions::TypePayloadMap& types_with_payloads);
+ const syncable::ModelTypePayloadMap& types_with_payloads);
void ScheduleConfig(const syncable::ModelTypeBitSet& types);
void ScheduleClearUserData();
@@ -150,9 +151,10 @@ class SyncerThread : public sessions::SyncSession::Delegate {
// 'Impl' here refers to real implementation of public functions, running on
// |thread_|.
void StartImpl(Mode mode);
- void ScheduleNudgeImpl(const base::TimeDelta& delay,
- NudgeSource source,
- const sessions::TypePayloadMap& types_with_payloads);
+ void ScheduleNudgeImpl(
+ const base::TimeDelta& delay,
+ NudgeSource source,
+ const syncable::ModelTypePayloadMap& types_with_payloads);
void ScheduleConfigImpl(const ModelSafeRoutingInfo& routing_info,
const std::vector<ModelSafeWorker*>& workers);
void ScheduleClearUserDataImpl();
diff --git a/chrome/browser/sync/engine/syncer_thread2_unittest.cc b/chrome/browser/sync/engine/syncer_thread2_unittest.cc
index 0a54d02..70d2f73 100644
--- a/chrome/browser/sync/engine/syncer_thread2_unittest.cc
+++ b/chrome/browser/sync/engine/syncer_thread2_unittest.cc
@@ -130,12 +130,13 @@ class SyncerThread2Test : public testing::Test {
event->Signal();
}
- // Compare a ModelTyepBitSet to a TypePayloadMap, ignoring payload values.
- bool CompareModelTypeBitSetToTypePayloadMap(
+ // Compare a ModelTypeBitSet to a ModelTypePayloadMap, ignoring
+ // payload values.
+ bool CompareModelTypeBitSetToModelTypePayloadMap(
const syncable::ModelTypeBitSet& lhs,
- const sessions::TypePayloadMap& rhs) {
+ const syncable::ModelTypePayloadMap& rhs) {
size_t count = 0;
- for (sessions::TypePayloadMap::const_iterator i = rhs.begin();
+ for (syncable::ModelTypePayloadMap::const_iterator i = rhs.begin();
i != rhs.end(); ++i, ++count) {
if (!lhs.test(i->first))
return false;
@@ -192,7 +193,7 @@ TEST_F(SyncerThread2Test, Nudge) {
done.TimedWait(timeout());
EXPECT_EQ(1U, records.snapshots.size());
- EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(model_types,
+ EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types,
records.snapshots[0]->source.types));
EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
records.snapshots[0]->source.updates_source);
@@ -208,7 +209,7 @@ TEST_F(SyncerThread2Test, Nudge) {
done.TimedWait(timeout());
EXPECT_EQ(1U, records2.snapshots.size());
- EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(model_types,
+ EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(model_types,
records2.snapshots[0]->source.types));
EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
records2.snapshots[0]->source.updates_source);
@@ -235,7 +236,8 @@ TEST_F(SyncerThread2Test, NudgeCoalescing) {
EXPECT_EQ(1U, r.snapshots.size());
EXPECT_GE(r.times[0], optimal_time);
- EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(types1 | types2 | types3,
+ EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(
+ types1 | types2 | types3,
r.snapshots[0]->source.types));
EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
r.snapshots[0]->source.updates_source);
@@ -247,7 +249,7 @@ TEST_F(SyncerThread2Test, NudgeCoalescing) {
syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_NOTIFICATION, types3);
done.TimedWait(timeout());
EXPECT_EQ(1U, r2.snapshots.size());
- EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(types3,
+ EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(types3,
r2.snapshots[0]->source.types));
EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
r2.snapshots[0]->source.updates_source);
@@ -258,7 +260,7 @@ TEST_F(SyncerThread2Test, NudgeWithPayloads) {
syncer_thread()->Start(SyncerThread::NORMAL_MODE);
base::WaitableEvent done(false, false);
SyncShareRecords records;
- sessions::TypePayloadMap model_types_with_payloads;
+ syncable::ModelTypePayloadMap model_types_with_payloads;
model_types_with_payloads[syncable::BOOKMARKS] = "test";
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
@@ -299,7 +301,7 @@ TEST_F(SyncerThread2Test, NudgeWithPayloadsCoalescing) {
EXPECT_CALL(*syncer(), SyncShare(_,_,_))
.WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
WithArg<0>(RecordSyncShare(&r, 1U, &done))));
- sessions::TypePayloadMap types1, types2, types3;
+ syncable::ModelTypePayloadMap types1, types2, types3;
types1[syncable::BOOKMARKS] = "test1";
types2[syncable::AUTOFILL] = "test2";
types3[syncable::THEMES] = "test3";
@@ -315,10 +317,10 @@ TEST_F(SyncerThread2Test, NudgeWithPayloadsCoalescing) {
EXPECT_EQ(1U, r.snapshots.size());
EXPECT_GE(r.times[0], optimal_time);
- sessions::TypePayloadMap coalesced_types;
- sessions::CoalescePayloads(&coalesced_types, types1);
- sessions::CoalescePayloads(&coalesced_types, types2);
- sessions::CoalescePayloads(&coalesced_types, types3);
+ syncable::ModelTypePayloadMap coalesced_types;
+ syncable::CoalescePayloads(&coalesced_types, types1);
+ syncable::CoalescePayloads(&coalesced_types, types2);
+ syncable::CoalescePayloads(&coalesced_types, types3);
EXPECT_EQ(coalesced_types, r.snapshots[0]->source.types);
EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
r.snapshots[0]->source.updates_source);
@@ -477,7 +479,7 @@ TEST_F(SyncerThread2Test, ConfigurationMode) {
syncer_thread()->Stop();
EXPECT_EQ(1U, records.snapshots.size());
- EXPECT_TRUE(CompareModelTypeBitSetToTypePayloadMap(config_types,
+ EXPECT_TRUE(CompareModelTypeBitSetToModelTypePayloadMap(config_types,
records.snapshots[0]->source.types));
}
diff --git a/chrome/browser/sync/engine/syncer_thread_adapter.cc b/chrome/browser/sync/engine/syncer_thread_adapter.cc
index 34b3a00..174e49a 100644
--- a/chrome/browser/sync/engine/syncer_thread_adapter.cc
+++ b/chrome/browser/sync/engine/syncer_thread_adapter.cc
@@ -62,7 +62,7 @@ bool SyncerThreadAdapter::RequestResume() {
}
s3::NudgeSource LegacyToNewSyncerThreadSource(SyncerThread::NudgeSource s) {
- switch(s) {
+ switch (s) {
case SyncerThread::kNotification:
return s3::NUDGE_SOURCE_NOTIFICATION;
case SyncerThread::kContinuation:
@@ -110,7 +110,7 @@ void SyncerThreadAdapter::NudgeSyncerWithDataTypes(
void SyncerThreadAdapter::NudgeSyncerWithPayloads(
int milliseconds_from_now,
SyncerThread::NudgeSource source,
- const sessions::TypePayloadMap& model_types_with_payloads) {
+ const syncable::ModelTypePayloadMap& model_types_with_payloads) {
DCHECK_NE(SyncerThread::kClearPrivateData, source);
if (using_new_impl_) {
new_impl_->ScheduleNudgeWithPayloads(
diff --git a/chrome/browser/sync/engine/syncer_thread_adapter.h b/chrome/browser/sync/engine/syncer_thread_adapter.h
index a47bb1a..bc35305 100644
--- a/chrome/browser/sync/engine/syncer_thread_adapter.h
+++ b/chrome/browser/sync/engine/syncer_thread_adapter.h
@@ -1,6 +1,9 @@
// 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.
+#ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_ADAPTER_H_
+#define CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_ADAPTER_H_
+#pragma once
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
@@ -9,6 +12,7 @@
#include "chrome/browser/sync/engine/syncer_thread2.h"
#include "chrome/browser/sync/sessions/sync_session_context.h"
#include "chrome/browser/sync/syncable/model_type.h"
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
namespace browser_sync {
@@ -33,7 +37,7 @@ class SyncerThreadAdapter {
void NudgeSyncerWithPayloads(
int milliseconds_from_now,
SyncerThread::NudgeSource source,
- const sessions::TypePayloadMap& model_types_with_payloads);
+ const syncable::ModelTypePayloadMap& model_types_with_payloads);
void SetNotificationsEnabled(bool enabled);
void CreateSyncer(const std::string& dirname);
@@ -48,3 +52,5 @@ class SyncerThreadAdapter {
};
} // namespace browser_sync
+
+#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_ADAPTER_H_
diff --git a/chrome/browser/sync/engine/syncer_thread_unittest.cc b/chrome/browser/sync/engine/syncer_thread_unittest.cc
index f5d8049..2d91e1f 100644
--- a/chrome/browser/sync/engine/syncer_thread_unittest.cc
+++ b/chrome/browser/sync/engine/syncer_thread_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 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.
@@ -172,8 +172,8 @@ class SyncerThreadWithSyncerTest : public testing::Test,
// Compare a provided TypePayloadMap to the pending nudge info stored in the
// SyncerThread vault.
- bool CompareNudgeTypesToVault(const sessions::TypePayloadMap& lhs) {
- const sessions::TypePayloadMap& vault_nudge_types =
+ bool CompareNudgeTypesToVault(const syncable::ModelTypePayloadMap& lhs) {
+ const syncable::ModelTypePayloadMap& vault_nudge_types =
syncer_thread()->vault_.pending_nudge_types_;
return lhs == vault_nudge_types;
}
@@ -182,10 +182,10 @@ class SyncerThreadWithSyncerTest : public testing::Test,
// SyncerThread vault. Nudge info in vault must not have any non-empty
// payloads.
bool CompareNudgeTypesBitSetToVault(const syncable::ModelTypeBitSet& lhs) {
- sessions::TypePayloadMap model_types_with_payloads =
- sessions::MakeTypePayloadMapFromBitSet(lhs, std::string());
+ syncable::ModelTypePayloadMap model_types_with_payloads =
+ syncable::ModelTypePayloadMapFromBitSet(lhs, std::string());
size_t count = 0;
- for (sessions::TypePayloadMap::const_iterator i =
+ for (syncable::ModelTypePayloadMap::const_iterator i =
syncer_thread()->vault_.pending_nudge_types_.begin();
i != syncer_thread()->vault_.pending_nudge_types_.end();
++i, ++count) {
@@ -832,7 +832,7 @@ TEST_F(SyncerThreadWithSyncerTest, NudgeWithPayloads) {
// The SyncerThread should be waiting for the poll now. Nudge it to sync
// immediately (5ms).
- sessions::TypePayloadMap nudge_types;
+ syncable::ModelTypePayloadMap nudge_types;
nudge_types[syncable::BOOKMARKS] = "test";
connection()->ExpectGetUpdatesRequestPayloads(nudge_types);
@@ -868,7 +868,7 @@ TEST_F(SyncerThreadWithSyncerTest, NudgeWithPayloadsCoalesced) {
// The SyncerThread should be waiting for the poll now. Nudge it to sync
// immediately (5ms).
- sessions::TypePayloadMap nudge_types;
+ syncable::ModelTypePayloadMap nudge_types;
nudge_types[syncable::BOOKMARKS] = "books";
// Paused so we can verify the nudge types safely.
diff --git a/chrome/browser/sync/engine/syncer_unittest.cc b/chrome/browser/sync/engine/syncer_unittest.cc
index 0aa7e35..20e641e 100644
--- a/chrome/browser/sync/engine/syncer_unittest.cc
+++ b/chrome/browser/sync/engine/syncer_unittest.cc
@@ -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.
//
@@ -154,8 +154,8 @@ class SyncerTest : public testing::Test,
std::vector<ModelSafeWorker*> workers;
GetModelSafeRoutingInfo(&info);
GetWorkers(&workers);
- sessions::TypePayloadMap types =
- sessions::MakeTypePayloadMapFromRoutingInfo(info, std::string());
+ syncable::ModelTypePayloadMap types =
+ syncable::ModelTypePayloadMapFromRoutingInfo(info, std::string());
return new SyncSession(context_.get(), this,
sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types),
info, workers);
diff --git a/chrome/browser/sync/notifier/invalidation_notifier.cc b/chrome/browser/sync/notifier/invalidation_notifier.cc
index 1e35781..0936e1e 100644
--- a/chrome/browser/sync/notifier/invalidation_notifier.cc
+++ b/chrome/browser/sync/notifier/invalidation_notifier.cc
@@ -86,8 +86,8 @@ void InvalidationNotifier::OnIncomingNotification(
model_types.set();
}
- browser_sync::sessions::TypePayloadMap type_payloads =
- browser_sync::sessions::MakeTypePayloadMapFromBitSet(
+ syncable::ModelTypePayloadMap type_payloads =
+ syncable::ModelTypePayloadMapFromBitSet(
model_types, notification_payload);
FOR_EACH_OBSERVER(SyncNotifierObserver, observer_list_,
OnIncomingNotification(type_payloads));
diff --git a/chrome/browser/sync/notifier/p2p_notifier.cc b/chrome/browser/sync/notifier/p2p_notifier.cc
index 12d031b..c0b8d7f 100644
--- a/chrome/browser/sync/notifier/p2p_notifier.cc
+++ b/chrome/browser/sync/notifier/p2p_notifier.cc
@@ -6,7 +6,7 @@
#include "chrome/browser/sync/notifier/sync_notifier_observer.h"
#include "chrome/browser/sync/protocol/service_constants.h"
-#include "chrome/browser/sync/sessions/session_state.h"
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
#include "jingle/notifier/listener/mediator_thread_impl.h"
#include "jingle/notifier/listener/talk_mediator_impl.h"
@@ -113,8 +113,8 @@ void P2PNotifier::MaybeEmitNotification() {
VLOG(1) << "No enabled types -- not emitting notification";
return;
}
- browser_sync::sessions::TypePayloadMap type_payloads =
- browser_sync::sessions::MakeTypePayloadMapFromBitSet(
+ syncable::ModelTypePayloadMap type_payloads =
+ syncable::ModelTypePayloadMapFromBitSet(
syncable::ModelTypeBitSetFromSet(enabled_types_), std::string());
FOR_EACH_OBSERVER(SyncNotifierObserver, observer_list_,
OnIncomingNotification(type_payloads));
diff --git a/chrome/browser/sync/notifier/sync_notifier_observer.h b/chrome/browser/sync/notifier/sync_notifier_observer.h
index 2978d17..79439ce 100644
--- a/chrome/browser/sync/notifier/sync_notifier_observer.h
+++ b/chrome/browser/sync/notifier/sync_notifier_observer.h
@@ -8,7 +8,7 @@
#include <string>
-#include "chrome/browser/sync/sessions/session_state.h"
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
namespace sync_notifier {
@@ -18,7 +18,7 @@ class SyncNotifierObserver {
virtual ~SyncNotifierObserver() {}
virtual void OnIncomingNotification(
- const browser_sync::sessions::TypePayloadMap& type_payloads) = 0;
+ const syncable::ModelTypePayloadMap& type_payloads) = 0;
virtual void OnNotificationStateChange(bool notifications_enabled) = 0;
// TODO(nileshagrawal): Find a way to hide state handling inside the
diff --git a/chrome/browser/sync/sessions/session_state.cc b/chrome/browser/sync/sessions/session_state.cc
index 27457fb..3bf80a8 100644
--- a/chrome/browser/sync/sessions/session_state.cc
+++ b/chrome/browser/sync/sessions/session_state.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 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.
@@ -20,65 +20,16 @@ using std::vector;
namespace browser_sync {
namespace sessions {
-TypePayloadMap MakeTypePayloadMapFromBitSet(
- const syncable::ModelTypeBitSet& types,
- const std::string& payload) {
- TypePayloadMap types_with_payloads;
- for (size_t i = syncable::FIRST_REAL_MODEL_TYPE;
- i < types.size(); ++i) {
- if (types[i]) {
- types_with_payloads[syncable::ModelTypeFromInt(i)] = payload;
- }
- }
- return types_with_payloads;
-}
-
-TypePayloadMap MakeTypePayloadMapFromRoutingInfo(
- const ModelSafeRoutingInfo& routes,
- const std::string& payload) {
- TypePayloadMap types_with_payloads;
- for (ModelSafeRoutingInfo::const_iterator i = routes.begin();
- i != routes.end(); ++i) {
- types_with_payloads[i->first] = payload;
- }
- return types_with_payloads;
-}
-
-DictionaryValue* TypePayloadMapToValue(const TypePayloadMap& type_payloads) {
- DictionaryValue* value = new DictionaryValue();
- for (TypePayloadMap::const_iterator it = type_payloads.begin();
- it != type_payloads.end(); ++it) {
- value->SetString(syncable::ModelTypeToString(it->first), it->second);
- }
- return value;
-}
-
-void CoalescePayloads(TypePayloadMap* original,
- const TypePayloadMap& update) {
- for (TypePayloadMap::const_iterator i = update.begin();
- i != update.end(); ++i) {
- if (original->count(i->first) == 0) {
- // If this datatype isn't already in our map, add it with whatever payload
- // it has.
- (*original)[i->first] = i->second;
- } else if (i->second.length() > 0) {
- // If this datatype is already in our map, we only overwrite the payload
- // if the new one is non-empty.
- (*original)[i->first] = i->second;
- }
- }
-}
-
SyncSourceInfo::SyncSourceInfo()
: updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN) {}
SyncSourceInfo::SyncSourceInfo(
- const TypePayloadMap& t)
+ const syncable::ModelTypePayloadMap& t)
: updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN), types(t) {}
SyncSourceInfo::SyncSourceInfo(
const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u,
- const TypePayloadMap& t)
+ const syncable::ModelTypePayloadMap& t)
: updates_source(u), types(t) {}
SyncSourceInfo::~SyncSourceInfo() {}
@@ -87,7 +38,7 @@ DictionaryValue* SyncSourceInfo::ToValue() const {
DictionaryValue* value = new DictionaryValue();
value->SetString("updatesSource",
GetUpdatesSourceString(updates_source));
- value->Set("types", TypePayloadMapToValue(types));
+ value->Set("types", syncable::ModelTypePayloadMapToValue(types));
return value;
}
diff --git a/chrome/browser/sync/sessions/session_state.h b/chrome/browser/sync/sessions/session_state.h
index 479cc7f..2a2c94a 100644
--- a/chrome/browser/sync/sessions/session_state.h
+++ b/chrome/browser/sync/sessions/session_state.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 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.
@@ -24,6 +24,7 @@
#include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/sessions/ordered_commit_set.h"
#include "chrome/browser/sync/syncable/model_type.h"
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
#include "chrome/browser/sync/syncable/syncable.h"
class DictionaryValue;
@@ -37,46 +38,22 @@ namespace sessions {
class UpdateProgress;
-// A container that contains a set of datatypes with possible string payloads.
-typedef std::map<syncable::ModelType, std::string> TypePayloadMap;
-
-// Helper utils for building TypePayloadMaps.
-// Make a TypePayloadMap from all the types in a ModelTypeBitSet using a
-// default payload.
-TypePayloadMap MakeTypePayloadMapFromBitSet(
- const syncable::ModelTypeBitSet& types,
- const std::string& payload);
-
-// Make a TypePayloadMap for all the enabled types in a ModelSafeRoutingInfo
-// using a default payload.
-TypePayloadMap MakeTypePayloadMapFromRoutingInfo(
- const ModelSafeRoutingInfo& routes,
- const std::string& payload);
-
-// Caller takes ownership of the returned dictionary.
-DictionaryValue* TypePayloadMapToValue(const TypePayloadMap& type_payloads);
-
-// Coalesce |update| into |original|, overwriting only when |update| has
-// a non-empty payload.
-void CoalescePayloads(TypePayloadMap* original, const TypePayloadMap& update);
-
// A container for the source of a sync session. This includes the update
// source, the datatypes triggering the sync session, and possible session
// specific payloads which should be sent to the server.
struct SyncSourceInfo {
SyncSourceInfo();
- SyncSourceInfo(
- const TypePayloadMap& t);
+ explicit SyncSourceInfo(const syncable::ModelTypePayloadMap& t);
SyncSourceInfo(
const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u,
- const TypePayloadMap& t);
+ const syncable::ModelTypePayloadMap& t);
~SyncSourceInfo();
// Caller takes ownership of the returned dictionary.
DictionaryValue* ToValue() const;
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source;
- TypePayloadMap types;
+ syncable::ModelTypePayloadMap types;
};
// Data pertaining to the status of an active Syncer object.
diff --git a/chrome/browser/sync/sessions/session_state_unittest.cc b/chrome/browser/sync/sessions/session_state_unittest.cc
index 3ac832f..eb9fc04 100644
--- a/chrome/browser/sync/sessions/session_state_unittest.cc
+++ b/chrome/browser/sync/sessions/session_state_unittest.cc
@@ -24,26 +24,14 @@ using test::ExpectStringValue;
class SessionStateTest : public testing::Test {};
-TEST_F(SessionStateTest, TypePayloadMapToValue) {
- TypePayloadMap payloads;
- payloads[syncable::BOOKMARKS] = "bookmarkpayload";
- payloads[syncable::APPS] = "";
-
- scoped_ptr<DictionaryValue> value(TypePayloadMapToValue(payloads));
- EXPECT_EQ(2u, value->size());
- ExpectStringValue("bookmarkpayload", *value, "Bookmarks");
- ExpectStringValue("", *value, "Apps");
- EXPECT_FALSE(value->HasKey("Preferences"));
-}
-
TEST_F(SessionStateTest, SyncSourceInfoToValue) {
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source =
sync_pb::GetUpdatesCallerInfo::PERIODIC;
- TypePayloadMap types;
+ syncable::ModelTypePayloadMap types;
types[syncable::PREFERENCES] = "preferencespayload";
types[syncable::EXTENSIONS] = "";
scoped_ptr<DictionaryValue> expected_types_value(
- TypePayloadMapToValue(types));
+ syncable::ModelTypePayloadMapToValue(types));
SyncSourceInfo source_info(updates_source, types);
diff --git a/chrome/browser/sync/sessions/sync_session_unittest.cc b/chrome/browser/sync/sessions/sync_session_unittest.cc
index 0f433de..88850f60 100644
--- a/chrome/browser/sync/sessions/sync_session_unittest.cc
+++ b/chrome/browser/sync/sessions/sync_session_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 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.
@@ -266,12 +266,14 @@ TEST_F(SyncSessionTest, ResetTransientState) {
TEST_F(SyncSessionTest, Coalesce) {
std::vector<ModelSafeWorker*> workers_one, workers_two;
ModelSafeRoutingInfo routes_one, routes_two;
- TypePayloadMap one_type = sessions::MakeTypePayloadMapFromBitSet(
- ParamsMeaningJustOneEnabledType(),
- std::string());;
- TypePayloadMap all_types = sessions::MakeTypePayloadMapFromBitSet(
- ParamsMeaningAllEnabledTypes(),
- std::string());;
+ syncable::ModelTypePayloadMap one_type =
+ syncable::ModelTypePayloadMapFromBitSet(
+ ParamsMeaningJustOneEnabledType(),
+ std::string());
+ syncable::ModelTypePayloadMap all_types =
+ syncable::ModelTypePayloadMapFromBitSet(
+ ParamsMeaningAllEnabledTypes(),
+ std::string());
SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type);
SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types);
@@ -302,15 +304,16 @@ TEST_F(SyncSessionTest, Coalesce) {
TEST_F(SyncSessionTest, MakeTypePayloadMapFromBitSet) {
syncable::ModelTypeBitSet types;
std::string payload = "test";
- TypePayloadMap types_with_payloads = MakeTypePayloadMapFromBitSet(types,
- payload);
+ syncable::ModelTypePayloadMap types_with_payloads =
+ syncable::ModelTypePayloadMapFromBitSet(types,
+ payload);
EXPECT_TRUE(types_with_payloads.empty());
types[syncable::BOOKMARKS] = true;
types[syncable::PASSWORDS] = true;
types[syncable::AUTOFILL] = true;
payload = "test2";
- types_with_payloads = MakeTypePayloadMapFromBitSet(types, payload);
+ types_with_payloads = syncable::ModelTypePayloadMapFromBitSet(types, payload);
ASSERT_EQ(3U, types_with_payloads.size());
EXPECT_EQ(types_with_payloads[syncable::BOOKMARKS], payload);
@@ -320,8 +323,8 @@ TEST_F(SyncSessionTest, MakeTypePayloadMapFromBitSet) {
TEST_F(SyncSessionTest, MakeTypePayloadMapFromRoutingInfo) {
std::string payload = "test";
- TypePayloadMap types_with_payloads
- = MakeTypePayloadMapFromRoutingInfo(routes_, payload);
+ syncable::ModelTypePayloadMap types_with_payloads
+ = syncable::ModelTypePayloadMapFromRoutingInfo(routes_, payload);
ASSERT_EQ(routes_.size(), types_with_payloads.size());
for (ModelSafeRoutingInfo::iterator iter = routes_.begin();
iter != routes_.end();
@@ -331,7 +334,7 @@ TEST_F(SyncSessionTest, MakeTypePayloadMapFromRoutingInfo) {
}
TEST_F(SyncSessionTest, CoalescePayloads) {
- TypePayloadMap original;
+ syncable::ModelTypePayloadMap original;
std::string empty_payload;
std::string payload1 = "payload1";
std::string payload2 = "payload2";
@@ -341,7 +344,7 @@ TEST_F(SyncSessionTest, CoalescePayloads) {
original[syncable::AUTOFILL] = payload2;
original[syncable::THEMES] = payload3;
- TypePayloadMap update;
+ syncable::ModelTypePayloadMap update;
update[syncable::BOOKMARKS] = empty_payload; // Same.
update[syncable::PASSWORDS] = empty_payload; // Overwrite with empty.
update[syncable::AUTOFILL] = payload1; // Overwrite with non-empty.
diff --git a/chrome/browser/sync/syncable/model_type_payload_map.cc b/chrome/browser/sync/syncable/model_type_payload_map.cc
new file mode 100644
index 0000000..af1bbca
--- /dev/null
+++ b/chrome/browser/sync/syncable/model_type_payload_map.cc
@@ -0,0 +1,61 @@
+// 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.
+
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
+
+#include "base/values.h"
+
+namespace syncable {
+
+ModelTypePayloadMap ModelTypePayloadMapFromBitSet(
+ const syncable::ModelTypeBitSet& types,
+ const std::string& payload) {
+ ModelTypePayloadMap types_with_payloads;
+ for (size_t i = syncable::FIRST_REAL_MODEL_TYPE;
+ i < types.size(); ++i) {
+ if (types[i]) {
+ types_with_payloads[syncable::ModelTypeFromInt(i)] = payload;
+ }
+ }
+ return types_with_payloads;
+}
+
+ModelTypePayloadMap ModelTypePayloadMapFromRoutingInfo(
+ const browser_sync::ModelSafeRoutingInfo& routes,
+ const std::string& payload) {
+ ModelTypePayloadMap types_with_payloads;
+ for (browser_sync::ModelSafeRoutingInfo::const_iterator i = routes.begin();
+ i != routes.end(); ++i) {
+ types_with_payloads[i->first] = payload;
+ }
+ return types_with_payloads;
+}
+
+DictionaryValue* ModelTypePayloadMapToValue(
+ const ModelTypePayloadMap& type_payloads) {
+ DictionaryValue* value = new DictionaryValue();
+ for (ModelTypePayloadMap::const_iterator it = type_payloads.begin();
+ it != type_payloads.end(); ++it) {
+ value->SetString(syncable::ModelTypeToString(it->first), it->second);
+ }
+ return value;
+}
+
+void CoalescePayloads(ModelTypePayloadMap* original,
+ const ModelTypePayloadMap& update) {
+ for (ModelTypePayloadMap::const_iterator i = update.begin();
+ i != update.end(); ++i) {
+ if (original->count(i->first) == 0) {
+ // If this datatype isn't already in our map, add it with
+ // whatever payload it has.
+ (*original)[i->first] = i->second;
+ } else if (i->second.length() > 0) {
+ // If this datatype is already in our map, we only overwrite the
+ // payload if the new one is non-empty.
+ (*original)[i->first] = i->second;
+ }
+ }
+}
+
+} // namespace syncable
diff --git a/chrome/browser/sync/syncable/model_type_payload_map.h b/chrome/browser/sync/syncable/model_type_payload_map.h
new file mode 100644
index 0000000..212220e
--- /dev/null
+++ b/chrome/browser/sync/syncable/model_type_payload_map.h
@@ -0,0 +1,50 @@
+// 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.
+//
+// Definition of ModelTypePayloadMap and various utility functions.
+
+#ifndef CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_PAYLOAD_MAP_H_
+#define CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_PAYLOAD_MAP_H_
+#pragma once
+
+#include <map>
+#include <string>
+
+#include "chrome/browser/sync/engine/model_safe_worker.h"
+#include "chrome/browser/sync/syncable/model_type.h"
+
+class DictionaryValue;
+
+namespace syncable {
+
+// A container that contains a set of datatypes with possible string
+// payloads.
+typedef std::map<ModelType, std::string> ModelTypePayloadMap;
+
+// Helper functions for building ModelTypePayloadMaps.
+
+// Make a TypePayloadMap from all the types in a ModelTypeBitSet using
+// a default payload.
+ModelTypePayloadMap ModelTypePayloadMapFromBitSet(
+ const ModelTypeBitSet& model_types,
+ const std::string& payload);
+
+// Make a TypePayloadMap for all the enabled types in a
+// ModelSafeRoutingInfo using a default payload.
+ModelTypePayloadMap ModelTypePayloadMapFromRoutingInfo(
+ const browser_sync::ModelSafeRoutingInfo& routes,
+ const std::string& payload);
+
+// Caller takes ownership of the returned dictionary.
+DictionaryValue* ModelTypePayloadMapToValue(
+ const ModelTypePayloadMap& model_type_payloads);
+
+// Coalesce |update| into |original|, overwriting only when |update| has
+// a non-empty payload.
+void CoalescePayloads(ModelTypePayloadMap* original,
+ const ModelTypePayloadMap& update);
+
+} // namespace syncable
+
+#endif // CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_PAYLOAD_MAP_H_
diff --git a/chrome/browser/sync/syncable/model_type_payload_map_unittest.cc b/chrome/browser/sync/syncable/model_type_payload_map_unittest.cc
new file mode 100644
index 0000000..264505e
--- /dev/null
+++ b/chrome/browser/sync/syncable/model_type_payload_map_unittest.cc
@@ -0,0 +1,38 @@
+// 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.
+
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
+
+#include <string>
+
+#include "base/scoped_ptr.h"
+#include "base/values.h"
+#include "chrome/test/values_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace syncable {
+namespace {
+
+using test::ExpectBooleanValue;
+using test::ExpectDictionaryValue;
+using test::ExpectIntegerValue;
+using test::ExpectListValue;
+using test::ExpectStringValue;
+
+class ModelTypePayloadMapTest : public testing::Test {};
+
+TEST_F(ModelTypePayloadMapTest, TypePayloadMapToValue) {
+ ModelTypePayloadMap payloads;
+ payloads[syncable::BOOKMARKS] = "bookmarkpayload";
+ payloads[syncable::APPS] = "";
+
+ scoped_ptr<DictionaryValue> value(ModelTypePayloadMapToValue(payloads));
+ EXPECT_EQ(2u, value->size());
+ ExpectStringValue("bookmarkpayload", *value, "Bookmarks");
+ ExpectStringValue("", *value, "Apps");
+ EXPECT_FALSE(value->HasKey("Preferences"));
+}
+
+} // namespace
+} // namespace syncable
diff --git a/chrome/browser/sync/tools/sync_listen_notifications.cc b/chrome/browser/sync/tools/sync_listen_notifications.cc
index ee63194..e0e1eeb 100644
--- a/chrome/browser/sync/tools/sync_listen_notifications.cc
+++ b/chrome/browser/sync/tools/sync_listen_notifications.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <cstdio>
#include <string>
#include "base/at_exit.h"
@@ -14,6 +15,7 @@
#include "chrome/browser/sync/notifier/sync_notifier_factory.h"
#include "chrome/browser/sync/notifier/sync_notifier_observer.h"
#include "chrome/browser/sync/syncable/model_type.h"
+#include "chrome/browser/sync/syncable/model_type_payload_map.h"
// This is a simple utility that initializes a sync notifier and
// listens to any received notifications.
@@ -27,8 +29,8 @@ class NotificationPrinter : public sync_notifier::SyncNotifierObserver {
virtual ~NotificationPrinter() {}
virtual void OnIncomingNotification(
- const browser_sync::sessions::TypePayloadMap& type_payloads) {
- for (browser_sync::sessions::TypePayloadMap::const_iterator it =
+ const syncable::ModelTypePayloadMap& type_payloads) {
+ for (syncable::ModelTypePayloadMap::const_iterator it =
type_payloads.begin(); it != type_payloads.end(); ++it) {
LOG(INFO) << "Notification: type = "
<< syncable::ModelTypeToString(it->first)
@@ -69,12 +71,13 @@ int main(int argc, char* argv[]) {
// TODO(akalin): Write a wrapper script that gets a token for an
// email and password and passes that in to this utility.
if (email.empty() || token.empty()) {
- printf("Usage: %s --email=foo@bar.com --token=token\n\n"
- "See sync_notifier_factory.cc for more switches.\n\n"
- "Run chrome and set a breakpoint on "
- "SyncNotifierImpl::UpdateCredentials() after\n"
- "logging into sync to get the token to pass into this utility.\n",
- argv[0]);
+ std::printf("Usage: %s --email=foo@bar.com --token=token\n\n"
+ "See sync_notifier_factory.cc for more switches.\n\n"
+ "Run chrome and set a breakpoint on "
+ "SyncNotifierImpl::UpdateCredentials() after\n"
+ "logging into sync to get the token to pass into this "
+ "utility.\n",
+ argv[0]);
return -1;
}