Index: webkit/browser/fileapi/sandbox_isolated_origin_database.cc |
diff --git a/webkit/browser/fileapi/sandbox_isolated_origin_database.cc b/webkit/browser/fileapi/sandbox_isolated_origin_database.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..17b365da24c8672fe0580aeac0fe611163649277 |
--- /dev/null |
+++ b/webkit/browser/fileapi/sandbox_isolated_origin_database.cc |
@@ -0,0 +1,82 @@ |
+// Copyright 2013 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 "webkit/browser/fileapi/sandbox_isolated_origin_database.h" |
+ |
+#include "base/file_util.h" |
+#include "base/logging.h" |
+#include "webkit/browser/fileapi/sandbox_origin_database.h" |
+ |
+namespace fileapi { |
+ |
+// Special directory name for isolated origin. |
+const base::FilePath::CharType kOriginDirectory[] = FILE_PATH_LITERAL("iso"); |
+ |
+SandboxIsolatedOriginDatabase::SandboxIsolatedOriginDatabase( |
+ const std::string& origin, |
+ const base::FilePath& file_system_directory) |
+ : migration_checked_(false), |
+ origin_(origin), |
+ file_system_directory_(file_system_directory) { |
+} |
+ |
+SandboxIsolatedOriginDatabase::~SandboxIsolatedOriginDatabase() { |
+} |
+ |
+bool SandboxIsolatedOriginDatabase::HasOriginPath( |
+ const std::string& origin) { |
+ MigrateDatabaseIfNeeded(); |
+ return (origin_ == origin); |
+} |
+ |
+bool SandboxIsolatedOriginDatabase::GetPathForOrigin( |
+ const std::string& origin, base::FilePath* directory) { |
+ MigrateDatabaseIfNeeded(); |
+ if (origin != origin_) |
+ return false; |
+ *directory = base::FilePath(kOriginDirectory); |
+ return true; |
+} |
+ |
+bool SandboxIsolatedOriginDatabase::RemovePathForOrigin( |
+ const std::string& origin) { |
+ return true; |
+} |
+ |
+bool SandboxIsolatedOriginDatabase::ListAllOrigins( |
+ std::vector<OriginRecord>* origins) { |
+ MigrateDatabaseIfNeeded(); |
+ origins->push_back(OriginRecord(origin_, base::FilePath(kOriginDirectory))); |
+ return true; |
+} |
+ |
+void SandboxIsolatedOriginDatabase::DropDatabase() { |
+} |
+ |
+void SandboxIsolatedOriginDatabase::MigrateDatabaseIfNeeded() { |
+ if (migration_checked_) |
+ return; |
+ |
+ migration_checked_ = true; |
+ // See if we have non-isolated version of sandbox database. |
+ scoped_ptr<SandboxOriginDatabase> database( |
+ new SandboxOriginDatabase(file_system_directory_)); |
+ if (!database->HasOriginPath(origin_)) |
+ return; |
+ |
+ base::FilePath directory_name; |
+ if (database->GetPathForOrigin(origin_, &directory_name) && |
+ directory_name != base::FilePath(kOriginDirectory)) { |
+ base::FilePath from_path = file_system_directory_.Append(directory_name); |
+ base::FilePath to_path = file_system_directory_.Append(kOriginDirectory); |
+ |
+ if (file_util::PathExists(to_path)) |
+ file_util::Delete(to_path, true /* recursive */); |
+ file_util::Move(from_path, to_path); |
+ } |
+ |
+ database->RemoveDatabase(); |
+} |
+ |
+} // namespace fileapi |