summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-11 02:49:05 +0000
committermrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-11 02:49:05 +0000
commitb4113d5feb3b47f5f9aaa4e7aeeacc0d95d81f36 (patch)
treee455862522cfe5a297c70edbce743e021a5769af
parent1c966c891f7f495fd08c84b58ec145bd6bd7d181 (diff)
downloadchromium_src-b4113d5feb3b47f5f9aaa4e7aeeacc0d95d81f36.zip
chromium_src-b4113d5feb3b47f5f9aaa4e7aeeacc0d95d81f36.tar.gz
chromium_src-b4113d5feb3b47f5f9aaa4e7aeeacc0d95d81f36.tar.bz2
For the immediate milestone, exclude History and Thumbnails from being backed up by Time Machine. The bug describes appropriate long-term solutions to this problem.
BUG=259595 TEST=Launch Chrome. Inspect the following files found in ~/Library/Application Support/Chromium/Default/: a) History, b) History-journal, c) Thumbnails, and d) Thumbnails-journal and verify that they are not being backed up by Time Machine. Review URL: http://codereview.chromium.org/387016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31644 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/mac_util.h3
-rw-r--r--base/mac_util.mm18
-rw-r--r--base/mac_util_unittest.mm24
-rw-r--r--chrome/browser/history/history_database.cc13
-rw-r--r--chrome/browser/history/thumbnail_database.cc12
5 files changed, 69 insertions, 1 deletions
diff --git a/base/mac_util.h b/base/mac_util.h
index a65576d..ed49e2f 100644
--- a/base/mac_util.h
+++ b/base/mac_util.h
@@ -89,6 +89,9 @@ void GrabWindowSnapshot(NSWindow* window,
// returns - path to the application bundle, or empty on error
FilePath GetAppBundlePath(const FilePath& exec_name);
+// Set the Time Machine exclusion property for the given file.
+bool SetFileBackupExclusion(const FilePath& file_path, bool exclude);
+
} // namespace mac_util
#endif // BASE_MAC_UTIL_H_
diff --git a/base/mac_util.mm b/base/mac_util.mm
index 0eee0e2..1418453 100644
--- a/base/mac_util.mm
+++ b/base/mac_util.mm
@@ -237,4 +237,22 @@ FilePath GetAppBundlePath(const FilePath& exec_name) {
return FilePath();
}
+bool SetFileBackupExclusion(const FilePath& file_path, bool exclude) {
+ NSString* filePath =
+ [NSString stringWithUTF8String:file_path.value().c_str()];
+ NSURL* url = [NSURL fileURLWithPath:filePath];
+ // Note that we always set CSBackupSetItemExcluded's excludeByPath param
+ // to true. This prevents a problem with toggling the setting: if the file
+ // is excluded with excludeByPath set to true then excludeByPath must
+ // also be true when un-excluding the file, otherwise the un-excluding
+ // will be ignored.
+ bool success =
+ CSBackupSetItemExcluded((CFURLRef)url, exclude, true) == noErr;
+ if (!success)
+ LOG(WARNING) << "Failed to set backup excluson for file '"
+ << file_path.value().c_str() << "'. Continuing.";
+ return success;
+}
+
+
} // namespace mac_util
diff --git a/base/mac_util_unittest.mm b/base/mac_util_unittest.mm
index 0abdee7..5e97356 100644
--- a/base/mac_util_unittest.mm
+++ b/base/mac_util_unittest.mm
@@ -8,6 +8,7 @@
#include "base/mac_util.h"
#include "base/file_path.h"
+#include "base/file_util.h"
#include "base/scoped_nsobject.h"
#include "base/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -101,3 +102,26 @@ TEST_F(MacUtilTest, TestGetAppBundlePath) {
out.value().c_str()) << "loop: " << i;
}
}
+
+TEST_F(MacUtilTest, TestExcludeFileFromBackups) {
+ NSString* homeDirectory = NSHomeDirectory();
+ NSString* dummyFilePath =
+ [homeDirectory stringByAppendingPathComponent:@"DummyFile"];
+ const char* dummy_file_path = [dummyFilePath fileSystemRepresentation];
+ ASSERT_TRUE(dummy_file_path);
+ FilePath file_path(dummy_file_path);
+ // It is not actually necessary to have a physical file in order to
+ // set its exclusion property.
+ NSURL* fileURL = [NSURL URLWithString:dummyFilePath];
+ // Reset the exclusion in case it was set previously.
+ mac_util::SetFileBackupExclusion(file_path, false);
+ Boolean excludeByPath;
+ // Initial state should be non-excluded.
+ EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath));
+ // Exclude the file.
+ EXPECT_TRUE(mac_util::SetFileBackupExclusion(file_path, true));
+ EXPECT_TRUE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath));
+ // Un-exclude the file.
+ EXPECT_TRUE(mac_util::SetFileBackupExclusion(file_path, false));
+ EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath));
+}
diff --git a/chrome/browser/history/history_database.cc b/chrome/browser/history/history_database.cc
index 87367a4..37296b0 100644
--- a/chrome/browser/history/history_database.cc
+++ b/chrome/browser/history/history_database.cc
@@ -7,9 +7,11 @@
#include <algorithm>
#include <set>
#include <string>
-
#include "app/sql/transaction.h"
#include "base/file_util.h"
+#if defined(OS_MACOSX)
+#include "base/mac_util.h"
+#endif
#include "base/histogram.h"
#include "base/rand_util.h"
#include "base/string_util.h"
@@ -88,6 +90,15 @@ InitStatus HistoryDatabase::Init(const FilePath& history_name,
if (!committer.Begin())
return INIT_FAILURE;
+#if defined(OS_MACOSX)
+ // Exclude the history file and its journal from backups.
+ mac_util::SetFileBackupExclusion(history_name, true);
+ FilePath::StringType history_name_string(history_name.value());
+ history_name_string += "-journal";
+ FilePath history_journal_name(history_name_string);
+ mac_util::SetFileBackupExclusion(history_journal_name, true);
+#endif
+
// Prime the cache.
db_.Preload();
diff --git a/chrome/browser/history/thumbnail_database.cc b/chrome/browser/history/thumbnail_database.cc
index 96aebf7..8ce38da 100644
--- a/chrome/browser/history/thumbnail_database.cc
+++ b/chrome/browser/history/thumbnail_database.cc
@@ -8,6 +8,9 @@
#include "app/sql/statement.h"
#include "app/sql/transaction.h"
#include "base/file_util.h"
+#if defined(OS_MACOSX)
+#include "base/mac_util.h"
+#endif
#include "base/time.h"
#include "base/string_util.h"
#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
@@ -63,6 +66,15 @@ InitStatus ThumbnailDatabase::Init(const FilePath& db_name,
sql::Transaction transaction(&db_);
transaction.Begin();
+#if defined(OS_MACOSX)
+ // Exclude the thumbnails file and its journal from backups.
+ mac_util::SetFileBackupExclusion(db_name, true);
+ FilePath::StringType db_name_string(db_name.value());
+ db_name_string += "-journal";
+ FilePath db_journal_name(db_name_string);
+ mac_util::SetFileBackupExclusion(db_journal_name, true);
+#endif
+
// Create the tables.
if (!meta_table_.Init(&db_, kCurrentVersionNumber,
kCompatibleVersionNumber) ||