Actually delete databases in CookiesTreeModel.
BUG=34633
TEST=delete a database while it's opened in the renderer
Review URL: http://codereview.chromium.org/600104
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39346 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: ec3d1456bdbfd7d7806e51dd1e59088f691495ec
diff --git a/base/file_util.h b/base/file_util.h
index cdedfc4..a145acc 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -332,6 +332,9 @@
// Deprecated temporary compatibility function.
bool GetFileInfo(const std::wstring& file_path, FileInfo* info);
+// Set the time of the last modification. Useful for unit tests.
+bool SetLastModifiedTime(const FilePath& file_path, base::Time last_modified);
+
#if defined(OS_POSIX)
// Store inode number of |path| in |inode|. Return true on success.
bool GetInode(const FilePath& path, ino_t* inode);
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index fe24259..6e8735a 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -14,6 +14,7 @@
#include <sys/errno.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
@@ -458,6 +459,13 @@
return true;
}
+bool SetLastModifiedTime(const FilePath& file_path, base::Time last_modified) {
+ struct timeval times[2];
+ times[0] = last_modified.ToTimeVal();
+ times[1] = last_modified.ToTimeVal();
+ return (utimes(file_path.value().c_str(), times) == 0);
+}
+
bool GetInode(const FilePath& path, ino_t* inode) {
struct stat buffer;
int result = stat(path.value().c_str(), &buffer);
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 35233ba..31bb46f 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -1389,4 +1389,28 @@
#endif
}
+TEST_F(FileUtilTest, LastModified) {
+ FilePath data_dir = test_dir_.Append(FILE_PATH_LITERAL("FilePathTest"));
+
+ // Create a fresh, empty copy of this directory.
+ if (file_util::PathExists(data_dir)) {
+ ASSERT_TRUE(file_util::Delete(data_dir, true));
+ }
+ ASSERT_TRUE(file_util::CreateDirectory(data_dir));
+
+ FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt")));
+ std::string data("hello");
+ ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length()));
+
+ base::Time modification_time;
+ // Note that this timestamp is divisible by two (seconds) - FAT stores
+ // modification times with 2s resolution.
+ ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT",
+ &modification_time));
+ ASSERT_TRUE(file_util::SetLastModifiedTime(foobar, modification_time));
+ file_util::FileInfo file_info;
+ ASSERT_TRUE(file_util::GetFileInfo(foobar, &file_info));
+ ASSERT_TRUE(file_info.last_modified == modification_time);
+}
+
} // namespace
diff --git a/base/time.h b/base/time.h
index 538659d..6e9a8a4 100644
--- a/base/time.h
+++ b/base/time.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -26,6 +26,11 @@
#include "base/basictypes.h"
+#if defined(OS_POSIX)
+// For struct timeval.
+#include <sys/time.h>
+#endif
+
#if defined(OS_WIN)
// For FILETIME in FromFileTime, until it moves to a new converter class.
// See TODO(iyengar) below.
@@ -241,6 +246,9 @@
static Time FromDoubleT(double dt);
double ToDoubleT() const;
+#if defined(OS_POSIX)
+ struct timeval ToTimeVal() const;
+#endif
#if defined(OS_WIN)
static Time FromFileTime(FILETIME ft);
diff --git a/base/time_posix.cc b/base/time_posix.cc
index af7ee25..60771af 100644
--- a/base/time_posix.cc
+++ b/base/time_posix.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -190,4 +190,12 @@
return result;
}
+struct timeval Time::ToTimeVal() const {
+ struct timeval result;
+ int64 us = us_ - kTimeTToMicrosecondsOffset;
+ result.tv_sec = us / Time::kMicrosecondsPerSecond;
+ result.tv_usec = us % Time::kMicrosecondsPerSecond;
+ return result;
+}
+
} // namespace base