diff options
Diffstat (limited to 'sync')
-rw-r--r-- | sync/internal_api/DEPS | 1 | ||||
-rw-r--r-- | sync/internal_api/public/util/sync_db_util.h | 30 | ||||
-rw-r--r-- | sync/internal_api/sync_db_util.cc | 38 | ||||
-rw-r--r-- | sync/protocol/DEPS | 1 | ||||
-rw-r--r-- | sync/protocol/device_info_specifics.proto | 4 | ||||
-rw-r--r-- | sync/protocol/proto_value_conversions.cc | 10 | ||||
-rw-r--r-- | sync/sync_internal_api.gypi | 2 |
7 files changed, 86 insertions, 0 deletions
diff --git a/sync/internal_api/DEPS b/sync/internal_api/DEPS index 13e6b8a..42ab18e 100644 --- a/sync/internal_api/DEPS +++ b/sync/internal_api/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+net/http", "+net/test", "+net/url_request", + "+sql", "+sync/base", "+sync/engine", "+sync/js", diff --git a/sync/internal_api/public/util/sync_db_util.h b/sync/internal_api/public/util/sync_db_util.h new file mode 100644 index 0000000..3784a10 --- /dev/null +++ b/sync/internal_api/public/util/sync_db_util.h @@ -0,0 +1,30 @@ +// Copyright 2014 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 SYNC_INTERNAL_API_PUBLIC_UTIL_SYNC_DB_UTIL_H_ +#define SYNC_INTERNAL_API_PUBLIC_UTIL_SYNC_DB_UTIL_H_ + +#include "base/callback.h" +#include "base/memory/ref_counted.h" +#include "base/time/time.h" +#include "sync/base/sync_export.h" + +namespace base { +class FilePath; +class SingleThreadTaskRunner; +} // namespace base + +namespace syncer { + +// Check integrity of sync DB under |sync_dir|. Invoke |callback| with last +// modified time if integrity check passes, with NULL time otherwise. This +// is called on either sync thread or IO thread. +SYNC_EXPORT void CheckSyncDbLastModifiedTime( + const base::FilePath& sync_dir, + scoped_refptr<base::SingleThreadTaskRunner> callback_runner, + base::Callback<void(base::Time)> callback); + +} // namesapce syncer + +#endif // SYNC_INTERNAL_API_PUBLIC_UTIL_SYNC_DB_UTIL_H_ diff --git a/sync/internal_api/sync_db_util.cc b/sync/internal_api/sync_db_util.cc new file mode 100644 index 0000000..c12889d --- /dev/null +++ b/sync/internal_api/sync_db_util.cc @@ -0,0 +1,38 @@ +// Copyright 2014 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 "sync/internal_api/public/util/sync_db_util.h" + +#include "base/files/file_path.h" +#include "base/single_thread_task_runner.h" +#include "sql/connection.h" +#include "sync/syncable/directory.h" + +namespace syncer { + +void CheckSyncDbLastModifiedTime( + const base::FilePath& sync_dir, + scoped_refptr<base::SingleThreadTaskRunner> callback_runner, + base::Callback<void(base::Time)> callback) { + const base::FilePath sync_db = + sync_dir.Append(syncable::Directory::kSyncDatabaseFilename); + + base::File f(sync_db, base::File::FLAG_OPEN | base::File::FLAG_READ); + base::File::Info info; + if (!f.IsValid() || !f.GetInfo(&info)) { + callback_runner->PostTask(FROM_HERE, base::Bind(callback, base::Time())); + return; + } + f.Close(); + + sql::Connection db; + if (!db.Open(sync_db) || !db.QuickIntegrityCheck()) { + callback_runner->PostTask(FROM_HERE, base::Bind(callback, base::Time())); + } else { + callback_runner->PostTask(FROM_HERE, + base::Bind(callback, info.last_modified)); + } +} + +} // namespace syncer diff --git a/sync/protocol/DEPS b/sync/protocol/DEPS index f8f9de5..d623db8 100644 --- a/sync/protocol/DEPS +++ b/sync/protocol/DEPS @@ -1,4 +1,5 @@ include_rules = [ "+sync/base", "+sync/internal_api/public/base", + "+sync/util", ] diff --git a/sync/protocol/device_info_specifics.proto b/sync/protocol/device_info_specifics.proto index 67eb469..f87b361 100644 --- a/sync/protocol/device_info_specifics.proto +++ b/sync/protocol/device_info_specifics.proto @@ -34,4 +34,8 @@ message DeviceInfoSpecifics { // The Chrome instance's version. Updated (if necessary) on every startup. optional string chrome_version = 5; + + // Last time when pre-sync data on the device was saved. The device can be + // restored to state back to this time. In millisecond since UNIX epoch. + optional int64 backup_timestamp = 6; } diff --git a/sync/protocol/proto_value_conversions.cc b/sync/protocol/proto_value_conversions.cc index 8e58af4..2716210 100644 --- a/sync/protocol/proto_value_conversions.cc +++ b/sync/protocol/proto_value_conversions.cc @@ -10,8 +10,10 @@ #include "base/base64.h" #include "base/basictypes.h" +#include "base/i18n/time_formatting.h" #include "base/logging.h" #include "base/strings/string_number_conversions.h" +#include "base/time/time.h" #include "base/values.h" #include "sync/internal_api/public/base/unique_position.h" #include "sync/protocol/app_list_specifics.pb.h" @@ -41,6 +43,7 @@ #include "sync/protocol/theme_specifics.pb.h" #include "sync/protocol/typed_url_specifics.pb.h" #include "sync/protocol/unique_position.pb.h" +#include "sync/util/time.h" namespace syncer { @@ -82,6 +85,11 @@ base::ListValue* MakeRepeatedValue(const F& fields, V* (*converter_fn)(T)) { return list; } +base::StringValue* MakeTimestampValue(int64 tm) { + return new base::StringValue( + base::TimeFormatShortDateAndTime(syncer::ProtoTimeToTime(tm))); +} + } // namespace // Helper macros to reduce the amount of boilerplate. @@ -102,6 +110,7 @@ base::ListValue* MakeRepeatedValue(const F& fields, V* (*converter_fn)(T)) { #define SET_INT64(field) SET(field, MakeInt64Value) #define SET_INT64_REP(field) SET_REP(field, MakeInt64Value) #define SET_STR(field) SET(field, new base::StringValue) +#define SET_TIME_STR(field) SET(field, MakeTimestampValue) #define SET_STR_REP(field) \ value->Set(#field, \ MakeRepeatedValue<const std::string&, \ @@ -489,6 +498,7 @@ base::DictionaryValue* DeviceInfoSpecificsToValue( SET_ENUM(device_type, GetDeviceTypeString); SET_STR(sync_user_agent); SET_STR(chrome_version); + SET_TIME_STR(backup_timestamp); return value; } diff --git a/sync/sync_internal_api.gypi b/sync/sync_internal_api.gypi index 1ff913f..7d92f68 100644 --- a/sync/sync_internal_api.gypi +++ b/sync/sync_internal_api.gypi @@ -135,6 +135,7 @@ 'internal_api/public/util/report_unrecoverable_error_function.h', 'internal_api/public/util/sync_string_conversions.cc', 'internal_api/public/util/sync_string_conversions.h', + 'internal_api/public/util/sync_db_util.h', 'internal_api/public/util/syncer_error.cc', 'internal_api/public/util/syncer_error.h', 'internal_api/public/util/unrecoverable_error_handler.h', @@ -152,6 +153,7 @@ 'internal_api/sync_context_proxy.cc', 'internal_api/sync_context_proxy_impl.cc', 'internal_api/sync_context_proxy_impl.h', + 'internal_api/sync_db_util.cc', 'internal_api/sync_encryption_handler_impl.cc', 'internal_api/sync_encryption_handler_impl.h', 'internal_api/sync_manager_factory.cc', |