Chromium Code Reviews| Index: chrome/browser/sync/syncable/syncable.cc |
| diff --git a/chrome/browser/sync/syncable/syncable.cc b/chrome/browser/sync/syncable/syncable.cc |
| index a279e518aaaa8ec07ca891ec5b9a43b67930a666..40a6cfb504bc7cc56657cab53370d48ef165a7f6 100644 |
| --- a/chrome/browser/sync/syncable/syncable.cc |
| +++ b/chrome/browser/sync/syncable/syncable.cc |
| @@ -4,20 +4,6 @@ |
| #include "chrome/browser/sync/syncable/syncable.h" |
| -#include "build/build_config.h" |
| - |
| -#include <sys/stat.h> |
| -#if defined(OS_POSIX) |
| -#include <sys/time.h> |
| -#endif |
| -#include <sys/types.h> |
| -#include <time.h> |
| -#if defined(OS_MACOSX) |
| -#include <CoreFoundation/CoreFoundation.h> |
| -#elif defined(OS_WIN) |
| -#include <shlwapi.h> // for PathMatchSpec |
| -#endif |
| - |
| #include <algorithm> |
| #include <cstring> |
| #include <functional> |
| @@ -36,7 +22,6 @@ |
| #include "base/stl_util.h" |
| #include "base/string_number_conversions.h" |
| #include "base/string_util.h" |
| -#include "base/time.h" |
| #include "base/tracked.h" |
| #include "base/utf_string_conversions.h" |
| #include "base/values.h" |
| @@ -112,25 +97,6 @@ ListValue* EntryKernelMutationMapToValue( |
| return list; |
| } |
| -int64 Now() { |
| -#if defined(OS_WIN) |
| - FILETIME filetime; |
| - SYSTEMTIME systime; |
| - GetSystemTime(&systime); |
| - SystemTimeToFileTime(&systime, &filetime); |
| - // MSDN recommends converting via memcpy like this. |
| - LARGE_INTEGER n; |
| - memcpy(&n, &filetime, sizeof(filetime)); |
| - return n.QuadPart; |
| -#elif defined(OS_POSIX) |
| - struct timeval tv; |
| - gettimeofday(&tv, NULL); |
| - return static_cast<int64>(tv.tv_sec); |
| -#else |
| -#error NEED OS SPECIFIC Now() implementation |
| -#endif |
| -} |
| - |
| namespace { |
| // A ScopedIndexUpdater temporarily removes an entry from an index, |
| @@ -277,6 +243,10 @@ StringValue* Int64ToValue(int64 i) { |
| return Value::CreateStringValue(base::Int64ToString(i)); |
| } |
| +StringValue* TimeToValue(const base::Time& t) { |
| + return Value::CreateStringValue(browser_sync::GetTimeDebugString(t)); |
| +} |
| + |
| StringValue* IdToValue(const Id& id) { |
| return id.ToValue(); |
| } |
| @@ -298,6 +268,11 @@ DictionaryValue* EntryKernel::ToValue() const { |
| &GetInt64FieldString, &Int64ToValue, |
| BASE_VERSION + 1, INT64_FIELDS_END - 1); |
| + // Time fields. |
| + SetFieldValues(*this, kernel_info, |
| + &GetTimeFieldString, &TimeToValue, |
| + TIME_FIELDS_BEGIN, TIME_FIELDS_END - 1); |
| + |
| // ID fields. |
| SetFieldValues(*this, kernel_info, |
| &GetIdFieldString, &IdToValue, |
| @@ -585,6 +560,8 @@ void ZeroFields(EntryKernel* entry, int first_field) { |
| // initialize to empty. |
| for ( ; i < INT64_FIELDS_END; ++i) |
| entry->put(static_cast<Int64Field>(i), 0); |
| + if (i < TIME_FIELDS_END) |
|
Nicolas Zea
2011/09/21 18:09:12
Any reason you don't zero out the time fields?
akalin
2011/09/21 19:37:35
ZeroFields is called immediately shortly construct
|
| + i = TIME_FIELDS_END; |
| for ( ; i < ID_FIELDS_END; ++i) |
| entry->mutable_ref(static_cast<IdField>(i)).Clear(); |
| for ( ; i < BIT_FIELDS_END; ++i) |
| @@ -1408,7 +1385,7 @@ void MutableEntry::Init(WriteTransaction* trans, const Id& parent_id, |
| kernel_->mark_dirty(trans->directory_->kernel_->dirty_metahandles); |
| kernel_->put(PARENT_ID, parent_id); |
| kernel_->put(NON_UNIQUE_NAME, name); |
| - const int64 now = Now(); |
| + const base::Time& now = base::Time::Now(); |
| kernel_->put(CTIME, now); |
| kernel_->put(MTIME, now); |
| // We match the database defaults here |
| @@ -1504,6 +1481,15 @@ bool MutableEntry::Put(Int64Field field, const int64& value) { |
| return true; |
| } |
| +bool MutableEntry::Put(TimeField field, const base::Time& value) { |
| + DCHECK(kernel_); |
| + if (kernel_->ref(field) != value) { |
| + kernel_->put(field, value); |
| + kernel_->mark_dirty(dir()->kernel_->dirty_metahandles); |
| + } |
| + return true; |
| +} |
| + |
| bool MutableEntry::Put(IdField field, const Id& value) { |
| DCHECK(kernel_); |
| if (kernel_->ref(field) != value) { |
| @@ -1876,6 +1862,11 @@ std::ostream& operator<<(std::ostream& os, const Entry& entry) { |
| os << g_metas_columns[i].name << ": " |
| << kernel->ref(static_cast<Int64Field>(i)) << ", "; |
| } |
| + for ( ; i < TIME_FIELDS_END; ++i) { |
| + os << g_metas_columns[i].name << ": " |
| + << browser_sync::GetTimeDebugString( |
| + kernel->ref(static_cast<TimeField>(i))) << ", "; |
| + } |
| for ( ; i < ID_FIELDS_END; ++i) { |
| os << g_metas_columns[i].name << ": " |
| << kernel->ref(static_cast<IdField>(i)) << ", "; |