diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-18 10:02:26 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-18 10:02:26 +0000 |
commit | ec3d1456bdbfd7d7806e51dd1e59088f691495ec (patch) | |
tree | 7f85308cde8eab9ffebcb4910894c184060ba15f /base | |
parent | 4236df757e45014700da962b9a20d46f61b4440f (diff) | |
download | chromium_src-ec3d1456bdbfd7d7806e51dd1e59088f691495ec.zip chromium_src-ec3d1456bdbfd7d7806e51dd1e59088f691495ec.tar.gz chromium_src-ec3d1456bdbfd7d7806e51dd1e59088f691495ec.tar.bz2 |
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
Diffstat (limited to 'base')
-rw-r--r-- | base/file_util.h | 5 | ||||
-rw-r--r-- | base/file_util_posix.cc | 10 | ||||
-rw-r--r-- | base/file_util_unittest.cc | 26 | ||||
-rw-r--r-- | base/file_util_win.cc | 12 | ||||
-rw-r--r-- | base/time.h | 10 | ||||
-rw-r--r-- | base/time_posix.cc | 10 |
6 files changed, 67 insertions, 6 deletions
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 @@ bool GetFileInfo(const FilePath& file_path, FileInfo* info); // 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 @@ bool GetFileInfo(const FilePath& file_path, FileInfo* results) { 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 @@ TEST_F(FileUtilTest, Contains) { #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/file_util_win.cc b/base/file_util_win.cc index 9265ce2..32b6811 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.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. @@ -589,6 +589,16 @@ bool GetFileInfo(const FilePath& file_path, FileInfo* results) { return true; } +bool SetLastModifiedTime(const FilePath& file_path, base::Time last_modified) { + FILETIME timestamp(last_modified.ToFileTime()); + ScopedHandle file_handle( + CreateFile(file_path.value().c_str(), FILE_WRITE_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); + BOOL ret = SetFileTime(file_handle.Get(), NULL, ×tamp, ×tamp); + return ret != 0; +} + FILE* OpenFile(const FilePath& filename, const char* mode) { std::wstring w_mode = ASCIIToWide(std::string(mode)); FILE* file; 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 @@ class Time { 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 @@ struct timespec TimeDelta::ToTimeSpec() const { 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 |