summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/syncable
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-10 23:41:40 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-10 23:41:40 +0000
commit2b85b67a2938a787ecb3344bb555937e6ef87c9a (patch)
tree31e8769ffbf4244af44baa91f69a9cc6f7f62df2 /chrome/browser/sync/syncable
parent8fe16d6423f526223016df11b2ae0630672efe8c (diff)
downloadchromium_src-2b85b67a2938a787ecb3344bb555937e6ef87c9a.zip
chromium_src-2b85b67a2938a787ecb3344bb555937e6ef87c9a.tar.gz
chromium_src-2b85b67a2938a787ecb3344bb555937e6ef87c9a.tar.bz2
[Sync] Add more conversions to Value for sync types
This is a prerequisite for exposing some functions to chrome://sync-internals. Cleaned up some test code also. BUG=69500 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=74489 Review URL: http://codereview.chromium.org/6476016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74521 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/syncable')
-rw-r--r--chrome/browser/sync/syncable/model_type.cc13
-rw-r--r--chrome/browser/sync/syncable/model_type.h5
-rw-r--r--chrome/browser/sync/syncable/model_type_unittest.cc33
3 files changed, 51 insertions, 0 deletions
diff --git a/chrome/browser/sync/syncable/model_type.cc b/chrome/browser/sync/syncable/model_type.cc
index 1aea654..0ff67bd 100644
--- a/chrome/browser/sync/syncable/model_type.cc
+++ b/chrome/browser/sync/syncable/model_type.cc
@@ -7,6 +7,7 @@
#include <sstream>
#include "base/metrics/histogram.h"
+#include "base/values.h"
#include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/protocol/app_specifics.pb.h"
#include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
@@ -255,6 +256,18 @@ bool ModelTypeBitSetFromString(
return iss.eof();
}
+ListValue* ModelTypeBitSetToValue(const ModelTypeBitSet& model_types) {
+ ListValue* value = new ListValue();
+ for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
+ if (model_types[i]) {
+ value->Append(
+ Value::CreateStringValue(
+ ModelTypeToString(ModelTypeFromInt(i))));
+ }
+ }
+ return value;
+}
+
// For now, this just implements UMA_HISTOGRAM_LONG_TIMES. This can be adjusted
// if we feel the min, max, or bucket count amount are not appropriate.
#define SYNC_FREQ_HISTOGRAM(name, time) UMA_HISTOGRAM_CUSTOM_TIMES( \
diff --git a/chrome/browser/sync/syncable/model_type.h b/chrome/browser/sync/syncable/model_type.h
index 308f516..62f1787 100644
--- a/chrome/browser/sync/syncable/model_type.h
+++ b/chrome/browser/sync/syncable/model_type.h
@@ -17,6 +17,8 @@
#include "base/logging.h"
#include "base/time.h"
+class ListValue;
+
namespace sync_pb {
class EntitySpecifics;
class SyncEntity;
@@ -113,6 +115,9 @@ bool ModelTypeBitSetFromString(
const std::string& model_type_bitset_string,
ModelTypeBitSet* model_types);
+// Caller takes ownership of returned list.
+ListValue* ModelTypeBitSetToValue(const ModelTypeBitSet& model_types);
+
// Posts timedeltas to histogram of datatypes. Allows tracking of the frequency
// at which datatypes cause syncs.
void PostTimeToTypeHistogram(ModelType model_type, base::TimeDelta time);
diff --git a/chrome/browser/sync/syncable/model_type_unittest.cc b/chrome/browser/sync/syncable/model_type_unittest.cc
new file mode 100644
index 0000000..b15f0a0
--- /dev/null
+++ b/chrome/browser/sync/syncable/model_type_unittest.cc
@@ -0,0 +1,33 @@
+// 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.h"
+
+#include <string>
+
+#include "base/scoped_ptr.h"
+#include "base/values.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace syncable {
+namespace {
+
+class ModelTypeTest : public testing::Test {};
+
+TEST_F(ModelTypeTest, ModelTypeBitSetToValue) {
+ ModelTypeBitSet model_types;
+ model_types.set(syncable::BOOKMARKS);
+ model_types.set(syncable::APPS);
+
+ scoped_ptr<ListValue> value(ModelTypeBitSetToValue(model_types));
+ EXPECT_EQ(2u, value->GetSize());
+ std::string types[2];
+ EXPECT_TRUE(value->GetString(0, &types[0]));
+ EXPECT_TRUE(value->GetString(1, &types[1]));
+ EXPECT_EQ("Bookmarks", types[0]);
+ EXPECT_EQ("Apps", types[1]);
+}
+
+} // namespace
+} // namespace syncable