diff options
Diffstat (limited to 'sync/internal_api')
-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 |
3 files changed, 69 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 |